Skip to content
Merged
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
2 changes: 1 addition & 1 deletion resource/RosTfTree.ui
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
<item>
<widget class="InteractiveGraphicsView" name="graphics_view">
<property name="renderHints">
<set>QPainter::Antialiasing|QPainter::HighQualityAntialiasing|QPainter::SmoothPixmapTransform|QPainter::TextAntialiasing</set>
<set>QPainter::Antialiasing|QPainter::SmoothPixmapTransform|QPainter::TextAntialiasing</set>
</property>
<property name="resizeAnchor">
<enum>QGraphicsView::AnchorViewCenter</enum>
Expand Down
16 changes: 10 additions & 6 deletions src/rqt_tf_tree/dotcode_tf.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,16 @@ def generate_dotcode(self,

yaml_data = tf2_frame_srv.call(FrameGraph.Request()).frame_yaml

def default_tftree_construct_mapping(self, node, deep=False):
data = self.construct_mapping_org(node, deep)
return {(str(key) if isinstance(key, int) else key): data[key] for key in data}

yaml.SafeLoader.construct_mapping_org = yaml.SafeLoader.construct_mapping
yaml.SafeLoader.construct_mapping = default_tftree_construct_mapping
# Patch SafeLoader.construct_mapping only once. Re-patching would
# save the already-patched function as construct_mapping_org,
# causing it to call itself recursively (RecursionError).
if not hasattr(yaml.SafeLoader, 'construct_mapping_org'):
def default_tftree_construct_mapping(self, node, deep=False):
data = self.construct_mapping_org(node, deep)
return {(str(key) if isinstance(key, int) else key): data[key] for key in data}

yaml.SafeLoader.construct_mapping_org = yaml.SafeLoader.construct_mapping
yaml.SafeLoader.construct_mapping = default_tftree_construct_mapping

data = yaml_parser.safe_load(yaml_data)
self.graph = self.generate(data, timer.now().nanoseconds / S_TO_NS)
Expand Down
24 changes: 15 additions & 9 deletions src/rqt_tf_tree/tf_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __init__(self, context):
self._widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % context.serial_number()))

self._scene = QGraphicsScene()
self._scene.setBackgroundBrush(Qt.white)
self._scene.setBackgroundBrush(Qt.GlobalColor.white)
self._widget.graphics_view.setScene(self._scene)

self._widget.clear_buffer_push_button.setIcon(QIcon.fromTheme('edit-delete'))
Expand All @@ -96,7 +96,10 @@ def __init__(self, context):

self._widget.highlight_connections_check_box.toggled.connect(self._redraw_graph_view)
self._widget.auto_fit_graph_check_box.toggled.connect(self._redraw_graph_view)
self._widget.fit_in_view_push_button.setIcon(QIcon.fromTheme('zoom-original'))
# 'zoom-fit-best' is the freedesktop standard name; fall back to the
# legacy 'zoom-best-fit' for themes (e.g. ubuntu-mono-*) that lack it.
self._widget.fit_in_view_push_button.setIcon(
QIcon.fromTheme('zoom-fit-best', QIcon.fromTheme('zoom-best-fit')))
self._widget.fit_in_view_push_button.pressed.connect(self._fit_in_view)

self._widget.load_dot_push_button.setIcon(QIcon.fromTheme('document-open'))
Expand All @@ -109,7 +112,7 @@ def __init__(self, context):
self._widget.save_as_image_push_button.pressed.connect(self._save_image)

self._deferred_fit_in_view.connect(self._fit_in_view,
Qt.QueuedConnection)
Qt.ConnectionType.QueuedConnection)
self._deferred_fit_in_view.emit()

context.add_widget(self._widget)
Expand Down Expand Up @@ -206,7 +209,7 @@ def _load_dot(self, file_name=None):

def _fit_in_view(self):
self._widget.graphics_view.fitInView(self._scene.itemsBoundingRect(),
Qt.KeepAspectRatio)
Qt.AspectRatioMode.KeepAspectRatio)

def _save_dot(self):
file_name, _ = QFileDialog.getSaveFileName(self._widget,
Expand All @@ -217,10 +220,13 @@ def _save_dot(self):
return

file = QFile(file_name)
if not file.open(QIODevice.WriteOnly | QIODevice.Text):
if not file.open(QIODevice.OpenModeFlag.WriteOnly | QIODevice.OpenModeFlag.Text):
return

file.write(self._current_dotcode)
dotcode = self._current_dotcode
if isinstance(dotcode, str):
dotcode = dotcode.encode()
file.write(dotcode)
file.close()

def _save_svg(self):
Expand All @@ -237,7 +243,7 @@ def _save_svg(self):
generator.setSize((self._scene.sceneRect().size() * 2.0).toSize())

painter = QPainter(generator)
painter.setRenderHint(QPainter.Antialiasing)
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
self._scene.render(painter)
painter.end()

Expand All @@ -251,9 +257,9 @@ def _save_image(self):
return

img = QImage((self._scene.sceneRect().size() * 2.0).toSize(),
QImage.Format_ARGB32_Premultiplied)
QImage.Format.Format_ARGB32_Premultiplied)
painter = QPainter(img)
painter.setRenderHint(QPainter.Antialiasing)
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
self._scene.render(painter)
painter.end()
img.save(file_name)
Loading