Example #1
0
 def createGUIElements(self):
     ''' Build the GUI based on the parameters for the tool '''
     for i, param in enumerate(self.tooltypearray):
         # print 'creatgui element %d, %s' %(i, param)
         #Swap in the passed params if they exist... loop through each passed
         #param and see if it matches... if so swap it in
         if self.optional_params.has_key(str(param[0])):
             param[2] = self.optional_params[str(param[0])]
         #print "Key: %s , Val: %s" % (param[0],param[1])
         widgetTemp = QWidget(self.variableBox)
         widgetTemp.setObjectName(QString("test_widget").append(QString(i)))
         self.test_widget.append(widgetTemp)
         hlayout = QHBoxLayout(widgetTemp)
         self.hboxlayout.append(hlayout)
         hlayout.setMargin(4)
         hlayout.setSpacing(4)
         hlayout.setObjectName(QString("hboxlayout").append(QString(i)))
         test_text = QLabel(widgetTemp)
         self.test_text.append(test_text)
         test_text.setObjectName(QString("test_text").append(QString(i)))
         paramName = param[0].strip()
         if param[2].strip() == "Required":
             palette = test_text.palette()
             palette.setColor(QPalette.WindowText, Qt.red)
             test_text.setPalette(palette)
         test_text.setText(paramName)
         test_text_type = QLabel(widgetTemp)
         self.test_text_type.append(test_text_type)
         test_text_type.setObjectName(
             QString("test_text_type").append(QString(i)))
         paramName = param[1].strip()
         test_text_type.setText(
             QString("(").append(paramName).append(QString(")")))
         hlayout.addWidget(test_text)
         hlayout.addWidget(test_text_type)
         if param[1] == 'db_connection_hook':
             test_line = QComboBox(widgetTemp)
             db_connection_choices = get_db_connection_names()
             for i in db_connection_choices:
                 test_line.addItem(QString(i))
             self.test_line.append(test_line)
             test_line.setEnabled(True)
             test_line.setMinimumSize(QSize(200, 0))
             test_line.setObjectName(
                 QString("test_line").append(QString(i)))
             index = test_line.findText(param[2], Qt.MatchExactly)
             test_line.setCurrentIndex(index)
         else:
             test_line = QLineEdit(widgetTemp)
             self.test_line.append(test_line)
             test_line.setEnabled(True)
             test_line.setMinimumSize(QSize(200, 0))
             test_line.setObjectName(
                 QString("test_line").append(QString(i)))
             test_line.setText(QString(param[2]))
         hlayout.addWidget(test_line)
         # If we have a dir_path or file_path add a select button
         if (paramName == QString('dir_path')) or (paramName
                                                   == QString('file_path')):
             pbnSelect = QPushButton(widgetTemp)
             pbnSelect.setObjectName(
                 QString('pbnSelect').append(QString(i)))
             pbnSelect.setText(QString("Select..."))
             pbnSelectDelegate = FileDialogSignal(typeName=paramName,
                                                  param=test_line)
             QObject.connect(
                 pbnSelectDelegate.o,
                 SIGNAL("buttonPressed(PyQt_PyObject,PyQt_PyObject)"),
                 self.on_pbnSelect_released)
             QObject.connect(pbnSelect, SIGNAL("released()"),
                             pbnSelectDelegate.relayButtonSignal)
             self.test_line_delegates.append(pbnSelectDelegate)
             self.test_line_buttons.append(pbnSelect)
             hlayout.addWidget(pbnSelect)
         self.vboxlayout.addWidget(widgetTemp)
         self.adjustSize()
     # Jesse adding help text from opusHelp
     tool_path = self.optional_params.get('tool_path', '')
     try:
         exec_stmt = 'from %s.%s import opusHelp' % (tool_path,
                                                     self.module_name)
         exec exec_stmt
         help = QString(opusHelp())
         self.toolhelpEdit.insertPlainText(help)
     except Exception, e:
         help = 'could not find opusHelp function in tool module'
         self.toolhelpEdit.insertPlainText(help)
    def toolTypeSelected(self, index):
        #print "Got a new selection"
        #print self.comboBox.itemText(index)

        self.typeSelection = str(self.comboBox.itemText(index))
        for testw in self.test_widget:
            self.vboxlayout.removeWidget(testw)
            testw.hide()
        self.tooltypearray = []
        self.test_widget = []
        self.test_text = []
        self.test_line = []

        # The tool_config will always have tool_config name
        self.tooltypearray.append(["Tool Config Name","tool_config",""])

        # Now look up the selected connection type and present to the user...
        # First we start at the tool_library
        tool_name = str(self.typeSelection)
        tool_node = self.tool_nodes[tool_name]
        for param_node in tool_node.find('params'):
            type_val = param_node.get('param_type')
            default_val = param_node.text or ''
            self.tooltypearray.append([param_node.get('name'), type_val, default_val])

        for i, param in enumerate(self.tooltypearray):
            # print "Key: %s , Val: %s" % (param[0],param[1])
            paramName = str(param[0] or '').strip()
            type_val = str(param[1] or '').strip()
            default_val = str(param[2] or '').strip()

            if (i==0):
                widgetTemp = QFrame(self.variableBox)
                widgetTemp.setFrameStyle(QFrame.Panel | QFrame.Raised)
                widgetTemp.setLineWidth(2)
            else:
                widgetTemp = QWidget(self.variableBox)
            widgetTemp.setObjectName(QString("test_widget").append(QString(i)))
            self.test_widget.append(widgetTemp)
            hlayout = QHBoxLayout(widgetTemp)
            self.hboxlayout.append(hlayout)
            hlayout.setMargin(4)
            hlayout.setSpacing(4)
            hlayout.setObjectName(QString("hboxlayout").append(QString(i)))
            test_text = QLabel(widgetTemp)
            self.test_text.append(test_text)
            test_text.setObjectName(QString("test_text").append(QString(i)))
            if type_val == "Required":
                palette = test_text.palette()
                palette.setColor(QPalette.WindowText,Qt.red)
                test_text.setPalette(palette)
            test_text.setText(paramName)
            test_text_type = QLabel(widgetTemp)
            self.test_text_type.append(test_text_type)
            test_text_type.setObjectName(QString("test_text_type").append(QString(i)))
            paramName = type_val
            test_text_type.setText(QString("(").append(paramName).append(QString(")")))
            hlayout.addWidget(test_text)
            hlayout.addWidget(test_text_type)
            if type_val == 'db_connection_hook':
                test_line = QComboBox(widgetTemp)
                db_connection_choices = get_db_connection_names()
                for i in db_connection_choices:
                    test_line.addItem(QString(i))
                self.test_line.append(test_line)
                test_line.setEnabled(True)
                test_line.setMinimumSize(QSize(200,0))
                test_line.setObjectName(QString("test_line").append(QString(i)))
            else:
                test_line = QLineEdit(widgetTemp)
                self.test_line.append(test_line)
                test_line.setEnabled(True)
                test_line.setMinimumSize(QSize(200,0))
                test_line.setObjectName(QString("test_line").append(QString(i)))
