Skip to content

Commit 829326f

Browse files
committed
optimized proxy mode code
1 parent d9e84b7 commit 829326f

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

NodeGraphQt/qgraphics/node_base.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __init__(self, name='node', parent=None):
3838
self._x_item = XDisabledItem(self, 'DISABLED')
3939
self._input_items = OrderedDict()
4040
self._output_items = OrderedDict()
41-
self._widgets = {}
41+
self._widgets = OrderedDict()
4242
self._proxy_mode = False
4343
self._proxy_mode_threshold = 70
4444

@@ -439,12 +439,16 @@ def post_init(self, viewer=None, pos=None):
439439
def auto_switch_mode(self):
440440
"""
441441
Decide whether to draw the node with proxy mode.
442+
(this is called at the start in the "self.paint()" function.)
442443
"""
443444
if ITEM_CACHE_MODE is QtWidgets.QGraphicsItem.ItemCoordinateCache:
444445
return
446+
445447
rect = self.sceneBoundingRect()
446-
l = self.viewer().mapToGlobal(self.viewer().mapFromScene(rect.topLeft()))
447-
r = self.viewer().mapToGlobal(self.viewer().mapFromScene(rect.topRight()))
448+
l = self.viewer().mapToGlobal(
449+
self.viewer().mapFromScene(rect.topLeft()))
450+
r = self.viewer().mapToGlobal(
451+
self.viewer().mapFromScene(rect.topRight()))
448452
# width is the node width in screen
449453
width = r.x() - l.x()
450454

@@ -453,27 +457,29 @@ def auto_switch_mode(self):
453457
def set_proxy_mode(self, mode):
454458
"""
455459
Set whether to draw the node with proxy mode.
460+
(proxy mode toggles visibility for some qgraphic items in the node.)
456461
457462
Args:
458-
mode (bool).
463+
mode (bool): true to enable proxy mode.
459464
"""
460465
if mode is self._proxy_mode:
461466
return
462-
463467
self._proxy_mode = mode
464468

465469
visible = not mode
466470

471+
# node widget visibility
467472
for w in self._widgets.values():
468473
w.widget().setVisible(visible)
474+
475+
# input port text visibility.
469476
for port, text in self._input_items.items():
470-
port.setVisible(visible)
471-
if text.visible_:
477+
if port.display_name:
472478
text.setVisible(visible)
473479

480+
# output port text visibility.
474481
for port, text in self._output_items.items():
475-
port.setVisible(visible)
476-
if text.visible_:
482+
if port.display_name:
477483
text.setVisible(visible)
478484

479485
self._text_item.setVisible(visible)
@@ -587,7 +593,6 @@ def _add_port(self, port):
587593
text.font().setPointSize(8)
588594
text.setFont(text.font())
589595
text.setVisible(port.display_name)
590-
text.visible_ = port.display_name
591596
text.setCacheMode(ITEM_CACHE_MODE)
592597
if port.port_type == IN_PORT:
593598
self._input_items[port] = text

0 commit comments

Comments
 (0)