def __init__(self, masteruri, screen_name, nodename, user=None, parent=None): ''' Creates the window, connects the signals and init the class. ''' QWidget.__init__(self, parent) # load the UI file screen_dock_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'ui', 'logscreen', 'ScreenWidget.ui') loadUi(screen_dock_file, self) self.setObjectName("ScreenWidget") self.setWindowIcon(nm.settings().icon('crystal_clear_show_io.png')) # self.setFeatures(QDockWidget.DockWidgetFloatable | QDockWidget.DockWidgetMovable | QDockWidget.DockWidgetClosable) self.pauseButton.setIcon(nm.settings().icon('sekkyumu_pause.png')) self._valid = True self._logpath = '' self._lock = threading.RLock() self.finished = False self.qfile = None self.thread = None self._info = '' self._masteruri = '' self._nodename = nodename self._first_fill = True self._seek_start = -1 self._seek_end = -1 self._pause_read_end = False self._ssh_output_file = None self._ssh_error_file = None self._ssh_input_file = None self._on_pause = False self._char_format_end = None self.logframe.setVisible(False) self.loglevelButton.toggled.connect(self.on_toggle_loggers) self.logger_handler = None # connect to the button signals self.output.connect(self._on_output) self.output_prefix.connect(self._on_output_prefix) self.error_signal.connect(self._on_error) self.auth_signal.connect(self.on_request_pw) self.clearCloseButton.clicked.connect(self.clear) # self.pauseButton.clicked.connect(self.stop) self.pauseButton.toggled.connect(self.pause) self.clear_signal.connect(self.clear) self.loggerFilterInput.textChanged.connect(self.on_logger_filter_changed) self.textBrowser.verticalScrollBar().valueChanged.connect(self.on_scrollbar_position_changed) self.textBrowser.verticalScrollBar().rangeChanged.connect(self.on_scrollbar_range_changed) self.textBrowser.set_reader(self) self.tf = TerminalFormats() self.hl = ScreenHighlighter(self.textBrowser.document()) self.searchFrame.setVisible(False) self.grepFrame.setVisible(False) self.grepLineEdit.textChanged.connect(self.on_grep_changed) self._shortcut_search = QShortcut(QKeySequence(self.tr("Ctrl+F", "Activate search")), self) self._shortcut_search.activated.connect(self.on_search) self._shortcut_grep = QShortcut(QKeySequence(self.tr("Ctrl+G", "Activate grep")), self) self._shortcut_grep.activated.connect(self.on_grep) self.searchLineEdit.editingFinished.connect(self.on_search_prev) self.searchNextButton.clicked.connect(self.on_search_next) self.searchPrevButton.clicked.connect(self.on_search_prev) # self.visibilityChanged.connect(self.stop) self._connect(masteruri, screen_name, nodename, user)
def __init__(self, model, ui_file): super(NotesWidget, self).__init__() self._model = model loadUi(ui_file, self) self._model.rowsInserted.connect(self.update_status) self._model.rowsRemoved.connect(self.update_status) self.table_view.setModel(self._model) self.table_view.verticalScrollBar().rangeChanged.connect(self._handle_change_scroll) self._last_scroll_max = self.table_view.verticalScrollBar().maximum() self.input_field.returnPressed.connect(self._handle_insert_entry) self.take_button.clicked.connect(self._handle_start_take) self.load_button.clicked.connect(self._handle_load) self.save_button.clicked.connect(self._handle_save) self._delete_shortcut = QShortcut(QKeySequence('Delete'), self) self._delete_shortcut.activated.connect(self._delete_selected) self._load_shortcut = QShortcut(QKeySequence('Ctrl+O'), self) self._load_shortcut.activated.connect(self._handle_load) self._save_shortcut = QShortcut(QKeySequence('Ctrl+S'), self) self._save_shortcut.activated.connect(self._handle_save)
def __init__(self, model: QAbstractTableModel, ui_file: str, node: Node): """Initialize the NotesWidget. :param model :param ui_file Path to ui file. :param node Handle to a node, used for logging """ super(NotesWidget, self).__init__() self._model = model self._can_save = True self._has_autosave = True self._autosave_file = None save_path = f"{Path.home()}{self.SAVE_DIRECTORY_FROM_HOME}" if not os.path.exists(save_path): os.makedirs(save_path) self._last_save_file = ( f"{save_path}/note-taker" f"-{datetime.now().strftime('%Y-%m-%d-%H:%M')}") self._node = node loadUi(ui_file, self) self._model.rowsInserted.connect(lambda parent, first, last: [ self.update_status(), self._set_saved(False), self._autosave(first, last, self.INSERT), ]) self._model.rowsRemoved.connect(lambda parent, first, last: [ self.update_status(), self._set_saved(False), self._autosave(first, last, self.REMOVE), ]) self.table_view.setModel(self._model) self.table_view.verticalScrollBar().rangeChanged.connect( self._handle_change_scroll) self._last_scroll_max = self.table_view.verticalScrollBar().maximum() self.input_field.returnPressed.connect(self._handle_insert_entry) self.take_button.clicked.connect(self._handle_start_take) self.load_button.clicked.connect(self._handle_load) self.save_button.clicked.connect(self._handle_save) self.autosave_check_box.stateChanged.connect(self._handle_autosave) self.autosave_check_box.setChecked(self._has_autosave) self.autosave_check_box.setEnabled(False) self._delete_shortcut = QShortcut(QKeySequence("Delete"), self) self._delete_shortcut.activated.connect(self._delete_selected) self._load_shortcut = QShortcut(QKeySequence("Ctrl+O"), self) self._load_shortcut.activated.connect(self._handle_load) self._save_shortcut = QShortcut(QKeySequence("Ctrl+S"), self) self._save_shortcut.activated.connect(self._handle_save)
def _create_tag_menu(self, parent=None): # creates a tag menu tag_menu = QMenu("ROS Tags", parent) # group tag add_group_tag_action = QAction("<group>", self, statusTip="", triggered=self._on_add_group_tag) add_group_tag_action.setShortcuts(QKeySequence("Ctrl+Shift+g")) tag_menu.addAction(add_group_tag_action) # node tag add_node_tag_action = QAction("<node>", self, statusTip="", triggered=self._on_add_node_tag) add_node_tag_action.setShortcuts(QKeySequence("Ctrl+Shift+n")) tag_menu.addAction(add_node_tag_action) # node tag with all attributes add_node_tag_all_action = QAction("<node all>", self, statusTip="", triggered=self._on_add_node_tag_all) tag_menu.addAction(add_node_tag_all_action) # include tag with all attributes add_include_tag_all_action = QAction("<include>", self, statusTip="", triggered=self._on_add_include_tag_all) add_include_tag_all_action.setShortcuts(QKeySequence("Ctrl+Shift+i")) tag_menu.addAction(add_include_tag_all_action) # remap add_remap_tag_action = QAction("<remap>", self, statusTip="", triggered=self._on_add_remap_tag) add_remap_tag_action.setShortcuts(QKeySequence("Ctrl+Shift+r")) tag_menu.addAction(add_remap_tag_action) # env tag add_env_tag_action = QAction("<env>", self, statusTip="", triggered=self._on_add_env_tag) tag_menu.addAction(add_env_tag_action) # param tag add_param_tag_action = QAction("<param>", self, statusTip="", triggered=self._on_add_param_tag) add_param_tag_action.setShortcuts(QKeySequence("Ctrl+Shift+p")) tag_menu.addAction(add_param_tag_action) # param capability group tag add_param_cap_group_tag_action = QAction("<param capability group>", self, statusTip="", triggered=self._on_add_param_cap_group_tag) add_param_cap_group_tag_action.setShortcuts(QKeySequence("Ctrl+Alt+p")) tag_menu.addAction(add_param_cap_group_tag_action) # param tag with all attributes add_param_tag_all_action = QAction("<param all>", self, statusTip="", triggered=self._on_add_param_tag_all) tag_menu.addAction(add_param_tag_all_action) # rosparam tag with all attributes add_rosparam_tag_all_action = QAction("<rosparam>", self, statusTip="", triggered=self._on_add_rosparam_tag_all) tag_menu.addAction(add_rosparam_tag_all_action) # arg tag with default definition add_arg_tag_default_action = QAction("<arg default>", self, statusTip="", triggered=self._on_add_arg_tag_default) add_arg_tag_default_action.setShortcuts(QKeySequence("Ctrl+Shift+a")) tag_menu.addAction(add_arg_tag_default_action) # arg tag with value definition add_arg_tag_value_action = QAction("<arg value>", self, statusTip="", triggered=self._on_add_arg_tag_value) add_arg_tag_value_action.setShortcuts(QKeySequence("Ctrl+Alt+a")) tag_menu.addAction(add_arg_tag_value_action) # test tag add_test_tag_action = QAction("<test>", self, statusTip="", triggered=self._on_add_test_tag) add_test_tag_action.setShortcuts(QKeySequence("Ctrl+Alt+t")) tag_menu.addAction(add_test_tag_action) # test tag with all attributes add_test_tag_all_action = QAction("<test all>", self, statusTip="", triggered=self._on_add_test_tag_all) tag_menu.addAction(add_test_tag_all_action) return tag_menu
def __init__(self, context): super(ConversationViewPlugin, self).__init__(context) self.setObjectName('ConversationViewPlugin') self._widget = QWidget() if context.serial_number() > 1: self._widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % context.serial_number())) ui_file = os.path.join( rospkg.RosPack().get_path('rqt_conversation_view'), 'resource', 'conversation_view.ui') loadUi(ui_file, self._widget) context.add_widget(self._widget) self.send_shortcut = QShortcut(QKeySequence("Ctrl+Return"), self._widget, self.handle_button_send) self._widget.buttonSend.clicked.connect(self.handle_button_send) self._widget.textInput.setFocus() self.signalAddItem.connect(self.add_item_to_conversation_view) self.pub_input = rospy.Publisher('recognized_word', RecognizedWord, queue_size=10) rospy.Subscriber('raising_events', RaisingEvents, self.handle_raising_events) rospy.Subscriber('reply', Reply, self.handle_reply)
def show_custom_context_menu(self, pos): if self.isReadOnly(): return menu = QTextEdit.createStandardContextMenu(self) formattext_action = None if isinstance(self.hl, XmlHighlighter): formattext_action = QAction("Format XML", self, statusTip="", triggered=self.toprettyxml) else: formattext_action = QAction("Format as YAML", self, statusTip="", triggered=self.toprettyyaml) formattext_action.setShortcuts(QKeySequence("Ctrl+Shift+F")) menu.addAction(formattext_action) # if not self.textCursor().selectedText(): # self.setTextCursor(self.cursorForPosition(pos)) submenu = self._create_context_menu_for_tag() if submenu is not None: menu.addMenu(submenu) argmenu = self._create_context_substitution_menu() if argmenu is not None: menu.addMenu(argmenu) menu.exec_(self.mapToGlobal(pos))
def action_connect(self): ''' Connects the actions in the top bar to the corresponding functions, and sets their shortcuts :return: ''' self._widget.actionNew.triggered.connect(self.new) self._widget.actionOpen.triggered.connect(self.open) self._widget.actionSave.triggered.connect(self.save) self._widget.actionSave_as.triggered.connect(self.save_as) self._widget.actionInit.triggered.connect(self.goto_init) self._widget.actionCurrent_Frame.triggered.connect(self.goto_frame) self._widget.actionNext_Frame.triggered.connect(self.goto_next) self._widget.actionAnimation.triggered.connect(self.play) self._widget.actionAnimation_until_Frame.triggered.connect(self.play_until) self._widget.actionDuplicate_Frame.triggered.connect(self.duplicate) self._widget.actionDelete_Frame.triggered.connect(self.delete) self._widget.actionLeft.triggered.connect(lambda: self.mirrorFrame("L")) self._widget.actionRight.triggered.connect(lambda: self.mirrorFrame("R")) self._widget.actionInvert.triggered.connect(self.invertFrame) self._widget.actionUndo.triggered.connect(self.undo) self._widget.actionRedo.triggered.connect(self.redo) self._widget.actionHelp.triggered.connect(self.help) self._widget.buttonRecord.clicked.connect(self.record) self._widget.buttonRecord.shortcut = QShortcut(QKeySequence("Space"), self._widget) self._widget.buttonRecord.shortcut.activated.connect(self.record) self._widget.frameList.keyPressed.connect(self.delete) self._widget.treeModeSelector.currentIndexChanged.connect(self.treeModeChanged)
def __init__(self, model, ui_file): super(NotesWidget, self).__init__() self._model = model self._can_save = True self._has_autosave = True self._autosave_file = None self._last_save_file = None loadUi(ui_file, self) self._model.rowsInserted.connect(lambda parent, first, last: [ self.update_status(), self._set_saved(False), self._autosave(first, last, self.INSERT) ]) self._model.rowsRemoved.connect(lambda parent, first, last: [ self.update_status(), self._set_saved(False), self._autosave(first, last, self.REMOVE) ]) self.table_view.setModel(self._model) self.table_view.verticalScrollBar().rangeChanged.connect( self._handle_change_scroll) self._last_scroll_max = self.table_view.verticalScrollBar().maximum() self.input_field.returnPressed.connect(self._handle_insert_entry) self.take_button.clicked.connect(self._handle_start_take) self.load_button.clicked.connect(self._handle_load) self.save_button.clicked.connect(self._handle_save) self.autosave_check_box.stateChanged.connect(self._handle_autosave) self.autosave_check_box.setChecked(self._has_autosave) self.autosave_check_box.setEnabled(False) self._delete_shortcut = QShortcut(QKeySequence('Delete'), self) self._delete_shortcut.activated.connect(self._delete_selected) self._load_shortcut = QShortcut(QKeySequence('Ctrl+O'), self) self._load_shortcut.activated.connect(self._handle_load) self._save_shortcut = QShortcut(QKeySequence('Ctrl+S'), self) self._save_shortcut.activated.connect(self._handle_save)
def __init__(self, node): super(ExamplesWidget, self).__init__() self.setObjectName('ExamplesWidget') self.node = node pkg_name = 'examples_rqt' ui_filename = 'examples_rqt.ui' topic_name = 'cmd_vel' service_name = 'led_control' _, package_path = get_resource('packages', pkg_name) ui_file = os.path.join(package_path, 'share', pkg_name, 'resource', ui_filename) loadUi(ui_file, self) self.pub_velocity = Twist() self.pub_velocity.linear.x = 0.0 self.pub_velocity.angular.z = 0.0 self.sub_velocity = Twist() self.sub_velocity.linear.x = 0.0 self.sub_velocity.angular.z = 0.0 self.slider_x.setValue(0) self.lcd_number_x.display(0.0) self.lcd_number_yaw.display(0.0) qos_profile = 0 qos = self.get_qos(qos_profile) self.publisher = self.node.create_publisher(Twist, topic_name, qos) self.subscriber = self.node.create_subscription(Twist, topic_name, self.cmd_callback, qos) self.service_server = self.node.create_service(SetBool, service_name, self.srv_callback) self.service_client = self.node.create_client(SetBool, service_name) update_timer = QTimer(self) update_timer.timeout.connect(self.update_data) update_timer.start(self.redraw_interval) self.push_button_w.pressed.connect(self.on_increase_x_linear_pressed) self.push_button_x.pressed.connect(self.on_decrease_x_linear_pressed) self.push_button_a.pressed.connect(self.on_increase_z_angular_pressed) self.push_button_d.pressed.connect(self.on_decrease_z_angular_pressed) self.push_button_s.pressed.connect(self.on_stop_pressed) self.radio_button_led_on.clicked.connect(self.call_led_service) self.radio_button_led_off.clicked.connect(self.call_led_service) self.push_button_w.setShortcut('w') self.push_button_x.setShortcut('x') self.push_button_a.setShortcut('a') self.push_button_d.setShortcut('d') self.push_button_s.setShortcut('s') self.shortcut_space = QShortcut(QKeySequence(Qt.Key_Space), self) self.shortcut_space.setContext(Qt.ApplicationShortcut) self.shortcut_space.activated.connect(self.push_button_s.pressed) self.radio_button_led_on.setShortcut('o') self.radio_button_led_off.setShortcut('f')
def add_buttons(self, colors): vbx = QVBoxLayout() i = 1 for color in colors: but = QPushButton('Color {} ({})'.format(color, i)) but.clicked.connect(self.clicked(color)) but_short = QShortcut(QKeySequence("Ctrl+" + str(i)), self) but_short.activated.connect(self.clicked(color)) i += 1 vbx.addWidget(but) vbx.addStretch(1) self.color_buttons.setLayout(vbx)
def __init__(self, menu_button): QMenu.__init__(self) self.button = menu_button try: rqt_icon_path = roslib.packages.find_resource( 'rqt_gui', 'rqt.png').pop() menu_button.setText('') menu_button.setIcon(QIcon(rqt_icon_path)) # creates a default config menu self.action_rqt_console = QAction( QIcon.fromTheme('mail-message-new'), "&Console", self, statusTip= '"<p>Starts a python GUI plugin for displaying and filtering ' 'ROS log messages that is connected to the selected master.</p>"', triggered=self.on_show_console_clicked) self.addAction(self.action_rqt_console) self.action_rqt_logger_level = QAction( QIcon.fromTheme('format-indent-more'), "&Logger Level", self, statusTip= '"<p>Starts a python GUI plugin for configuring the level of ' 'ROS loggers that is connected to the selected master.</p>"', triggered=self.on_show_logger_level_clicked) self.addAction(self.action_rqt_logger_level) self.action_rqt_tf_tree = QAction( QIcon.fromTheme('preferences-system-network'), "&TF Tree", self, statusTip= '"<p>Starts a python GUI plugin for visualizing the TF tree' 'that is connected to the selected master.</p>"', triggered=self.on_show_tf_tree_clicked) self.addAction(self.action_rqt_tf_tree) self.action_rqt_ros_graph = QAction( QIcon(":/icons/button_graph.png"), "Ros &Graph", self, statusTip= '"<p>Starts a python GUI plugin for visualizing the ROS computation graph' 'that is connected to the selected master</p>"', triggered=self.on_show_ros_graph_clicked) self.addAction(self.action_rqt_ros_graph) self.action_rosbag_record = QAction( QIcon.fromTheme('media-record'), "rosbag record", self, statusTip= '"<p>Starts the rosbag record with selected topics</p>"', triggered=self.on_start_rosbag_clicked) self.addAction(self.action_rosbag_record) self.action_rqt_rviz = QAction(QIcon.fromTheme('image-x-generic'), "R&Viz", self, statusTip='"<p>Starts RViz</p>"', triggered=self.on_show_rviz_clicked) self.addAction(self.action_rqt_rviz) self.addSeparator() self.action_rqt = QAction( QIcon(rqt_icon_path), "&Rqt GUI", self, statusTip='"<p>Start the rqt GUI' 'that is connected to the selected master</p>"', triggered=self.on_start_rqt_clicked) self.addAction(self.action_rqt) self.action_terminal = QAction( QIcon(":/icons/crystal_clear_show_io.png"), "&Terminal", self, statusTip='"<p>Start terminal on selected host</p>"', triggered=self.on_start_terminal) self.action_terminal.setShortcut(QKeySequence("Ctrl+T")) self.addAction(self.action_terminal) menu_button.setMenu(self) except Exception as e: print('%s' % e) menu_button.setEnabled(False) menu_button.setToolTip( 'rqt_gui not found! Please install rqt to use its plugins!')
def __init__(self, context): super(RobotSteering, self).__init__(context) self.setObjectName('RobotSteering') self._publisher = None self._widget = QWidget() ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'RobotSteering.ui') loadUi(ui_file, self._widget) self._widget.setObjectName('RobotSteeringUi') if context.serial_number() > 1: self._widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % context.serial_number())) context.add_widget(self._widget) self._widget.topic_line_edit.textChanged.connect( self._on_topic_changed) self._widget.x_linear_slider.valueChanged.connect( self._on_parameter_changed) self._widget.z_angular_slider.valueChanged.connect( self._on_parameter_changed) self._widget.increase_x_linear_push_button.pressed.connect( self._on_increase_x_linear_pressed) self._widget.decrease_x_linear_push_button.pressed.connect( self._on_decrease_x_linear_pressed) self._widget.increase_z_angular_push_button.pressed.connect( self._on_increase_z_angular_pressed) self._widget.decrease_z_angular_push_button.pressed.connect( self._on_decrease_z_angular_pressed) self._widget.stop_push_button.pressed.connect(self._on_stop_pressed) self.shortcut_w = QShortcut(QKeySequence(Qt.Key_W), self._widget) self.shortcut_w.setContext(Qt.ApplicationShortcut) self.shortcut_w.activated.connect(self._on_increase_x_linear_pressed) self.shortcut_s = QShortcut(QKeySequence(Qt.Key_S), self._widget) self.shortcut_s.setContext(Qt.ApplicationShortcut) self.shortcut_s.activated.connect(self._on_decrease_x_linear_pressed) self.shortcut_a = QShortcut(QKeySequence(Qt.Key_A), self._widget) self.shortcut_a.setContext(Qt.ApplicationShortcut) self.shortcut_a.activated.connect(self._on_increase_z_angular_pressed) self.shortcut_d = QShortcut(QKeySequence(Qt.Key_D), self._widget) self.shortcut_d.setContext(Qt.ApplicationShortcut) self.shortcut_d.activated.connect(self._on_decrease_z_angular_pressed) self.shortcut_shift_w = QShortcut(QKeySequence(Qt.SHIFT + Qt.Key_W), self._widget) self.shortcut_shift_w.setContext(Qt.ApplicationShortcut) self.shortcut_shift_w.activated.connect( self._on_strong_increase_x_linear_pressed) self.shortcut_shift_s = QShortcut(QKeySequence(Qt.SHIFT + Qt.Key_S), self._widget) self.shortcut_shift_s.setContext(Qt.ApplicationShortcut) self.shortcut_shift_s.activated.connect( self._on_strong_decrease_x_linear_pressed) self.shortcut_shift_a = QShortcut(QKeySequence(Qt.SHIFT + Qt.Key_A), self._widget) self.shortcut_shift_a.setContext(Qt.ApplicationShortcut) self.shortcut_shift_a.activated.connect( self._on_strong_increase_z_angular_pressed) self.shortcut_shift_d = QShortcut(QKeySequence(Qt.SHIFT + Qt.Key_D), self._widget) self.shortcut_shift_d.setContext(Qt.ApplicationShortcut) self.shortcut_shift_d.activated.connect( self._on_strong_decrease_z_angular_pressed) self.shortcut_space = QShortcut(QKeySequence(Qt.Key_Space), self._widget) self.shortcut_space.setContext(Qt.ApplicationShortcut) self.shortcut_space.activated.connect(self._on_stop_pressed) # timer to consecutively send twist messages self._update_parameter_timer = QTimer(self) self._update_parameter_timer.timeout.connect( self._on_parameter_changed) self._update_parameter_timer.start(100)
def __init__(self): super(MyWidget, self).__init__() self.brd = CvBridge() self.view = RGB ui_file = os.path.join( rospkg.RosPack().get_path('balloon_color_picker'), 'resource', 'ColorPlugin.ui') rospy.loginfo('uifile {}'.format(ui_file)) # self.log_info('uifile {}'.format(ui_file)) loadUi(ui_file, self) # Give QObjects reasonable names self.setObjectName('ColorPluginUi') self.uav_name = os.environ['UAV_NAME'] self.orig_h = 920 self.orig_w = 1080 self.hist_hsv_orig_h = 180 self.hist_hsv_orig_w = 256 self.hist_lab_orig_h = 256 self.hist_lab_orig_w = 256 self.hist_status = HSV self.select_status = HIST_SELECTION self.crop_stat = IMG self.hist_mask = np.zeros([self.hist_hsv_orig_h, self.hist_hsv_orig_w]) self.hist_mask_lab = np.zeros( [self.hist_lab_orig_h, self.hist_lab_orig_w]) self.cur_hist_hs = None self.cur_hist_ab = None self.selected_count = 0 # ROS services # #{ ros services self.sigma_caller = rospy.ServiceProxy('change_sigma', ChangeSigma) self.sigma_lab_caller = rospy.ServiceProxy('change_sigma_lab', ChangeSigmaLab) self.caller = rospy.ServiceProxy('capture', Capture) self.capture_cropped_srv = rospy.ServiceProxy('capture_cropped', CaptureCropped) self.get_count = rospy.ServiceProxy('get_count', GetCount) self.clear_count = rospy.ServiceProxy('clear_count', ClearCount) self.get_config = rospy.ServiceProxy('get_config', GetConfig) self.get_params = rospy.ServiceProxy('get_params', Params) self.freeze_service = rospy.ServiceProxy('freeze', Freeze) self.update_service = rospy.ServiceProxy('change_obd', UpdateObd) self.change_callback = rospy.ServiceProxy('change_callback', ChangeCallback) self.capture_hist = rospy.ServiceProxy('capture_hist', CaptureHist) # #} end of ros services rospy.wait_for_service('capture') rospy.loginfo( 'waiting for service "get_params" from computation module \n if this is more than 5 secs check for topic remapping' ) # self.log_info('waiting for service') rospy.loginfo('uav_name {}'.format(os.environ['UAV_NAME'])) # self.log_info('uav_name {}'.format(os.environ['UAV_NAME'])) rospy.wait_for_service('get_params') self.config_path, self.save_path, self.circled_param, self.circle_filter_param, self.circle_luv_param, self.object_detect_param, self.save_to_drone = self.set_params( ) # SUBS # #{ ros subs self.balloon_sub = rospy.Subscriber(self.circled_param, RosImg, self.img_callback, queue_size=1) self.filter_sub = rospy.Subscriber(self.circle_filter_param, RosImg, self.filter_callback, queue_size=1) self.filter_luv = rospy.Subscriber(self.circle_luv_param, RosImg, self.luv_callback, queue_size=1) self.obj_det_sb = rospy.Subscriber(self.object_detect_param, RosImg, self.obj_det_callback, queue_size=1) # self.hsv = message_filters.Subscriber(self.circle_filter_param, RosImg) # self.luv = message_filters.Subscriber(self.circle_luv_param, RosImg) # self.ts = message_filters.ApproximateTimeSynchronizer([self.luv, self.hsv], 1, 0.5) # self.ts.registerCallback(self.both_callback) # #} end of ros subs self.colors = self.load_config(self.config_path) self.add_buttons(self.colors) # # DEFAULT IMAGE # img = cv2.imread('/home/mrs/balloon_workspace/src/ros_packages/balloon_color_picker/data/blue.png') # cv2.cvtColor(img, cv2.COLOR_BGR2RGB) # h,w,c = img.shape # q_img = QImage(img.data, w,h,3*w, QImage.Format_RGB888) # q = QPixmap.fromImage(q_img) #DIRECTORY #default self.directory.setText(self.save_path + "Red.yaml") self.color_name = "red" self.save_button.clicked.connect(self.save_config) #PLOT self.figure = Figure() self.figure_luv = Figure() self.canvas = FigureCanvas(self.figure) self.canvas_luv = FigureCanvas(self.figure_luv) self.canvas.setParent(self.inner) # self.toolbar = NavigationToolbar(self.canvas,self) # self.toolbar_luv = NavigationToolbar(self.canvas_luv,self) # self.toolbar.setParent(self.inner) # self.toolbar_luv.setParent(self.inner_luv) self.canvas_luv.setParent(self.inner_luv) self.inner_luv.hide() self.inner_luv_hist.hide() #SLIDER CONFIG # #{ slider config self.sigma_slider.setRange(0, 100) self.sigma_slider.setSingleStep(1) self.sigma_slider.setValue(6) self.sigma_slider.valueChanged.connect(self.slider_event) self.sigma_slider_s.setRange(0, 100) self.sigma_slider_s.setSingleStep(1) self.sigma_slider_s.setValue(6) self.sigma_slider_s.valueChanged.connect(self.slider_event) self.sigma_slider_v.setRange(0, 100) self.sigma_slider_v.setSingleStep(1) self.sigma_slider_v.setValue(80) self.sigma_slider_v.valueChanged.connect(self.slider_event) self.sigma_slider_lab.setRange(0, 100) self.sigma_slider_lab.setSingleStep(1) self.sigma_slider_lab.setValue(80) self.sigma_slider_lab.valueChanged.connect(self.slider_event_lab) self.sigma_slider_a.setRange(0, 100) self.sigma_slider_a.setSingleStep(1) self.sigma_slider_a.setValue(6) self.sigma_slider_a.valueChanged.connect(self.slider_event_lab) self.sigma_slider_b.setRange(0, 100) self.sigma_slider_b.setSingleStep(1) self.sigma_slider_b.setValue(6) self.sigma_slider_b.valueChanged.connect(self.slider_event_lab) # #} end of slider config # #{ font configs #SIGMA TEXT font = self.font() font.setPointSize(16) self.sigma_value.setFont(font) self.sigma_value_s.setFont(font) self.sigma_value_v.setFont(font) self.sigma_value_lab.setFont(font) self.sigma_value_a.setFont(font) self.sigma_value_b.setFont(font) #IMAGE COUNT TEXT self.image_count.setFont(font) #BOX FOR BUTTONS font # self.color_buttons.setFont(font) font.setPointSize(14) self.sigma_value.setFont(font) self.log_text.setFont(font) #LAB HSV TEXT font.setPointSize(23) self.label_lab.setFont(font) self.label_lab.hide() self.label_hsv.setFont(font) self.label_hsv.hide() # #} end of font configs # BUTTONS self.change.clicked.connect(self.switch_view_hsv) self.change_both.clicked.connect(self.switch_view_both) self.change_luv.clicked.connect(self.switch_view_luv) self.change_object.clicked.connect(self.switch_view_object_detect) self.capture_button.clicked.connect(self.capture) self.clear_button.clicked.connect(self.clear) self.freeze_button.clicked.connect(self.freeze) self.update_button.clicked.connect(self.update_obd) # self.wdg_img.setPixmap(q) # self.box_layout.addWidget(self.toolbar) # self.inner.box_layout.addWidget(self.canvas) #shortcuts self.short_capture = QShortcut(QKeySequence("C"), self) self.short_capture.activated.connect(self.capture) self.short_hsv = QShortcut(QKeySequence("1"), self) self.short_hsv.activated.connect(self.switch_view_hsv) self.short_lab = QShortcut(QKeySequence("2"), self) self.short_lab.activated.connect(self.switch_view_luv) self.short_object_detect = QShortcut(QKeySequence("3"), self) self.short_object_detect.activated.connect( self.switch_view_object_detect) self.short_object_detect_update = QShortcut(QKeySequence("U"), self) self.short_object_detect_update.activated.connect(self.update_obd) self.short_both = QShortcut(QKeySequence("4"), self) self.short_both.activated.connect(self.switch_view_both) self.short_save = QShortcut(QKeySequence("S"), self) self.short_save.activated.connect(self.save_config) self.short_clear = QShortcut(QKeySequence("N"), self) self.short_clear.activated.connect(self.clear) self.short_freeze = QShortcut(QKeySequence("F"), self) self.short_freeze.activated.connect(self.freeze) vbx = QVBoxLayout() but_hsv = QRadioButton() but_hsv.setText('HSV') but_hsv.setChecked(True) self.color_space = 'HSV' but_hsv.clicked.connect(self.set_colorspace_hsv) vbx.addWidget(but_hsv) but_lab = QRadioButton() but_lab.setText('LAB') but_lab.clicked.connect(self.set_colorspace_lab) vbx.addWidget(but_lab) vbx.addStretch(1) self.radio_buttons.setLayout(vbx) vbx_method = QVBoxLayout() but_lut = QRadioButton() but_lut.setText('LUT') but_lut.setChecked(False) but_lut.clicked.connect(self.set_method_lut) vbx_method.addWidget(but_lut) but_thr = QRadioButton() but_thr.setText('Threshold') but_thr.setChecked(True) but_thr.clicked.connect(self.set_method_thr) vbx_method.addWidget(but_thr) vbx.addStretch(1) self.radio_buttons_method.setLayout(vbx_method) self.load_method = 'THR' # self.mousePressEvent.connect(self.mousePressEvent) self.plotted = False self._rubber = None self.frozen = False
def _create_tag_menu(self, parent=None): # creates a tag menu tag_menu = QMenu("ROS Tags", parent) # group tag add_group_tag_action = QAction("<group>", self, statusTip="", triggered=self._on_add_group_tag) add_group_tag_action.setShortcuts(QKeySequence("Ctrl+Shift+g")) tag_menu.addAction(add_group_tag_action) # node tag add_node_tag_action = QAction("<node>", self, statusTip="", triggered=self._on_add_node_tag) add_node_tag_action.setShortcuts(QKeySequence("Ctrl+Shift+n")) tag_menu.addAction(add_node_tag_action) # node tag with all attributes add_node_tag_all_action = QAction("<node all>", self, statusTip="", triggered=self._on_add_node_tag_all) tag_menu.addAction(add_node_tag_all_action) # include tag with all attributes add_include_tag_all_action = QAction("<include>", self, statusTip="", triggered=self._on_add_include_tag_all) add_include_tag_all_action.setShortcuts(QKeySequence("Ctrl+Shift+i")) tag_menu.addAction(add_include_tag_all_action) # remap add_remap_tag_action = QAction("<remap>", self, statusTip="", triggered=self._on_add_remap_tag) add_remap_tag_action.setShortcuts(QKeySequence("Ctrl+Shift+r")) tag_menu.addAction(add_remap_tag_action) # env tag add_env_tag_action = QAction("<env>", self, statusTip="", triggered=self._on_add_env_tag) tag_menu.addAction(add_env_tag_action) # param tag add_param_clipboard_tag_action = QAction("<param value>", self, statusTip="add value from clipboard", triggered=self._on_add_param_clipboard_tag) add_param_clipboard_tag_action.setShortcuts(QKeySequence("Ctrl+Shift+p")) tag_menu.addAction(add_param_clipboard_tag_action) add_param_tag_action = QAction("<param>", self, statusTip="", triggered=self._on_add_param_tag) add_param_tag_action.setShortcuts(QKeySequence("Ctrl+Shift+Alt+p")) tag_menu.addAction(add_param_tag_action) # param tag with all attributes add_param_tag_all_action = QAction("<param all>", self, statusTip="", triggered=self._on_add_param_tag_all) tag_menu.addAction(add_param_tag_all_action) # rosparam tag with all attributes add_rosparam_tag_all_action = QAction("<rosparam>", self, statusTip="", triggered=self._on_add_rosparam_tag_all) tag_menu.addAction(add_rosparam_tag_all_action) # arg tag with default definition add_arg_tag_default_action = QAction("<arg default>", self, statusTip="", triggered=self._on_add_arg_tag_default) add_arg_tag_default_action.setShortcuts(QKeySequence("Ctrl+Shift+a")) tag_menu.addAction(add_arg_tag_default_action) # arg tag with value definition add_arg_tag_value_action = QAction("<arg value>", self, statusTip="", triggered=self._on_add_arg_tag_value) add_arg_tag_value_action.setShortcuts(QKeySequence("Ctrl+Alt+a")) tag_menu.addAction(add_arg_tag_value_action) # test tag add_test_tag_action = QAction("<test>", self, statusTip="", triggered=self._on_add_test_tag) add_test_tag_action.setShortcuts(QKeySequence("Ctrl+Alt+t")) tag_menu.addAction(add_test_tag_action) # test tag with all attributes add_test_tag_all_action = QAction("<test all>", self, statusTip="", triggered=self._on_add_test_tag_all) tag_menu.addAction(add_test_tag_all_action) sub_cp_menu = QMenu("Custom parameters", parent) show_cp_dialog_action = QAction("Show Dialog", self, statusTip="", triggered=self._show_custom_parameter_dialog) show_cp_dialog_action.setShortcuts(QKeySequence("Ctrl+Shift+d")) sub_cp_menu.addAction(show_cp_dialog_action) add_cp_associations_action = QAction("nm/associations", self, statusTip="", triggered=self._on_add_cp_associations) add_cp_associations_action.setShortcuts(QKeySequence("Ctrl+Alt+a")) sub_cp_menu.addAction(add_cp_associations_action) sub_cp_as_menu = QMenu("Autostart", parent) add_cp_as_delay_action = QAction("delay", self, statusTip="", triggered=self._on_add_cp_as_delay) sub_cp_as_menu.addAction(add_cp_as_delay_action) add_cp_as_exclude_action = QAction("exclude", self, statusTip="", triggered=self._on_add_cp_as_exclude) sub_cp_as_menu.addAction(add_cp_as_exclude_action) add_cp_as_req_publisher_action = QAction("required publisher", self, statusTip="", triggered=self._on_add_cp_as_req_publisher) sub_cp_as_menu.addAction(add_cp_as_req_publisher_action) sub_cp_menu.addMenu(sub_cp_as_menu) sub_cp_r_menu = QMenu("Respawn", parent) add_cp_r_max_action = QAction("max", self, statusTip="", triggered=self._on_add_cp_r_max) sub_cp_r_menu.addAction(add_cp_r_max_action) add_cp_r_min_runtime_action = QAction("min_runtime", self, statusTip="", triggered=self._on_add_cp_r_min_runtime) sub_cp_r_menu.addAction(add_cp_r_min_runtime_action) add_cp_r_delay_action = QAction("delay", self, statusTip="", triggered=self._on_add_cp_r_delay) sub_cp_r_menu.addAction(add_cp_r_delay_action) sub_cp_menu.addMenu(sub_cp_r_menu) add_cp_capability_group_action = QAction("capability_group", self, statusTip="", triggered=self._on_add_cp_capability_group) add_cp_capability_group_action.setShortcuts(QKeySequence("Ctrl+Alt+p")) sub_cp_menu.addAction(add_cp_capability_group_action) add_cp_kill_on_stop_action = QAction("nm/kill_on_stop", self, statusTip="True or time to wait in ms", triggered=self._on_add_cp_kill_on_stop) add_cp_kill_on_stop_action.setShortcuts(QKeySequence("Ctrl+Shift+k")) sub_cp_menu.addAction(add_cp_kill_on_stop_action) tag_menu.addMenu(sub_cp_menu) return tag_menu
def initialize_shortcuts(self): self.ctrl_z = QShortcut(QKeySequence(self.tr("Ctrl+Z")), self) self.ctrl_shift_z = QShortcut(QKeySequence(self.tr("Ctrl+Shift+Z")), self)
def __init__(self, context): super(EUFSRobotSteeringGUI, self).__init__(context) self.setObjectName('EUFSRobotSteeringGUI') rp = rospkg.RosPack() # Create QWidget self._widget = QWidget() # Get path to UI file which is a sibling of this file ui_file = os.path.join(rp.get_path('ros_can_sim'), 'resource', 'EUFSRobotSteeringGUI.ui') # Extend the widget with all attributes and children from UI file loadUi(ui_file, self._widget) self._widget.setObjectName('EUFSRobotSteeringGUI') # Show _widget.windowTitle on left-top of each plugin (when # it's set in _widget). This is useful when you open multiple # plugins at once. Also if you open multiple instances of your # plugin at once, these lines add number to make it easy to # tell from pane to pane. if context.serial_number() > 1: self._widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % context.serial_number())) # Add widget to the user interface context.add_widget(self._widget) self._publisher = None self.inputs = ["Speed", "Acceleration", "Jerk"] self._widget.input_select_menu.addItems(self.inputs) self._widget.input_select_menu.setCurrentIndex(1) self._widget.topic_line_edit.textChanged.connect( self._on_topic_changed) self._widget.stop_push_button.pressed.connect(self._on_stop_pressed) self._widget.linear_slider.valueChanged.connect( self._on_linear_slider_changed) self._widget.angular_slider.valueChanged.connect( self._on_angular_slider_changed) self._widget.increase_linear_push_button.pressed.connect( self._on_strong_increase_linear_pressed) self._widget.reset_linear_push_button.pressed.connect( self._on_reset_linear_pressed) self._widget.decrease_linear_push_button.pressed.connect( self._on_strong_decrease_linear_pressed) self._widget.increase_angular_push_button.pressed.connect( self._on_strong_increase_angular_pressed) self._widget.reset_angular_push_button.pressed.connect( self._on_reset_angular_pressed) self._widget.decrease_angular_push_button.pressed.connect( self._on_strong_decrease_angular_pressed) self._widget.max_linear_double_spin_box.valueChanged.connect( self._on_max_linear_changed) self._widget.min_linear_double_spin_box.valueChanged.connect( self._on_min_linear_changed) self._widget.max_angular_double_spin_box.valueChanged.connect( self._on_max_angular_changed) self._widget.min_angular_double_spin_box.valueChanged.connect( self._on_min_angular_changed) self.shortcut_w = QShortcut(QKeySequence(Qt.Key_W), self._widget) self.shortcut_w.setContext(Qt.ApplicationShortcut) self.shortcut_w.activated.connect(self._on_increase_linear_pressed) self.shortcut_x = QShortcut(QKeySequence(Qt.Key_X), self._widget) self.shortcut_x.setContext(Qt.ApplicationShortcut) self.shortcut_x.activated.connect(self._on_reset_linear_pressed) self.shortcut_s = QShortcut(QKeySequence(Qt.Key_S), self._widget) self.shortcut_s.setContext(Qt.ApplicationShortcut) self.shortcut_s.activated.connect(self._on_decrease_linear_pressed) self.shortcut_a = QShortcut(QKeySequence(Qt.Key_A), self._widget) self.shortcut_a.setContext(Qt.ApplicationShortcut) self.shortcut_a.activated.connect(self._on_increase_angular_pressed) self.shortcut_z = QShortcut(QKeySequence(Qt.Key_Z), self._widget) self.shortcut_z.setContext(Qt.ApplicationShortcut) self.shortcut_z.activated.connect(self._on_reset_angular_pressed) self.shortcut_d = QShortcut(QKeySequence(Qt.Key_D), self._widget) self.shortcut_d.setContext(Qt.ApplicationShortcut) self.shortcut_d.activated.connect(self._on_decrease_angular_pressed) self.shortcut_shift_w = QShortcut(QKeySequence(Qt.SHIFT + Qt.Key_W), self._widget) self.shortcut_shift_w.setContext(Qt.ApplicationShortcut) self.shortcut_shift_w.activated.connect( self._on_strong_increase_linear_pressed) self.shortcut_shift_x = QShortcut(QKeySequence(Qt.SHIFT + Qt.Key_X), self._widget) self.shortcut_shift_x.setContext(Qt.ApplicationShortcut) self.shortcut_shift_x.activated.connect(self._on_reset_linear_pressed) self.shortcut_shift_s = QShortcut(QKeySequence(Qt.SHIFT + Qt.Key_S), self._widget) self.shortcut_shift_s.setContext(Qt.ApplicationShortcut) self.shortcut_shift_s.activated.connect( self._on_strong_decrease_linear_pressed) self.shortcut_shift_a = QShortcut(QKeySequence(Qt.SHIFT + Qt.Key_A), self._widget) self.shortcut_shift_a.setContext(Qt.ApplicationShortcut) self.shortcut_shift_a.activated.connect( self._on_strong_increase_angular_pressed) self.shortcut_shift_z = QShortcut(QKeySequence(Qt.SHIFT + Qt.Key_Z), self._widget) self.shortcut_shift_z.setContext(Qt.ApplicationShortcut) self.shortcut_shift_z.activated.connect(self._on_reset_angular_pressed) self.shortcut_shift_d = QShortcut(QKeySequence(Qt.SHIFT + Qt.Key_D), self._widget) self.shortcut_shift_d.setContext(Qt.ApplicationShortcut) self.shortcut_shift_d.activated.connect( self._on_strong_decrease_angular_pressed) self.shortcut_space = QShortcut(QKeySequence(Qt.Key_Space), self._widget) self.shortcut_space.setContext(Qt.ApplicationShortcut) self.shortcut_space.activated.connect(self._on_stop_pressed) self.shortcut_space = QShortcut(QKeySequence(Qt.SHIFT + Qt.Key_Space), self._widget) self.shortcut_space.setContext(Qt.ApplicationShortcut) self.shortcut_space.activated.connect(self._on_stop_pressed) self._widget.stop_push_button.setToolTip( self._widget.stop_push_button.toolTip() + ' ' + self.tr('([Shift +] Space)')) self._widget.increase_linear_push_button.setToolTip( self._widget.increase_linear_push_button.toolTip() + ' ' + self.tr('([Shift +] W)')) self._widget.reset_linear_push_button.setToolTip( self._widget.reset_linear_push_button.toolTip() + ' ' + self.tr('([Shift +] X)')) self._widget.decrease_linear_push_button.setToolTip( self._widget.decrease_linear_push_button.toolTip() + ' ' + self.tr('([Shift +] S)')) self._widget.increase_angular_push_button.setToolTip( self._widget.increase_angular_push_button.toolTip() + ' ' + self.tr('([Shift +] A)')) self._widget.reset_angular_push_button.setToolTip( self._widget.reset_angular_push_button.toolTip() + ' ' + self.tr('([Shift +] Z)')) self._widget.decrease_angular_push_button.setToolTip( self._widget.decrease_angular_push_button.toolTip() + ' ' + self.tr('([Shift +] D)')) # timer to consecutively send AckermannDriveStamped messages self._update_parameter_timer = QTimer(self) self._update_parameter_timer.timeout.connect( self._on_parameter_changed) self._update_parameter_timer.start(100) self.zero_cmd_sent = False
def __init__(self, node): super(ExamplesWidget, self).__init__() self.setObjectName('ExamplesWidget') self.node = node self.REDRAW_INTERVAL = 30 self.PUBLISH_INTERVAL = 100 self.CMD_VEL_X_FACTOR = 1000.0 self.CMD_VEL_YAW_FACTOR = -10.0 pkg_name = 'rqt_example' ui_filename = 'rqt_example.ui' topic_name = 'cmd_vel' service_name = 'led_control' _, package_path = get_resource('packages', pkg_name) ui_file = os.path.join(package_path, 'share', pkg_name, 'resource', ui_filename) loadUi(ui_file, self) self.pub_velocity = Twist() self.pub_velocity.linear.x = 0.0 self.pub_velocity.angular.z = 0.0 self.sub_velocity = Twist() self.sub_velocity.linear.x = 0.0 self.sub_velocity.angular.z = 0.0 self.slider_x.setValue(0) self.lcd_number_x.display(0.0) self.lcd_number_yaw.display(0.0) qos = QoSProfile(depth=10) self.publisher = self.node.create_publisher(Twist, topic_name, qos) self.subscriber = self.node.create_subscription( Twist, topic_name, self.get_velocity, qos) self.service_server = self.node.create_service(SetBool, service_name, self.set_led_status) self.service_client = self.node.create_client(SetBool, service_name) self.publish_timer = QTimer(self) self.publish_timer.timeout.connect(self.send_velocity) self.publish_timer.start(self.PUBLISH_INTERVAL) self.update_timer = QTimer(self) self.update_timer.timeout.connect(self.update_indicators) self.update_timer.start(self.REDRAW_INTERVAL) self.push_button_w.pressed.connect(self.increase_linear_x) self.push_button_x.pressed.connect(self.decrease_linear_x) self.push_button_a.pressed.connect(self.increase_angular_z) self.push_button_d.pressed.connect(self.decrease_angular_z) self.push_button_s.pressed.connect(self.set_stop) self.push_button_w.setShortcut('w') self.push_button_x.setShortcut('x') self.push_button_a.setShortcut('a') self.push_button_d.setShortcut('d') self.push_button_s.setShortcut('s') self.shortcut_space = QShortcut(QKeySequence(Qt.Key_Space), self) self.shortcut_space.setContext(Qt.ApplicationShortcut) self.shortcut_space.activated.connect(self.push_button_s.pressed) self.radio_button_led_on.clicked.connect(self.call_led_service) self.radio_button_led_off.clicked.connect(self.call_led_service) self.radio_button_led_on.setShortcut('o') self.radio_button_led_off.setShortcut('f')
def __init__(self, context): super(RobotSteering, self).__init__(context) self.setObjectName('RobotSteering') self._publisher = None self._widget = QWidget() rp = rospkg.RosPack() ui_file = os.path.join(rp.get_path('rqt_robot_steering'), 'resource', 'RobotSteering.ui') loadUi(ui_file, self._widget) self._widget.setObjectName('RobotSteeringUi') if context.serial_number() > 1: self._widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % context.serial_number())) context.add_widget(self._widget) self._widget.topic_line_edit.textChanged.connect( self._on_topic_changed) self._widget.stop_push_button.pressed.connect(self._on_stop_pressed) self._widget.x_linear_slider.valueChanged.connect( self._on_x_linear_slider_changed) self._widget.z_angular_slider.valueChanged.connect( self._on_z_angular_slider_changed) self._widget.increase_x_linear_push_button.pressed.connect( self._on_strong_increase_x_linear_pressed) self._widget.reset_x_linear_push_button.pressed.connect( self._on_reset_x_linear_pressed) self._widget.decrease_x_linear_push_button.pressed.connect( self._on_strong_decrease_x_linear_pressed) self._widget.increase_z_angular_push_button.pressed.connect( self._on_strong_increase_z_angular_pressed) self._widget.reset_z_angular_push_button.pressed.connect( self._on_reset_z_angular_pressed) self._widget.decrease_z_angular_push_button.pressed.connect( self._on_strong_decrease_z_angular_pressed) self._widget.max_x_linear_double_spin_box.valueChanged.connect( self._on_max_x_linear_changed) self._widget.min_x_linear_double_spin_box.valueChanged.connect( self._on_min_x_linear_changed) self._widget.max_z_angular_double_spin_box.valueChanged.connect( self._on_max_z_angular_changed) self._widget.min_z_angular_double_spin_box.valueChanged.connect( self._on_min_z_angular_changed) self.shortcut_w = QShortcut(QKeySequence(Qt.Key_W), self._widget) self.shortcut_w.setContext(Qt.ApplicationShortcut) self.shortcut_w.activated.connect(self._on_increase_x_linear_pressed) self.shortcut_x = QShortcut(QKeySequence(Qt.Key_X), self._widget) self.shortcut_x.setContext(Qt.ApplicationShortcut) self.shortcut_x.activated.connect(self._on_reset_x_linear_pressed) self.shortcut_s = QShortcut(QKeySequence(Qt.Key_S), self._widget) self.shortcut_s.setContext(Qt.ApplicationShortcut) self.shortcut_s.activated.connect(self._on_decrease_x_linear_pressed) self.shortcut_a = QShortcut(QKeySequence(Qt.Key_A), self._widget) self.shortcut_a.setContext(Qt.ApplicationShortcut) self.shortcut_a.activated.connect(self._on_increase_z_angular_pressed) self.shortcut_z = QShortcut(QKeySequence(Qt.Key_Z), self._widget) self.shortcut_z.setContext(Qt.ApplicationShortcut) self.shortcut_z.activated.connect(self._on_reset_z_angular_pressed) self.shortcut_d = QShortcut(QKeySequence(Qt.Key_D), self._widget) self.shortcut_d.setContext(Qt.ApplicationShortcut) self.shortcut_d.activated.connect(self._on_decrease_z_angular_pressed) self.shortcut_shift_w = QShortcut(QKeySequence(Qt.SHIFT + Qt.Key_W), self._widget) self.shortcut_shift_w.setContext(Qt.ApplicationShortcut) self.shortcut_shift_w.activated.connect( self._on_strong_increase_x_linear_pressed) self.shortcut_shift_x = QShortcut(QKeySequence(Qt.SHIFT + Qt.Key_X), self._widget) self.shortcut_shift_x.setContext(Qt.ApplicationShortcut) self.shortcut_shift_x.activated.connect( self._on_reset_x_linear_pressed) self.shortcut_shift_s = QShortcut(QKeySequence(Qt.SHIFT + Qt.Key_S), self._widget) self.shortcut_shift_s.setContext(Qt.ApplicationShortcut) self.shortcut_shift_s.activated.connect( self._on_strong_decrease_x_linear_pressed) self.shortcut_shift_a = QShortcut(QKeySequence(Qt.SHIFT + Qt.Key_A), self._widget) self.shortcut_shift_a.setContext(Qt.ApplicationShortcut) self.shortcut_shift_a.activated.connect( self._on_strong_increase_z_angular_pressed) self.shortcut_shift_z = QShortcut(QKeySequence(Qt.SHIFT + Qt.Key_Z), self._widget) self.shortcut_shift_z.setContext(Qt.ApplicationShortcut) self.shortcut_shift_z.activated.connect( self._on_reset_z_angular_pressed) self.shortcut_shift_d = QShortcut(QKeySequence(Qt.SHIFT + Qt.Key_D), self._widget) self.shortcut_shift_d.setContext(Qt.ApplicationShortcut) self.shortcut_shift_d.activated.connect( self._on_strong_decrease_z_angular_pressed) self.shortcut_space = QShortcut(QKeySequence(Qt.Key_Space), self._widget) self.shortcut_space.setContext(Qt.ApplicationShortcut) self.shortcut_space.activated.connect(self._on_stop_pressed) self.shortcut_space = QShortcut(QKeySequence(Qt.SHIFT + Qt.Key_Space), self._widget) self.shortcut_space.setContext(Qt.ApplicationShortcut) self.shortcut_space.activated.connect(self._on_stop_pressed) self._widget.stop_push_button.setToolTip( self._widget.stop_push_button.toolTip() + ' ' + self.tr('([Shift +] Space)')) self._widget.increase_x_linear_push_button.setToolTip( self._widget.increase_x_linear_push_button.toolTip() + ' ' + self.tr('([Shift +] W)')) self._widget.reset_x_linear_push_button.setToolTip( self._widget.reset_x_linear_push_button.toolTip() + ' ' + self.tr('([Shift +] X)')) self._widget.decrease_x_linear_push_button.setToolTip( self._widget.decrease_x_linear_push_button.toolTip() + ' ' + self.tr('([Shift +] S)')) self._widget.increase_z_angular_push_button.setToolTip( self._widget.increase_z_angular_push_button.toolTip() + ' ' + self.tr('([Shift +] A)')) self._widget.reset_z_angular_push_button.setToolTip( self._widget.reset_z_angular_push_button.toolTip() + ' ' + self.tr('([Shift +] Z)')) self._widget.decrease_z_angular_push_button.setToolTip( self._widget.decrease_z_angular_push_button.toolTip() + ' ' + self.tr('([Shift +] D)')) # timer to consecutively send twist messages self._update_parameter_timer = QTimer(self) self._update_parameter_timer.timeout.connect( self._on_parameter_changed) self._update_parameter_timer.start(100) self.zero_cmd_sent = False
def __init__(self, context): super(RosBehaviourTree, self).__init__(context) self.setObjectName('RosBehaviourTree') parser = argparse.ArgumentParser() RosBehaviourTree.add_arguments(parser, False) # if the context doesn't have an argv attribute then assume we're running with --no-roscore if not hasattr(context, 'argv'): args = sys.argv[1:] # Can run the viewer with or without live updating. Running without is # intended for viewing of bags only self.live_update = False else: args = context.argv() self.live_update = True parsed_args = parser.parse_args(args) self.context = context self.initialized = False self._current_dotcode = None # dotcode for the tree that is currently displayed self._viewing_bag = False # true if a bag file is loaded # True if next or previous buttons are pressed. Reset if the tree being # viewed is the last one in the list. self._browsing_timeline = False self._widget = QWidget() # factory builds generic dotcode items self.dotcode_factory = PygraphvizFactory() # PydotFactory() # self.dotcode_factory = PygraphvizFactory() # generator builds rosgraph self.dotcode_generator = RosBehaviourTreeDotcodeGenerator() self.current_topic = None self.behaviour_sub = None self._tip_message = None # message of the tip of the tree self._saved_settings_topic = None # topic subscribed to by previous instance self.visibility_level = py_trees.common.VisibilityLevel.DETAIL # dot_to_qt transforms into Qt elements using dot layout self.dot_to_qt = DotToQtGenerator() rp = rospkg.RosPack() ui_file = os.path.join(rp.get_path('rqt_py_trees'), 'resource', 'RosBehaviourTree.ui') loadUi(ui_file, self._widget, {'InteractiveGraphicsView': InteractiveGraphicsView}) self._widget.setObjectName('RosBehaviourTreeUi') if hasattr(context, 'serial_number') and context.serial_number() > 1: self._widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % context.serial_number())) self._scene = QGraphicsScene() self._scene.setBackgroundBrush(Qt.white) self._widget.graphics_view.setScene(self._scene) self._widget.highlight_connections_check_box.toggled.connect( self._redraw_graph_view) self._widget.auto_fit_graph_check_box.toggled.connect( self._redraw_graph_view) self._widget.fit_in_view_push_button.setIcon( QIcon.fromTheme('zoom-original')) self._widget.fit_in_view_push_button.pressed.connect(self._fit_in_view) self._widget.load_bag_push_button.setIcon( QIcon.fromTheme('document-open')) self._widget.load_bag_push_button.pressed.connect(self._load_bag) self._widget.load_dot_push_button.setIcon( QIcon.fromTheme('document-open')) self._widget.load_dot_push_button.pressed.connect(self._load_dot) self._widget.save_dot_push_button.setIcon( QIcon.fromTheme('document-save-as')) self._widget.save_dot_push_button.pressed.connect(self._save_dot) self._widget.save_as_svg_push_button.setIcon( QIcon.fromTheme('document-save-as')) self._widget.save_as_svg_push_button.pressed.connect(self._save_svg) self._widget.save_as_image_push_button.setIcon( QIcon.fromTheme('image')) self._widget.save_as_image_push_button.pressed.connect( self._save_image) for text in visibility.combo_to_py_trees: self._widget.visibility_level_combo_box.addItem(text) self._widget.visibility_level_combo_box.setCurrentIndex( self.visibility_level) self._widget.visibility_level_combo_box.currentIndexChanged[ 'QString'].connect(self._update_visibility_level) # set up the function that is called whenever the box is resized - # ensures that the timeline is correctly drawn. self._widget.resizeEvent = self._resize_event self._timeline = None self._timeline_listener = None # Connect the message changed function of this object to a corresponding # signal. This signal will be activated whenever the message being # viewed changes. self._message_changed.connect(self.message_changed) self._message_cleared.connect(self.message_cleared) # Set up combo box for topic selection # when the refresh_combo signal happens, update the combo topics available self._refresh_combo.connect(self._update_combo_topics) # filter events to catch the event which opens the combo box self._combo_event_filter = RosBehaviourTree.ComboBoxEventFilter( self._refresh_combo) self._widget.topic_combo_box.installEventFilter( self._combo_event_filter) self._widget.topic_combo_box.activated.connect(self._choose_topic) self._update_combo_topics() # Set up navigation buttons self._widget.previous_tool_button.pressed.connect(self._previous) self._widget.previous_tool_button.setIcon( QIcon.fromTheme('go-previous')) self._widget.next_tool_button.pressed.connect(self._next) self._widget.next_tool_button.setIcon(QIcon.fromTheme('go-next')) self._widget.first_tool_button.pressed.connect(self._first) self._widget.first_tool_button.setIcon(QIcon.fromTheme('go-first')) self._widget.last_tool_button.pressed.connect(self._last) self._widget.last_tool_button.setIcon(QIcon.fromTheme('go-last')) # play, pause and stop buttons self._widget.play_tool_button.pressed.connect(self._play) self._widget.play_tool_button.setIcon( QIcon.fromTheme('media-playback-start')) self._widget.stop_tool_button.pressed.connect(self._stop) self._widget.stop_tool_button.setIcon( QIcon.fromTheme('media-playback-stop')) # also connect the navigation buttons so that they stop the timer when # pressed while the tree is playing. self._widget.first_tool_button.pressed.connect(self._stop) self._widget.previous_tool_button.pressed.connect(self._stop) self._widget.last_tool_button.pressed.connect(self._stop) self._widget.next_tool_button.pressed.connect(self._stop) # set up shortcuts for navigation (vim) next_shortcut_vi = QShortcut(QKeySequence("l"), self._widget) next_shortcut_vi.activated.connect( self._widget.next_tool_button.pressed) previous_shortcut_vi = QShortcut(QKeySequence("h"), self._widget) previous_shortcut_vi.activated.connect( self._widget.previous_tool_button.pressed) first_shortcut_vi = QShortcut(QKeySequence("^"), self._widget) first_shortcut_vi.activated.connect( self._widget.first_tool_button.pressed) last_shortcut_vi = QShortcut(QKeySequence("$"), self._widget) last_shortcut_vi.activated.connect( self._widget.last_tool_button.pressed) # shortcuts for emacs next_shortcut_emacs = QShortcut(QKeySequence("Ctrl+f"), self._widget) next_shortcut_emacs.activated.connect( self._widget.next_tool_button.pressed) previous_shortcut_emacs = QShortcut(QKeySequence("Ctrl+b"), self._widget) previous_shortcut_emacs.activated.connect( self._widget.previous_tool_button.pressed) first_shortcut_emacs = QShortcut(QKeySequence("Ctrl+a"), self._widget) first_shortcut_emacs.activated.connect( self._widget.first_tool_button.pressed) last_shortcut_emacs = QShortcut(QKeySequence("Ctrl+e"), self._widget) last_shortcut_emacs.activated.connect( self._widget.last_tool_button.pressed) # set up stuff for dotcode cache self._dotcode_cache_capacity = 50 self._dotcode_cache = {} # cache is ordered on timestamps from messages, but earliest timestamp # isn't necessarily the message that was viewed the longest time ago, so # need to store keys self._dotcode_cache_keys = [] # set up stuff for scene cache (dotcode cache doesn't seem to make much difference) self._scene_cache_capacity = 50 self._scene_cache = {} self._scene_cache_keys = [] # Update the timeline buttons to correspond with a completely # uninitialised state. self._set_timeline_buttons(first_snapshot=False, previous_snapshot=False, next_snapshot=False, last_snapshot=False) self._deferred_fit_in_view.connect(self._fit_in_view, Qt.QueuedConnection) self._deferred_fit_in_view.emit() # This is used to store a timer which controls how fast updates happen when the play button is pressed. self._play_timer = None # updates the view self._refresh_view.connect(self._refresh_tree_graph) self._force_refresh = False if self.live_update: context.add_widget(self._widget) else: self.initialized = True # this needs to be set for trees to be displayed context.setCentralWidget(self._widget) if parsed_args.bag: self._load_bag(parsed_args.bag) elif parsed_args.latest_bag: # if the latest bag is requested, load it from the default directory, or # the one specified in the args bag_dir = parsed_args.bag_dir or os.getenv( 'ROS_HOME', os.path.expanduser('~/.ros')) + '/behaviour_trees' self.open_latest_bag(bag_dir, parsed_args.by_time)