def __init__( self, parent = None ): super(XKeyValueDialog, self).__init__(parent) # create the interface self._keyEdit = XLineEdit(self) self._keyEdit.setMaximumWidth(80) self._keyEdit.setHint( 'set key' ) self._valueEdit = XLineEdit(self) self._valueEdit.setHint( 'set value' ) hbox = QHBoxLayout() hbox.addWidget(self._keyEdit) hbox.addWidget(self._valueEdit) opts = QDialogButtonBox.Ok | QDialogButtonBox.Cancel buttons = QDialogButtonBox( opts, Qt.Horizontal, self ) vbox = QVBoxLayout() vbox.addLayout(hbox) vbox.addWidget(buttons) # update the look and size self.setLayout(vbox) self.setWindowTitle('Edit Pair') self.setMinimumWidth(350) self.adjustSize() self.setFixedHeight(self.height()) # create connections buttons.accepted.connect( self.accept ) buttons.rejected.connect( self.reject )
def getText(cls, parent=None, windowTitle='Get Text', label='', text='', plain=True, wrapped=True): """ Prompts the user for a text entry using the text edit class. :param parent | <QWidget> windowTitle | <str> label | <str> text | <str> plain | <bool> | return plain text or not :return (<str> text, <bool> accepted) """ # create the dialog dlg = QDialog(parent) dlg.setWindowTitle(windowTitle) # create the layout layout = QVBoxLayout() # create the label if label: lbl = QLabel(dlg) lbl.setText(label) layout.addWidget(lbl) # create the widget widget = cls(dlg) widget.setText(text) if not wrapped: widget.setLineWrapMode(XTextEdit.NoWrap) layout.addWidget(widget) # create the buttons btns = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, dlg) layout.addWidget(btns) dlg.setLayout(layout) dlg.adjustSize() # create connections btns.accepted.connect(dlg.accept) btns.rejected.connect(dlg.reject) if dlg.exec_(): if plain: return (widget.toPlainText(), True) else: return (widget.toHtml(), True) else: return ('', False)
def getDialog(cls, name, parent=None): """ Generates a dialog for this class widget and returns it. :param parent | <QtGui.QWidget> || None :return <QtGui.QDialog> """ key = '_{0}__{1}_dialog'.format(cls.__name__, name) dlgref = getattr(cls, key, None) if dlgref is not None: dlg = dlgref() if dlg: return dlg if parent is None: parent = QApplication.activeWindow() dlg = QDialog(parent) # create widget widget = cls(dlg) dlg.__dict__['_mainwidget'] = widget widget.layout().setContentsMargins(0, 0, 0, 0) # create buttons opts = QDialogButtonBox.Save | QDialogButtonBox.Cancel buttons = QDialogButtonBox(opts, Qt.Horizontal, dlg) # create layout layout = QVBoxLayout() layout.addWidget(widget) layout.addWidget(buttons) dlg.setLayout(layout) dlg.resize(widget.minimumSize() + QSize(15, 15)) widget.resizeRequested.connect(dlg.adjustSize) # create connections buttons.accepted.connect(widget.save) buttons.rejected.connect(dlg.reject) widget.saved.connect(dlg.accept) widget.setFocus() dlg.adjustSize() if parent and parent.window(): center = parent.window().geometry().center() dlg.move(center.x() - dlg.width() / 2.0, center.y() - dlg.height() / 2.0) setattr(cls, key, weakref.ref(dlg)) return dlg
def edit( cls, record, parent = None, uifile = '', commit = True ): """ Prompts the user to edit the inputed record. :param record | <orb.Table> parent | <QWidget> :return <bool> | accepted """ # create the dialog dlg = QDialog(parent) dlg.setWindowTitle('Edit %s' % record.schema().name()) # create the widget cls = record.schema().property('widgetClass', cls) widget = cls(dlg) if ( uifile ): widget.setUiFile(uifile) widget.setRecord(record) widget.layout().setContentsMargins(0, 0, 0, 0) # create buttons opts = QDialogButtonBox.Save | QDialogButtonBox.Cancel btns = QDialogButtonBox(opts, Qt.Horizontal, dlg) # create layout layout = QVBoxLayout() layout.addWidget(widget) layout.addWidget(btns) dlg.setLayout(layout) dlg.adjustSize() # create connections #btns.accepted.connect(widget.save) btns.rejected.connect(dlg.reject) widget.saved.connect(dlg.accept) if ( dlg.exec_() ): if commit: result = widget.record().commit() if 'errored' in result: QMessageBox.information(self.window(), 'Error Committing to Database', result['errored']) return False return True return False
def edit(parent, template, actions=None): """ Prompts the user to edit the menu template with the given actions. \ If no actions are supplied, then the actions from the parent will \ be used. :param parent | <QWidget> template | <str> actions | {<str> name: <QAction>, .. } || None :return (<str> template, <bool> accepted) """ # collect the potential actions from the widget if (actions is None): actions = {} for action in parent.actions(): key = nativestring(action.objectName()) if (not key): key = nativestring(action.text()).replace('&', '') if (key): actions[key] = action if (not actions): return ('', False) dlg = QDialog(parent) dlg.setWindowTitle('Edit Menu') widget = XMenuTemplateWidget(dlg) widget.setActions(actions) widget.setMenuTemplate(template) widget.layout().setContentsMargins(0, 0, 0, 0) opts = QDialogButtonBox.Save | QDialogButtonBox.Cancel btns = QDialogButtonBox(opts, Qt.Horizontal, dlg) btns.accepted.connect(dlg.accept) btns.rejected.connect(dlg.reject) layout = QVBoxLayout() layout.addWidget(widget) layout.addWidget(btns) dlg.setLayout(layout) dlg.adjustSize() dlg.resize(650, 400) if (dlg.exec_()): return (widget.menuTemplate(), True) return ('', False)
def create( cls, model, parent = None, uifile = '', commit = True ): """ Prompts the user to create a new record for the inputed table. :param model | <subclass of orb.Table> parent | <QWidget> :return <orb.Table> || None/ | instance of the inputed table class """ # create the dialog dlg = QDialog(parent) dlg.setWindowTitle('Create %s' % model.schema().name()) # create the widget cls = model.schema().property('widgetClass', cls) widget = cls(dlg) if ( uifile ): widget.setUiFile(uifile) widget.setModel(model) widget.layout().setContentsMargins(0, 0, 0, 0) # create buttons opts = QDialogButtonBox.Save | QDialogButtonBox.Cancel btns = QDialogButtonBox(opts, Qt.Horizontal, dlg) # create layout layout = QVBoxLayout() layout.addWidget(widget) layout.addWidget(btns) dlg.setLayout(layout) dlg.adjustSize() # create connections btns.accepted.connect(widget.save) btns.rejected.connect(dlg.reject) widget.saved.connect(dlg.accept) if ( dlg.exec_() ): record = widget.record() if ( commit ): record.commit() return record return None
def getPlainText( parent, title, caption, text = '' ): """ Prompts the user for more advanced text input. :param parent | <QWidget> || None title | <str> caption | <str> text | <str> :return (<str>, <bool> accepted) """ dlg = QDialog(parent) dlg.setWindowTitle(title) label = QLabel(dlg) label.setText(caption) edit = QTextEdit(dlg) edit.setText(text) edit.selectAll() opts = QDialogButtonBox.Ok | QDialogButtonBox.Cancel btns = QDialogButtonBox(opts, Qt.Horizontal, dlg) btns.accepted.connect(dlg.accept) btns.rejected.connect(dlg.reject) layout = QVBoxLayout() layout.addWidget(label) layout.addWidget(edit) layout.addWidget(btns) dlg.setLayout(layout) dlg.adjustSize() if ( dlg.exec_() ): return (edit.toPlainText(), True) return ('', False)
def __init__(self, parent=None, buttons=None): super(XPopupWidget, self).__init__(parent) # define custom properties self._anchor = XPopupWidget.Anchor.TopCenter self._autoCalculateAnchor = False self._autoCloseOnAccept = True self._autoCloseOnReject = True self._autoCloseOnFocusOut = False self._autoDefault = True self._first = True self._animated = False self._currentMode = None self._positionLinkedTo = [] self._possibleAnchors = XPopupWidget.Anchor.all() # define controls self._result = 0 self._resizable = True self._popupPadding = 10 self._titleBarVisible = True self._buttonBoxVisible = True self._dialogButton = QToolButton(self) self._closeButton = QToolButton(self) self._scrollArea = QScrollArea(self) self._sizeGrip = QSizeGrip(self) self._sizeGrip.setFixedWidth(12) self._sizeGrip.setFixedHeight(12) self._leftSizeGrip = QSizeGrip(self) self._leftSizeGrip.setFixedWidth(12) self._leftSizeGrip.setFixedHeight(12) if buttons is None: buttons = QDialogButtonBox.NoButton self._buttonBox = QDialogButtonBox(buttons, Qt.Horizontal, self) self._buttonBox.setContentsMargins(3, 0, 3, 9) self._scrollArea.setWidgetResizable(True) self._scrollArea.setFrameShape(QScrollArea.NoFrame) self._scrollArea.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) palette = self.palette() self._scrollArea.setPalette(palette) self._dialogButton.setToolTip('Popout to Dialog') self._closeButton.setToolTip('Close Popup') for btn in (self._dialogButton, self._closeButton): btn.setAutoRaise(True) btn.setIconSize(QSize(14, 14)) btn.setMaximumSize(16, 16) # setup the icons icon = QIcon(projexui.resources.find('img/dialog.png')) self._dialogButton.setIcon(icon) icon = QIcon(projexui.resources.find('img/close.png')) self._closeButton.setIcon(icon) # define the ui hlayout = QHBoxLayout() hlayout.setSpacing(0) hlayout.addStretch(1) hlayout.addWidget(self._dialogButton) hlayout.addWidget(self._closeButton) hlayout.setContentsMargins(0, 0, 0, 0) hlayout2 = QHBoxLayout() hlayout2.addWidget(self._buttonBox) hlayout2.setContentsMargins(0, 0, 3, 0) vlayout = QVBoxLayout() vlayout.addLayout(hlayout) vlayout.addWidget(self._scrollArea) vlayout.addLayout(hlayout2) vlayout.setContentsMargins(3, 2, 3, 2) vlayout.setSpacing(0) self.setLayout(vlayout) self.setPositionLinkedTo(parent) # set default properties self.setAutoFillBackground(True) self.setBackgroundRole(QPalette.Window) self.setWindowTitle('Popup') self.setFocusPolicy(Qt.StrongFocus) self.setCurrentMode(XPopupWidget.Mode.Popup) # create connections self._dialogButton.clicked.connect(self.setDialogMode) self._closeButton.clicked.connect(self.reject) self._buttonBox.accepted.connect(self.accept) self._buttonBox.rejected.connect(self.reject) self._buttonBox.clicked.connect(self.handleButtonClick)