diff --git a/.travis.yml b/.travis.yml index 204760b..f206d3a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,7 @@ install: # check python2 compatibility - if [ "${CHECK_PYTHON2_COMPILE}" == "true" ]; then python2 -m compileall .; exit $?; fi # check python3 compatibility - - if [ "${CHECK_PYTHON3_COMPILE}" == "true" ]; then bash -c "ret=0; trap 'ret=1' ERR; python3 -m compileall .; 2to3 -w -f except -f execfile -f has_key -f import -f raw_input -f zip .; git diff --exit-code . > /dev/null; echo Exitting with \$ret; exit \$ret"; exit $?; fi + - if [ "${CHECK_PYTHON3_COMPILE}" == "true" ]; then bash -c "ret=0; trap 'ret=1' ERR; python3 -m compileall .; 2to3 -w -f except -f execfile -f has_key -f raw_input -f zip .; git diff --exit-code . > /dev/null; echo Exitting with \$ret; exit \$ret"; exit $?; fi # either install the latest released version of ros_buildfarm - pip install pyyaml==5.4.1 ## latest pyyaml raises TypeError: load() missing 1 required positional argument: 'Loader' - pip install ros_buildfarm diff --git a/smach_viewer/CMakeLists.txt b/smach_viewer/CMakeLists.txt index 5668faf..698de9a 100644 --- a/smach_viewer/CMakeLists.txt +++ b/smach_viewer/CMakeLists.txt @@ -11,5 +11,5 @@ catkin_package( ) # Install targets -install(PROGRAMS scripts/smach_viewer.py +catkin_install_python(PROGRAMS scripts/smach_viewer.py DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}) diff --git a/smach_viewer/package.xml b/smach_viewer/package.xml index ffc5cf5..919bd15 100644 --- a/smach_viewer/package.xml +++ b/smach_viewer/package.xml @@ -1,4 +1,4 @@ - + smach_viewer 4.0.0 @@ -25,14 +25,24 @@ rostest - smach_ros - smach_msgs - - wxpython - graphviz - python-gi - python-gi-cairo - gtk3 + cv_bridge + smach_ros + smach_msgs + + wxpython + python-xdot + python3-xdot + python3-wxgtk4.0 + graphviz + python-gi + python3-gi + python-rospkg + python3-rospkg + python-qt5-bindings + python3-qt5-bindings + python-gi-cairo + python3-gi-cairo + gtk3 diff --git a/smach_viewer/scripts/smach_viewer.py b/smach_viewer/scripts/smach_viewer.py index e026f9f..116de5f 100755 --- a/smach_viewer/scripts/smach_viewer.py +++ b/smach_viewer/scripts/smach_viewer.py @@ -53,6 +53,8 @@ import numpy as np import base64 +from distutils.version import LooseVersion + try: import wxversion if wxversion.checkInstalled("2.8"): @@ -92,6 +94,8 @@ def import_non_local(name, custom_name=None): os.chdir(cur_dir) # Remove this dir from path sys.path = [a for a in sys.path if a not in [this_dir, this_dir_cwd]] + # Ignore path ending with smach_viewer/lib/smach_viewer + sys.path = [a for a in sys.path if not a.endswith('smach_viewer/lib/smach_viewer')] # from smach_viewer.xdot import wxxdot from xdot.ui.elements import * @@ -702,10 +706,16 @@ def __init__(self): toolbar.AddControl(toggle_auto_focus) toolbar.AddControl(wx.StaticText(toolbar,-1," ")) - toolbar.AddLabelTool(wx.ID_HELP, 'Help', - wx.ArtProvider.GetBitmap(wx.ART_HELP,wx.ART_OTHER,(16,16)) ) - toolbar.AddLabelTool(wx.ID_SAVE, 'Save', - wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE,wx.ART_OTHER,(16,16)) ) + if LooseVersion(wx.__version__) >= LooseVersion('4.0'): + toolbar.AddTool(wx.ID_HELP, 'Help', + wx.ArtProvider.GetBitmap(wx.ART_HELP,wx.ART_OTHER,(16,16)) ) + toolbar.AddTool(wx.ID_SAVE, 'Save', + wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE,wx.ART_OTHER,(16,16)) ) + else: + toolbar.AddLabelTool(wx.ID_HELP, 'Help', + wx.ArtProvider.GetBitmap(wx.ART_HELP,wx.ART_OTHER,(16,16)) ) + toolbar.AddLabelTool(wx.ID_SAVE, 'Save', + wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE,wx.ART_OTHER,(16,16)) ) toolbar.Realize() self.Bind(wx.EVT_TOOL, self.ShowControlsDialog, id=wx.ID_HELP) @@ -1190,15 +1200,24 @@ def _update_server_list(self): # self.set_server(self._servers[0]) def OnTimer(self, event): + if self._pub.get_num_connections() < 1: + rospy.logwarn_once("Publishing {} requires at least one subscriber".format(self._pub.name)) + return # image context = wx.ClientDC(self) memory = wx.MemoryDC() x, y = self.ClientSize - bitmap = wx.EmptyBitmap(x, y, -1) + if LooseVersion(wx.__version__) >= LooseVersion('4.0'): + bitmap = wx.Bitmap(x, y, -1) + else: + bitmap = wx.EmptyBitmap(x, y, -1) memory.SelectObject(bitmap) memory.Blit(0, 0, x, y, context, 0, 0) memory.SelectObject(wx.NullBitmap) - buf = wx.ImageFromBitmap(bitmap).GetDataBuffer() + if LooseVersion(wx.__version__) >= LooseVersion('4.0'): + buf = bitmap.ConvertToImage().GetDataBuffer() + else: + buf = wx.ImageFromBitmap(bitmap).GetDataBuffer() img = np.frombuffer(buf, dtype=np.uint8) bridge = cv_bridge.CvBridge() img_msg = bridge.cv2_to_imgmsg(img.reshape((y, x, 3)), encoding='rgb8') diff --git a/smach_viewer/src/smach_viewer/xdot/wxxdot.py b/smach_viewer/src/smach_viewer/xdot/wxxdot.py index 44c7448..dc54b2f 100644 --- a/smach_viewer/src/smach_viewer/xdot/wxxdot.py +++ b/smach_viewer/src/smach_viewer/xdot/wxxdot.py @@ -20,13 +20,16 @@ # along with this program. If not, see . try: - from .xdot.ui.elements import * - from .xdot.ui.animation import * - from .xdot.dot.lexer import * - from .xdot.dot.parser import * + # intentionally use from xdot, instead of from .xdot, because we want to use local xdot for Python2 and system xdot for Python3 + from xdot.ui.elements import * + from xdot.ui.animation import * + from xdot.dot.lexer import * + from xdot.dot.parser import * import subprocess except: - from .xdot import * + from xdot import * + +from distutils.version import LooseVersion # Python 3 renamed the unicode type to str, the old str type has been replaced by bytes. if sys.version_info[0] >= 3: @@ -309,7 +312,10 @@ def set_highlight(self, items): ### Cursor manipulation def set_cursor(self, cursor_type): - self.cursor = wx.StockCursor(cursor_type) + if LooseVersion(wx.__version__) >= LooseVersion('4.0'): + self.cursor = wx.Cursor(cursor_type) + else: + self.cursor = wx.StockCursor(cursor_type) self.SetCursor(self.cursor) ### Zooming methods