Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use Python 3 compatible syntax #421

Merged
merged 1 commit into from
Jan 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions rqt_bag/src/rqt_bag/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

import bag_helper
from plugins.message_view import MessageView
from plugins.topic_message_view import TopicMessageView
from plugins.timeline_renderer import TimelineRenderer
from timeline_cache import TimelineCache
import rqt_bag.bag_helper
from rqt_bag.plugins.message_view import MessageView
from rqt_bag.plugins.topic_message_view import TopicMessageView
from rqt_bag.plugins.timeline_renderer import TimelineRenderer
from rqt_bag.timeline_cache import TimelineCache
6 changes: 3 additions & 3 deletions rqt_bag/src/rqt_bag/bag_timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from python_qt_binding.QtCore import Qt, QTimer, qWarning, Signal
from python_qt_binding.QtWidgets import QGraphicsScene, QMessageBox

import bag_helper
import rqt_bag.bag_helper

from .timeline_frame import TimelineFrame
from .message_listener_thread import MessageListenerThread
Expand Down Expand Up @@ -673,7 +673,7 @@ def step_next_message(self):
def record_bag(self, filename, all=True, topics=[], regex=False, limit=0):
try:
self._recorder = Recorder(filename, bag_lock=self._bag_lock, all=all, topics=topics, regex=regex, limit=limit)
except Exception, ex:
except Exception as ex:
qWarning('Error opening bag for recording [%s]: %s' % (filename, str(ex)))
return

Expand Down Expand Up @@ -721,7 +721,7 @@ def _message_recorded(self, topic, msg, t):
for listener in self._listeners[topic]:
try:
listener.timeline_changed()
except Exception, ex:
except Exception as ex:
qWarning('Error calling timeline_changed on %s: %s' % (type(listener), str(ex)))

### Views / listeners
Expand Down
2 changes: 1 addition & 1 deletion rqt_bag/src/rqt_bag/bag_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from python_qt_binding.QtWidgets import QFileDialog, QGraphicsView, QWidget

import rosbag
import bag_helper
import rqt_bag.bag_helper
from .bag_timeline import BagTimeline
from .topic_selection import TopicSelection

Expand Down
2 changes: 1 addition & 1 deletion rqt_bag/src/rqt_bag/message_listener_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def run(self):
try:
event = ListenerEvent(bag_msg_data)
QCoreApplication.postEvent(self.listener, event)
except Exception, ex:
except Exception as ex:
qWarning('Error notifying listener %s: %s' % (type(self.listener), str(ex)))

