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

[RFC][ENH] OWWidget: Input/output summary #2556

Merged
merged 18 commits into from
Nov 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
4 changes: 4 additions & 0 deletions Orange/widgets/icons/input-empty.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions Orange/widgets/icons/input-partial.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions Orange/widgets/icons/input.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions Orange/widgets/icons/output-empty.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions Orange/widgets/icons/output-partial.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions Orange/widgets/icons/output.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
102 changes: 102 additions & 0 deletions Orange/widgets/tests/test_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from Orange.widgets.settings import Setting
from Orange.widgets.tests.base import WidgetTest
from Orange.widgets.widget import OWWidget, Msg
from Orange.widgets.utils.messagewidget import MessagesWidget


class DummyComponent(OWComponent):
Expand Down Expand Up @@ -150,6 +151,46 @@ def test_garbage_collect_from_scheme(self):
self.assertTrue(len(spyf) == 1 or spyf.wait(1000))
self.assertIsNone(ref())

def _status_bar_visible_test(self, widget):
# type: (OWWidget) -> None
# Test that statusBar().setVisible collapses/expands the bottom margins
sb = widget.statusBar()
m1 = widget.contentsMargins().bottom()
sb.setVisible(False)
m2 = widget.contentsMargins().bottom()
self.assertLess(m2, m1)
self.assertEqual(m2, 0)
sb.setVisible(True)
m3 = widget.contentsMargins().bottom()
self.assertEqual(sb.height(), m3)
self.assertNotEqual(m3, 0)

def test_status_bar(self):
# Test that statusBar().setVisible collapses/expands the bottom margins
w = MyWidget()
self._status_bar_visible_test(w)
# run through drawing code (for coverage)
w.statusBar().grab()

def test_status_bar_no_basic_layout(self):
# Test that statusBar() works when widget defines
# want_basic_layout=False
with patch.object(MyWidget, "want_basic_layout", False):
w = MyWidget()
self._status_bar_visible_test(w)

def test_status_bar_action(self):
w = MyWidget()
action = w.findChild(QAction, "action-show-status-bar") # type: QAction
self.assertIsNotNone(action)
action.setEnabled(True)
action.setChecked(True)
self.assertTrue(w.statusBar().isVisibleTo(w))
action.setChecked(False)
self.assertFalse(w.statusBar().isVisibleTo(w))
w.statusBar().hide()
self.assertFalse(action.isChecked())


class WidgetMsgTestCase(WidgetTest):

Expand Down Expand Up @@ -269,3 +310,64 @@ def __init__(self, obj):
self.__mapper = DestroyedSignalSpy.Mapper()
obj.destroyed.connect(self.__mapper.destroyed_)
super().__init__(self.__mapper.destroyed_)


class WidgetTestInfoSummary(WidgetTest):
def test_info_set_warn(self):
test = self

class TestW(OWWidget):
name = "a"
def __init__(self):
super().__init__()
with test.assertWarns(DeprecationWarning):
self.info = 4
TestW()

def test_io_summaries(self):
w = MyWidget()
info = w.info # type: StateInfo
inmsg = w.findChild(MessagesWidget, "input-summary") # type: MessagesWidget
outmsg = w.findChild(MessagesWidget, "output-summary") # type: MessagesWidget
self.assertEqual(len(inmsg.messages()), 0)
self.assertEqual(len(outmsg.messages()), 0)

w.info.set_input_summary(w.info.NoInput)
w.info.set_output_summary(w.info.NoOutput)

self.assertEqual(len(inmsg.messages()), 1)
self.assertFalse(inmsg.summarize().isEmpty())
self.assertEqual(len(outmsg.messages()), 1)
self.assertFalse(outmsg.summarize().isEmpty())

info.set_input_summary("Foo")

self.assertEqual(len(inmsg.messages()), 1)
self.assertEqual(inmsg.summarize().text, "Foo")
self.assertFalse(inmsg.summarize().icon.isNull())

info.set_input_summary("Foo", "A foo that bars",)

info.set_input_summary(None)
info.set_output_summary(None)

self.assertTrue(inmsg.summarize().isEmpty())
self.assertTrue(outmsg.summarize().isEmpty())

info.set_output_summary("Foobar", "42")

self.assertEqual(len(outmsg.messages()), 1)
self.assertEqual(outmsg.summarize().text, "Foobar")
self.assertFalse(outmsg.summarize().icon.isNull())

with self.assertRaises(TypeError):
info.set_input_summary(None, "a")

with self.assertRaises(TypeError):
info.set_input_summary(info.NoInput, "a")

with self.assertRaises(TypeError):
info.set_output_summary(None, "a")

with self.assertRaises(TypeError):
info.set_output_summary(info.NoOutput, "a")
1 change: 1 addition & 0 deletions Orange/widgets/utils/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ def msg(m):
self.message_bar.clear()
if messages:
self.message_bar.setMessages((m, msg(m)) for m in messages)
self.message_bar.setVisible(bool(messages))

def insert_message_bar(self):
"""Insert message bar into the widget.
Expand Down
Loading