class PaletteDisplay(QWidget): def __init__(self, colors, window): super(PaletteDisplay, self).__init__(window) self.window = window self.main_editor = self.window.window.window self.color_display_list = [] self.layout = QHBoxLayout() self.layout.setSpacing(0) self.layout.setMargin(0) self.layout.setContentsMargins(0, 0, 0, 0) self.setLayout(self.layout) for idx, color in enumerate(colors): color_display = ColorDisplay(idx, self) color_display.set_color(color.name(), create=True) color_display.colorChanged.connect(self.on_color_change) self.layout.addWidget(color_display, 0, Qt.AlignCenter) self.color_display_list.append(color_display) def set_color(self, idx, color): self.color_display_list[idx].set_color(color.name()) def on_color_change(self, idx, color): self.main_editor.update_view()
def __init__(self, text, item): QWidget.__init__(self) self.setMouseTracking(True) self.text = text self.item = item self.label = QLabel() self.checkBox = QCheckBox("") self.checkBox.setTristate(True) self.checkBox.stateChanged.connect(self.check_box_state_changed) layout = QHBoxLayout() layout.setMargin(0) layout.addWidget(self.checkBox) layout.addWidget(self.label) layout.addStretch() self.setLayout(layout)
def __init__(self, quad): QWidget.__init__(self) self.setMouseTracking(True) self.quad = quad self.nameLabel = QLabel( f'<b>{quad[ID]}</b><br><span style="color:grey;">' f'{quad[PERCENT_COVERED]} % covered</span>') self.iconLabel = QLabel() pixmap = QPixmap(PLACEHOLDER_THUMB, 'SVG') thumb = pixmap.scaled(48, 48, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation) self.iconLabel.setPixmap(thumb) self.checkBox = QCheckBox("") self.checkBox.stateChanged.connect(self.check_box_state_changed) layout = QHBoxLayout() layout.setMargin(0) layout.addWidget(self.checkBox) vlayout = QVBoxLayout() vlayout.setMargin(0) vlayout.addWidget(self.iconLabel) self.iconWidget = QWidget() self.iconWidget.setFixedSize(48, 48) self.iconWidget.setLayout(vlayout) layout.addWidget(self.iconWidget) layout.addWidget(self.nameLabel) layout.addStretch() self.setLayout(layout) download_thumbnail(quad[LINKS][THUMBNAIL], self) self.footprint = QgsRubberBand(iface.mapCanvas(), QgsWkbTypes.PolygonGeometry) self.footprint.setFillColor(QUADS_AOI_COLOR) self.footprint.setStrokeColor(QUADS_AOI_COLOR) self.footprint.setWidth(2) self.footprintfill = QgsRubberBand(iface.mapCanvas(), QgsWkbTypes.PolygonGeometry) self.footprintfill.setFillColor(QUADS_AOI_BODY_COLOR) self.footprintfill.setWidth(0) self.update_footprint_brush() self.hide_solid_interior() self.show_footprint() self.setStyleSheet( "QuadInstanceItemWidget{border: 2px solid transparent;}")
def __init__(self, mosaic): QWidget.__init__(self) self.mosaic = mosaic title = mosaic_title(mosaic) self.nameLabel = QLabel( f'<span style="color:black;"><b>{title}</b></span>' f'<br><span style="color:grey;">{mosaic[NAME]}</span>') self.iconLabel = QLabel() self.toolsButton = QLabel() self.toolsButton.setPixmap(COG_ICON.pixmap(QSize(18, 18))) self.toolsButton.mousePressEvent = self.showContextMenu pixmap = QPixmap(PLACEHOLDER_THUMB, "SVG") thumb = pixmap.scaled(48, 48, Qt.KeepAspectRatio, Qt.SmoothTransformation) self.iconLabel.setPixmap(thumb) self.checkBox = QCheckBox("") self.checkBox.stateChanged.connect(self.basemapSelected.emit) layout = QHBoxLayout() layout.setMargin(2) layout.addWidget(self.checkBox) vlayout = QVBoxLayout() vlayout.setMargin(0) vlayout.addWidget(self.iconLabel) self.iconWidget = QWidget() self.iconWidget.setFixedSize(48, 48) self.iconWidget.setLayout(vlayout) layout.addWidget(self.iconWidget) layout.addWidget(self.nameLabel) layout.addStretch() layout.addWidget(self.toolsButton) layout.addSpacing(10) self.setLayout(layout) if THUMB in mosaic[LINKS]: download_thumbnail(mosaic[LINKS][THUMB], self) else: THUMBNAIL_DEFAULT_URL = ( "https://tiles.planet.com/basemaps/v1/planet-tiles/" "{name}/thumb?api_key={apikey}") download_thumbnail( THUMBNAIL_DEFAULT_URL.format( name=mosaic[NAME], apikey=PlanetClient.getInstance().api_key()), self, )
def __init__(self, data, data_catalogue_client): QFrame.__init__(self) self.data = data self.dataCatalogueClient = data_catalogue_client layout = QHBoxLayout() layout.setMargin(0) self.radioButton = QRadioButton() self.radioButton.toggled.connect(self.radioButtonToggled) layout.addWidget(self.radioButton) self.button = QPushButton() self.button.clicked.connect(self.buttonClicked) self.updateContent() layout.addStretch() layout.addWidget(self.button) self.setLayout(layout) self.setStyleSheet("QFrame { background-color: white; }") if (QgsSettings().value("/kadasrouting/activeValhallaTilesID", "default") == self.data["id"]): self.radioButton.setChecked(True)
def __init__(self, parent, tree, name, value, action=None): QTreeWidgetItem.__init__(self, parent) self.parent = parent self.tree = tree self.name = name self._value = value self.combo = None self.setText(0, name) widget = None if isinstance(value, QgsColorButton): widget = value elif isinstance(value, bool): if value: self.setCheckState(1, Qt.Checked) else: self.setCheckState(1, Qt.Unchecked) elif isinstance(value, tuple): self.combo = QComboBox() self.combo.setSizeAdjustPolicy(0) for option in value: self.combo.addItem(option) widget = self.combo else: self.setText(1, unicode(value)) if action: layout = QHBoxLayout() layout.setMargin(0) if widget: layout.addWidget(widget) button = QToolButton() button.setDefaultAction(action) button.setText(action.text()) layout.addWidget(button) layout.addStretch(1) widget = QWidget() widget.setLayout(layout) if widget: self.tree.setItemWidget(self, 1, widget)
def init_form(self): self._boundingbox = GaugeWidgetHorizontal( ) if self._horizontal else GaugeWidgetVertical() self._boundingbox.changed_event = self.__update if self._show_spinboxes: self._form = hwidget = QWidget() if self._horizontal: hlayout = QHBoxLayout() else: hlayout = QVBoxLayout() if conf.PYFORMS_USE_QT5: hlayout.setContentsMargins(0, 0, 0, 0) else: hlayout.setMargin(0) hwidget.setLayout(hlayout) self._min_spinbox = QSpinBox() self._min_spinbox.valueChanged.connect(self.__min_spinbox_changed) self._min_spinbox.setMaximumWidth(95) self._max_spinbox = QSpinBox() self._max_spinbox.valueChanged.connect(self.__max_spinbox_changed) self._max_spinbox.setMaximumWidth(95) if self._horizontal: hlayout.addWidget(self._min_spinbox) else: hlayout.addWidget(self._max_spinbox) hlayout.addWidget(self._boundingbox) if self._horizontal: hlayout.addWidget(self._max_spinbox) else: hlayout.addWidget(self._min_spinbox) else: self._form = self._boundingbox super(ControlBoundingSlider, self).init_form()
class ImageLayout(QDialog): def __init__(self, path, title): QDialog.__init__(self) #self.setModal(False) offset = 100#px windowsSize = [GetSystemMetrics(0)-offset, GetSystemMetrics(1)-offset] self.setWindowTitle(title) self.setWindowFlags(Qt.Window)# | Qt.WindowTitleHint | Qt.WindowCloseButtonHint | Qt.CustomizeWindowHint) self.horizontalLayout = QHBoxLayout(self) self.horizontalLayout.setMargin(0) self.webView = QtWebEngine.QWebEngineView(self) sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.webView.sizePolicy().hasHeightForWidth()) self.webView.setSizePolicy(sizePolicy) self.horizontalLayout.addWidget(self.webView) self.webView.settings().setAttribute(QtWebEngine.QWebEngineSettings.PluginsEnabled, True) self.webView.show() self.webView.load(QUrl(path)) # Change path to actual file. QApplication.restoreOverrideCursor() self.exec_() #self.show() def closeEvent(self, evnt): self.webView.close() self.close()
def value(self, value): ControlBase.label.fset(self, value) for item in range(self.form.count(), -1, -1): self.form.removeItem(item) for item in value: if isinstance(item, tuple): widget = QFrame(self.form) layout = QVBoxLayout() if conf.PYFORMS_USE_QT5: layout.setContentsMargins(0, 0, 0, 0) else: layout.setMargin(0) widget.setLayout(layout) for e in item[1]: if isinstance(e, tuple): hwidget = QFrame(self.form) hlayout = QHBoxLayout() if conf.PYFORMS_USE_QT5: hlayout.setContentsMargins(0, 0, 0, 0) else: hlayout.setMargin(0) hwidget.setLayout(hlayout) for ee in e: hlayout.addWidget(ee.form) widget.layout().addWidget(hwidget) else: widget.layout().addWidget(e.form) self.form.addItem(widget, item[0]) else: self.form.addItem(item.form, item.label)
def generate_panel(self, formset): """ Generate a panel for the module form with all the controls formset format example: [('_video', '_arenas', '_run'), {"Player":['_threshold', "_player", "=", "_results", "_query"], "Background image":[(' ', '_selectBackground', '_paintBackground'), '_image']}, "_progress"] tuple: will display the controls in the same horizontal line list: will display the controls in the same vertical line dict: will display the controls in a tab widget '||': will plit the controls in a horizontal line '=': will plit the controls in a vertical line @param formset: Form configuration @type formset: list """ control = None if '=' in formset: control = QSplitter(QtCore.Qt.Vertical) tmp = list(formset) index = tmp.index('=') firstPanel = self.generate_panel(formset[0:index]) secondPanel = self.generate_panel(formset[index + 1:]) control.addWidget(firstPanel) control.addWidget(secondPanel) self._splitters.append(control) return control elif '||' in formset: control = QSplitter(QtCore.Qt.Horizontal) tmp = list(formset) rindex = lindex = index = tmp.index('||') rindex -= 1 rindex += 2 if isinstance(formset[lindex - 1], int): lindex = lindex - 1 if len(formset) > rindex and isinstance(formset[index + 1], int): rindex += 1 firstPanel = self.generate_panel(formset[0:lindex]) secondPanel = self.generate_panel(formset[rindex:]) if isinstance(formset[index - 1], int): firstPanel.setMaximumWidth(formset[index - 1]) if isinstance(formset[index + 1], int): secondPanel.setMaximumWidth(formset[index + 1]) control.addWidget(firstPanel) control.addWidget(secondPanel) self._splitters.append(control) return control control = QFrame(self) layout = None if type(formset) is tuple: layout = QHBoxLayout() for row in formset: if isinstance(row, (list, tuple)): panel = self.generate_panel(row) layout.addWidget(panel) elif row == " ": spacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) layout.addItem(spacer) elif type(row) is dict: c = self.generate_tabs(row) layout.addWidget(c) self._tabs.append(c) else: param = self.controls.get(row, None) if param is None: label = QLabel() label.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) # layout.addWidget( label ) if row.startswith('info:'): label.setText(row[5:]) font = QFont() font.setPointSize(10) label.setFont(font) label.setAccessibleName('info') elif row.startswith('h1:'): label.setText(row[3:]) font = QFont() font.setPointSize(17) font.setBold(True) label.setFont(font) label.setAccessibleName('h1') elif row.startswith('h2:'): label.setText(row[3:]) font = QFont() font.setPointSize(16) font.setBold(True) label.setFont(font) label.setAccessibleName('h2') elif row.startswith('h3:'): label.setText(row[3:]) font = QFont() font.setPointSize(15) font.setBold(True) label.setFont(font) label.setAccessibleName('h3') elif row.startswith('h4:'): label.setText(row[3:]) font = QFont() font.setPointSize(14) font.setBold(True) label.setFont(font) label.setAccessibleName('h4') elif row.startswith('h5:'): label.setText(row[3:]) font = QFont() font.setPointSize(12) font.setBold(True) label.setFont(font) label.setAccessibleName('h5') else: label.setText(row) font = QFont() font.setPointSize(10) label.setFont(font) label.setAccessibleName('msg') label.setToolTip(label.text()) layout.addWidget(label) else: param.parent = self param.name = row layout.addWidget(param.form) elif type(formset) is list: layout = QVBoxLayout() for row in formset: if isinstance(row, (list, tuple)): panel = self.generate_panel(row) layout.addWidget(panel) elif row == " ": spacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding) layout.addItem(spacer) elif type(row) is dict: c = self.generate_tabs(row) layout.addWidget(c) self._tabs.append(c) else: param = self.controls.get(row, None) if param is None: label = QLabel() label.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) label.resize(30, 30) # layout.addWidget( label ) if row.startswith('info:'): label.setText(row[5:]) font = QFont() font.setPointSize(10) label.setFont(font) label.setAccessibleName('info') elif row.startswith('h1:'): label.setText(row[3:]) font = QFont() font.setPointSize(17) font.setBold(True) label.setFont(font) label.setAccessibleName('h1') elif row.startswith('h2:'): label.setText(row[3:]) font = QFont() font.setPointSize(16) font.setBold(True) label.setFont(font) label.setAccessibleName('h2') elif row.startswith('h3:'): label.setText(row[3:]) font = QFont() font.setPointSize(15) font.setBold(True) label.setFont(font) label.setAccessibleName('h3') elif row.startswith('h4:'): label.setText(row[3:]) font = QFont() font.setPointSize(14) font.setBold(True) label.setFont(font) label.setAccessibleName('h4') elif row.startswith('h5:'): label.setText(row[3:]) font = QFont() font.setPointSize(12) font.setBold(True) label.setFont(font) label.setAccessibleName('h5') else: label.setText(row) font = QFont() font.setPointSize(10) label.setFont(font) label.setAccessibleName('msg') label.setToolTip(label.text()) layout.addWidget(label) else: param.parent = self param.name = row layout.addWidget(param.form) if conf.PYFORMS_USE_QT5: layout.setContentsMargins(0, 0, 0, 0) else: layout.setMargin(0) control.setLayout(layout) return control
class LocationInputWidget(QWidget): pointUpdated = pyqtSignal(QgsPointXY) def __init__( self, canvas, locationSymbolPath=":/kadas/icons/pin_red", pinAnchorX=0.5, pinAnchorY=1, ): QWidget.__init__(self) # UI self.canvas = canvas self.locationSymbolPath = locationSymbolPath # By default the anchor is 0.5, 1 which means in the middle bottom of the symbol self.pinAnchorX = pinAnchorX self.pinAnchorY = pinAnchorY self.layout = QHBoxLayout() self.layout.setMargin(0) self.searchBox = AutoCompleteWidget() self.searchBox.finished.connect(self.getLocation) self.searchBox.error.connect(pushWarning) self.layout.addWidget(self.searchBox) self.btnGPS = QToolButton() self.btnGPS.setToolTip(self.tr("Get GPS location")) self.btnGPS.setIcon(icon("gps.png")) self.btnGPS.clicked.connect(self.getCoordFromGPS) self.layout.addWidget(self.btnGPS) self.btnMapTool = QToolButton() self.btnMapTool.setCheckable(True) self.btnMapTool.setToolTip(self.tr("Choose location on the map")) self.btnMapTool.setIcon(QIcon(":/kadas/icons/pick")) self.btnMapTool.toggled.connect(self.btnMapToolClicked) self.layout.addWidget(self.btnMapTool) self.setLayout(self.layout) self.prevMapTool = self.canvas.mapTool() self.mapTool = None self.canvas.mapToolSet.connect(self._mapToolSet) self.point = None self.pin = None self.locationName = "" self._gpsConnection = None def getLocation(self, dictionary): label = dictionary["label"] lat = dictionary["lat"] lon = dictionary["lon"] self.setPointFromLonLat(lon, lat) self.setLocationName(label) def textChanged(self, text): self.addPin() def _mapToolSet(self, new, old): if not new == self.mapTool: self.btnMapTool.blockSignals(True) self.btnMapTool.setChecked(False) self.btnMapTool.blockSignals(False) def getCoordFromGPS(self): connection = getGpsConnection() if connection: info = connection.currentGPSInformation() pointString = "{:.6f},{:.6f}".format(info.longitude, info.latitude) self.searchBox.setText(pointString) self.setPoint(QgsPointXY(info.longitude, info.latitude)) # TODO: Perhaps put reverse geocoding here self.setLocationName(pointString) else: pushWarning(self.tr("Cannot connect to GPS")) def createMapTool(self): self.mapTool = PointCaptureMapTool(self.canvas) self.mapTool.canvasClicked.connect(self.updatePoint) self.mapTool.complete.connect(self.stopSelectingPoint) def btnMapToolClicked(self, checked): if checked: self.startSelectingPoint() else: self.stopSelectingPoint() def startSelectingPoint(self): """Start selecting a point (when the map tool button is clicked)""" self.createMapTool() self.canvas.setMapTool(self.mapTool) def updatePoint(self, point, button): """When the map tool click the map canvas""" outCrs = QgsCoordinateReferenceSystem(4326) canvasCrs = self.canvas.mapSettings().destinationCrs() transform = QgsCoordinateTransform(canvasCrs, outCrs, QgsProject.instance()) wgspoint = transform.transform(point) pointString = "{:.6f},{:.6f}".format(wgspoint.x(), wgspoint.y()) self.searchBox.setText(pointString) self.setPoint(wgspoint) # TODO: Perhaps put reverse geocoding here self.setLocationName(pointString) def stopSelectingPoint(self): """Finish selecting a point.""" self.mapTool = self.canvas.mapTool() self.canvas.setMapTool(self.prevMapTool) def addPin(self): # Remove an existing pin first self.removePin() try: if not self.point: return inCrs = QgsCoordinateReferenceSystem(4326) canvasCrs = self.canvas.mapSettings().destinationCrs() transform = QgsCoordinateTransform(inCrs, canvasCrs, QgsProject.instance()) canvasPoint = transform.transform(self.point) self.searchBox.setStyleSheet("color: black;") except WrongLocationException: self.searchBox.setStyleSheet("color: red;") return canvasCrs = self.canvas.mapSettings().destinationCrs() self.pin = KadasPinItem(canvasCrs) self.pin.setPosition(KadasItemPos(canvasPoint.x(), canvasPoint.y())) self.pin.setAnchorX(self.pinAnchorX) self.pin.setAnchorY(self.pinAnchorY) self.pin.setFilePath(self.locationSymbolPath) LOG.debug("self.pin position %s, %s" % (self.pin.position().x(), self.pin.position().y())) LOG.debug("pin anchor %s, %s" % (self.pin.anchorX(), self.pin.anchorY())) KadasMapCanvasItemManager.addItem(self.pin) def removePin(self): if self.pin: KadasMapCanvasItemManager.removeItem(self.pin) def text(self): # TODO add getter for the searchbox text. return self.searchBox.text() def setText(self, text): # TODO add setter for the searchbox text. Currently searchbox doesn't publish its setText self.searchBox.setText(text) def clearSearchBox(self): self.setText("") def deletePoint(self): self.point = None self.removePin() def setPoint(self, point): self.point = point LOG.debug("Current point is %s" % self.point.asWkt()) self.pointUpdated.emit(self.point) self.addPin() def setPointFromLonLat(self, lon, lat): self.setPoint(QgsPointXY(lon, lat)) def setLocationName(self, name): self.locationName = name
def init_form(self): # Get the current path of the file rootPath = os.path.dirname(__file__) vlayout = QVBoxLayout() hlayout = QHBoxLayout() if conf.PYFORMS_USE_QT5: hlayout.setContentsMargins(0, 0, 0, 0) vlayout.setContentsMargins(0, 0, 0, 0) else: hlayout.setMargin(0) vlayout.setMargin(0) self.setLayout(vlayout) # Add scroll area scrollarea = QScrollArea() scrollarea.setMinimumHeight(140) scrollarea.setWidgetResizable(True) scrollarea.keyPressEvent = self.__scrollAreaKeyPressEvent scrollarea.keyReleaseEvent = self.__scrollAreaKeyReleaseEvent vlayout.addWidget(scrollarea) # vlayout.setContentsMargins(5, 5, 5, 5) # The timeline widget widget = TimelineWidget(self) widget._scroll = scrollarea # widget.setMinimumHeight(1000) scrollarea.setWidget(widget) # TODO Options buttons # btn_1 = QtGui.QPushButton("?") # btn_2 = QtGui.QPushButton("?") # vlayout_options = QtGui.QVBoxLayout() # vlayout_options.addWidget(btn_1) # vlayout_options.addWidget(btn_2) # hlayout.addLayout(vlayout_options) # hlayout.addWidget(btn_1) # hlayout.addWidget(btn_2) # Timeline zoom slider slider = QSlider(QtCore.Qt.Horizontal) slider.setFocusPolicy(QtCore.Qt.NoFocus) slider.setMinimum(1) slider.setMaximum(100) slider.setValue(10) slider.setPageStep(1) slider.setTickPosition(QSlider.NoTicks) # TicksBothSides slider.valueChanged.connect(self.__scaleSliderChange) slider_label_zoom_in = QLabel() slider_label_zoom_out = QLabel() slider_label_zoom_in.setPixmap( conf.PYFORMS_PIXMAP_EVENTTIMELINE_ZOOM_IN) slider_label_zoom_out.setPixmap( conf.PYFORMS_PIXMAP_EVENTTIMELINE_ZOOM_OUT) self._zoomLabel = QLabel("100%") hlayout.addWidget(self._zoomLabel) hlayout.addWidget(slider_label_zoom_out) hlayout.addWidget(slider) hlayout.addWidget(slider_label_zoom_in) # hlayout.setContentsMargins(5, 0, 5, 5) # Import/Export Buttons btn_import = QPushButton("Import") btn_import.setIcon(conf.PYFORMS_ICON_EVENTTIMELINE_IMPORT) btn_import.clicked.connect(self.__import) btn_export = QPushButton("Export") btn_export.setIcon(conf.PYFORMS_ICON_EVENTTIMELINE_EXPORT) btn_export.clicked.connect(self.__export) # importexport_vlayout = QtGui.QVBoxLayout() # importexport_vlayout.adimdWidget(btn_import) # importexport_vlayout.addWidget(btn_export) # hlayout.addLayout(importexport_vlayout) hlayout.addWidget(btn_import) hlayout.addWidget(btn_export) vlayout.addLayout(hlayout) self._time = widget self._scrollArea = scrollarea
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)))