ros-visualization / rqt_graph

http://wiki.ros.org/rqt_graph
26 stars 27 forks source link

TypeError Exception in saving dot file #90

Open keivanzavari opened 11 months ago

keivanzavari commented 11 months ago

I am running rqt_graph on Noetic and noticed that storing the graph as a dot file throws an exception:

Traceback (most recent call last):
  File "/opt/ros/noetic/lib/python3/dist-packages/rqt_graph/ros_graph.py", line 414, in _save_dot
    handle.write(self._current_dotcode)
TypeError: write(self, Union[QByteArray, bytes, bytearray]): argument 1 has unexpected type 'str'

After searching around and finding these

It seems that on line 414 it seems binary should be passed to the write function

404     def _save_dot(self):
405         file_name, _ = QFileDialog.getSaveFileName(
406             self._widget, self.tr('Save as DOT'), 'rosgraph.dot', self.tr('DOT graph (*.dot)'))
407         if file_name is None or file_name == '':
408             return
409 
410         handle = QFile(file_name)
411         if not handle.open(QIODevice.WriteOnly | QIODevice.Text):
412             return
413 
414         handle.write(self._current_dotcode)
415         handle.close()

This is despite the fact that handle has an if statement before it. Do I understand this correctly? After adjusting the line to:

414         handle.write(f"{self._current_dotcode}".encode())

the problem goes away and I can successfully store the dot file.