diff --git a/Orange/widgets/report/owreport.py b/Orange/widgets/report/owreport.py index 2761cc232bb..b2ff4dc5ab6 100644 --- a/Orange/widgets/report/owreport.py +++ b/Orange/widgets/report/owreport.py @@ -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): @@ -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() @@ -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 += "" diff --git a/Orange/widgets/report/tests/test_report.py b/Orange/widgets/report/tests/test_report.py index f071b59e7db..a56f0ddcfa6 100644 --- a/Orange/widgets/report/tests/test_report.py +++ b/Orange/widgets/report/tests/test_report.py @@ -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 @@ -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()