def __init__(self, context): super(QuestionDialogPlugin, self).__init__(context) # Give QObjects reasonable names self.setObjectName('QuestionDialogPlugin') font_size = rospy.get_param("~font_size", 40) # Create QWidget self._widget = QWidget() self._widget.setFont(QFont("Times", font_size, QFont.Bold)) self._layout = QVBoxLayout(self._widget) self._text_browser = QTextBrowser(self._widget) self._layout.addWidget(self._text_browser) self._button_layout = QHBoxLayout() self._layout.addLayout(self._button_layout) # layout = QVBoxLayout(self._widget) # layout.addWidget(self.button) self._widget.setObjectName('QuestionDialogPluginUI') if context.serial_number() > 1: self._widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % context.serial_number())) context.add_widget(self._widget) # Setup service provider self.service = rospy.Service('question_dialog', QuestionDialog, self.service_callback) self.response_ready = False self.response = None self.buttons = [] self.text_label = None self.text_input = None self.connect(self._widget, SIGNAL("update"), self.update) self.connect(self._widget, SIGNAL("timeout"), self.timeout)
def add_item(self, obj, parent=None): #obj.num_index = 0 #TODO. if obj.num_index == -1: obj.num_index = self.last_index if parent == None: parent = self if obj in parent.children: self.build_indexs() return parent.children.append(obj) self.build_indexs() self.connect_signals(obj.children) self.connect(obj, SIGNAL('checked_changed'), self.check_changed) #Objects value changes. self.connect(obj, SIGNAL('value_changed'), self.param_changed) #Todo figure out how to fix this correctly if obj.json['checked']: self.active_members.append(obj) self.param_changed(obj) self.build_active(obj.children)
def connect_signals(self, objects=None): if objects == None: objects = self.children for obj in objects: #Object is checked / unchecked. self.connect(obj, SIGNAL('checked_changed'), self.check_changed) #Objects value changes. self.connect(obj, SIGNAL('value_changed'), self.param_changed) self.connect_signals(obj.children)
def _init_events(self): # List item click event self.resource_list_tree_widget.itemClicked.connect(self._resource_selected) self.resource_list_tree_widget.itemDoubleClicked.connect(self._resource_double_clicked) # Button event connect self.capture_resource_btn.pressed.connect(self._capture_resource) self.release_resource_btn.pressed.connect(self._release_resource) # Event emitter self.connect(self, SIGNAL("capture"), self._show_capture_resource_message) self.connect(self, SIGNAL("release"), self._show_release_resource_message) self.connect(self, SIGNAL("error"), self._show_error_resource_message) self.connect(self, SIGNAL("refresh_resource_list"), self._refresh_resource_list)
def load_world_list(self): success, message, self._world_list = self._callback['list_world']() if success: self._update_world_list() else: self.emit(SIGNAL("show_message"), self, "Failed", message)
def _init_admin_app_interface(self): self.admin_app_interface = AdminAppInterface() try: self.admin_app_interface._init_admin_app_interface() self.admin_app_interface._reg_event_callback(self._refresh_service) except NotFoundException as e: self.emit(SIGNAL("show_message"), self._widget, "Failed", e)
def _load_world(self): #world_name = self.world_name_text.toPlainText() world_name = str(self.list_world_combobox.currentText()) success, message, self._map_name_list, self._annotation_name_list = self._callback[ 'load_world'](world_name) if success: self._world_name = world_name self._selected_map = self._map_name_list[0] self.emit(SIGNAL("update_map_selector")) self._new_annotation_name_list = [] self.emit(SIGNAL("update_annotation_list")) self._enable_buttons(True) else: self.emit(SIGNAL("show_message"), self, "Failed", message)
def create_process(self): self.shell.clear() self.process = QProcess(self) self.process.setProcessChannelMode(QProcess.MergedChannels) env = [ unicode(key_val_pair) for key_val_pair in self.process.systemEnvironment() ] env.append('TERM=xterm') env.append('COLORTERM=gnome-terminal') self.process.setEnvironment(env) # Working directory if self.wdir is not None: self.process.setWorkingDirectory(self.wdir) self.process.readyReadStandardOutput.connect(self.write_output) self.process.finished.connect(self.finished) self.process.finished.connect(self.close_signal) self.process.start('/bin/bash', ['-i']) running = self.process.waitForStarted() self.set_running_state(running) if not running: self.shell.addPlainText("Process failed to start") else: self.shell.setFocus() self.emit(SIGNAL('started()')) return self.process
def service_callback(self, req): self.response_ready = False self.request = req self._widget.emit(SIGNAL("update")) # Start timer against wall clock here instead of the ros clock. start_time = time.time() while not self.response_ready: if self.request != req: # The request got preempted by a new request. return RoomDialogResponse(RoomDialogRequest.PREEMPTED, "") if req.timeout != RoomDialogRequest.NO_TIMEOUT: current_time = time.time() if current_time - start_time > req.timeout: self._widget.emit(SIGNAL("timeout")) return RoomDialogResponse(RoomDialogRequest.TIMED_OUT, "") time.sleep(0.2) return self.response
def _save_annotation(self): success, message = self._callback['save_annotation']() if success: success, message, self._map_name_list, self._annotation_name_list = self._callback[ 'load_world'](self._world_name) if success: self.emit(SIGNAL("update_map_selector")) self._new_annotation_name_list = [] self.emit(SIGNAL("update_annotation_list")) self._enable_buttons(True) else: self.emit(SIGNAL("show_message"), self, "Failed", message) else: self.emit(SIGNAL("show_message"), self, "Failed", message)
def __init__(self, parent=None): super(QCameraView, self).__init__(parent) self.scene = QGraphicsScene(self) self.setScene(self.scene) self._load_default_image() self.connect(self, SIGNAL("load_default_image"), self._load_default_image)
def _init_event(self): self._widget.enable_disable_btn.pressed.connect(self._toggle_service) self._widget.refresh_btn.pressed.connect(self._refresh_service) self._widget.save_configuration_btn.pressed.connect( self._save_parmeters) self._widget.service_tree_widget.itemClicked.connect( self._select_service_tree_item) # concert item click event self._refresh_service_list_signal.connect(self._update_service_list) self.connect(self, SIGNAL("show_message"), utils.show_message)
def update_scene(self, object_name, data): if object_name == 'map': self._drawing_objects['map'] = data['map'] elif object_name == 'annotations': self._drawing_objects['annotations'] = data['annotations'] elif object_name == 'new_annotations': self._drawing_objects['new_annotations'] = data['new_annotations'] elif object_name == 'on_annotation': self._drawing_objects['on_annotation'] = data self.emit(SIGNAL("draw_scene"), object_name)
def _select_map_item_clicked(self, item_index): # if item_index is -1, combobox got reset if item_index >= 0 and self.map_select_combobox.count( ) > 1: # this is to avoid being selected when the first item is added in the combobox self._selected_map = self.map_select_combobox.itemText(item_index) print(str("in item clicked : " + self._selected_map)) success, message = self._callback['load_map'](self._selected_map) if not success: self.emit(SIGNAL("show_message"), self, "Failed", message)
def process_level_status(self, msg): level_found = False for level in self.levels: if msg.level_id == level.level_id: self.current_level = level.level_id level_found = True break if not level_found: self.current_level = None self._widget.emit(SIGNAL("update_button_status"))
def _remove_annotation(self): if self._selected_annotation: ann_list, names = self._callback['remove_annotation']( self._selected_annotation) if ann_list == 'annotations': self._annotation_name_list = names elif ann_list == 'new_annotations': self._new_annotation_name_list = names self.emit(SIGNAL("update_annotation_list"))
def _toggle_service(self): if self.current_service['enabled']: print "Disable Service: %s" % self.current_service['name'] (success, message) = self.admin_app_interface.disable_service( self.current_service['name']) self._set_enable_params_layout(True) else: print "Enable Service: %s" % self.current_service['name'] (success, message) = self.admin_app_interface.eable_service( self.current_service['name']) self._set_enable_params_layout(False) if success: self.emit(SIGNAL("show_message"), self._widget, "Success", message) else: self.emit(SIGNAL("show_message"), self._widget, "Failure", message) self.current_service = None self._widget.enable_disable_btn.setDisabled(True) self._widget.enable_disable_btn.setText("Enable/Disable")
def _add_annotation(self): if self.annotation: self._get_annotating_info() anno = copy.deepcopy(self.annotation) if anno['name'] == '': self.emit(SIGNAL('show_message'), self, "Failed", "Name is empty!") elif self.anno_type == 'ar_track_alvar_msgs/AlvarMarker' and not anno[ 'name'].isdigit(): self.emit(SIGNAL('show_message'), self, "Failed", "Marker ID should be int!") else: self._new_annotation_name_list = self._callback[ 'add_annotation'](anno, self.anno_type) self.emit(SIGNAL("update_annotation_list")) self._clear_on_annotation() self.ar_marker_cbox.setCheckState(Qt.Unchecked) self.location_cbox.setCheckState(Qt.Unchecked) self._clear_edit_annotation_box()
def _save_parmeters(self): params = {} result = False msg = "" if not self.current_service: msg = "Not selected service" elif self.current_service['enabled']: msg = "service is already enabled!" elif self.params_layout_items: for item in self.params_layout_items: params[item[0].text()] = item[1].toPlainText().strip() (result, msg) = self.admin_app_interface.set_srv_parameters( self.current_service['name'], params) else: msg = "No params infomation" if result: self.emit(SIGNAL("show_message"), self._widget, "Success", "Saved Parameters") else: self.emit(SIGNAL("show_message"), self._widget, "Failed", msg)
def __init__(self, parent=None): super(LifeFrame, self).__init__(parent) self._ui = Ui_life_frame() self._motion = Rotate('/mobile_base/commands/velocity') self._motion_thread = None self._timer = QTimer() #self._timer.setInterval(60000) #60s self._timer.setInterval(250) #60s QObject.connect(self._timer, SIGNAL('timeout()'), self, SLOT('update_progress_callback()')) self._state = LifeFrame.STATE_STOPPED self._is_alive = False # Used to indicate whether the frame is alive or not (see hibernate/restore methods)
def __init__(self, context): super(LevelSelectorPlugin, self).__init__(context) # Give QObjects reasonable names self.setObjectName('LevelSelectorPlugin') # Create QWidget self._widget = QWidget() # self._widget.setFont(QFont("Times", 15, QFont.Bold)) self._button_layout = QVBoxLayout(self._widget) self.buttons = [] self.text_label = QLabel("Waiting for MultiLevelMapData...", self._widget) self._button_layout.addWidget(self.text_label) self._widget.setObjectName('LevelSelectorPluginUI') if context.serial_number() > 1: self._widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % context.serial_number())) context.add_widget(self._widget) self.connect(self._widget, SIGNAL("update_buttons"), self.update_buttons) self.connect(self._widget, SIGNAL("update_button_status"), self.update_button_status) # Subcribe to the multi level map data to get information about all the maps. self.multimap_subscriber = rospy.Subscriber("map_metadata", MultiLevelMapData, self.process_multimap) self.levels = [] self.current_level = None # Subscribe to the current level we are on. self.status_subscriber = None # Create a service proxy to change the current level. self.level_selector_proxy = rospy.ServiceProxy( "level_mux/change_current_level", ChangeCurrentLevel) self.level_selector_proxy.wait_for_service()
def load_json(self, jsons): #TODO delete objects. self.children = [] types = loadItems() for json in jsons: obj = JsonToObject(types, json) #self.add_item(obj) self.children.append(obj) self.build_active() self.connect_signals() self.build_indexs() self.emit(SIGNAL('RESET'))
def _init_events(self): self.on_map_received = self.map_view.map_cb self.map_view._scene.mousePressEvent = self._mousePressEvent self.map_view._scene.mouseReleaseEvent = self._mouseReleaseEvent self.map_view._scene.mouseMoveEvent = self._mouseMoveEvent self.ar_marker_cbox.stateChanged.connect(self._check_ar_marker_cbox) self.location_cbox.stateChanged.connect(self._check_location_cbox) self.add_annotation_btn.clicked.connect(self._add_annotation) self.remove_annotation_btn.clicked.connect(self._remove_annotation) self.save_annotation_btn.clicked.connect(self._save_annotation) self.load_world_btn.clicked.connect(self._load_world) self.map_select_combobox.currentIndexChanged.connect( self._select_map_item_clicked) self.annotations_list_widget.itemClicked.connect( self._annotation_list_item_clicked) self.connect(self, SIGNAL("show_message"), utils.show_message) self.connect(self, SIGNAL("draw_scene"), self.draw_scene) self.connect(self, SIGNAL("update_annotation_list"), self._update_annotation_list) self.connect(self, SIGNAL("update_map_selector"), self._update_map_selector)
def setConfigData(self, objects, parent=None): if parent == None: self.clear() self.command = objects #self.top.children = objects.children #self.top.children = objects.children parent = self.top #parent.children = objects.children for obj in objects: index = self.addConfigItem(obj, parent) #self.setConfigData(obj, index) self.layoutChanged.emit() self.emit(SIGNAL("layoutChanged()"))
def create_process(self, script_path=None): self.shell.clear() self.process = QProcess(self) self.process.setProcessChannelMode(QProcess.MergedChannels) env = [] for key_val_pair in self.process.systemEnvironment(): try: value = unicode(key_val_pair) except NameError: value = str(key_val_pair) env.append(value) env.append('TERM=xterm') env.append('COLORTERM=gnome-terminal') self.process.setEnvironment(env) # Working directory if self.wdir is not None: self.process.setWorkingDirectory(self.wdir) self.process.readyReadStandardOutput.connect(self.write_output) self.process.finished.connect(self.finished) self.process.finished.connect(self.close_signal) if script_path: options = [ "-c 'source %s; /bin/bash -i'" % os.path.abspath(script_path)] else: options = ['-i'] self.process.start('/bin/bash', options) running = self.process.waitForStarted() self.set_running_state(running) if not running: self.shell.addPlainText("Process failed to start") else: self.shell.setFocus() self.emit(SIGNAL('started()')) return self.process
def log(self, level, message): self.emit(SIGNAL('logMessage'), level, message)
def __init__(self, context): self._context = context super(Teleop, self).__init__(context) # I'd like these to be also configurable via the gui self.maximum_linear_velocity = rospy.get_param( '~maximum_linear_velocity', 2.0) self.maximum_angular_velocity = rospy.get_param( '~maximum_angular_velocity', 90 * Teleop.degrees_to_radians) rospy.loginfo( "Rocon Teleop : maximum velocities [%s, %s]" % (self.maximum_linear_velocity, self.maximum_angular_velocity)) self.initialised = False self.is_setting_dlg_live = False self._widget = QWidget() rospack = rospkg.RosPack() ui_file = os.path.join(rospack.get_path('concert_qt_teleop'), 'ui', 'concert_teleop.ui') loadUi( ui_file, self._widget, { 'QCameraView': QCameraView, 'QVirtualJoystickView': QVirtualJoystickView }) if context.serial_number() > 1: self._widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % context.serial_number())) #list item click event self._widget.robot_list_tree_widget.itemClicked.connect( self._select_robot_list_tree_item) self._widget.robot_list_tree_widget.itemDoubleClicked.connect( self._dbclick_robot_list_item) #button event connection self._widget.capture_teleop_btn.pressed.connect(self._capture_teleop) self._widget.release_teleop_btn.pressed.connect(self._release_teleop) #signal event connection self._update_robot_list_signal.connect(self._update_robot_list) self.connect(self, SIGNAL("capture"), self._show_capture_teleop_message) self.connect(self, SIGNAL("release"), self._show_release_teleop_message) self.connect(self, SIGNAL("error"), self._show_error_teleop_message) context.add_widget(self._widget) self._widget.release_teleop_btn.setEnabled(False) self.teleop_app_info = TeleopManager( image_received_slot=self._widget.camera_view. on_compressed_image_received, event_callback=self._refresh_robot_list, capture_event_callback=self._capture_event_callback, release_event_callback=self._release_event_callback, error_event_callback=self._error_event_callback, ) self.robot_item_list = {} self.current_robot = None self.current_captured_robot = None #virtual joystick self._widget.virtual_joystick_view.joystick_feedback().connect( self.on_joystick_feedback) self._widget.virtual_joystick_view.mouse_released().connect( self.on_mouse_released) #keyboard control for k in self._widget.children(): try: k.keyPressEvent = self.on_key_press k.keyReleaseEvent = self.on_key_release except: pass
def _error_event_callback(self, err): try: self.emit(SIGNAL("error"), err) except: pass
def _release_event_callback(self, rtn): try: self.emit(SIGNAL("release"), rtn) except: pass
def _capture_event_callback(self, rtn): try: self.emit(SIGNAL("capture"), rtn) except: pass