#            test_line = QLineEdit(widgetTemp)
#            self.test_line.append(test_line)
#            test_line.setEnabled(True)
#            test_line.setMinimumSize(QSize(200,0))
#            test_line.setObjectName(QString("test_line").append(QString(i)))
#            test_line.setText(QString(""))
            hlayout.addWidget(test_line)
            self.vboxlayout.addWidget(widgetTemp)
    def createEditor(self, parent_view, option, index):
        """ PyQt API Method -- See the PyQt documentation for a description """

        default_editor = QItemDelegate.createEditor(self, parent_view, option, index)
        if not index.isValid():
            return default_editor

        item = index.internalPointer()
        node = item.node

        # editing of left hand columns is handled by dialogs etc, don't allow direct editing
        if index.column() == 0:
            pass
        elif index.column() == 1:
            # Combobox for multiple choices
            editor = default_editor

            # CK delete the following comment if the xml schema is complete and does'nt contain any 'choices'

            #            if node.get('choices') is not None:
            #                editor = QComboBox(parent_view)
            #                choices = [s.strip() for s in node.get('choices').split('|')]
            #                for item in choices:
            #                    editor.addItem(item)
            #                # Select the current choice
            #                choice = node.text.strip() if node.text else ''
            #                if choice in choices:
            #                    editor.setCurrentIndex(choices.index(choice))

            # Create and prepare an editor for the node

            # Select database connection
            if node.get("type") == "db_connection_hook":
                editor = QComboBox(parent_view)
                # Get connection names from database_server_connections.xml
                choices = get_db_connection_names()
                # Populate the editor with the choices
                for i in choices:
                    editor.addItem(i)
            # Select files and folders
            elif node.get("type") in ("file_path", "dir_path"):
                editor_file = QFileDialog()
                filter_str = QString("*.*")
                editor_file.setFilter(filter_str)
                editor_file.setAcceptMode(QFileDialog.AcceptOpen)
                current_value = index.model().data(index, Qt.DisplayRole).toString()
                if node.get("type") == "file_path":
                    method = editor_file.getOpenFileName
                    title = "Please select a file..."
                else:
                    method = editor_file.getExistingDirectory
                    title = "Please select a directory..."
                fd = method(self.parent_view, title, current_value)

                # Check for cancel
                if len(fd) == 0:
                    new_value = current_value
                else:
                    new_value = QString(fd)
                editor = QItemDelegate.createEditor(self, self.parent_view, option, index)
                if type(editor) == QLineEdit:
                    editor.setText(new_value)
            # Edit passwords
            elif node.get("type") == "password":
                editor.setText(str(node.text or ""))
                editor.setStyleSheet("QLineEdit { background-color: red }")
                editor.setEchoMode(QLineEdit.PasswordEchoOnEdit)
            # Use default editor
            else:
                if type(editor) == QLineEdit:
                    txt = index.model().data(index, Qt.DisplayRole).toString()
                    editor.setText(txt)
            return editor
 def createGUIElements(self):
     ''' Build the GUI based on the parameters for the tool '''
     for i, param in enumerate(self.tooltypearray):
         # print 'creatgui element %d, %s' %(i, param)
         #Swap in the passed params if they exist... loop through each passed
         #param and see if it matches... if so swap it in
         if self.optional_params.has_key(str(param[0])):
             param[2] = self.optional_params[str(param[0])]
         #print "Key: %s , Val: %s" % (param[0],param[1])
         widgetTemp = QWidget(self.variableBox)
         widgetTemp.setObjectName(QString("test_widget").append(QString(i)))
         self.test_widget.append(widgetTemp)
         hlayout = QHBoxLayout(widgetTemp)
         self.hboxlayout.append(hlayout)
         hlayout.setMargin(4)
         hlayout.setSpacing(4)
         hlayout.setObjectName(QString("hboxlayout").append(QString(i)))
         test_text = QLabel(widgetTemp)
         self.test_text.append(test_text)
         test_text.setObjectName(QString("test_text").append(QString(i)))
         paramName = param[0].strip()
         if param[2].strip() == "Required":
             palette = test_text.palette()
             palette.setColor(QPalette.WindowText,Qt.red)
             test_text.setPalette(palette)
         test_text.setText(paramName)
         test_text_type = QLabel(widgetTemp)
         self.test_text_type.append(test_text_type)
         test_text_type.setObjectName(QString("test_text_type").append(QString(i)))
         paramName = param[1].strip()
         test_text_type.setText(QString("(").append(paramName).append(QString(")")))
         hlayout.addWidget(test_text)
         hlayout.addWidget(test_text_type)
         if param[1] == 'db_connection_hook':
             test_line = QComboBox(widgetTemp)
             db_connection_choices = get_db_connection_names()
             for i in db_connection_choices:
                 test_line.addItem(QString(i))
             self.test_line.append(test_line)
             test_line.setEnabled(True)
             test_line.setMinimumSize(QSize(200,0))
             test_line.setObjectName(QString("test_line").append(QString(i)))
             index = test_line.findText(param[2], Qt.MatchExactly)
             test_line.setCurrentIndex(index)
         else:
             test_line = QLineEdit(widgetTemp)
             self.test_line.append(test_line)
             test_line.setEnabled(True)
             test_line.setMinimumSize(QSize(200,0))
             test_line.setObjectName(QString("test_line").append(QString(i)))
             test_line.setText(QString(param[2]))
         hlayout.addWidget(test_line)
         # If we have a dir_path or file_path add a select button
         if (paramName == QString('dir_path')) or (paramName == QString('file_path')):
             pbnSelect = QPushButton(widgetTemp)
             pbnSelect.setObjectName(QString('pbnSelect').append(QString(i)))
             pbnSelect.setText(QString("Select..."))
             pbnSelectDelegate = FileDialogSignal(typeName=paramName,param=test_line)
             QObject.connect(pbnSelectDelegate.o, SIGNAL("buttonPressed(PyQt_PyObject,PyQt_PyObject)"),
                             self.on_pbnSelect_released)
             QObject.connect(pbnSelect, SIGNAL("released()"), pbnSelectDelegate.relayButtonSignal)
             self.test_line_delegates.append(pbnSelectDelegate)
             self.test_line_buttons.append(pbnSelect)
             hlayout.addWidget(pbnSelect)
         self.vboxlayout.addWidget(widgetTemp)
         self.adjustSize()
     # Jesse adding help text from opusHelp
     tool_path = self.optional_params.get('tool_path','')
     try:
         exec_stmt = 'from %s.%s import opusHelp' % (tool_path, self.module_name)
         exec exec_stmt
         help = QString(opusHelp())
         self.toolhelpEdit.insertPlainText(help)
     except Exception, e:
         help = 'could not find opusHelp function in tool module'
         self.toolhelpEdit.insertPlainText(help)
    def createEditor(self, parent_view, option, index):
        ''' PyQt API Method -- See the PyQt documentation for a description '''

        default_editor = QItemDelegate.createEditor(self, parent_view, option, index)
        if not index.isValid():
            return default_editor

        item = index.internalPointer()
        node = item.node

        # editing of left hand columns is handled by dialogs etc, don't allow direct editing
        if index.column() == 0:
            pass
        elif index.column() == 1:
            # Combobox for multiple choices
            editor = default_editor


            # Create and prepare an editor for the node

            # Select database connection
            if node.get('choices') is not None:
                editor = QComboBox(parent_view)
                choices = [s.strip() for s in node.get('choices').split('|')]
                for item in choices:
                    editor.addItem(item)
                # Select the current choice
                choice = node.text.strip() if node.text else ''
                if choice in choices:
                    editor.setCurrentIndex(choices.index(choice))
            elif node.get('type') == 'db_connection_hook':
                editor = QComboBox(parent_view)
                # Get connection names from database_server_connections.xml
                choices = get_db_connection_names()
                # Populate the editor with the choices
                for i in choices:
                    editor.addItem(i)
            # Select files and folders
            elif node.get('type') in ('file_path', 'dir_path'):
                editor_file = QFileDialog()
                filter_str = QString("*.*")
                editor_file.setFilter(filter_str)
                editor_file.setAcceptMode(QFileDialog.AcceptOpen)
                current_value = \
                    index.model().data(index, Qt.DisplayRole).toString()
                if node.get('type') == 'file_path':
                    method = editor_file.getOpenFileName
                    title = 'Please select a file...'
                else:
                    method = editor_file.getExistingDirectory
                    title = 'Please select a directory...'
                fd = method(self.parent_view, title, current_value)

                # Check for cancel
                if len(fd) == 0:
                    new_value = current_value
                else:
                    new_value = QString(fd)
                editor = QItemDelegate.createEditor(self, self.parent_view,
                                                    option, index)
                if type(editor) == QLineEdit:
                    editor.setText(new_value)
            # Edit passwords
            elif node.get('type') == 'password':
                editor.setText(str(node.text or ''))
                editor.setStyleSheet('QLineEdit { background-color: red }')
                editor.setEchoMode(QLineEdit.PasswordEchoOnEdit)
            # Use default editor
            else:
                if type(editor) == QLineEdit:
                    txt = index.model().data(index, Qt.DisplayRole).toString()
                    editor.setText(txt)
            return editor