def stop(self):
Expand Down
24 changes: 14 additions & 10 deletions rqt_bag/src/rqt_bag/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
Recorder subscribes to ROS messages and writes them to a bag file.
"""

import Queue
from __future__ import print_function
try:
from queue import Queue
except ImportError:
from Queue import Queue
import re
import threading
import time
Expand Down Expand Up @@ -78,7 +82,7 @@ def __init__(self, filename, bag_lock=None, all=True, topics=[], regex=False, li
self._limited_topics = set()
self._failed_topics = set()
self._last_update = time.time()
self._write_queue = Queue.Queue()
self._write_queue = Queue()
self._paused = False
self._stop_condition = threading.Condition()
self._stop_flag = False
Expand Down Expand Up @@ -159,16 +163,16 @@ def _run_master_check(self):
self._message_count[topic] = 0

self._subscriber_helpers[topic] = _SubscriberHelper(self, topic, pytype)
except Exception, ex:
print >> sys.stderr, 'Error subscribing to %s (ignoring): %s' % (topic, str(ex))
except Exception as ex:
print('Error subscribing to %s (ignoring): %s' % (topic, str(ex)), file=sys.stderr)
self._failed_topics.add(topic)

# Wait a while
self._stop_condition.acquire()
self._stop_condition.wait(self._master_check_interval)

except Exception, ex:
print >> sys.stderr, 'Error recording to bag: %s' % str(ex)
except Exception as ex:
print('Error recording to bag: %s' % str(ex), file=sys.stderr)

# Unsubscribe from all topics
for topic in list(self._subscriber_helpers.keys()):
Expand All @@ -177,8 +181,8 @@ def _run_master_check(self):
# Close the bag file so that the index gets written
try:
self._bag.close()
except Exception, ex:
print >> sys.stderr, 'Error closing bag [%s]: %s' % (self._bag.filename, str(ex))
except Exception as ex:
print('Error closing bag [%s]: %s' % (self._bag.filename, str(ex)))

def _should_subscribe_to(self, topic):
if self._all:
Expand Down Expand Up @@ -232,8 +236,8 @@ def _run_write(self):
for listener in self._listeners:
listener(topic, m, t)

except Exception, ex:
print >> sys.stderr, 'Error write to bag: %s' % str(ex)
except Exception as ex:
print('Error write to bag: %s' % str(ex), file=sys.stderr)


class _SubscriberHelper(object):
Expand Down
7 changes: 5 additions & 2 deletions rqt_bag/src/rqt_bag/timeline_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@


import bisect
import Queue
try:
from queue import Queue
except ImportError:
from Queue import Queue
import threading
import time

Expand All @@ -52,7 +55,7 @@ def __init__(self, loader, listener=None, max_cache_size=100):
self.last_accessed = {} # topic -> [(access time, timestamp), ...]
self.item_access = {} # topic -> timestamp -> access time
self.max_cache_size = max_cache_size # max number of items to cache (per topic)
self.queue = Queue.Queue()
self.queue = Queue()
self.setDaemon(True)
self.start()

Expand Down
10 changes: 7 additions & 3 deletions rqt_bag_plugins/src/rqt_bag_plugins/image_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

from __future__ import print_function
import array
from cStringIO import StringIO
try:
from cStringIO import StringIO
except ImportError:
from io import StringIO
import sys

from PIL import Image
Expand Down Expand Up @@ -82,8 +86,8 @@ def imgmsg_to_pil(img_msg, rgba=True):

return pil_img

except Exception, ex:
print >> sys.stderr, 'Can\'t convert image: %s' % ex
except Exception as ex:
print('Can\'t convert image: %s' % ex, file=sys.stderr)
return None


Expand Down
13 changes: 7 additions & 6 deletions rqt_bag_plugins/src/rqt_bag_plugins/image_timeline_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

from __future__ import print_function
import rospy

# HACK workaround for upstream pillow issue python-pillow/Pillow#400
Expand All @@ -45,7 +46,7 @@

from rqt_bag import TimelineCache, TimelineRenderer

import image_helper
import rqt_bag_plugins.image_helper

from python_qt_binding.QtCore import Qt
from python_qt_binding.QtGui import QBrush, QPen, QPixmap
Expand Down Expand Up @@ -161,12 +162,12 @@ def _load_thumbnail(self, topic, stamp, thumbnail_details):
# Convert from ROS image to PIL image
try:
pil_image = image_helper.imgmsg_to_pil(msg)
except Exception, ex:
print >> sys.stderr, 'Error loading image on topic %s: %s' % (topic, str(ex))
except Exception as ex:
print('Error loading image on topic %s: %s' % (topic, str(ex)), file=sys.stderr)
pil_image = None

if not pil_image:
print >> sys.stderr, 'Disabling renderer on %s' % topic
print('Disabling renderer on %s' % topic, file=sys.stderr)
self.timeline.set_renderer_active(topic, False)
return None, None

Expand All @@ -179,7 +180,7 @@ def _load_thumbnail(self, topic, stamp, thumbnail_details):

return msg_stamp, thumbnail

except Exception, ex:
print >> sys.stderr, 'Error loading image on topic %s: %s' % (topic, str(ex))
except Exception as ex:
print('Error loading image on topic %s: %s' % (topic, str(ex)), file=sys.stderr)
raise
return None, None
2 changes: 1 addition & 1 deletion rqt_bag_plugins/src/rqt_bag_plugins/image_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from PIL.ImageQt import ImageQt

from rqt_bag import TopicMessageView
import image_helper
import rqt_bag_plugins.image_helper

from python_qt_binding.QtGui import QPixmap
from python_qt_binding.QtWidgets import QGraphicsScene, QGraphicsView
Expand Down
2 changes: 1 addition & 1 deletion rqt_dep/src/rqt_dep/dotcode_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def generate(self, dotcode_factory):
packages_in_stacks.append(package_name)
self._generate_package(dotcode_factory, g, package_name)

for package_name, attributes in self.packages.iteritems():
for package_name, attributes in self.packages.items():
if package_name not in packages_in_stacks:
self._generate_package(dotcode_factory, graph, package_name, attributes)
for name1, name2 in self.edges.keys():
Expand Down
6 changes: 3 additions & 3 deletions rqt_dep/src/rqt_dep/ros_pack_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def _generate_tool_tip(self, url):
try:
service_type = rosservice.get_service_type(service_name)
tool_tip += '\n %s [%s]' % (service_name, service_type)
except rosservice.ROSServiceIOException, e:
except rosservice.ROSServiceIOException as e:
tool_tip += '\n %s' % (e)
return tool_tip
elif item_type == 'topic':
Expand All @@ -334,9 +334,9 @@ def _redraw_graph_scene(self):
for item in self._scene.items():
self._scene.removeItem(item)
self._scene.clear()
for node_item in self._nodes.itervalues():
for node_item in self._nodes.values():
self._scene.addItem(node_item)
for edge_items in self._edges.itervalues():
for edge_items in self._edges.values():
for edge_item in edge_items:
edge_item.add_to_scene(self._scene)

Expand Down
2 changes: 1 addition & 1 deletion rqt_graph/src/rqt_graph/dotcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def _calc_statistic_info(self, sub, topic, pub=None):
if pub is None and sub in self.edges and topic in self.edges[sub]:
conns = len(self.edges[sub][topic])
if conns == 1:
pub = next(self.edges[sub][topic].iterkeys())
pub = next(self.edges[sub][topic].keys())
else:
penwidth = self._calc_edge_penwidth(sub,topic)
color = self._calc_edge_color(sub,topic)
Expand Down
4 changes: 2 additions & 2 deletions rqt_graph/src/rqt_graph/ros_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,9 @@ def _redraw_graph_view(self):
highlight_level=highlight_level,
same_label_siblings=True)

for node_item in nodes.itervalues():
for node_item in nodes.values():
self._scene.addItem(node_item)
for edge_items in edges.itervalues():
for edge_items in edges.values():
for edge_item in edge_items:
edge_item.add_to_scene(self._scene)

Expand Down
2 changes: 1 addition & 1 deletion rqt_msg/src/rqt_msg/messages_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def _rightclick_menu(self, event):

else:
raise
except rosmsg.ROSMsgException, e:
except rosmsg.ROSMsgException as e:
QMessageBox.warning(self, self.tr('Warning'),
self.tr('The selected item component ' +
'does not have text to view.'))
Expand Down
6 changes: 3 additions & 3 deletions rqt_plot/src/rqt_plot/data_plot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@
from rqt_py_common.ini_helper import pack, unpack

try:
from pyqtgraph_data_plot import PyQtGraphDataPlot
from .pyqtgraph_data_plot import PyQtGraphDataPlot
except ImportError as e:
PyQtGraphDataPlot = None

try:
from mat_data_plot import MatDataPlot
from .mat_data_plot import MatDataPlot
except ImportError as e:
MatDataPlot = None

try:
from qwt_data_plot import QwtDataPlot
from .qwt_data_plot import QwtDataPlot
except ImportError as e:
QwtDataPlot = None

Expand Down
4 changes: 2 additions & 2 deletions rqt_plot/src/rqt_plot/rosplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def _ros_cb(self, msg):
else:
self.buff_x.append(rospy.get_time() - self.start_time)
#self.axes[index].plot(datax, buff_y)
except AttributeError, e:
except AttributeError as e:
self.error = RosPlotException("Invalid topic spec [%s]: %s" % (self.name, str(e)))
finally:
self.lock.release()
Expand Down Expand Up @@ -197,5 +197,5 @@ def generate_field_evals(fields):
else:
evals.append(_field_eval(f))
return evals
except Exception, e:
except Exception as e:
raise RosPlotException("cannot parse field reference [%s]: %s" % (fields, str(e)))
9 changes: 4 additions & 5 deletions rqt_publisher/src/rqt_publisher/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,13 @@ def _change_publisher_expression(self, publisher_info, topic_name, new_value):
self._fill_message_slots(publisher_info['message_instance'], publisher_info['topic_name'], publisher_info['expressions'], publisher_info['counter'])
try:
publisher_info['message_instance']._check_types()
except Exception, e:
error_str = str(e)
print 'serialization error:', error_str
except Exception as e:
print('serialization error: %s' % e)
if old_expression is not None:
publisher_info['expressions'][topic_name] = old_expression
else:
del publisher_info['expressions'][topic_name]
return '%s %s: %s' % (expression, error_prefix, error_str)
return '%s %s: %s' % (expression, error_prefix, e)
return expression
else:
return '%s %s evaluating as "%s"' % (expression, error_prefix, slot_type.__name__)
Expand All @@ -223,7 +222,7 @@ def _create_message_instance(self, type_str):

base_message_type = roslib.message.get_message_class(base_type_str)
if base_message_type is None:
print 'Could not create message of type "%s".' % base_type_str
print('Could not create message of type "%s".' % base_type_str)
return None

if array_size is not None:
Expand Down
2 changes: 1 addition & 1 deletion rqt_py_common/src/rqt_py_common/extended_combo_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(self, parent=None):
self.setCompleter(self.completer)

# connect signals
self.lineEdit().textEdited[unicode].connect(self.filter_model.setFilterFixedString)
self.lineEdit().textEdited[str].connect(self.filter_model.setFilterFixedString)
self.completer.activated.connect(self.on_completer_activated)
self.setItems.connect(self.onSetItems)

Expand Down
9 changes: 8 additions & 1 deletion rqt_py_common/src/rqt_py_common/ini_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ def unpack(data):
"""
if data is None or data == '':
data = []
elif isinstance(data, basestring):
elif is_string(data):
data = [data]
return data


def is_string(s):
"""Check if the argument is a string which works for both Python 2 and 3."""
try:
return isinstance(s, basestring)
except NameError:
return isinstance(s, str)
2 changes: 1 addition & 1 deletion rqt_py_common/src/rqt_py_common/rosaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ def rosaction_cmd_prototype(args):
# if not options.silent:
# print(file=sys.stderr, "Invalid package: '%s'"%e)
# sys.exit(getattr(os, 'EX_USAGE', 1))
except ValueError, e:
except ValueError as e:
if not options.silent:
sys.stderr.write("Invalid type: '%s'" % e)
sys.exit(getattr(os, 'EX_USAGE', 1))
Expand Down
Loading