def _create_context_tag_menu(self): parent_tag, inblock, attrs = self._get_parent_tag() if not parent_tag: return None menu = QtGui.QMenu(self) menu.triggered.connect(self._context_activated) text = self.toPlainText() pos = self.textCursor().position() - 1 try: if not inblock: # create a menu with attributes attributes = sorted(list((set(XmlHighlighter.LAUNCH_ATTR[parent_tag]) - set(attrs)))) for attr in attributes: action = menu.addAction(attr.rstrip('=')) action.setData('%s"'%attr if text[pos] == ' ' else ' %s"'%attr) else: # create a menu with tags tags = sorted(XmlHighlighter.LAUNCH_CHILDS[parent_tag]) if not tags: return None for tag in tags: data = '<%s></%s>'%(tag, tag) if XmlHighlighter.LAUNCH_CHILDS[tag] else '<%s/>'%tag if text[pos] == '<': data = data[1:] action = menu.addAction(tag) action.setData(data) except: # import traceback # print traceback.format_exc() return None return menu
def _create_tag_button(self, parent=None): btn = QtGui.QPushButton(parent) btn.setObjectName("tagButton") btn.setText(QtGui.QApplication.translate("XmlEditor", "Add tag", None, QtGui.QApplication.UnicodeUTF8)) btn.setShortcut(QtGui.QApplication.translate("XmlEditor", "Ctrl+T", None, QtGui.QApplication.UnicodeUTF8)) btn.setToolTip('Adds a ROS launch tag to launch file (Ctrl+T)') # creates a tag menu tag_menu = QtGui.QMenu(btn) # group tag add_group_tag_action = QtGui.QAction("<group>", self, statusTip="", triggered=self._on_add_group_tag) tag_menu.addAction(add_group_tag_action) # node tag add_node_tag_action = QtGui.QAction("<node>", self, statusTip="", triggered=self._on_add_node_tag) tag_menu.addAction(add_node_tag_action) # node tag with all attributes add_node_tag_all_action = QtGui.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 = QtGui.QAction("<include>", self, statusTip="", triggered=self._on_add_include_tag_all) tag_menu.addAction(add_include_tag_all_action) # remap add_remap_tag_action = QtGui.QAction("<remap>", self, statusTip="", triggered=self._on_add_remap_tag) tag_menu.addAction(add_remap_tag_action) # env tag add_env_tag_action = QtGui.QAction("<env>", self, statusTip="", triggered=self._on_add_env_tag) tag_menu.addAction(add_env_tag_action) # param tag add_param_tag_action = QtGui.QAction("<param>", self, statusTip="", triggered=self._on_add_param_tag) tag_menu.addAction(add_param_tag_action) # param tag with all attributes add_param_tag_all_action = QtGui.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 = QtGui.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 = QtGui.QAction("<arg default>", self, statusTip="", triggered=self._on_add_arg_tag_default) tag_menu.addAction(add_arg_tag_default_action) # arg tag with value definition add_arg_tag_value_action = QtGui.QAction("<arg value>", self, statusTip="", triggered=self._on_add_arg_tag_value) tag_menu.addAction(add_arg_tag_value_action) # test tag add_test_tag_action = QtGui.QAction("<test>", self, statusTip="", triggered=self._on_add_test_tag) tag_menu.addAction(add_test_tag_action) # test tag with all attributes add_test_tag_all_action = QtGui.QAction("<test all>", self, statusTip="", triggered=self._on_add_test_tag_all) tag_menu.addAction(add_test_tag_all_action) btn.setMenu(tag_menu) return btn
def _create_context_substitution_menu(self): text = self.toPlainText() pos = self.textCursor().position() - 1 try: if text[pos] == '$' or (text[pos] == '(' and text[pos-1] == '$'): menu = QtGui.QMenu(self) menu.triggered.connect(self._context_activated) for arg in self.SUBSTITUTION_ARGS: action = menu.addAction("%s"%arg) action.setData("(%s"%arg if text[pos] == '$' else "%s"%arg) return menu except: pass return None
def __init__(self, parent=None): ''' Creates the window, connects the signals and init the class. ''' QtGui.QDockWidget.__init__(self, parent) # initialize parameter self.__current_path = os.path.expanduser('~') # load the UI file ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'LaunchFilesDockWidget.ui') loadUi(ui_file, self) # initialize the view for the launch files self.launchlist_model = LaunchListModel() self.launchlist_proxyModel = QtGui.QSortFilterProxyModel(self) self.launchlist_proxyModel.setSourceModel(self.launchlist_model) self.xmlFileView.setModel(self.launchlist_proxyModel) self.xmlFileView.setAlternatingRowColors(True) self.xmlFileView.activated.connect(self.on_launch_selection_activated) self.xmlFileView.setDragDropMode(QtGui.QAbstractItemView.DragOnly) self.xmlFileView.setDragEnabled(True) sm = self.xmlFileView.selectionModel() sm.selectionChanged.connect(self.on_xmlFileView_selection_changed) # self.searchPackageLine.setVisible(False) self.searchPackageLine.textChanged.connect(self.set_package_filter) self.searchPackageLine.focusInEvent = self._searchline_focusInEvent # connect to the button signals self.refreshXmlButton.clicked.connect(self.on_refresh_xml_clicked) self.editXmlButton.clicked.connect(self.on_edit_xml_clicked) self.newXmlButton.clicked.connect(self.on_new_xml_clicked) self.openXmlButton.clicked.connect(self.on_open_xml_clicked) self.transferButton.clicked.connect(self.on_transfer_file_clicked) self.loadXmlButton.clicked.connect(self.on_load_xml_clicked) self.loadXmlAsDefaultButton.clicked.connect(self.on_load_as_default) # creates a default config menu start_menu = QtGui.QMenu(self) self.loadDeafaultAtHostAct = QtGui.QAction( "&Load default config on host", self, statusTip="Loads the default config at given host", triggered=self.on_load_as_default_at_host) start_menu.addAction(self.loadDeafaultAtHostAct) self.loadXmlAsDefaultButton.setMenu(start_menu) #initialize the progress queue self.progress_queue = ProgressQueue(self.progressFrame_cfg, self.progressBar_cfg, self.progressCancelButton_cfg)
def __init__(self, parent=None): super(QTreeView, self).__init__(parent) self.selected_index = None self.ConfigHeader = ConfigTreeModel(None) self.setModel(self.ConfigHeader) self.setEditTriggers(QtGui.QAbstractItemView.AllEditTriggers) self.delagate = ItemDelegate(self) self.setItemDelegate(self.delagate) self.setEditTriggers(QAbstractItemView.AllEditTriggers) self.setAlternatingRowColors(True) style = """ QTreeView { background-color: #EAF5FF; alternate-background-color: #D5EAFF; } QTreeView::item { border: 1px solid #d9d9d9; border-top-color: transparent; border-bottom-color: transparent; } QTreeView::item:hover { background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e7effd, stop: 1 #cbdaf1); border: 1px solid #bfcde4; } QTreeView::item:selected { border: 1px solid #567dbc; } QTreeView::item:selected:active{ background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6ea1f1, stop: 1 #567dbc); } QTreeView::item:selected:!active { background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6b9be8, stop: 1 #577fbf); } """ self.setStyleSheet(style) #self.delagate.closeEditor.connect(self.param_changed) self.ConfigHeader.dataChanged.connect(self.param_changed) self.pressed.connect( self.presseda) self.data = None self.supported_types = loadItems() self.menu_Enabled = True self.convert_actions = [] self.menuAddItem = QtGui.QMenu(self) self.menuAddItem.setTitle(QtGui.QApplication.translate("Right CLick", "Add Item..", None, QApplication.UnicodeUTF8)) self.menuAddItem.setObjectName(_fromUtf8("menuAddItem")) self.menuConvertTo = QtGui.QMenu(self) self.menuConvertTo.setTitle(QtGui.QApplication.translate("Right CLick", "Convert To..", None, QApplication.UnicodeUTF8)) self.menuConvertTo.setObjectName(_fromUtf8("menuConvertTo")) self.menuAddItem = QtGui.QMenu(self) self.menuAddItem.setTitle(QtGui.QApplication.translate("Right CLick", "Add Item..", None, QApplication.UnicodeUTF8)) self.menuAddItem.setObjectName(_fromUtf8("menuAddItem")) #Set up drag and drop stuff... self.dragEnabled() self.acceptDrops() self.showDropIndicator() self.setDragDropMode(QAbstractItemView.InternalMove) #TODO add convert to / add item types # types = loadItems() # for type, val in types.items(): # name = val().json['gui_type'] # # act = QtGui.QAction(self) # act.my_type = val # act.setText(QtGui.QApplication.translate("MainWindow", name, None, QtGui.QApplication.UnicodeUTF8)) # act.setObjectName(_fromUtf8("actionConvertTo" + name)) # act.triggered.connect(self.convert_to) # self.menuConvertTo.addAction(act) # # self.type_names = [] # self.type_definitions = {} # for type, val in types.items(): # name = val().json['gui_type'] # # self.type_names.append(name) # self.type_definitions[name] = val # act = QtGui.QAction(self) # act.my_type = type # act.setText(QtGui.QApplication.translate("MainWindow", name, None, QtGui.QApplication.UnicodeUTF8)) # act.setObjectName(_fromUtf8("actionAddItem" + name)) # act.triggered.connect(self.add_param) # self.menuAddItem.addAction(act) self.actionDelete_Item = QtGui.QAction(self) self.actionDelete_Item.setText('Delete Item') self.actionDelete_Item.triggered.connect(self.delete_item) self.actionEdit_Item = QtGui.QAction(self) self.actionEdit_Item.setText('Edit Item') self.actionEdit_Item.triggered.connect(self.edit_item)