From e3d452357b2ca54f14aaeb3f87f88aa88d35280a Mon Sep 17 00:00:00 2001 From: jchanvfx Date: Thu, 4 May 2023 22:15:30 +1200 Subject: [PATCH] sub graph tab bar improvements. --- NodeGraphQt/nodes/group_node.py | 18 +++++++++++++++++- NodeGraphQt/widgets/viewer_nav.py | 15 ++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/NodeGraphQt/nodes/group_node.py b/NodeGraphQt/nodes/group_node.py index 9bc967f9..ecbc47ad 100644 --- a/NodeGraphQt/nodes/group_node.py +++ b/NodeGraphQt/nodes/group_node.py @@ -44,7 +44,7 @@ def get_sub_graph(self): or returns None. Returns: - SubGraph or None: sub graph controller. + SubGraph: sub graph controller. """ return self.graph.sub_graphs.get(self.id) @@ -91,6 +91,22 @@ def collapse(self): """ self.graph.collapse_group_node(self) + def set_name(self, name=''): + super(GroupNode, self).set_name(name) + # update the tab bar and navigation labels. + sub_graph = self.get_sub_graph() + if sub_graph: + nav_widget = sub_graph.navigation_widget + nav_widget.update_label_item(self.name(), self.id) + + if sub_graph.parent_graph.is_root: + root_graph = sub_graph.parent_graph + tab_bar = root_graph.widget.tabBar() + for idx in range(tab_bar.count()): + if tab_bar.tabToolTip(idx) == self.id: + tab_bar.setTabText(idx, self.name()) + break + def add_input(self, name='input', multi_input=False, display_name=True, color=None, locked=False, painter_func=None): port = super(GroupNode, self).add_input( diff --git a/NodeGraphQt/widgets/viewer_nav.py b/NodeGraphQt/widgets/viewer_nav.py index b58802e6..ef809e71 100644 --- a/NodeGraphQt/widgets/viewer_nav.py +++ b/NodeGraphQt/widgets/viewer_nav.py @@ -87,7 +87,8 @@ def paint(self, painter, option, index): text_rect = QtCore.QRectF( rect.center().x() - (font_width / 2) + txt_offset, rect.center().y() - (font_height / 2), - font_width, font_height) + font_width, font_height + ) painter.drawText(text_rect, item.text()) painter.restore() @@ -144,15 +145,23 @@ def add_label_item(self, label, node_id): item.setToolTip(node_id) metrics = QtGui.QFontMetrics(item.font()) if hasattr(metrics, 'horizontalAdvance'): - width = metrics.horizontalAdvance(item.text()) + 30 + width = metrics.horizontalAdvance(item.text()) else: - width = metrics.width(item.text()) + 30 + width = metrics.width(item.text()) + width *= 1.5 item.setSizeHint(QtCore.QSize(width, 20)) self.model().appendRow(item) self.selectionModel().setCurrentIndex( self.model().indexFromItem(item), QtCore.QItemSelectionModel.ClearAndSelect) + def update_label_item(self, label, node_id): + rows = reversed(range(self.model().rowCount())) + for r in rows: + item = self.model().item(r, 0) + if item.toolTip() == node_id: + item.setText(label) + def remove_label_item(self, node_id): rows = reversed(range(1, self.model().rowCount())) node_ids = [self.model().item(r, 0).toolTip() for r in rows]