def __init__(self, parent=None, info=False): QFrame.__init__(self, parent=parent) self.setObjectName('MessageFrame') self.questionid = self.TYPE_INVALID self.text = "" self.data = MessageData(None) self.IMAGES = { 1: QPixmap(), 2: nm.settings().pixmap('question.png').scaled( self.ICON_SIZE, self.ICON_SIZE, Qt.IgnoreAspectRatio, Qt.SmoothTransformation), 3: nm.settings().pixmap('crystal_clear_launch_file.png').scaled( self.ICON_SIZE, self.ICON_SIZE, Qt.IgnoreAspectRatio, Qt.SmoothTransformation), 4: nm.settings().pixmap('default_cfg.png').scaled( self.ICON_SIZE, self.ICON_SIZE, Qt.IgnoreAspectRatio, Qt.SmoothTransformation), 5: nm.settings().pixmap('crystal_clear_nodelet_q.png').scaled( self.ICON_SIZE, self.ICON_SIZE, Qt.IgnoreAspectRatio, Qt.SmoothTransformation), 6: nm.settings().pixmap( 'crystal_clear_launch_file_transfer.png').scaled( self.ICON_SIZE, self.ICON_SIZE, Qt.IgnoreAspectRatio, Qt.SmoothTransformation), 7: nm.settings().pixmap('crystal_clear_binary.png').scaled( self.ICON_SIZE, self.ICON_SIZE, Qt.IgnoreAspectRatio, Qt.SmoothTransformation), 8: nm.settings().pixmap('crystal_clear_no_io.png').scaled( self.ICON_SIZE, self.ICON_SIZE, Qt.IgnoreAspectRatio, Qt.SmoothTransformation), 9: nm.settings().pixmap('crystal_clear_run_zeroconf.png').scaled( self.ICON_SIZE, self.ICON_SIZE, Qt.IgnoreAspectRatio, Qt.SmoothTransformation), 10: nm.settings().pixmap('crystal_clear_run_zeroconf.png').scaled( self.ICON_SIZE, self.ICON_SIZE, Qt.IgnoreAspectRatio, Qt.SmoothTransformation), 11: nm.settings().pixmap('sekkyumu_restart.png').scaled( self.ICON_SIZE, self.ICON_SIZE, Qt.IgnoreAspectRatio, Qt.SmoothTransformation) } self._new_request = False self._in_resp_process = False self.ui = QFrame() ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'ui', 'MessageFrame.ui') loadUi(ui_file, self.ui) color = QColor(255, 207, 121) self.ui.questionOkButton.setIcon( nm.settings().icon('crystal_clear_button_apply.png')) self.ui.questionCancelButton.setIcon( nm.settings().icon('crystal_clear_button_close.png')) self.ui.listLabel.setTextInteractionFlags(Qt.TextSelectableByMouse) self.ui.questionLabel.setTextInteractionFlags(Qt.TextSelectableByMouse) self.ui.setVisible(False) self.ui.listLabel.setVisible(False) self.ui.questionOkButton.clicked.connect(self._on_question_ok) self.ui.questionCancelButton.clicked.connect(self._on_question_cancel) self.ui.checkBox_dnaa.stateChanged.connect( self._on_checkbox_state_changed) self._ask = 'ask' if info: color = QColor(232, 104, 80) self.ui.questionCancelButton.setVisible(False) self._ask = 'show' bg_style = "QFrame#questionFame { background-color: %s;}" % color.name( ) self.ui.setStyleSheet("%s" % (bg_style)) self._queue = MessageQueue() self._do_not_ask = {}
def __init__(self, items=list(), buttons=QDialogButtonBox.Cancel | QDialogButtonBox.Ok, exclusive=False, preselect_all=False, title='', description='', icon='', parent=None, select_if_single=True, checkitem1='', checkitem2='', closein=0, store_geometry=''): ''' Creates an input dialog. @param items: a list with strings @type items: C{list()} ''' QDialog.__init__(self, parent=parent) self.setObjectName(' - '.join(['SelectDialog', utf8(items)])) self.verticalLayout = QVBoxLayout(self) self.verticalLayout.setObjectName("verticalLayout") self.verticalLayout.setContentsMargins(3, 3, 3, 3) # add filter row self.filter_field = EnhancedLineEdit(self) self.filter_field.setPlaceholderText("filter") self.filter_field.textChanged.connect(self._on_filter_changed) self.verticalLayout.addWidget(self.filter_field) if description: self.description_frame = QFrame(self) descriptionLayout = QHBoxLayout(self.description_frame) # descriptionLayout.setContentsMargins(1, 1, 1, 1) if icon: self.icon_label = QLabel(self.description_frame) self.icon_label.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) self.icon_label.setPixmap( QPixmap(icon).scaled(30, 30, Qt.KeepAspectRatio)) descriptionLayout.addWidget(self.icon_label) self.description_label = QLabel(self.description_frame) self.description_label.setWordWrap(True) self.description_label.setText(description) descriptionLayout.addWidget(self.description_label) self.verticalLayout.addWidget(self.description_frame) # create area for the parameter self.content = MainBox(self) if items: self.scroll_area = QScrollArea(self) self.scroll_area.setFocusPolicy(Qt.NoFocus) self.scroll_area.setObjectName("scroll_area") self.scroll_area.setWidgetResizable(True) self.scroll_area.setWidget(self.content) self.verticalLayout.addWidget(self.scroll_area) self.checkitem1 = checkitem1 self.checkitem1_result = False self.checkitem2 = checkitem2 self.checkitem2_result = False # add select all option if not exclusive and items: self._ignore_next_toggle = False self.select_all_checkbox = QCheckBox('all entries') self.select_all_checkbox.setTristate(True) self.select_all_checkbox.stateChanged.connect( self._on_select_all_checkbox_stateChanged) self.verticalLayout.addWidget(self.select_all_checkbox) self.content.toggled.connect(self._on_main_toggle) if self.checkitem1: self.checkitem1_checkbox = QCheckBox(self.checkitem1) self.checkitem1_checkbox.stateChanged.connect( self._on_select_checkitem1_checkbox_stateChanged) self.verticalLayout.addWidget(self.checkitem1_checkbox) if self.checkitem2: self.checkitem2_checkbox = QCheckBox(self.checkitem2) self.checkitem2_checkbox.stateChanged.connect( self._on_select_checkitem2_checkbox_stateChanged) self.verticalLayout.addWidget(self.checkitem2_checkbox) if not items: spacerItem = QSpacerItem(1, 1, QSizePolicy.Expanding, QSizePolicy.Expanding) self.verticalLayout.addItem(spacerItem) self._close_timer = None self._closein = closein - 1 if closein > 0: self.closein_label = QLabel("OK in %d sec..." % closein) self.closein_label.setAlignment(Qt.AlignRight) self.verticalLayout.addWidget(self.closein_label) self._close_timer = threading.Timer(1.0, self._on_close_timer) self._close_timer.start() # create buttons self.buttonBox = QDialogButtonBox(self) self.buttonBox.setObjectName("buttonBox") self.buttonBox.setOrientation(Qt.Horizontal) self.buttonBox.setStandardButtons(buttons) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) self.verticalLayout.addWidget(self.buttonBox) # set the input fields if items: self.content.createFieldsFromValues(items, exclusive) if (select_if_single and len(items) == 1) or preselect_all: self.select_all_checkbox.setCheckState(Qt.Checked) if not items or len(items) < 7: self.filter_field.setVisible(False) # restore from configuration file self._geometry_name = store_geometry if store_geometry and nm.settings().store_geometry: settings = nm.settings().qsettings(nm.settings().CFG_GUI_FILE) settings.beginGroup(store_geometry) self.resize(settings.value("size", QSize(480, 320))) pos = settings.value("pos", QPoint(0, 0)) if pos.x() != 0 and pos.y() != 0: self.move(pos) settings.endGroup()
def __init__(self, context): super(MyPlugin, self).__init__(context) #os.system('roslaunch centauri6dof_moveit_config demo.launch') self.setObjectName('MyPlugin') # 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 # Create QWidget self._widget = QWidget() robot = MICRobot.RobotCommander() scene = MICPlanningSceneInterface.PlanningSceneInterface() group_name = "centauri6dof_arm" group = MICMoveGroupCommander.MoveGroupCommander(group_name) display_trajectory_publisher = rospy.Publisher('/move_group/display_planned_path', moveit_msgs.msg.DisplayTrajectory, queue_size=20) # We can get the name of the reference frame for this robot: planning_frame = group.get_planning_frame() print "============ Reference frame: %s" % planning_frame # We can also print the name of the end-effector link for this group: eef_link = group.get_end_effector_link() print "============ End effector: %s" % eef_link # We can get a list of all the groups in the robot: group_names = robot.get_group_names() print "============ Robot Groups:", robot.get_group_names() # Sometimes for debugging it is useful to print the entire state of the # robot: print "============ Printing robot state" print robot.get_current_state() print "" self.robot = robot self.scene = scene self.group = group self.display_trajectory_publisher = display_trajectory_publisher self.planning_frame = planning_frame self.eef_link = eef_link self.group_names = group_names # Get path to UI file which should be in the "resource" folder of this package ui_file = os.path.join(rospkg.RosPack().get_path('rqt_mypkg'), 'resource', 'MyPlugin.ui') # Extend the widget with all attributes and children from UI file loadUi(ui_file, self._widget) # Give QObjects reasonable names self._widget.setObjectName('MyPluginUi') # 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. rospy.Subscriber("/move_group/fake_controller_joint_states", JointState, self.joint_states_callback) self.username = os.path.expanduser("~") target = "logo_uao.png" initial_dir = self.username+'/catkin_ws/src' path_file = '' for root, _, files in os.walk(initial_dir): if target in files: path_file = os.path.join(root, target) break #To search for the username img = QPixmap(path_file) self._widget.LabelImageUao.setPixmap(img) self._widget.Path1Button.setIcon(QIcon.fromTheme('media-playback-start')) self._widget.Path1Button.clicked[bool].connect(self.fcn_path_1) self._widget.Path2Button.setIcon(QIcon.fromTheme('media-playback-start')) self._widget.Path2Button.clicked[bool].connect(self.fcn_path_2) self._widget.PlayButton.setIcon(QIcon.fromTheme('media-record')) self._widget.PlayButton.clicked[bool].connect(self._Send_joints_teleoperation) self._widget.HomeButton.setIcon(QIcon.fromTheme('go-home')) self._widget.HomeButton.clicked[bool].connect(self._Center_joints_teleoperation) self._widget.RandomizeButton.setIcon(QIcon.fromTheme('software-update-available')) self._widget.RandomizeButton.clicked[bool].connect(self._Randomize_joints_teleoperation) self._widget.GripperButton.setIcon(QIcon.fromTheme('software-update-available')) self._widget.GripperButton.clicked[bool].connect(self._fcn_gripper) self._widget.SavePoseButton.setIcon(QIcon.fromTheme('document-save')) self._widget.SavePoseButton.clicked[bool].connect(self._save_pose) self._widget.DeletePoseButton.setIcon(QIcon.fromTheme('edit-clear')) self._widget.DeletePoseButton.clicked[bool].connect(self._delete_pose) self._widget.ExecutePathButton.setIcon(QIcon.fromTheme('media-playback-start')) self._widget.ExecutePathButton.clicked[bool].connect(self._execute_path) self._widget.SaveTrajectoryButton.setIcon(QIcon.fromTheme('document-send')) self._widget.SaveTrajectoryButton.clicked[bool].connect(self._write_csv) self._widget.ImportTrajectoryButton.setIcon(QIcon.fromTheme('document-open')) self._widget.ImportTrajectoryButton.clicked[bool].connect(self._read_csv) self._widget.PreviewButton.setIcon(QIcon.fromTheme('software-update-available')) self._widget.PreviewButton.clicked[bool].connect(self._Preview_pose_sliders) self.goal = ArmJointState() self.arr_sl = [self._widget.SlJoint1,self._widget.SlJoint2,self._widget.SlJoint3,self._widget.SlJoint4,self._widget.SlJoint5,self._widget.SlJoint6] self.arr_ShowSl = [self._widget.ShowJoint1,self._widget.ShowJoint2,self._widget.ShowJoint3,self._widget.ShowJoint4,self._widget.ShowJoint5,self._widget.ShowJoint6] self.pub2 = rospy.Publisher('joint_steps', ArmJointState, queue_size=50) rate = rospy.Rate(20) # 20hz self.savePose = [] self.trajectory = [] self.count_save_pose = 0 self.joint_visualizer = [] lista_arq = '' if os.path.exists(self.username+"/trajectories_centauri6dof"): for i in os.listdir(self.username+"/trajectories_centauri6dof"): lista_arq+=(i+'\n') print(lista_arq) else: os.makedirs(self.username+"/trajectories_centauri6dof") #for i in lista_arq: self._widget.ShowText.setText("Saved paths: \n" + lista_arq ) gripper = {'open': 0, 'banana': 70, 'box': 50} upright = [0, 0, 0, 0, 0, 0, 0] #predefined movements for pick and place of an box box_pick = [0, 2700, 18000, 0, 1500, 0, gripper['box']] box_move = [0, 1200, 14000, 0, 0, 0, gripper['box']] box_place = [8000, 3300, 16000, 0, 1100, 0, gripper['open']] banana_pick = [8000, 3735, 13600, 0, 1040, 0, gripper['banana']] banana_move = [8000, 1412, 6600, 0, 1040, 0, 80, gripper['banana']] banana_place = [3555, 2733, 13399, 0, 1960, 0, 0, gripper['open']] self.object_trajectories = {"box": [upright, box_pick, box_move, box_place, upright], "banana": [upright, banana_pick, banana_move, banana_place, upright]} for i in xrange(0,6): self.arr_sl[i].setEnabled(True) self.arr_sl[i].setMaximum(90) self.arr_sl[i].setMinimum(-90) self.arr_sl[i].setValue(0) self.arr_sl[i].valueChanged.connect(self.joints_changes) self.arr_ShowSl[i].setEnabled(True) self.arr_ShowSl[i].setText(str(self.arr_sl[i].value())) self._widget.SlJoint2.setMaximum(80) self._widget.SlJoint2.setMinimum(-80) self._widget.SlJoint4.setMaximum(75) self._widget.SlJoint4.setMinimum(-75) self._widget.spinBoxRepeat.setMaximum(20) self._widget.spinBoxRepeat.setMinimum(-20) self._widget.spinBoxRepeat.setValue(0) 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.grip = 0 self.count_save_pose = 0 self.activate = 0
def __init__(self, icon, title, text, detailed_text="", buttons=Cancel | Ok, parent=None): QDialog.__init__(self, parent=parent) self.setWindowFlags(self.windowFlags() & ~Qt.WindowTitleHint) self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint & ~Qt.WindowMinimizeButtonHint) self.setObjectName('MessageBox') self._use_checkbox = True self.text = text self.verticalLayout = QVBoxLayout(self) self.verticalLayout.setObjectName("verticalLayout") self.verticalLayout.setContentsMargins(1, 1, 1, 1) self.horizontalLayout = QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") self.horizontalLayout.setContentsMargins(1, 1, 1, 1) # create icon pixmap = None style_option = QStyleOption() if icon == self.NoIcon: pass elif icon == self.Question: pixmap = QApplication.style().standardPixmap( QStyle.SP_MessageBoxQuestion, style_option) elif icon == self.Information: pixmap = QApplication.style().standardPixmap( QStyle.SP_MessageBoxInformation, style_option) elif icon == self.Warning: pixmap = QPixmap(":icons/crystal_clear_warning_56.png") elif icon == self.Critical: pixmap = QApplication.style().standardPixmap( QStyle.SP_MessageBoxCritical, style_option) spacerItem = QSpacerItem(10, 60, QSizePolicy.Minimum, QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem) self.icon_label = QLabel() if pixmap is not None: self.icon_label.setPixmap(pixmap) self.icon_label.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) self.horizontalLayout.addWidget(self.icon_label) spacerItem = QSpacerItem(10, 60, QSizePolicy.Minimum, QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem) # add message self.message_label = QLabel(text) self.message_label.setWordWrap(True) self.message_label.setScaledContents(True) self.message_label.setOpenExternalLinks(True) self.horizontalLayout.addWidget(self.message_label) self.verticalLayout.addLayout(self.horizontalLayout) # create buttons self.buttonBox = QDialogButtonBox(self) self.buttonBox.setObjectName("buttonBox") self.buttonBox.setOrientation(Qt.Horizontal) self._accept_button = None self._reject_button = None self._buttons = buttons self._create_buttons(buttons) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) self.verticalLayout.addWidget(self.buttonBox) if detailed_text: self.btn_show_details = QPushButton(self.tr('Details...')) self.btn_show_details.setCheckable(True) self.btn_show_details.setChecked(True) self.btn_show_details.toggled.connect(self.on_toggled_details) self.buttonBox.addButton(self.btn_show_details, QDialogButtonBox.ActionRole) # create area for detailed text self.textEdit = textEdit = QTextEdit(self) textEdit.setObjectName("textEdit") textEdit.setReadOnly(True) textEdit.setText(detailed_text) # textEdit.setVisible(False) self.verticalLayout.addWidget(self.textEdit) self.resize(480, self.verticalLayout.totalSizeHint().height()) buttons_in_box = self.buttonBox.buttons() if buttons_in_box: self.buttonBox.buttons()[0].setFocus()
def pixmap(self, name): return QPixmap(self.icon_path(name))
def __init__(self, items=list(), buttons=QDialogButtonBox.Cancel | QDialogButtonBox.Ok, exclusive=False, preselect_all=False, title='', description='', icon='', parent=None, select_if_single=True, checkitem1='', checkitem2=''): ''' Creates an input dialog. @param items: a list with strings @type items: C{list()} ''' QDialog.__init__(self, parent=parent) self.setObjectName(' - '.join(['SelectDialog', str(items)])) self.verticalLayout = QVBoxLayout(self) self.verticalLayout.setObjectName("verticalLayout") self.verticalLayout.setContentsMargins(1, 1, 1, 1) # add filter row self.filter_frame = QFrame(self) filterLayout = QHBoxLayout(self.filter_frame) filterLayout.setContentsMargins(1, 1, 1, 1) label = QLabel("Filter:", self.filter_frame) self.filter_field = EnchancedLineEdit(self.filter_frame) filterLayout.addWidget(label) filterLayout.addWidget(self.filter_field) self.filter_field.textChanged.connect(self._on_filter_changed) self.verticalLayout.addWidget(self.filter_frame) if description: self.description_frame = QFrame(self) descriptionLayout = QHBoxLayout(self.description_frame) # descriptionLayout.setContentsMargins(1, 1, 1, 1) if icon: self.icon_label = QLabel(self.description_frame) self.icon_label.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) self.icon_label.setPixmap(QPixmap(icon).scaled(30, 30, Qt.KeepAspectRatio)) descriptionLayout.addWidget(self.icon_label) self.description_label = QLabel(self.description_frame) self.description_label.setWordWrap(True) self.description_label.setText(description) descriptionLayout.addWidget(self.description_label) self.verticalLayout.addWidget(self.description_frame) # create area for the parameter self.content = MainBox(self) if items: self.scroll_area = QScrollArea(self) self.scroll_area.setFocusPolicy(Qt.NoFocus) self.scroll_area.setObjectName("scroll_area") self.scroll_area.setWidgetResizable(True) self.scroll_area.setWidget(self.content) self.verticalLayout.addWidget(self.scroll_area) self.checkitem1 = checkitem1 self.checkitem1_result = False self.checkitem2 = checkitem2 self.checkitem2_result = False # add select all option if not exclusive and items: self._ignore_next_toggle = False self.select_all_checkbox = QCheckBox('all entries') self.select_all_checkbox.setTristate(True) self.select_all_checkbox.stateChanged.connect(self._on_select_all_checkbox_stateChanged) self.verticalLayout.addWidget(self.select_all_checkbox) self.content.toggled.connect(self._on_main_toggle) if self.checkitem1: self.checkitem1_checkbox = QCheckBox(self.checkitem1) self.checkitem1_checkbox.stateChanged.connect(self._on_select_checkitem1_checkbox_stateChanged) self.verticalLayout.addWidget(self.checkitem1_checkbox) if self.checkitem2: self.checkitem2_checkbox = QCheckBox(self.checkitem2) self.checkitem2_checkbox.stateChanged.connect(self._on_select_checkitem2_checkbox_stateChanged) self.verticalLayout.addWidget(self.checkitem2_checkbox) if not items: spacerItem = QSpacerItem(1, 1, QSizePolicy.Expanding, QSizePolicy.Expanding) self.verticalLayout.addItem(spacerItem) # create buttons self.buttonBox = QDialogButtonBox(self) self.buttonBox.setObjectName("buttonBox") self.buttonBox.setOrientation(Qt.Horizontal) self.buttonBox.setStandardButtons(buttons) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) self.verticalLayout.addWidget(self.buttonBox) # set the input fields if items: self.content.createFieldsFromValues(items, exclusive) if (select_if_single and len(items) == 1) or preselect_all: self.select_all_checkbox.setCheckState(Qt.Checked) if not items or len(items) < 7: self.filter_frame.setVisible(False)
def __init__(self, contex): super(PropaGatorGUI, self).__init__(contex) # Initilize variables self._float_status = False self.last_odom_msg = Odometry() self._current_controller = 'Controller: Unknown' self._controller = '' self._controllers = [] # Assign a name self.setObjectName('PropaGatorGUI') # Create a widget self._widget = QWidget() loadUi(os.path.join(cwd, 'propagatorgui.ui'), self._widget) self._widget.setObjectName('PropaGatorGUI') contex.add_widget(self._widget) # Grab all the children from the widget self._kill_label = self._widget.findChild(QLabel, 'kill_label') self._float_label = self._widget.findChild(QLabel, 'float_label') self._controller_label = self._widget.findChild( QLabel, 'controller_label') self._odom_x_label = self._widget.findChild(QLabel, 'odom_x_label') self._odom_y_label = self._widget.findChild(QLabel, 'odom_y_label') self._odom_yaw_label = self._widget.findChild(QLabel, 'odom_yaw_label') self._odom_d_x_label = self._widget.findChild(QLabel, 'odom_d_x_label') self._odom_d_y_label = self._widget.findChild(QLabel, 'odom_d_y_label') self._odom_d_yaw_label = self._widget.findChild( QLabel, 'odom_d_yaw_label') self._placeholder_label = self._widget.findChild( QLabel, 'placeholder_label') self._kill_push_btn = self._widget.findChild(QPushButton, 'kill_push_btn') self._float_push_btn = self._widget.findChild(QPushButton, 'float_push_btn') self._controller_combo_box = self._widget.findChild( QComboBox, 'controller_combo_box') # Load images self._green_indicator = QPixmap( os.path.join(cwd, 'green_indicator.png')) self._red_indicator = QPixmap(os.path.join(cwd, 'red_indicator.png')) self._placeholder_image = QPixmap(os.path.join(cwd, 'placeholder.png')) # Set up ROS interfaces self._kill_listener = KillListener() self._kill_broadcaster = KillBroadcaster( id='PropaGator GUI', description='PropaGator GUI kill') self._odom_sub = rospy.Subscriber('/odom', Odometry, self._odom_cb) self._float_sub = rospy.Subscriber('/controller/float_status', Bool, self._float_cb) self._float_proxy = rospy.ServiceProxy('/controller/float_mode', FloatMode) self._current_controller_sub = rospy.Subscriber( '/controller/current_controller', String, self._current_controller_cb) self._get_all_controllers_proxy = rospy.ServiceProxy( '/controller/get_all_controllers', get_all_controllers) self._request_controller_proxy = rospy.ServiceProxy( '/controller/request_controller', request_controller) # Connect push buttons self._kill_push_btn.toggled.connect(self._on_kill_push_btn_toggle) self._float_push_btn.toggled.connect(self._on_float_push_btn_toggle) # Connect combo boxes self._controller_combo_box.activated[str].connect( self._controller_combo_box_cb) # Set up update timer at 10Hz # A Qt timer is used instead of a ros timer since Qt components are updated self.update_timer = QTimer() self.update_timer.timeout.connect(self._onUpdate) self.update_timer.start(100) # Temp self._placeholder_label.setPixmap(self._placeholder_image)
def __init__(self, gameFrame, fieldImageLabel): self.frame = gameFrame self.field = fieldImageLabel rp = rospkg.RosPack() ip_filename = os.path.join(rp.get_path('bitbots_live_tool_rqt'), 'resource', 'ip_config.yaml') with open(ip_filename, "r") as file: config = yaml.load(file) self.fieldfilename = config.get("FIELD_IMAGE") self.field_scale_global = config.get("FIELD_SCALE") self.default_positions = config.get("DEFAULT_POSITIONS") file.close() print("Config: " + self.fieldfilename + ", " + str(self.field_scale_global)) rp = rospkg.RosPack() self.fieldfilename = os.path.join( BallPool.rp.get_path('bitbots_live_tool_rqt'), 'resource', self.fieldfilename) self.fieldPixmap = QPixmap(self.fieldfilename) self.field.setPixmap(self.fieldPixmap) field_width = self.fieldPixmap.width() field_height = self.fieldPixmap.height() self.field_aspect = float(field_width) / float(field_height) self.frame_aspect = float(self.frame.width()) / float( self.frame.height()) self.field_border = 40 # margin to frame self.transform = QTransform() self.fieldIsSwitched = False self.icon_timeout = 3 self.team_colors = {3: "cyan", 2: "magenta"} if self.field_aspect >= self.frame_aspect: # self.field_size_x = self.frame.width() - self.field_border * 2 self.field_size_y = self.field_size_x / self.field_aspect else: self.field_size_y = self.frame.height() - self.field_border * 2 self.field_size_x = self.field_size_y / self.field_aspect self.field.setScaledContents(True) self.field.setFixedSize(self.field_size_x, self.field_size_y) self.field_scale = float(self.field_size_x) / float(field_width) #print(self.field_scale) self.screenMidX = int(self.frame.width() / 2) self.screenMidY = int(self.frame.height() / 2) self.field.move(self.screenMidX - int(self.field.width() / 2), self.screenMidY - int(self.field.height() / 2)) self.colors = ["red", "green", "yellow", "blue"] self.robots = {} # dict where keys are robot IDs self.tabToRobot = {} # dict where keys are tab-nrs [0-3] self.ball_pool = BallPool(self.frame, size=42) self.rob_pool = RobotPool(self.frame, size=48) self.opp_pool = OpponentPool(self.frame, size=42) self.team_pool = TeammatePool(self.frame, size=42) self.cross_pool = CrossPool(self.frame, size=34) self.undef_pool = UndefinedPool(self.frame, size=42)
def get_qpixmap(icon): pixmap = QPixmap() pixmap.loadFromData(icon.data, format=icon.format) return pixmap
def __init__(self, context): super(TelloPlugin, self).__init__(context) # Give QObjects reasonable names self.setObjectName('TelloPlugin') # 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) # load main widget self._widget = QWidget() self.ui = Ui_TelloPlugin() self.ui.setupUi(self._widget) self.ui.tabWidget.setCurrentIndex(0) self._widget.setObjectName('TelloPluginUi') # Add left and right key arrow blocking filter = KeySuppress() self.ui.tabWidget.installEventFilter(filter) 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) print("Tello widget added") # Tello node self.bridge = CvBridge() self.pos_listener = TransformListener() # Add recorder and Recording Timer self.recording = False self.record_timer = QTimer() self.record_timer.timeout.connect(self.update_record_time) self.record_time = QTime(00,00,00) self.video_recorder = None self.VIDEO_TYPE = {'avi': cv2.VideoWriter_fourcc(*'XVID'), 'mp4': cv2.VideoWriter_fourcc(*'MP4V')} # System, process and Wifi interface info interface = "wlp2s0" ssid_names = "TELLO-FD143A" self.wifi_info = WifiInfo(interface, ssid_names) self.utility = GetUtility() # Callbacks GUI items self.ui.connect_button.clicked[bool].connect(self.handle_connect_clicked) self.ui.record_button.clicked[bool].connect(self.handle_record_clicked) self.ui.foto_button.clicked[bool].connect(self.handle_foto_clicked) self.ui.stop_button.clicked[bool].connect(self.handle_stop_clicked) self.ui.start_button.clicked[bool].connect(self.handle_start_clicked) self.ui.land_button.clicked[bool].connect(self.handle_land_clicked) self.ui.target_button.clicked[bool].connect(self.handle_target_clicked) self.ui.calibrate_button.clicked[bool].connect(self.handle_calibrate_clicked) # Set icons # get an instance of RosPack with the default search paths rospack = rospkg.RosPack() icon_path = rospack.get_path('tello_rqt_gui') + '/src/tello_rqt/resource/icons/' self.ui.record_button.setText('') # override text with icon self.ui.record_button.setIcon(QIcon(QPixmap(icon_path + 'video.png'))) self.ui.record_button.setIconSize(QSize(25,25)) self.ui.foto_button.setText('') # override text with icon self.ui.foto_button.setIcon(QIcon(QPixmap(icon_path + 'foto.png'))) self.ui.foto_button.setIconSize(QSize(25,25)) self.ui.label_record_time.setText('record') # Set bar values to 0 self.ui.link_bar.setValue(0) self.ui.battery_bar.setValue(0) self.ui.cpu_bar.setValue(0) self.ui.memory_bar.setValue(0) self.ui.temperature_bar.setValue(0) # create signals and slots for updates # never access widgets and GUI related things directly from a thread other than the main thread self.sig_connection_changed.connect(self.update_ui_state) self.sig_update_position.connect(self.update_position_data) self.sig_battery_percentage.connect(self.ui.battery_bar.setValue) self.sig_tello_link.connect(self.ui.link_bar.setValue) self.sig_wifi_sig_link.connect(self.ui.wifi_signal_bar.setValue) self.sig_cpu.connect(self.ui.cpu_bar.setValue) self.sig_memory.connect(self.ui.memory_bar.setValue) self.sig_temperature.connect(self.ui.temperature_bar.setValue) self.sig_height.connect(self.ui.label_height.setText) self.sig_speed.connect(self.ui.label_speed.setText) self.sig_flight_time.connect(self.ui.label_flight_time.setText) self.sig_image.connect(self.set_image) self.sig_battery_low.connect(self.ui.label_battery_low.setText) self.sig_is_flying.connect(self.ui.label_is_flying.setText) self.sig_fly_mode.connect(self.ui.label_fly_mode.setText) self.sig_fast_mode.connect(self.ui.label_fast_mode.setText) self.sig_remaining_time.connect(self.ui.label_remaining_time.setText) self.sig_foto_info.connect(self.ui.label_foto.setText) #self.sig_mission_state.connect(self.ui.label_mission_state.setText) # Connect signals from Tello, Controller und SLAM to GUI self.ns_tello = 'tello/' self.ns_controller = 'tello_controller/' self.topic_slam_pose = '/orb_slam2_mono/pose' self.topic_slam_scale = 'tello_controller/slam_real_world_scale' self.tello_state = self.STATE_DISCONNECTED.getname() self.pub_connect = rospy.Publisher(self.ns_tello+'connect', Empty, queue_size=1, latch=True) self.pub_disconnect = rospy.Publisher(self.ns_tello+'disconnect', Empty, queue_size=1, latch=True) self.pub_take_picture = rospy.Publisher(self.ns_tello+'take_picture', Empty, queue_size=1, latch=True) self.pub_mission_command = rospy.Publisher(self.ns_controller+'mission_command', String, queue_size=1, latch=True) self.sub_picture_update = rospy.Subscriber(self.ns_tello+'picture_update', String, self.cb_picture_update) self.sub_status = rospy.Subscriber(self.ns_tello+'status', TelloStatus, self.cb_status) self.sub_connection = rospy.Subscriber(self.ns_tello+'connection_state', String, self.cb_connection) self.sub_video = rospy.Subscriber('tello/camera/image_raw', Image, self.cb_video) self.sub_odom = rospy.Subscriber(self.ns_tello+'odom', Odometry, self.cb_odom, queue_size=1) self.sub_slam_pose = rospy.Subscriber(self.topic_slam_pose, PoseStamped, self.cb_slam_pose, queue_size=1) self.sub_slam_scale = rospy.Subscriber(self.topic_slam_scale, Float32, self.cb_slam_scale, queue_size=1) self.sub_mission = rospy.Subscriber(self.ns_controller+'mission_state', String, self.cb_mission_state) self.cv_image = None # create additional thread for system und process utility self.stop_threads = False self.thread = threading.Thread(target=self.update_sys_util, args=()) self.thread.start() print('init done')
def set_image(self, img_bgr): img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB) # switch b and r channel # Qt Image qt_image = QImage(img_rgb, img_rgb.shape[1], img_rgb.shape[0], QImage.Format_RGB888) self.ui.label_video.setPixmap(QPixmap(qt_image)) # set pixmap to label
def __init__(self, *args, **kwargs): QLabel.__init__(self) self._pixmap = QPixmap(self.pixmap())
def __init__(self, parent=None, info=False): QFrame.__init__(self, parent=parent) self.setObjectName('MessageFrame') self.questionid = self.TYPE_INVALID self.text = "" self.data = MessageData(None) self.IMAGES = { 1: QPixmap(), 2: QPixmap(':/icons/crystal_clear_question.png').scaled( self.ICON_SIZE, self.ICON_SIZE, Qt.IgnoreAspectRatio, Qt.SmoothTransformation), 3: QPixmap(':/icons/crystal_clear_launch_file.png').scaled( self.ICON_SIZE, self.ICON_SIZE, Qt.IgnoreAspectRatio, Qt.SmoothTransformation), 4: QPixmap(":/icons/default_cfg.png").scaled(self.ICON_SIZE, self.ICON_SIZE, Qt.IgnoreAspectRatio, Qt.SmoothTransformation), 5: QPixmap(":/icons/crystal_clear_nodelet_q.png").scaled( self.ICON_SIZE, self.ICON_SIZE, Qt.IgnoreAspectRatio, Qt.SmoothTransformation), 6: QPixmap(":/icons/crystal_clear_launch_file_transfer.png").scaled( self.ICON_SIZE, self.ICON_SIZE, Qt.IgnoreAspectRatio, Qt.SmoothTransformation), 7: QPixmap(":/icons/crystal_clear_question.png").scaled( self.ICON_SIZE, self.ICON_SIZE, Qt.IgnoreAspectRatio, Qt.SmoothTransformation), 8: QPixmap(":/icons/crystal_clear_no_io.png").scaled( self.ICON_SIZE, self.ICON_SIZE, Qt.IgnoreAspectRatio, Qt.SmoothTransformation) } self._new_request = False self.frameui = QFrame() ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'MessageFrame.ui') loadUi(ui_file, self.frameui) color = QColor(255, 207, 121) self.frameui.setVisible(False) self.frameui.scrollArea.setVisible(False) self.frameui.questionOkButton.clicked.connect(self._on_question_ok) self.frameui.questionCancelButton.clicked.connect( self._on_question_cancel) self.frameui.checkBox_dnaa.stateChanged.connect( self._on_checkbox_state_changed) self._ask = 'ask' if info: color = QColor(232, 104, 80) self.frameui.questionCancelButton.setVisible(False) self._ask = 'show' bg_style = "QFrame#questionFame { background-color: %s;}" % color.name( ) self.frameui.setStyleSheet("%s" % (bg_style)) self._queue = MessageQueue() self._do_not_ask = {}