def get_header_action(parent, map_name): label = QLabel(map_name) font = label.font() font.setBold(True) label.setFont(font) label.setStyleSheet('color: black; margin:5px; margin-left: 15px;') action = QWidgetAction(parent) action.setDisabled(True) action.setDefaultWidget(label) return action
def __evt_yeahdoc_contextMenu(self, p): """ context menu """ item = self.yeahdoclisttree.currentItem() if item == None or item.isDisabled(): pass else: menu = QMenu() # menu top action = QWidgetAction(self) title = item.text(0) if len(title) < 25: for i in range(len(title), 25): title = title + " " action.setDefaultWidget( QLabel(" <img src='%s'/> %s" % (getPath("iconDir", "yeahdoc/item.png"), title))) menu.addAction(action) menu.addSeparator() menu.addAction(self.__actions["__yeahdoc_open__"]) menu.addAction(self.__actions["__yeahdoc_edit__"]) # change class change_class_menu = QMenu() entry = YeahdocDatasSupply().bb_read1_simple(item.getMark()) current_categoryid = entry['categoryid'] for class_item in YeahdocDatasSupply().bc_list(): action = QAction(class_item["title"], self, \ triggered=lambda re, item=item, categoryid=str(class_item["id"]): \ self.__evt_change_category(categoryid, item)) action.setIcon(QIcon(getPath("iconDir", "yeahdoc/flag/%s" % str(class_item["img"])))) action.setIconVisibleInMenu(True) # mark current class id menu checked if class_item['id'] == current_categoryid: action.setCheckable(True) action.setChecked(True) action.setDisabled(True) change_class_menu.addAction(action) action = QAction(QIcon(getPath("iconDir", "yeahdoc/change.png")), QApplication.translate("YeahdocList", "Change Category"), self) action.setIconVisibleInMenu(True) action.setMenu(change_class_menu) menu.addAction(action) menu.addAction(self.__actions["__yeahdoc_star__"]) menu.addAction(self.__actions["__yeahdoc_rename__"]) menu.addAction(self.__actions["__yeahdoc_delete__"]) menu.addSeparator() setmode = True if entry['lock'] == 0 else False action = QWidgetAction(self) widget = QWidget() layout = QHBoxLayout() layout.setSpacing(0) layout.setMargin(0) widget.setLayout(layout) widgetMore = QWidget() widgetMore.setVisible(False) layoutMore = QHBoxLayout() layoutMore.setSpacing(0) layoutMore.setMargin(0) widgetMore.setLayout(layoutMore) layout.addWidget(QLabel("<img src='%s'/>" % getPath("iconDir", "yeahdoc/password.png"))) passwordMore = QPushButton( QApplication.translate("YeahdocEditor", "Encrypt") if setmode else QApplication.translate( "YeahdocEditor", "Decrypt")) passwordMore.setFlat(True) layout.addWidget(passwordMore) passwordInput = QLineEdit() passwordInput.setEchoMode(QLineEdit.Password) passwordInput.setMaximumWidth(70) layoutMore.addWidget(passwordInput) if setmode: passwordInputAgain = QLineEdit() passwordInputAgain.setEchoMode(QLineEdit.Password) passwordInputAgain.setMaximumWidth(70) layoutMore.addWidget(QLabel(QApplication.translate("YeahdocEditor", "Re"))) layoutMore.addWidget(passwordInputAgain) passwordSubmit = QPushButton("OK") passwordSubmit.setFlat(True) layoutMore.addWidget(passwordSubmit) layout.addWidget(widgetMore) layout.addItem(QSpacerItem(0, 20, QSizePolicy.Expanding, QSizePolicy.Expanding)) action.setDefaultWidget(widget) QObject.connect(passwordSubmit, SIGNAL("clicked ()"), lambda: self.__evt_password(setmode, passwordInput.text(), passwordInputAgain.text() if setmode else "")) QObject.connect(passwordMore, SIGNAL("clicked ()"), lambda: widgetMore.setVisible(not widgetMore.isVisible())) menu.addAction(action) # show it. menu.exec_(self.mapToGlobal(self.yeahdoclisttree.mapTo(self, p)))