Example #1
0
 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 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 = str(action.objectName())
             if ( not key ):
                 key = str(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 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 = str(action.objectName())
                if (not key):
                    key = str(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)
Example #5
0
    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)
        dlg = getattr(cls, key, None)

        if dlg is not None:
            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, dlg)
        return dlg
 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)
     dlg = getattr(cls, key, None)
     
     if dlg is not None:
         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, dlg)
     return dlg
 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
Example #8
0
    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)
Example #9
0
 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)