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

Signal manager: Add a tooltip about mismatching types #324

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions i18n/si/msgs.jaml
Original file line number Diff line number Diff line change
Expand Up @@ -1290,13 +1290,11 @@ application/utils/addons.py:
install: false
--yes: false
--quiet: false
--satisfied-skip-solve: false
def `upgrade`:
={}: false
install: false
--yes: false
--quiet: false
--satisfied-skip-solve: false
def `uninstall`:
uninstall: false
--yes: false
Expand Down Expand Up @@ -1458,6 +1456,8 @@ canvas/items/linkitem.py:
def `__updateText`:
<nobr>{0}</nobr> \u2192 <nobr>{1}</nobr>: false
'<div align="center" style="font-size: small" >{0}</div>': false
def `__update_tooltip`:
{self.sourceItem.title()} is not providing the proper data type required by {self.sinkItem.title()}: {self.sourceItem.title()} ni priskrbel pravilnega podatkovnega tipa za {self.sinkItem.title()}
def `__updatePen`:
'#9CACB4': false
'#959595': false
Expand Down
15 changes: 14 additions & 1 deletion orangecanvas/canvas/items/linkitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ def setSourceItem(self, item, signal=None, anchor=None):
self.sourceItem.removeOutputAnchor(self.sourceAnchor)
self.sourceItem.selectedChanged.disconnect(
self.__updateSelectedState)
self.sourceItem.titleEditingFinished.disconnect(
self.__update_tooltip)
self.sourceItem = self.sourceAnchor = None

self.sourceItem = item
Expand All @@ -320,6 +322,7 @@ def setSourceItem(self, item, signal=None, anchor=None):
anchor = item.newOutputAnchor(signal)
if item is not None:
item.selectedChanged.connect(self.__updateSelectedState)
item.titleEditingFinished.connect(self.__update_tooltip)

if anchor != self.sourceAnchor:
if self.sourceAnchor is not None:
Expand Down Expand Up @@ -356,11 +359,13 @@ def setSinkItem(self, item, signal=None, anchor=None):
self.sinkAnchor.scenePositionChanged.disconnect(
self._sinkPosChanged
)

if self.sinkItem is not None:
self.sinkItem.removeInputAnchor(self.sinkAnchor)
self.sinkItem.selectedChanged.disconnect(
self.__updateSelectedState)
self.sinkItem.titleEditingFinished.disconnect(
self.__update_tooltip
)
self.sinkItem = self.sinkAnchor = None

self.sinkItem = item
Expand All @@ -370,6 +375,7 @@ def setSinkItem(self, item, signal=None, anchor=None):
anchor = item.newInputAnchor(signal)
if item is not None:
item.selectedChanged.connect(self.__updateSelectedState)
item.titleEditingFinished.connect(self.__update_tooltip)

if self.sinkAnchor != anchor:
if self.sinkAnchor is not None:
Expand Down Expand Up @@ -670,6 +676,13 @@ def setDynamicEnabled(self, enabled):
self.__dynamicEnabled = enabled
if self.__dynamic:
self.__updatePen()
self.__update_tooltip()

def __update_tooltip(self):
if self.__dynamicEnabled:
self.curveItem.setToolTip(None)
else:
self.curveItem.setToolTip(f"{self.sourceItem.title()} is not providing the proper data type required by {self.sinkItem.title()}")

def isDynamicEnabled(self):
# type: () -> bool
Expand Down
51 changes: 37 additions & 14 deletions orangecanvas/canvas/items/tests/test_linkitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,39 @@


class TestLinkItem(TestItems):
def test_linkitem(self):
def setUp(self):
super().setUp()

reg = small_testing_registry()

const_desc = reg.category("Constants")

one_desc = reg.widget("one")

one_item = NodeItem()
self.one_item = one_item = NodeItem()
one_item.setWidgetDescription(one_desc)
one_item.setWidgetCategory(const_desc)
one_item.setPos(0, 100)

negate_desc = reg.widget("negate")

negate_item = NodeItem()
self.negate_item = negate_item = NodeItem()
negate_item.setWidgetDescription(negate_desc)
negate_item.setWidgetCategory(const_desc)
negate_item.setPos(200, 100)
operator_desc = reg.category("Operators")

add_desc = reg.widget("add")

nb_item = NodeItem()
self.nb_item = nb_item = NodeItem()
nb_item.setWidgetDescription(add_desc)
nb_item.setWidgetCategory(operator_desc)

def test_linkitem(self):
one_item = self.one_item
negate_item = self.negate_item
nb_item = self.nb_item

one_item.setPos(0, 100)
negate_item.setPos(200, 100)
nb_item.setPos(400, 100)

self.scene.addItem(one_item)
Expand Down Expand Up @@ -92,15 +100,15 @@ def test_linkitem(self):

def test_dynamic_link(self):
link = LinkItem()
anchor1 = AnchorPoint()
anchor2 = AnchorPoint()
anchor1 = self.one_item.newOutputAnchor()
anchor2 = self.nb_item.newInputAnchor()

self.scene.addItem(link)
self.scene.addItem(anchor1)
self.scene.addItem(anchor2)

link.setSourceItem(None, anchor=anchor1)
link.setSinkItem(None, anchor=anchor2)
link.setSourceItem(self.one_item, anchor=anchor1)
link.setSinkItem(self.nb_item, anchor=anchor2)

anchor2.setPos(100, 100)

Expand All @@ -112,6 +120,21 @@ def test_dynamic_link(self):

link.setDynamicEnabled(True)
self.assertTrue(link.isDynamicEnabled())
self.assertEqual(link.curveItem.toolTip(), "")

link.setDynamicEnabled(False)
self.assertIn("one", link.curveItem.toolTip())
self.assertIn("add", link.curveItem.toolTip())

self.one_item.setTitle("new name for source")
self.one_item.titleEditingFinished.emit()
self.assertIn("new name for source", link.curveItem.toolTip())
self.assertIn("add", link.curveItem.toolTip())

self.nb_item.setTitle("new name for sink")
self.nb_item.titleEditingFinished.emit()
self.assertIn("new name for source", link.curveItem.toolTip())
self.assertIn("new name for sink", link.curveItem.toolTip())

def advance():
clock = time.process_time()
Expand All @@ -126,12 +149,12 @@ def advance():

def test_link_enabled(self):
link = LinkItem()
anchor1 = AnchorPoint()
anchor2 = AnchorPoint()
anchor1 = self.one_item.newOutputAnchor()
anchor2 = self.nb_item.newInputAnchor()
anchor2.setPos(100, 100)

link.setSourceItem(None, anchor=anchor1)
link.setSinkItem(None, anchor=anchor2)
link.setSourceItem(self.one_item, anchor=anchor1)
link.setSinkItem(self.nb_item, anchor=anchor2)

link.setEnabled(False)
self.assertFalse(link.isEnabled())
Expand Down
Loading