Beispiel #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)
Beispiel #2
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)
Beispiel #3
0
 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)
Beispiel #5
0
    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)
Beispiel #6
0
 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
Beispiel #7
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)