Skip to content

Commit

Permalink
Merge pull request #3175 from robertcv/fixes/empty_report
Browse files Browse the repository at this point in the history
[FIX] OWReport: disable save and print on empty report
  • Loading branch information
ajdapretnar authored Aug 3, 2018
2 parents 410e45c + 77cf859 commit 8a40309
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Orange/widgets/report/owreport.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ def _setup_ui_(self):
box = gui.hBox(self.controlArea)
box.setContentsMargins(-6, 0, -6, 0)
self.save_button = gui.button(
box, self, "Save", callback=self.save_report
box, self, "Save", callback=self.save_report, disabled=True
)
self.print_button = gui.button(
box, self, "Print", callback=self._print_report
box, self, "Print", callback=self._print_report, disabled=True
)

class PyBridge(QObject):
Expand Down Expand Up @@ -232,11 +232,13 @@ def _table_selection_changed(self, new_selection, _):

def _remove_item(self, row):
self.table_model.removeRow(row)
self._empty_report()
self.report_changed = True
self._build_html()

def clear(self):
self.table_model.clear()
self._empty_report()
self.report_changed = True
self._build_html()

Expand All @@ -246,9 +248,15 @@ def _add_item(self, widget):
item = ReportItem(name, widget.report_html, self._get_scheme(),
widget.__module__, widget.icon)
self.table_model.add_item(item)
self._empty_report()
self.report_changed = True
return item

def _empty_report(self):
# disable save and print if no reports
self.save_button.setEnabled(self.table_model.rowCount())
self.print_button.setEnabled(self.table_model.rowCount())

def _build_html(self):
html = self.report_html_template
html += "<body>"
Expand Down
18 changes: 18 additions & 0 deletions Orange/widgets/report/tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from Orange.widgets.tests.base import WidgetTest
from Orange.widgets.visualize.owtreeviewer import OWTreeGraph
from Orange.widgets.data.owfile import OWFile
from Orange.widgets.data.owtable import OWDataTable
from Orange.widgets.evaluate.owcalibrationplot import OWCalibrationPlot
from Orange.widgets.evaluate.owliftcurve import OWLiftCurve
from Orange.widgets.evaluate.owrocanalysis import OWROCAnalysis
Expand Down Expand Up @@ -240,6 +241,23 @@ def test_report_widgets_all(self):
self.spec_widgets
self._create_report(widgets, rep, None)

def test_disable_saving_empty(self):
"""Test if save and print buttons are disabled on empty report"""
rep = OWReport.get_instance()
self.assertFalse(rep.save_button.isEnabled())
self.assertFalse(rep.print_button.isEnabled())

table = OWDataTable()
table.set_dataset(Table("iris"))
table.create_report_html()
rep.make_report(table)
self.assertTrue(rep.save_button.isEnabled())
self.assertTrue(rep.print_button.isEnabled())

rep.clear()
self.assertFalse(rep.save_button.isEnabled())
self.assertFalse(rep.print_button.isEnabled())


if __name__ == "__main__":
unittest.main()

0 comments on commit 8a40309

Please sign in to comment.