Example #6
0
    def toolTypeSelected(self, index):
        #print "Got a new selection"
        #print self.comboBox.itemText(index)

        self.typeSelection = str(self.comboBox.itemText(index))
        for testw in self.test_widget:
            self.vboxlayout.removeWidget(testw)
            testw.hide()
        self.tooltypearray = []
        self.test_widget = []
        self.test_text = []
        self.test_line = []

        # The tool_config will always have tool_config name
        self.tooltypearray.append(["Tool Config Name", "tool_config", ""])

        # Now look up the selected connection type and present to the user...
        # First we start at the tool_library
        tool_name = str(self.typeSelection)
        tool_node = self.tool_nodes[tool_name]
        for param_node in tool_node.find('params'):
            type_val = param_node.get('param_type')
            default_val = param_node.text or ''
            self.tooltypearray.append(
                [param_node.get('name'), type_val, default_val])

        for i, param in enumerate(self.tooltypearray):
            # print "Key: %s , Val: %s" % (param[0],param[1])
            paramName = str(param[0] or '').strip()
            type_val = str(param[1] or '').strip()
            default_val = str(param[2] or '').strip()

            if (i == 0):
                widgetTemp = QFrame(self.variableBox)
                widgetTemp.setFrameStyle(QFrame.Panel | QFrame.Raised)
                widgetTemp.setLineWidth(2)
            else:
                widgetTemp = QWidget(self.variableBox)
            widgetTemp.setObjectName(QString("test_widget").append(QString(i)))
            self.test_widget.append(widgetTemp)
            hlayout = QHBoxLayout(widgetTemp)
            self.hboxlayout.append(hlayout)
            hlayout.setMargin(4)
            hlayout.setSpacing(4)
            hlayout.setObjectName(QString("hboxlayout").append(QString(i)))
            test_text = QLabel(widgetTemp)
            self.test_text.append(test_text)
            test_text.setObjectName(QString("test_text").append(QString(i)))
            if type_val == "Required":
                palette = test_text.palette()
                palette.setColor(QPalette.WindowText, Qt.red)
                test_text.setPalette(palette)
            test_text.setText(paramName)
            test_text_type = QLabel(widgetTemp)
            self.test_text_type.append(test_text_type)
            test_text_type.setObjectName(
                QString("test_text_type").append(QString(i)))
            paramName = type_val
            test_text_type.setText(
                QString("(").append(paramName).append(QString(")")))
            hlayout.addWidget(test_text)
            hlayout.addWidget(test_text_type)
            if type_val == 'db_connection_hook':
                test_line = QComboBox(widgetTemp)
                db_connection_choices = get_db_connection_names()
                for i in db_connection_choices:
                    test_line.addItem(QString(i))
                self.test_line.append(test_line)
                test_line.setEnabled(True)
                test_line.setMinimumSize(QSize(200, 0))
                test_line.setObjectName(
                    QString("test_line").append(QString(i)))
            else:
                test_line = QLineEdit(widgetTemp)
                self.test_line.append(test_line)
                test_line.setEnabled(True)
                test_line.setMinimumSize(QSize(200, 0))
                test_line.setObjectName(
                    QString("test_line").append(QString(i)))
#            test_line = QLineEdit(widgetTemp)
#            self.test_line.append(test_line)
#            test_line.setEnabled(True)
#            test_line.setMinimumSize(QSize(200,0))
#            test_line.setObjectName(QString("test_line").append(QString(i)))
#            test_line.setText(QString(""))
            hlayout.addWidget(test_line)
            self.vboxlayout.addWidget(widgetTemp)