LoginSignup
10
2

More than 3 years have passed since last update.

rqt_graph をかわいくする(?)

Last updated at Posted at 2019-12-14

TL;DR

ROSにはかわいさが足りない。
rqt_graphで使われているフォントを変更してかわいくします。

フォントはどこで設定されているのか?

rqt_graphをはじめとして、ROS上のグラフ構造をdot言語を介してqtのGUI上に表現する処理は、qt_gui_coreメタパッケージ(https://github.com/ros-visualization/qt_gui_core) 内のqt_dotgraphパッケージ(https://github.com/ros-visualization/qt_gui_core/tree/kinetic-devel/qt_dotgraph) にまとめられています。

その中で、フォントは、GraphItemクラスにクラス変数_LABEL_FONTとして設定されています。このクラスではフォントと線の色が設定されています。

graph_item.py
class GraphItem(QGraphicsItemGroup):

    _COLOR_BLACK = QColor(0, 0, 0)
    _COLOR_BLUE = QColor(0, 0, 204)
    _COLOR_GREEN = QColor(0, 170, 0)
    _COLOR_ORANGE = QColor(255, 165, 0)
    _COLOR_RED = QColor(255, 0, 0)
    _COLOR_TEAL = QColor(0, 170, 170)

    _LABEL_FONT = QFont('sans', weight=QFont.Light)

    def __init__(self, highlight_level, parent=None):
        super(GraphItem, self).__init__(parent)
        self._highlight_level = highlight_level
        # use device depended font size to produce
        GraphItem._LABEL_FONT.setPixelSize(11)

(qt_dotgraphパッケージ graph_item.pyより)

フォントを変えてみよう

さて、いよいよフォントを変えてrqt_graphをかわいくします。今回はふい字を使います。まずはフォントをインストールしましょう。

# フォントをダウンロードして解凍
sudo apt install lhasa
wget http://marie.saiin.net/~huiko/huifonts/HuiFont109.lzh
lha x FuiFont109.lzh

# Ubuntuでは~/.fonts以下にフォントファイルを保存するとインストールできる
mkdir ~/.fonts
cp FuiFonts109.ttf ~/.fonts
fc-cache -fv

# インストール結果
fc-list | grep Hui
/home/user/.fonts/HuiFont29.ttf: ふい字,HuiFont:style=Regular

qt_dotgraphパッケージも用意しましょう

cd ~/catkin_ws/src
git clone https://github.com/ros-visualization/qt_gui_core
catkin build qt_gui_core

ソースコードはgraph_item.pyの44行目を以下のように変更します

qt_gui_core/qt_dotgraph/src/graph_item.py
_LABEL_FONT = QFont('HuiFont', weight=QFont.Light)

ここまで来たら準備完了です。適当なノードを立ち上げてrqt_graphを見てみましょう。
rqt_graph.png

かわいいですね!かわいい気がします!
qt_dotgraphrqt_graph以外にもrqt_tf_treeにも使われています。試してみましょう。
tf.png
めちゃくちゃ読みにくいけどかわいくなった気がします!やったぜ!

まとめ

今回はqt_dotgraphパッケージのコードを書き換えてrqt_graphrqt_tf_treeに使われているフォントを変更しました。
今回の結果がかわいいかはさておき、皆さんもお気に入りのフォントを設定して自分だけのrqt_graphを楽しんでください。

10
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
2