コード例 #1
0
    def init_inspection_test(self):

        button = QPushButton("Robot inspection (beta)")

        menu = QMenu("Menu")
        menu.setStyleSheet("QMenu { menu-scrollable: 1; }");
        submenus = []


        for i in range(5):
            # a component has fields which are either strings or arrays.
            s = menu.addMenu(str(i))
            for j in range(5):
                s.addAction(str(j), partial(self.subscribe_to_field_test, "blubber", j))

        button.setMenu(menu)

        return button
コード例 #2
0
    def init_inspection(self):

        button = QPushButton("Robot inspection (beta)")

        service_list_comps = '/meka_ros_publisher/list_components'
        service_list_fields = '/meka_ros_publisher/list_fields'
        service_req_values = '/meka_ros_publisher/request_values'
        rospy.loginfo("Waiting for %s, %s and %s", service_list_comps, service_list_fields, service_req_values)
        try:
            rospy.wait_for_service(service_list_comps, 4.0)
            rospy.wait_for_service(service_list_fields, 4.0)
            rospy.wait_for_service(service_req_values, 4.0)
        except rospy.ROSException:
            rospy.logerr("%s and/or %s did not show up. Giving up", service_list_comps, service_list_fields)
            return button
            
        self.list_comps_client = rospy.ServiceProxy(service_list_comps, ListComponents)
        self.list_fields_client = rospy.ServiceProxy(service_list_fields, ListFields)
        self.req_vals_client = rospy.ServiceProxy(service_req_values, RequestValues)
        rospy.loginfo("Found %s, %s and %s", service_list_comps, service_list_fields, service_req_values)

        # get all the components
        try:
            resp = self.list_comps_client("")
        except rospy.ServiceException:
            rospy.logerr("Could not call list_components")
            return button
            
        menu = QMenu("Menu")
        menu.setStyleSheet("QMenu { menu-scrollable: 1; }");
        submenus = []

        self.req_action = {}
        if(resp):
            for component in resp.components:
                s = menu.addMenu(component)
                self.req_action[component] = s.addAction("request fields", partial(self.request_fields, component, s))
                

        button.setMenu(menu)

        return button
コード例 #3
0
    def init_stiffness_ctrl(self):
        
        slayout = QVBoxLayout()
        
        prefix = "meka_roscontrol"
        suffix = "stiffness_controller/command"
        
        button = QPushButton("Stiffness controller (beta)")

        self.stiffness_pub = rospy.Publisher("/" + prefix + "/" + suffix, Float64MultiArray, queue_size=1)
        group_names = ["right_arm", "left_arm", "right_hand", "left_hand", "head", "torso", "zlift"]
        # slider for each group
        joint_names = [ "right_arm_j0",
                        "right_arm_j1",
                        "right_arm_j2",
                        "right_arm_j3",
                        "right_arm_j4",
                        "right_arm_j5",
                        "right_arm_j6",
                        "left_arm_j0",
                        "left_arm_j1",
                        "left_arm_j2",
                        "left_arm_j3",
                        "left_arm_j4",
                        "left_arm_j5",
                        "left_arm_j6",
                        "right_hand_j0",
                        "right_hand_j1",
                        "right_hand_j2",
                        "right_hand_j3",
                        "right_hand_j4",
                        "left_hand_j0",
                        "left_hand_j1",
                        "left_hand_j2",
                        "left_hand_j3",
                        "left_hand_j4",
                        "head_j0",
                        "head_j1",
                        "torso_j0",
                        "torso_j1",
                        "zlift_j0"]
        
        self._stiffness_dict = OrderedDict((name, 1.0) for name in joint_names)
        
        menu = QMenu("Menu")
        menu.setStyleSheet("QMenu { menu-scrollable: 1; }");
        self.stiffnessvals = {}
        for group in group_names:
            glayout = QHBoxLayout()
            glayout.addWidget(QLabel(group))
            slider = QSlider(Qt.Horizontal)
            slider.setRange(0,100)
            slider.setValue(100)
            slider.setTickPosition(QSlider.TicksBelow)
            slider.setTickInterval(10)
            slider.setFixedSize(200,15)
            slider.setSingleStep(10)
            slider.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))
            
            val = QLabel("1.0")
            btn = QPushButton("apply")
            self.stiffnessvals[group] = val
            btn.clicked.connect(partial(self.on_stiffness_apply, group))
            
            glayout.addWidget(slider)
            glayout.addWidget(val)
            glayout.addWidget(btn)
            
            slider.valueChanged.connect(partial(self.on_stiffness_change, slider, val, group))
            
            slayout.addLayout(glayout)
            
            
            groupm = menu.addMenu(group)
            #for joint in joint_names:
                #groupm.addAction("set stiffness", partial(self.set_stiffness, groupm))
                #if group in joint:
                #    groupm.addAction(self._stiffness_dict[joint])
                #    s.addAction(joint, partial(self.request_fields, component, s))
        
        

        button.setMenu(menu)

        return slayout
