def __init__(self, timeline, parent, topic): MessageView.__init__(self, timeline, topic) self._parent = parent self._stamp = None self._name = parent.objectName() self.toolbar = QToolBar() self._first_action = QAction(QIcon.fromTheme('go-first'), '', self.toolbar) self._first_action.triggered.connect(self.navigate_first) self.toolbar.addAction(self._first_action) self._prev_action = QAction(QIcon.fromTheme('go-previous'), '', self.toolbar) self._prev_action.triggered.connect(self.navigate_previous) self.toolbar.addAction(self._prev_action) self._next_action = QAction(QIcon.fromTheme('go-next'), '', self.toolbar) self._next_action.triggered.connect(self.navigate_next) self.toolbar.addAction(self._next_action) self._last_action = QAction(QIcon.fromTheme('go-last'), '', self.toolbar) self._last_action.triggered.connect(self.navigate_last) self.toolbar.addAction(self._last_action) parent.layout().addWidget(self.toolbar)
def __init__(self, context): super(Dashboard, self).__init__(context) self.context = context self.setup(context) if not hasattr(self, 'name'): self.name = 'Dashboard' if not hasattr(self, 'max_icon_size'): self.max_icon_size = QSize(50, 30) self._main_widget = QToolBar() self._main_widget.setIconSize(self.max_icon_size) self._main_widget.setObjectName(self.name) self._main_widget.setWindowTitle(self.name) if context.serial_number() > 1: self._main_widget.setWindowTitle(self._main_widget.windowTitle() + (' (%d)' % context.serial_number())) widgets = self.get_widgets() self._widgets = [] for v in widgets: for i in v: try: self._main_widget.addWidget(i) self._widgets.append(i) except: raise Exception( "All widgets must be a subclass of QWidget!") self._main_widget.addSeparator() # Display the dashboard context.add_toolbar(self._main_widget)
def __init__(self, context): super(EusGUI, self).__init__(context) # Give QObjects reasonable names self.setObjectName('EusGUI') self.msg = None # Create a container widget and give it a layout self._toolbar = QToolBar() self._toolbar.addWidget(QLabel('EusGUI')) self._container = QWidget() self._layout = QVBoxLayout() self._container.setLayout(self._layout) self._layout.addWidget(self._toolbar) self._prev_button = QPushButton('PREV') self._prev_button.clicked.connect(self._prev_cb) self._layout.addWidget(self._prev_button) self._refresh_button = QPushButton('DO IT AGAIN') self._refresh_button.clicked.connect(self._refresh_cb) self._layout.addWidget(self._refresh_button) self._next_button = QPushButton('NEXT') self._next_button.clicked.connect(self._next_cb) self._layout.addWidget(self._next_button) context.add_widget(self._container)
class TriangleGUI(Plugin): def __init__(self, context): super(TriangleGUI, self).__init__(context) # Give QObjects reasonable names self.setObjectName('TriangleGUI') # Process standalone plugin command-line arguments from argparse import ArgumentParser parser = ArgumentParser() # Add argument(s) to the parser. parser.add_argument("-q", "--quiet", action="store_true", dest="quiet", help="Put plugin in silent mode") args, unknowns = parser.parse_known_args(context.argv()) self._toolbar = QToolBar() self._toolbar.addWidget(QLabel('Triangle')) # Create a container widget and give it a layout self._container = QWidget() self._layout = QVBoxLayout() self._container.setLayout(self._layout) self._layout.addWidget(self._toolbar) # Add a button for killing nodes self._go_button = QPushButton('Go') self._go_button.clicked.connect(self._go) self._layout.addWidget(self._go_button) self._clear_button = QPushButton('Clear') self._clear_button.clicked.connect(self._clear) self._layout.addWidget(self._clear_button) # self._step_run_button.setStyleSheet('QPushButton {color: black}') context.add_widget(self._container) def _go(self): go = rospy.ServiceProxy('/triangle_screenpoint/go', Empty) go() def _clear(self): clear = rospy.ServiceProxy('/triangle_screenpoint/cancel', Empty) clear() def shutdown_plugin(self): pass def save_settings(self, plugin_settings, instance_settings): pass def restore_settings(self, plugin_settings, instance_settings): pass
def embed_toolbar(self, pid, toolbar_object_name): toolbar = QToolBar() toolbar.setObjectName(toolbar_object_name) embed_container = QX11EmbedContainer(toolbar) toolbar.addWidget(embed_container) #embed_container.clientClosed.connect(self._emit_close_signal) self._add_toolbar(toolbar) self._embed_containers[toolbar_object_name] = embed_container # setup mapping to signal change of orientation to client self._embed_toolbars[toolbar_object_name] = toolbar self._signal_mapper_toolbars.setMapping(toolbar, toolbar_object_name) toolbar.orientationChanged.connect(self._signal_mapper_toolbars.map) return embed_container.winId()
def __init__(self, context): super(ImageSnapShotGUI, self).__init__(context) # Give QObjects reasonable names self.setObjectName('ImageSnapShotGUI') # Process standalone plugin command-line arguments from argparse import ArgumentParser parser = ArgumentParser() # Add argument(s) to the parser. parser.add_argument("-q", "--quiet", action="store_true", dest="quiet", help="Put plugin in silent mode") args, unknowns = parser.parse_known_args(context.argv()) self._toolbar = QToolBar() self._toolbar.addWidget(QLabel('ImageSnapShot')) # Create a container widget and give it a layout self._container = QWidget() self._layout = QVBoxLayout() self._container.setLayout(self._layout) self._layout.addWidget(self._toolbar) # Add a button for .... self._go_button = QPushButton('Head') self._go_button.clicked.connect(self._head) self._layout.addWidget(self._go_button) self._clear_button = QPushButton('Larm') self._clear_button.clicked.connect(self._larm) self._layout.addWidget(self._clear_button) self._clear_button = QPushButton('Rarm') self._clear_button.clicked.connect(self._rarm) self._layout.addWidget(self._clear_button) self._clear_button = QPushButton('L FishEye') self._clear_button.clicked.connect(self._lfisheye) self._layout.addWidget(self._clear_button) self._clear_button = QPushButton('R FishEye') self._clear_button.clicked.connect(self._rfisheye) self._layout.addWidget(self._clear_button) # self._step_run_button.setStyleSheet('QPushButton {color: black}') context.add_widget(self._container) self._head_pub = rospy.Publisher('/head_snap/snapshot', std_msgs.msg.Empty) self._lhand_pub = rospy.Publisher('/lhand_snap/snapshot', std_msgs.msg.Empty) self._rhand_pub = rospy.Publisher('/rhand_snap/snapshot', std_msgs.msg.Empty) self._lfisheye_pub = rospy.Publisher('/lfisheye_snap/snapshot', std_msgs.msg.Empty) self._rfisheye_pub = rospy.Publisher('/rfisheye_snap/snapshot', std_msgs.msg.Empty)
def __init__(self, context): super(ToolBar, self).__init__(context) # Give QObjects reasonable names self.setObjectName('EnableAxis') # Process standalone plugin command-line arguments from argparse import ArgumentParser parser = ArgumentParser() # Add argument(s) to the parser. parser.add_argument("-q", "--quiet", action="store_true", dest="quiet", help="Put plugin in silent mode") args, unknowns = parser.parse_known_args(context.argv()) if not args.quiet: print 'arguments: ', args print 'unknowns: ', unknowns self._toolbar = QToolBar() self._palette = Palette() self._enableAxisWidget = EnableAxisWidget() context._handler._main_window.setPalette(self._palette.palette()) self._batteryWidget = BatteryWidget() # Add widget to the user interface self._toolbar.addWidget(self._enableAxisWidget) self._toolbar.addWidget(self._batteryWidget) context.add_toolbar(self._toolbar)
def __init__(self, context): super(TriangleGUI, self).__init__(context) # Give QObjects reasonable names self.setObjectName('TriangleGUI') # Process standalone plugin command-line arguments from argparse import ArgumentParser parser = ArgumentParser() # Add argument(s) to the parser. parser.add_argument("-q", "--quiet", action="store_true", dest="quiet", help="Put plugin in silent mode") args, unknowns = parser.parse_known_args(context.argv()) self._toolbar = QToolBar() self._toolbar.addWidget(QLabel('Triangle')) # Create a container widget and give it a layout self._container = QWidget() self._layout = QVBoxLayout() self._container.setLayout(self._layout) self._layout.addWidget(self._toolbar) # Add a button for killing nodes self._go_button = QPushButton('Go') self._go_button.clicked.connect(self._go) self._layout.addWidget(self._go_button) self._clear_button = QPushButton('Clear') self._clear_button.clicked.connect(self._clear) self._layout.addWidget(self._clear_button) # self._step_run_button.setStyleSheet('QPushButton {color: black}') context.add_widget(self._container)
def __init__(self, context, name = None): super(Dashboard, self).__init__(context) self.context = context self.setup(context) if not hasattr(self, 'name'): if not name: self.name = 'Dashboard' else: self.name = name self._main_widget = QToolBar() self._main_widget.setIconSize(QSize(80, 80)) self._main_widget.setObjectName(self.name) self._main_widget.setWindowTitle(self.name) widgets = self.get_widgets() layout = QHBoxLayout() self._widgets = [] for v in widgets: for i in v: try: self._main_widget.addWidget(i) self._widgets.append(i) except: raise(Exception("All widgets must be a subclass of QWidget!")) self._main_widget.addSeparator() # Display the dashboard context.add_toolbar(self._main_widget)
def __init__(self, context): super(Dashboard, self).__init__(context) self.context = context self.setup(context) if not hasattr(self, 'name'): self.name = 'Dashboard' if not hasattr(self, 'max_icon_size'): self.max_icon_size = QSize(50, 30) self._main_widget = QToolBar() self._main_widget.setIconSize(self.max_icon_size) self._main_widget.setObjectName(self.name) self._main_widget.setWindowTitle(self.name) if context.serial_number() > 1: self._main_widget.setWindowTitle(self._main_widget.windowTitle() + (' (%d)' % context.serial_number())) widgets = self.get_widgets() self._widgets = [] for v in widgets: for i in v: try: self._main_widget.addWidget(i) self._widgets.append(i) except: raise Exception("All widgets must be a subclass of QWidget!") self._main_widget.addSeparator() # Display the dashboard context.add_toolbar(self._main_widget)
class ToolBar(Plugin): def __init__(self, context): super(ToolBar, self).__init__(context) # Give QObjects reasonable names self.setObjectName('EnableAxis') # Process standalone plugin command-line arguments from argparse import ArgumentParser parser = ArgumentParser() # Add argument(s) to the parser. parser.add_argument("-q", "--quiet", action="store_true", dest="quiet", help="Put plugin in silent mode") args, unknowns = parser.parse_known_args(context.argv()) if not args.quiet: print 'arguments: ', args print 'unknowns: ', unknowns self._toolbar = QToolBar() self._palette = Palette() self._enableAxisWidget = EnableAxisWidget() context._handler._main_window.setPalette(self._palette.palette()) self._batteryWidget = BatteryWidget() # Add widget to the user interface self._toolbar.addWidget(self._enableAxisWidget) self._toolbar.addWidget(self._batteryWidget) context.add_toolbar(self._toolbar) def shutdown_plugin(self): # TODO unregister all publishers here pass def save_settings(self, plugin_settings, instance_settings): # TODO save intrinsic configuration, usually using: # instance_settings.set_value(k, v) pass def restore_settings(self, plugin_settings, instance_settings): # TODO restore intrinsic configuration, usually using: # v = instance_settings.value(k) pass
class EusGUI(Plugin): def __init__(self, context): super(EusGUI, self).__init__(context) # Give QObjects reasonable names self.setObjectName('EusGUI') self.msg = None # Create a container widget and give it a layout self._toolbar = QToolBar() self._toolbar.addWidget(QLabel('EusGUI')) self._container = QWidget() self._layout = QVBoxLayout() self._container.setLayout(self._layout) self._layout.addWidget(self._toolbar) self._prev_button = QPushButton('PREV') self._prev_button.clicked.connect(self._prev_cb) self._layout.addWidget(self._prev_button) self._refresh_button = QPushButton('DO IT AGAIN') self._refresh_button.clicked.connect(self._refresh_cb) self._layout.addWidget(self._refresh_button) self._next_button = QPushButton('NEXT') self._next_button.clicked.connect(self._next_cb) self._layout.addWidget(self._next_button) context.add_widget(self._container) def _prev_cb(self): func = rospy.ServiceProxy('prev', Empty) func() def _next_cb(self): func = rospy.ServiceProxy('next', Empty) func() def _refresh_cb(self): func = rospy.ServiceProxy('refresh', Empty) func() def shutdown_plugin(self): pass def save_settings(self, plugin_settings, instance_settings): pass def restore_settings(self, plugin_settings, instance_settings): pass
class Top(Plugin): NODE_FIELDS = [ 'pid', 'get_cpu_percent', 'get_memory_percent', 'get_num_threads' ] OUT_FIELDS = [ 'node_name', 'pid', 'cpu_percent', 'memory_percent', 'num_threads' ] FORMAT_STRS = ['%s', '%s', '%0.2f', '%0.2f', '%s'] NODE_LABELS = ['Node', 'PID', 'CPU %', 'Mem %', 'Num Threads'] SORT_TYPE = [str, str, float, float, float] TOOLTIPS = { 0: ('cmdline', lambda x: '\n'.join(textwrap.wrap(' '.join(x)))), 3: ('memory_info', lambda x: ('Resident: %0.2f MiB, Virtual: %0.2f MiB' % (x[0] / 2**20, x[1] / 2**20))) } _node_info = NodeInfo() name_filter = re.compile('') def __init__(self, context): super(Top, self).__init__(context) # Give QObjects reasonable names self.setObjectName('Top') # Process standalone plugin command-line arguments from argparse import ArgumentParser parser = ArgumentParser() # Add argument(s) to the parser. parser.add_argument("-q", "--quiet", action="store_true", dest="quiet", help="Put plugin in silent mode") args, unknowns = parser.parse_known_args(context.argv()) # if not args.quiet: # print 'arguments: ', args # print 'unknowns: ', unknowns self._selected_node = '' self._selected_node_lock = RLock() # Setup the toolbar self._toolbar = QToolBar() self._filter_box = QLineEdit() self._regex_box = QCheckBox() self._regex_box.setText('regex') self._toolbar.addWidget(QLabel('Filter')) self._toolbar.addWidget(self._filter_box) self._toolbar.addWidget(self._regex_box) self._filter_box.returnPressed.connect(self.update_filter) self._regex_box.stateChanged.connect(self.update_filter) # Create a container widget and give it a layout self._container = QWidget() self._container.setWindowTitle('Process Monitor') self._layout = QVBoxLayout() self._container.setLayout(self._layout) self._layout.addWidget(self._toolbar) # Create the table widget self._table_widget = QTreeWidget() self._table_widget.setObjectName('TopTable') self._table_widget.setColumnCount(len(self.NODE_LABELS)) self._table_widget.setHeaderLabels(self.NODE_LABELS) self._table_widget.itemClicked.connect(self._tableItemClicked) self._table_widget.setSortingEnabled(True) self._table_widget.setAlternatingRowColors(True) self._layout.addWidget(self._table_widget) context.add_widget(self._container) # Add a button for killing nodes self._kill_button = QPushButton('Kill Node') self._layout.addWidget(self._kill_button) self._kill_button.clicked.connect(self._kill_node) # Update twice since the first cpu% lookup will always return 0 self.update_table() self.update_table() self._table_widget.resizeColumnToContents(0) # Start a timer to trigger updates self._update_timer = QTimer() self._update_timer.setInterval(1000) self._update_timer.timeout.connect(self.update_table) self._update_timer.start() def _tableItemClicked(self, item, column): with self._selected_node_lock: self._selected_node = item.text(0) def update_filter(self, *args): if self._regex_box.isChecked(): expr = self._filter_box.text() else: expr = re.escape(self._filter_box.text()) self.name_filter = re.compile(expr) self.update_table() def _kill_node(self): self._node_info.kill_node(self._selected_node) def update_one_item(self, row, info): twi = TopWidgetItem() for col, field in enumerate(self.OUT_FIELDS): val = info[field] twi.setText(col, self.FORMAT_STRS[col] % val) self._table_widget.insertTopLevelItem(row, twi) for col, (key, func) in self.TOOLTIPS.iteritems(): twi.setToolTip(col, func(info[key])) with self._selected_node_lock: if twi.text(0) == self._selected_node: twi.setSelected(True) self._table_widget.setItemHidden( twi, len(self.name_filter.findall(info['node_name'])) == 0) def update_table(self): self._table_widget.clear() infos = self._node_info.get_all_node_fields(self.NODE_FIELDS) for nx, info in enumerate(infos): self.update_one_item(nx, info) def shutdown_plugin(self): self._update_timer.stop() def save_settings(self, plugin_settings, instance_settings): instance_settings.set_value('filter_text', self._filter_box.text()) instance_settings.set_value('is_regex', int(self._regex_box.checkState())) def restore_settings(self, plugin_settings, instance_settings): self._filter_box.setText(instance_settings.value('filter_text')) is_regex_int = instance_settings.value('is_regex') if is_regex_int: self._regex_box.setCheckState(Qt.CheckState(is_regex_int)) else: self._regex_box.setCheckState(Qt.CheckState(0)) self.update_filter()
class TopicMessageView(MessageView): """ A message view with a toolbar for navigating messages in a single topic. """ def __init__(self, timeline, parent, topic): MessageView.__init__(self, timeline, topic) self._parent = parent self._stamp = None self._name = parent.objectName() self.toolbar = QToolBar() self._first_action = QAction(QIcon.fromTheme('go-first'), '', self.toolbar) self._first_action.triggered.connect(self.navigate_first) self.toolbar.addAction(self._first_action) self._prev_action = QAction(QIcon.fromTheme('go-previous'), '', self.toolbar) self._prev_action.triggered.connect(self.navigate_previous) self.toolbar.addAction(self._prev_action) self._next_action = QAction(QIcon.fromTheme('go-next'), '', self.toolbar) self._next_action.triggered.connect(self.navigate_next) self.toolbar.addAction(self._next_action) self._last_action = QAction(QIcon.fromTheme('go-last'), '', self.toolbar) self._last_action.triggered.connect(self.navigate_last) self.toolbar.addAction(self._last_action) parent.layout().addWidget(self.toolbar) @property def parent(self): return self._parent @property def stamp(self): return self._stamp # MessageView implementation def message_viewed(self, bag, msg_details): _, _, self._stamp = msg_details[:3] # Events def navigate_first(self): for entry in self.timeline.get_entries([self.topic], *self.timeline._timeline_frame.play_region): self.timeline._timeline_frame.playhead = entry.time break def navigate_previous(self): last_entry = None for entry in self.timeline.get_entries([self.topic], self.timeline._timeline_frame.start_stamp, self.timeline._timeline_frame.playhead): if entry.time < self.timeline._timeline_frame.playhead: last_entry = entry if last_entry: self.timeline._timeline_frame.playhead = last_entry.time def navigate_next(self): for entry in self.timeline.get_entries([self.topic], self.timeline._timeline_frame.playhead, self.timeline._timeline_frame.end_stamp): if entry.time > self.timeline._timeline_frame.playhead: self.timeline._timeline_frame.playhead = entry.time break def navigate_last(self): last_entry = None for entry in self.timeline.get_entries([self.topic], *self.timeline._timeline_frame.play_region): last_entry = entry if last_entry: self.timeline._timeline_frame.playhead = last_entry.time
#!/usr/bin/env python import sys from python_qt_binding.QtCore import QSettings, Qt from python_qt_binding.QtGui import QAction, QApplication, QDockWidget, QToolBar, QMainWindow app = QApplication(sys.argv) settings = QSettings(QSettings.IniFormat, QSettings.UserScope, 'test', 'test') mw = QMainWindow() mw.resize(800, 600) mw.show() tb = QToolBar() tb.setObjectName('toolbar') mw.addToolBar(tb) count_dock_widgets = 0 def add_dock_widget(orientation): global count_dock_widgets count_dock_widgets += 1 dw = QDockWidget('dockwidget%d' % count_dock_widgets, mw) dw.setObjectName('dockwidget%d' % count_dock_widgets) mw.addDockWidget(Qt.BottomDockWidgetArea, dw, orientation) def add_horizontal(self): add_dock_widget(Qt.Horizontal) def add_vertical(self):
class Dashboard(Plugin): """ Base class from which dashboards should inherit. :param context: the plugin context :type context: qt_gui.plugin.Plugin """ def __init__(self, context): super(Dashboard, self).__init__(context) self.context = context self.setup(context) if not hasattr(self, 'name'): self.name = 'Dashboard' if not hasattr(self, 'max_icon_size'): self.max_icon_size = QSize(50, 30) self._main_widget = QToolBar() self._main_widget.setIconSize(self.max_icon_size) self._main_widget.setObjectName(self.name) self._main_widget.setWindowTitle(self.name) if context.serial_number() > 1: self._main_widget.setWindowTitle(self._main_widget.windowTitle() + (' (%d)' % context.serial_number())) widgets = self.get_widgets() self._widgets = [] for v in widgets: for i in v: try: self._main_widget.addWidget(i) self._widgets.append(i) except: raise Exception("All widgets must be a subclass of QWidget!") self._main_widget.addSeparator() # Display the dashboard context.add_toolbar(self._main_widget) def setup(self, context): """ Called during ``__init__`` Subclasses should do initialization here. NOTE when overriding this method you should provide a ``self.name`` to avoid naming conflicts. :param context: The plugin context :type context: qt_gui.plugin.Plugin """ pass def shutdown_plugin(self): """ Called when the toolbar is closed by Qt. """ for widget in self._widgets: if hasattr(widget, 'shutdown_widget'): widget.shutdown_widget() if hasattr(widget, 'close'): widget.close() self.shutdown_dashboard() def shutdown_dashboard(self): """ Called after shutdown plugin, subclasses should do cleanup here, not in shutdown_plugin """ pass def get_widgets(self): """ Most of the dashboard customization should be done here. If this function is not overriden the dashboard will display nothing. :returns: List of lists containing dashboard widgets. """ return []
class Dashboard(Plugin): """Base class from which dashboards should inherit.""" def __init__(self, context, name = None): super(Dashboard, self).__init__(context) self.context = context self.setup(context) if not hasattr(self, 'name'): if not name: self.name = 'Dashboard' else: self.name = name self._main_widget = QToolBar() self._main_widget.setIconSize(QSize(80, 80)) self._main_widget.setObjectName(self.name) self._main_widget.setWindowTitle(self.name) widgets = self.get_widgets() layout = QHBoxLayout() self._widgets = [] for v in widgets: for i in v: try: self._main_widget.addWidget(i) self._widgets.append(i) except: raise(Exception("All widgets must be a subclass of QWidget!")) self._main_widget.addSeparator() # Display the dashboard context.add_toolbar(self._main_widget) def setup(self, context): """Called during ``__init__`` Subclasses should do initialization here. .. note:: If this method is overriden it is important to call ``self.setObjectName()`` so that object names do not conflict. :param context: The plugin context :type context: qt_gui.plugin.Plugin """ pass def shutdown_plugin(self): """Called when the toolbar is closed by Qt. """ for widget in self._widgets: if hasattr(widget, 'close'): widget.close() self.shutdown_dashboard() def shutdown_dashboard(self): """Called after shutdown plugin, subclasses should do cleanup here, not in shutdown_plugin """ pass def get_widgets(self): """ Most of the dashboard customization should be done here. If this function is not overriden the dashboard will display nothing. :returns: List of lists containing dashboard widgets. """ return []
class TopicMessageView(MessageView): """ A message view with a toolbar for navigating messages in a single topic. """ def __init__(self, timeline, parent): MessageView.__init__(self, timeline) self._parent = parent self._topic = None self._stamp = None self._name = parent.objectName() self.parent.destroyed.connect(self._on_close) self.toolbar = QToolBar() self._first_action = QAction(QIcon.fromTheme('go-first'), '', self.toolbar) self._first_action.triggered.connect(self.navigate_first) self.toolbar.addAction(self._first_action) self._prev_action = QAction(QIcon.fromTheme('go-previous'), '', self.toolbar) self._prev_action.triggered.connect(self.navigate_previous) self.toolbar.addAction(self._prev_action) self._next_action = QAction(QIcon.fromTheme('go-next'), '', self.toolbar) self._next_action.triggered.connect(self.navigate_next) self.toolbar.addAction(self._next_action) self._last_action = QAction(QIcon.fromTheme('go-last'), '', self.toolbar) self._last_action.triggered.connect(self.navigate_last) self.toolbar.addAction(self._last_action) parent.layout().addWidget(self.toolbar) @property def parent(self): return self._parent @property def topic(self): return self._topic @property def stamp(self): return self._stamp # MessageView implementation def message_viewed(self, bag, msg_details): self._topic, _, self._stamp = msg_details[:3] # Events def _on_close(self): # TODO: needs to handle closing when a message hasn't been viewed yet if self._topic: self.timeline.popups.remove(self._name) self.timeline.remove_view(self._topic, self) def navigate_first(self): if not self.topic: return for entry in self.timeline.get_entries( self._topic, *self.timeline._timeline_frame.play_region): self.timeline._timeline_frame.playhead = entry.time break def navigate_previous(self): if not self.topic: return last_entry = None for entry in self.timeline.get_entries( self._topic, self.timeline._timeline_frame.start_stamp, self.timeline._timeline_frame.playhead): if entry.time < self.timeline._timeline_frame.playhead: last_entry = entry if last_entry: self.timeline._timeline_frame.playhead = last_entry.time def navigate_next(self): if not self.topic: return for entry in self.timeline.get_entries( self._topic, self.timeline._timeline_frame.playhead, self.timeline._timeline_frame.end_stamp): if entry.time > self.timeline._timeline_frame.playhead: self.timeline._timeline_frame.playhead = entry.time break def navigate_last(self): if not self.topic: return last_entry = None for entry in self.timeline.get_entries( self._topic, *self.timeline._timeline_frame.play_region): last_entry = entry if last_entry: self.timeline._timeline_frame.playhead = last_entry.time
class Dashboard(Plugin): """ Base class from which dashboards should inherit. :param context: the plugin context :type context: qt_gui.plugin.Plugin """ def __init__(self, context): super(Dashboard, self).__init__(context) self.context = context self.setup(context) if not hasattr(self, 'name'): self.name = 'Dashboard' if not hasattr(self, 'max_icon_size'): self.max_icon_size = QSize(50, 30) self._main_widget = QToolBar() self._main_widget.setIconSize(self.max_icon_size) self._main_widget.setObjectName(self.name) self._main_widget.setWindowTitle(self.name) if context.serial_number() > 1: self._main_widget.setWindowTitle(self._main_widget.windowTitle() + (' (%d)' % context.serial_number())) widgets = self.get_widgets() self._widgets = [] for v in widgets: for i in v: try: self._main_widget.addWidget(i) self._widgets.append(i) except: raise Exception( "All widgets must be a subclass of QWidget!") self._main_widget.addSeparator() # Display the dashboard context.add_toolbar(self._main_widget) def setup(self, context): """ Called during ``__init__`` Subclasses should do initialization here. NOTE when overriding this method you should provide a ``self.name`` to avoid naming conflicts. :param context: The plugin context :type context: qt_gui.plugin.Plugin """ pass def shutdown_plugin(self): """ Called when the toolbar is closed by Qt. """ for widget in self._widgets: if hasattr(widget, 'shutdown_widget'): widget.shutdown_widget() if hasattr(widget, 'close'): widget.close() self.shutdown_dashboard() def shutdown_dashboard(self): """ Called after shutdown plugin, subclasses should do cleanup here, not in shutdown_plugin """ pass def get_widgets(self): """ Most of the dashboard customization should be done here. If this function is not overriden the dashboard will display nothing. :returns: List of lists containing dashboard widgets. """ return []
class TopicMessageView(MessageView): """ A message view with a toolbar for navigating messages in a single topic. """ def __init__(self, timeline, parent, topic): MessageView.__init__(self, timeline, topic) self._parent = parent self._stamp = None self._name = parent.objectName() self.toolbar = QToolBar() self._first_action = QAction(QIcon.fromTheme('go-first'), '', self.toolbar) self._first_action.triggered.connect(self.navigate_first) self.toolbar.addAction(self._first_action) self._prev_action = QAction(QIcon.fromTheme('go-previous'), '', self.toolbar) self._prev_action.triggered.connect(self.navigate_previous) self.toolbar.addAction(self._prev_action) self._next_action = QAction(QIcon.fromTheme('go-next'), '', self.toolbar) self._next_action.triggered.connect(self.navigate_next) self.toolbar.addAction(self._next_action) self._last_action = QAction(QIcon.fromTheme('go-last'), '', self.toolbar) self._last_action.triggered.connect(self.navigate_last) self.toolbar.addAction(self._last_action) parent.layout().addWidget(self.toolbar) @property def parent(self): return self._parent @property def stamp(self): return self._stamp # MessageView implementation def message_viewed(self, bag, msg_details): _, _, self._stamp = msg_details[:3] # Events def navigate_first(self): for entry in self.timeline.get_entries( [self.topic], *self.timeline._timeline_frame.play_region): self.timeline._timeline_frame.playhead = entry.time break def navigate_previous(self): last_entry = None for entry in self.timeline.get_entries( [self.topic], self.timeline._timeline_frame.start_stamp, self.timeline._timeline_frame.playhead): if entry.time < self.timeline._timeline_frame.playhead: last_entry = entry if last_entry: self.timeline._timeline_frame.playhead = last_entry.time def navigate_next(self): for entry in self.timeline.get_entries( [self.topic], self.timeline._timeline_frame.playhead, self.timeline._timeline_frame.end_stamp): if entry.time > self.timeline._timeline_frame.playhead: self.timeline._timeline_frame.playhead = entry.time break def navigate_last(self): last_entry = None for entry in self.timeline.get_entries( [self.topic], *self.timeline._timeline_frame.play_region): last_entry = entry if last_entry: self.timeline._timeline_frame.playhead = last_entry.time
class Top(Plugin): NODE_FIELDS = [ 'pid', 'get_cpu_percent', 'get_memory_percent', 'get_num_threads'] OUT_FIELDS = ['node_name', 'pid', 'cpu_percent', 'memory_percent', 'num_threads' ] FORMAT_STRS = ['%s', '%s', '%0.2f', '%0.2f', '%s' ] NODE_LABELS = ['Node', 'PID', 'CPU %', 'Mem %', 'Num Threads' ] SORT_TYPE = [str, str, float, float, float ] TOOLTIPS = { 0: ('cmdline', lambda x: '\n'.join(textwrap.wrap(' '.join(x)))), 3: ('memory_info', lambda x: ('Resident: %0.2f MiB, Virtual: %0.2f MiB' % (x[0]/2**20, x[1]/2**20))) } _node_info = NodeInfo() name_filter = re.compile('') def __init__(self, context): super(Top, self).__init__(context) # Give QObjects reasonable names self.setObjectName('Top') # Process standalone plugin command-line arguments from argparse import ArgumentParser parser = ArgumentParser() # Add argument(s) to the parser. parser.add_argument("-q", "--quiet", action="store_true", dest="quiet", help="Put plugin in silent mode") args, unknowns = parser.parse_known_args(context.argv()) # if not args.quiet: # print 'arguments: ', args # print 'unknowns: ', unknowns self._selected_node = '' self._selected_node_lock = RLock() # Setup the toolbar self._toolbar = QToolBar() self._filter_box = QLineEdit() self._regex_box = QCheckBox() self._regex_box.setText('regex') self._toolbar.addWidget(QLabel('Filter')) self._toolbar.addWidget(self._filter_box) self._toolbar.addWidget(self._regex_box) self._filter_box.returnPressed.connect(self.update_filter) self._regex_box.stateChanged.connect(self.update_filter) # Create a container widget and give it a layout self._container = QWidget() self._container.setWindowTitle('Process Monitor') self._layout = QVBoxLayout() self._container.setLayout(self._layout) self._layout.addWidget(self._toolbar) # Create the table widget self._table_widget = QTreeWidget() self._table_widget.setObjectName('TopTable') self._table_widget.setColumnCount(len(self.NODE_LABELS)) self._table_widget.setHeaderLabels(self.NODE_LABELS) self._table_widget.itemClicked.connect(self._tableItemClicked) self._table_widget.setSortingEnabled(True) self._table_widget.setAlternatingRowColors(True) self._layout.addWidget(self._table_widget) context.add_widget(self._container) # Add a button for killing nodes self._kill_button = QPushButton('Kill Node') self._layout.addWidget(self._kill_button) self._kill_button.clicked.connect(self._kill_node) # Update twice since the first cpu% lookup will always return 0 self.update_table() self.update_table() self._table_widget.resizeColumnToContents(0) # Start a timer to trigger updates self._update_timer = QTimer() self._update_timer.setInterval(1000) self._update_timer.timeout.connect(self.update_table) self._update_timer.start() def _tableItemClicked(self, item, column): with self._selected_node_lock: self._selected_node = item.text(0) def update_filter(self, *args): if self._regex_box.isChecked(): expr = self._filter_box.text() else: expr = re.escape(self._filter_box.text()) self.name_filter = re.compile(expr) self.update_table() def _kill_node(self): self._node_info.kill_node(self._selected_node) def update_one_item(self, row, info): twi = TopWidgetItem() for col, field in enumerate(self.OUT_FIELDS): val = info[field] twi.setText(col, self.FORMAT_STRS[col] % val) self._table_widget.insertTopLevelItem(row, twi) for col, (key, func) in self.TOOLTIPS.iteritems(): twi.setToolTip(col, func(info[key])) with self._selected_node_lock: if twi.text(0) == self._selected_node: twi.setSelected(True) self._table_widget.setItemHidden(twi, len(self.name_filter.findall(info['node_name'])) == 0) def update_table(self): self._table_widget.clear() infos = self._node_info.get_all_node_fields(self.NODE_FIELDS) for nx, info in enumerate(infos): self.update_one_item(nx, info) def shutdown_plugin(self): self._update_timer.stop() def save_settings(self, plugin_settings, instance_settings): instance_settings.set_value('filter_text', self._filter_box.text()) instance_settings.set_value('is_regex', int(self._regex_box.checkState())) def restore_settings(self, plugin_settings, instance_settings): self._filter_box.setText(instance_settings.value('filter_text')) is_regex_int = instance_settings.value('is_regex') if is_regex_int: self._regex_box.setCheckState(Qt.CheckState(is_regex_int)) else: self._regex_box.setCheckState(Qt.CheckState(0)) self.update_filter()
def __init__(self, context): super(Top, self).__init__(context) # Give QObjects reasonable names self.setObjectName('Top') # Process standalone plugin command-line arguments from argparse import ArgumentParser parser = ArgumentParser() # Add argument(s) to the parser. parser.add_argument("-q", "--quiet", action="store_true", dest="quiet", help="Put plugin in silent mode") args, unknowns = parser.parse_known_args(context.argv()) # if not args.quiet: # print 'arguments: ', args # print 'unknowns: ', unknowns self._selected_node = '' self._selected_node_lock = RLock() # Setup the toolbar self._toolbar = QToolBar() self._filter_box = QLineEdit() self._regex_box = QCheckBox() self._regex_box.setText('regex') self._toolbar.addWidget(QLabel('Filter')) self._toolbar.addWidget(self._filter_box) self._toolbar.addWidget(self._regex_box) self._filter_box.returnPressed.connect(self.update_filter) self._regex_box.stateChanged.connect(self.update_filter) # Create a container widget and give it a layout self._container = QWidget() self._container.setWindowTitle('Process Monitor') self._layout = QVBoxLayout() self._container.setLayout(self._layout) self._layout.addWidget(self._toolbar) # Create the table widget self._table_widget = QTreeWidget() self._table_widget.setObjectName('TopTable') self._table_widget.setColumnCount(len(self.NODE_LABELS)) self._table_widget.setHeaderLabels(self.NODE_LABELS) self._table_widget.itemClicked.connect(self._tableItemClicked) self._table_widget.setSortingEnabled(True) self._table_widget.setAlternatingRowColors(True) self._layout.addWidget(self._table_widget) context.add_widget(self._container) # Add a button for killing nodes self._kill_button = QPushButton('Kill Node') self._layout.addWidget(self._kill_button) self._kill_button.clicked.connect(self._kill_node) # Update twice since the first cpu% lookup will always return 0 self.update_table() self.update_table() self._table_widget.resizeColumnToContents(0) # Start a timer to trigger updates self._update_timer = QTimer() self._update_timer.setInterval(1000) self._update_timer.timeout.connect(self.update_table) self._update_timer.start()