42
42
import pickle
43
43
import pprint
44
44
import copy
45
- import StringIO
45
+ try :
46
+ from StringIO import StringIO # for Python 2
47
+ except ImportError :
48
+ from io import StringIO # for Python 3
46
49
import colorsys
47
50
import time
48
51
import base64
49
52
50
- import wxversion
51
- if wxversion .checkInstalled ("2.8" ):
52
- wxversion .select ("2.8" )
53
- else :
54
- print ("wxversion 2.8 is not installed, installed versions are {}" .format (wxversion .getInstalled ()))
53
+ try :
54
+ import wxversion
55
+ if wxversion .checkInstalled ("2.8" ):
56
+ wxversion .select ("2.8" )
57
+ else :
58
+ print ("wxversion 2.8 is not installed, installed versions are {}" .format (wxversion .getInstalled ()))
59
+
60
+ ## this import system (or ros-released) xdot
61
+ # import xdot
62
+ ## need to import currnt package, but not to load this file
63
+ # http://stackoverflow.com/questions/6031584/importing-from-builtin-library-when-module-with-same-name-exists
64
+ def import_non_local (name , custom_name = None ):
65
+ import imp , sys
66
+
67
+ custom_name = custom_name or name
68
+
69
+ path = filter (lambda x : x != os .path .dirname (os .path .abspath (__file__ )), sys .path )
70
+ f , pathname , desc = imp .find_module (name , path )
71
+
72
+ module = imp .load_module (custom_name , f , pathname , desc )
73
+ if f :
74
+ f .close ()
75
+
76
+ return module
77
+
78
+ smach_viewer = import_non_local ('smach_viewer' )
79
+ from smach_viewer import xdot
80
+ from smach_viewer .xdot import wxxdot
81
+ from smach_viewer .xdot .xdot import TextShape
82
+ except :
83
+ # Guard against self import
84
+ this_dir = os .path .dirname (__file__ )
85
+ # Use os.getcwd() to aovid weird symbolic link problems
86
+ cur_dir = os .getcwd ()
87
+ os .chdir (this_dir )
88
+ this_dir_cwd = os .getcwd ()
89
+ os .chdir (cur_dir )
90
+ # Remove this dir from path
91
+ sys .path = [a for a in sys .path if a not in [this_dir , this_dir_cwd ]]
92
+ #
93
+ from smach_viewer .xdot import wxxdot
94
+ from xdot .ui .elements import *
95
+
96
+
55
97
import wx
56
98
import wx .richtext
57
99
58
100
import textwrap
59
101
60
- ## this import system (or ros-released) xdot
61
- # import xdot
62
- ## need to import currnt package, but not to load this file
63
- # http://stackoverflow.com/questions/6031584/importing-from-builtin-library-when-module-with-same-name-exists
64
- def import_non_local (name , custom_name = None ):
65
- import imp , sys
66
-
67
- custom_name = custom_name or name
68
-
69
- path = filter (lambda x : x != os .path .dirname (os .path .abspath (__file__ )), sys .path )
70
- f , pathname , desc = imp .find_module (name , path )
71
-
72
- module = imp .load_module (custom_name , f , pathname , desc )
73
- if f :
74
- f .close ()
75
-
76
- return module
77
-
78
- smach_viewer = import_non_local ('smach_viewer' )
79
- from smach_viewer import xdot
80
102
##
81
103
import smach
82
104
import smach_ros
@@ -167,8 +189,11 @@ def _load_local_data(self, msg):
167
189
"""Unpack the user data"""
168
190
try :
169
191
local_data = pickle .loads (msg .local_data )
170
- except KeyError :
171
- local_data = pickle .loads (base64 .b64decode (msg .local_data .encode ('utf-8' )))
192
+ except :
193
+ if isinstance (msg .local_data , str ):
194
+ local_data = pickle .loads (base64 .b64decode (msg .local_data ))
195
+ else :
196
+ local_data = pickle .loads (base64 .b64decode (bytes (str (msg .local_data ).encode ('utf-8' ))))
172
197
return local_data
173
198
174
199
def update_status (self , msg ):
@@ -460,7 +485,7 @@ def set_styles(self, selected_paths, depth, max_depth, items, subgraph_shapes, c
460
485
else :
461
486
if child_path in items :
462
487
for shape in items [child_path ].shapes :
463
- if not isinstance (shape ,xdot . xdot . TextShape ):
488
+ if not isinstance (shape ,TextShape ):
464
489
shape .pen .color = child_color
465
490
shape .pen .fillcolor = child_fillcolor
466
491
shape .pen .linewidth = child_linewidth
@@ -565,7 +590,7 @@ def __init__(self):
565
590
self .Bind (wx .EVT_TOOL , self .SaveDotGraph , id = wx .ID_SAVE )
566
591
567
592
# Create dot graph widget
568
- self .widget = xdot . wxxdot .WxDotWindow (graph_view , - 1 )
593
+ self .widget = wxxdot .WxDotWindow (graph_view , - 1 )
569
594
570
595
gv_vbox .Add (toolbar , 0 , wx .EXPAND )
571
596
gv_vbox .Add (self .widget , 1 , wx .EXPAND )
@@ -1071,4 +1096,4 @@ def main():
1071
1096
if __name__ == '__main__' :
1072
1097
rospy .init_node ('smach_viewer' ,anonymous = False , disable_signals = True ,log_level = rospy .INFO )
1073
1098
sys .argv = rospy .myargv ()
1074
- main ()
1099
+ main ()
0 commit comments