Skip to content

Commit

Permalink
sub graph tab bar improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
jchanvfx committed May 4, 2023
1 parent 742f5db commit e3d4523
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
18 changes: 17 additions & 1 deletion NodeGraphQt/nodes/group_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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(
Expand Down
15 changes: 12 additions & 3 deletions NodeGraphQt/widgets/viewer_nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit e3d4523

Please sign in to comment.