コード例 #4
0
ファイル: spelling.py プロジェクト: donny08/mishkal-02
    def contextMenuEvent(self, event):
        popup_menu = self.createStandardContextMenu()
        #~popup_menu = QMenu()
        #~self.setContextMenuPolicy()
        RightToLeft = 1
        # Select the word under the cursor.
        cursor = self.textCursor()
        cursor.select(QTextCursor.WordUnderCursor)
        self.setTextCursor(cursor)

        # Check if the selected word is misspelled and offer spelling
        # suggestions if it is.
        if self.textCursor().hasSelection():

            #~text = (unicode(self.textCursor().selectedText()))
            #this is a workaround for QT bug when double click selects Arabic punctuation marks
            # plus the word in the text editor see https://bugreports.qt-project.org/browse/QTBUG-42397
            #~ originaltext = unicode(self.textCursor().selectedText())
            originaltext = self.textCursor().selectedText()

            arabicmarks = [u'؟', u'،', u'؛', u'“', u'”', u'‘', u'’']
            holder = originaltext[-1]
            if holder in arabicmarks:
                self.pretxt = holder
            else:
                self.pretxt = ''
            text = originaltext.strip(u'؟،؛“”‘’')
            spell_menu = QMenu(u'المزيد...')
            spell_menu.setLayoutDirection(RightToLeft)
            # the word is aleady analyzed
            if self.dict.check(text):

                suggests = self.dict.suggest(text)
                for word in suggests[:10]:
                    action = SpellAction(word, spell_menu)
                    action.correct.connect(self.correctWord)
                    #~spell_menu.addAction(action)
                    popup_menu.addAction(action)

                #~spell_menu.setStyleSheet("QMenu {font: 32px;  margin: 2px;}")
                popup_menu.setStyleSheet("QMenu {font: 24px;}")
                # Only add the spelling suggests to the menu if there are
                # suggestions.

                #~if len(spell_menu.actions()) != 0:
                #~popup_menu.insertSeparator(popup_menu.actions()[0])
                #~popup_menu.insertMenu(popup_menu.actions()[0], spell_menu)
                if len(suggests) > 10:
                    for word in suggests[10:]:
                        action = SpellAction(word, spell_menu)
                        action.correct.connect(self.correctWord)
                        #~spell_menu.addAction(action)
                        spell_menu.addAction(action)
                    spell_menu.setStyleSheet("QMenu {font: 24px;}")

                    popup_menu.addSeparator()
                    popup_menu.addMenu(spell_menu)

                if len(suggests) == 1 and not araby.is_vocalized(suggests[0]):
                    addtodict_action = popup_menu.addAction(u'أضف للقاموس')
                    #~addtodict_action.triggered.connect( lambda x = x = originaltext: self.add_to_dict(x))
                    addtodict_action.triggered.connect(
                        lambda: self.add_to_dict(originaltext))
                    # if the word hs no suggestions
                    # we lookup for customized vocalization
                    suggests = self.dict.custom_dict.lookup(word)
                    for word in suggests:
                        action = SpellAction(word, spell_menu)
                        action.correct.connect(self.correctWord)
                        #~spell_menu.addAction(action)
                        popup_menu.addAction(action)

            else:
                # redo taskeel for this word
                #~pass;
                # if the word hs no suggestions
                # we lookup for customized vocalization
                suggests = self.dict.custom_dict.lookup(text)
                for word in suggests:
                    action = SpellAction(word, spell_menu)
                    action.correct.connect(self.correctWord)
                    #~spell_menu.addAction(action)
                    popup_menu.addAction(action)
        popup_menu.exec_(event.globalPos())