diff --git a/resource/RosTfTree.ui b/resource/RosTfTree.ui index 27f197e..52628b4 100644 --- a/resource/RosTfTree.ui +++ b/resource/RosTfTree.ui @@ -171,7 +171,7 @@ - QPainter::Antialiasing|QPainter::HighQualityAntialiasing|QPainter::SmoothPixmapTransform|QPainter::TextAntialiasing + QPainter::Antialiasing|QPainter::SmoothPixmapTransform|QPainter::TextAntialiasing QGraphicsView::AnchorViewCenter diff --git a/src/rqt_tf_tree/dotcode_tf.py b/src/rqt_tf_tree/dotcode_tf.py index 878f2e0..6a69b17 100644 --- a/src/rqt_tf_tree/dotcode_tf.py +++ b/src/rqt_tf_tree/dotcode_tf.py @@ -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) diff --git a/src/rqt_tf_tree/tf_tree.py b/src/rqt_tf_tree/tf_tree.py index a2ee7fe..7809b36 100644 --- a/src/rqt_tf_tree/tf_tree.py +++ b/src/rqt_tf_tree/tf_tree.py @@ -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')) @@ -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')) @@ -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) @@ -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, @@ -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): @@ -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() @@ -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)