Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] OWReport: disable save and print on empty report #3175

Merged
merged 2 commits into from
Aug 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()