Exemplo n.º 1
0
class AccountReassignPanel(Panel):
    def __init__(self, mainwindow):
        Panel.__init__(self, mainwindow)
        self._setupUi()
        self.model = mainwindow.model.account_reassign_panel
        self.model.view = self
        self.accountComboBox = ComboboxModel(model=self.model.account_list, view=self.accountComboBoxView)

        self.continueButton.clicked.connect(self.accept)
        self.cancelButton.clicked.connect(self.reject)

    def _setupUi(self):
        if ISWINDOWS:
            self.resize(250, 140)
        else:
            self.resize(340, 165)
        self.setWindowTitle(tr("Re-assign Account"))
        self.verticalLayout = QVBoxLayout(self)
        self.label = QLabel(self)
        self.label.setWordWrap(True)
        self.label.setText(tr(
            "You\'re about to delete a non-empty account. Select an account to re-assign its "
            "transactions to."
        ))
        self.verticalLayout.addWidget(self.label)
        self.accountComboBoxView = QComboBox(self)
        sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.accountComboBoxView.sizePolicy().hasHeightForWidth())
        self.accountComboBoxView.setSizePolicy(sizePolicy)
        self.accountComboBoxView.setMinimumSize(QSize(200, 0))
        self.verticalLayout.addWidget(self.accountComboBoxView)
        spacerItem = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
        self.verticalLayout.addItem(spacerItem)
        self.horizontalLayout = QHBoxLayout()
        spacerItem1 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
        self.horizontalLayout.addItem(spacerItem1)
        self.cancelButton = QPushButton(self)
        self.cancelButton.setText(tr("Cancel"))
        self.cancelButton.setShortcut("Esc")
        self.horizontalLayout.addWidget(self.cancelButton)
        self.continueButton = QPushButton(self)
        self.continueButton.setDefault(True)
        self.continueButton.setText(tr("Continue"))
        self.horizontalLayout.addWidget(self.continueButton)
        self.verticalLayout.addLayout(self.horizontalLayout)
Exemplo n.º 2
0
class ImportWindow(QWidget):
    def __init__(self, parent, doc):
        QWidget.__init__(self, parent, Qt.Window)
        self._setupUi()
        self.doc = doc
        self.model = ImportWindowModel(document=doc.model)
        self.swapOptionsComboBox = ComboboxModel(model=self.model.swap_type_list, view=self.swapOptionsComboBoxView)
        self.table = ImportTable(model=self.model.import_table, view=self.tableView)
        self.model.view = self
        self._setupColumns() # Can only be done after the model has been connected
        
        self.tabView.tabCloseRequested.connect(self.tabCloseRequested)
        self.tabView.currentChanged.connect(self.currentTabChanged)
        self.targetAccountComboBox.currentIndexChanged.connect(self.targetAccountChanged)
        self.importButton.clicked.connect(self.importClicked)
        self.swapButton.clicked.connect(self.swapClicked)
    
    def _setupUi(self):
        self.setWindowTitle(tr("Import"))
        self.resize(557, 407)
        self.verticalLayout = QtGui.QVBoxLayout(self)
        self.tabView = QTabBar(self)
        self.tabView.setMinimumSize(QtCore.QSize(0, 20))
        self.verticalLayout.addWidget(self.tabView)
        self.targetAccountLayout = QtGui.QHBoxLayout()
        self.targetAccountLabel = QtGui.QLabel(tr("Target Account:"))
        self.targetAccountLayout.addWidget(self.targetAccountLabel)
        self.targetAccountComboBox = QComboBox(self)
        self.targetAccountComboBox.setMinimumSize(QtCore.QSize(150, 0))
        self.targetAccountLayout.addWidget(self.targetAccountComboBox)
        spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
        self.targetAccountLayout.addItem(spacerItem)
        self.groupBox = QGroupBox(tr("Are some fields wrong? Fix them!"))
        self.gridLayout = QtGui.QGridLayout(self.groupBox)
        self.swapOptionsComboBoxView = QComboBox(self.groupBox)
        self.gridLayout.addWidget(self.swapOptionsComboBoxView, 0, 0, 1, 2)
        self.applyToAllCheckBox = QtGui.QCheckBox(tr("Apply to all accounts"))
        self.gridLayout.addWidget(self.applyToAllCheckBox, 1, 0, 1, 1)
        self.swapButton = QPushButton(tr("Fix"))
        self.gridLayout.addWidget(self.swapButton, 1, 1, 1, 1)
        self.targetAccountLayout.addWidget(self.groupBox)
        self.verticalLayout.addLayout(self.targetAccountLayout)
        self.tableView = TableView(self)
        self.tableView.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
        self.tableView.setDragEnabled(True)
        self.tableView.setDragDropMode(QtGui.QAbstractItemView.InternalMove)
        self.tableView.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
        self.tableView.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
        self.tableView.horizontalHeader().setHighlightSections(False)
        self.tableView.horizontalHeader().setMinimumSectionSize(18)
        self.tableView.verticalHeader().setVisible(False)
        self.tableView.verticalHeader().setDefaultSectionSize(18)
        self.verticalLayout.addWidget(self.tableView)
        self.horizontalLayout = QtGui.QHBoxLayout()
        spacerItem1 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
        self.horizontalLayout.addItem(spacerItem1)
        self.importButton = QPushButton(tr("Import"))
        self.horizontalLayout.addWidget(self.importButton)
        self.verticalLayout.addLayout(self.horizontalLayout)
        self.tabView.setTabsClosable(True)
        self.tabView.setDrawBase(False)
        self.tabView.setDocumentMode(True)
        self.tabView.setUsesScrollButtons(True)
    
    def _setupColumns(self):
        # Can't set widget alignment in a layout in the Designer
        l = self.targetAccountLayout
        l.setAlignment(self.targetAccountLabel, Qt.AlignTop)
        l.setAlignment(self.targetAccountComboBox, Qt.AlignTop)
    
    #--- Event Handlers
    def currentTabChanged(self, index):
        self.model.selected_pane_index = index
    
    def importClicked(self):
        self.model.import_selected_pane()
    
    def swapClicked(self):
        applyToAll = self.applyToAllCheckBox.isChecked()
        self.model.perform_swap(applyToAll)
    
    def tabCloseRequested(self, index):
        self.model.close_pane(index)
        self.tabView.removeTab(index)
    
    def targetAccountChanged(self, index):
        self.model.selected_target_account_index = index
        self.table.updateColumnsVisibility()
    
    #--- model --> view
    def close(self):
        self.hide()
    
    def close_selected_tab(self):
        self.tabView.removeTab(self.tabView.currentIndex())
    
    def refresh_target_accounts(self):
        # We disconnect the combobox because we don't want the clear() call to set the selected 
        # target index in the model.
        self.targetAccountComboBox.currentIndexChanged.disconnect(self.targetAccountChanged)
        self.targetAccountComboBox.clear()
        self.targetAccountComboBox.addItems(self.model.target_account_names)
        self.targetAccountComboBox.currentIndexChanged.connect(self.targetAccountChanged)
    
    def refresh_tabs(self):
        while self.tabView.count():
            self.tabView.removeTab(0)
        for pane in self.model.panes:
            self.tabView.addTab(pane.name)
    
    def set_swap_button_enabled(self, enabled):
        self.swapButton.setEnabled(enabled)
    
    def show(self):
        # For non-modal dialogs, show() is not enough to bring the window at the forefront, we have
        # to call raise() as well
        QWidget.show(self)
        self.raise_()
    
    def update_selected_pane(self):
        index = self.model.selected_pane_index
        if index != self.tabView.currentIndex(): # this prevents infinite loops
            self.tabView.setCurrentIndex(index)
        self.targetAccountComboBox.setCurrentIndex(self.model.selected_target_account_index)
        self.table.updateColumnsVisibility()
Exemplo n.º 3
0
class ReferencedTableEditor(QWidget):
    referenced_table_changed = pyqtSignal(str)

    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self.setupUi()

        self.cbo_ref_table.setInsertPolicy(QComboBox.InsertAlphabetically)

        self.cbo_ref_table.currentIndexChanged[str].connect(self._on_ref_table_changed)

    def setupUi(self):
        self.setObjectName("ReferencedTableEditor")
        self.gridLayout = QGridLayout(self)
        self.gridLayout.setVerticalSpacing(10)
        self.gridLayout.setObjectName("gridLayout")
        self.label_2 = QLabel(self)
        self.label_2.setMaximumSize(QSize(100, 16777215))
        self.label_2.setObjectName("label_2")
        self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1)
        self.cbo_source_field = QComboBox(self)
        self.cbo_source_field.setMinimumSize(QSize(0, 30))
        self.cbo_source_field.setObjectName("cbo_source_field")
        self.gridLayout.addWidget(self.cbo_source_field, 2, 1, 1, 1)
        self.label = QLabel(self)
        self.label.setObjectName("label")
        self.gridLayout.addWidget(self.label, 2, 0, 1, 1)
        self.label_3 = QLabel(self)
        self.label_3.setObjectName("label_3")
        self.gridLayout.addWidget(self.label_3, 3, 0, 1, 1)
        self.cbo_referencing_col = QComboBox(self)
        self.cbo_referencing_col.setMinimumSize(QSize(0, 30))
        self.cbo_referencing_col.setObjectName("cbo_referencing_col")
        self.gridLayout.addWidget(self.cbo_referencing_col, 3, 1, 1, 1)
        self.cbo_ref_table = QComboBox(self)
        self.cbo_ref_table.setMinimumSize(QSize(0, 30))
        self.cbo_ref_table.setObjectName("cbo_ref_table")
        self.gridLayout.addWidget(self.cbo_ref_table, 1, 1, 1, 1)

        self.label_2.setText(QApplication.translate("ReferencedTableEditor",
                                                    "References"))
        self.label.setText(QApplication.translate("ReferencedTableEditor",
                                                  "Data source field"))
        self.label_3.setText(QApplication.translate("ReferencedTableEditor",
                                                    "Referencing"))

        #Connect signals
        QMetaObject.connectSlotsByName(self)
        self.cbo_ref_table.currentIndexChanged[str].connect(self._load_source_table_fields)

    @pyqtSlot(str)
    def on_data_source_changed(self,data_source_name):
        """
        Loads data source fields for the given data source name.
        """
        self.load_data_source_fields(data_source_name)

    def _on_ref_table_changed(self, table):
        """
        Raise signal when the referenced table changes.
        :param table: Selected table name.
        :type table: str
        """
        self.referenced_table_changed.emit(table)

    def properties(self):
        """
        :returns: Returns the user-defined mapping of linked table and column
        pairings.
        :rtype: LinkedTableProps
        """
        l_table = self.cbo_ref_table.currentText()
        s_field = self.cbo_source_field.currentText()
        l_field = self.cbo_referencing_col.currentText()

        return LinkedTableProps(linked_table=l_table,
                                              source_field=s_field,
                                              linked_field=l_field)

    def set_properties(self, table_props):
        """
        Sets the combo selection based on the text in the linked table
        object properties.
        :param table_props: Object containing the linked table information.
        :type table_props: LinkedTableProps
        """
        setComboCurrentIndexWithText(self.cbo_ref_table, table_props.linked_table)
        setComboCurrentIndexWithText(self.cbo_referencing_col, table_props.linked_field)
        setComboCurrentIndexWithText(self.cbo_source_field, table_props.source_field)

    def load_data_source_fields(self, data_source_name):
        """
        Load fields/columns of the given data source.
        """
        if data_source_name == "":
            self.clear()

            return

        columns_names = table_column_names(data_source_name)

        if len(columns_names) == 0:
            return

        self.cbo_source_field.clear()
        self.cbo_source_field.addItem("")
        self.cbo_source_field.addItems(columns_names)

    def clear(self):
        """
        Resets combo box selections.
        """
        self._reset_combo_index(self.cbo_ref_table)
        self._reset_combo_index(self.cbo_referencing_col)
        self._reset_combo_index(self.cbo_source_field)

    def _reset_combo_index(self, combo):
        if combo.count > 0:
            combo.setCurrentIndex(0)

    def reset_referenced_table(self):
        self._reset_combo_index(self.cbo_ref_table)

    def load_link_tables(self, reg_exp=None, source=TABLES|VIEWS):
        self.cbo_ref_table.clear()
        self.cbo_ref_table.addItem("")

        ref_tables = []
        #Table source
        if (TABLES & source) == TABLES:
            ref_tables.extend(pg_tables())

        #View source
        if (VIEWS & source) == VIEWS:
            ref_tables.extend(pg_views())

        source_tables = []
        for t in ref_tables:
            if not reg_exp is None:
                if reg_exp.exactMatch(t):
                    source_tables.append(t)

            else:
                source_tables.append(t)

        self.cbo_ref_table.addItems(source_tables)

    def _load_source_table_fields(self, sel):
        self.cbo_referencing_col.clear()

        if not sel:
            return

        columns_names = table_column_names(sel)

        self.cbo_referencing_col.clear()
        self.cbo_referencing_col.addItem("")
        self.cbo_referencing_col.addItems(columns_names)
Exemplo n.º 4
0
class WindPanel(QFrame):
    def __init__(self, parent):
        QFrame.__init__(self, parent)
        #         self.frame_WindIA = QFrame(parent)
        sizePolicy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.sizePolicy().hasHeightForWidth())
        self.setSizePolicy(sizePolicy)
        self.setFrameShape(QFrame.StyledPanel)
        self.setFrameShadow(QFrame.Raised)
        self.setObjectName(("frame_WindIA"))
        self.horizontalLayout_32 = QHBoxLayout(self)
        self.horizontalLayout_32.setSpacing(0)
        self.horizontalLayout_32.setMargin(0)
        self.horizontalLayout_32.setObjectName(("horizontalLayout_32"))
        self.lblIA = QLabel(self)
        self.lblIA.setMinimumSize(QSize(140, 0))
        self.lblIA.setMaximumSize(QSize(100, 16777215))
        font = QFont()
        font.setFamily(("Arial"))
        font.setBold(False)
        font.setWeight(50)
        self.lblIA.setFont(font)
        self.lblIA.setObjectName(("lblIA"))
        self.horizontalLayout_32.addWidget(self.lblIA)
        self.comboBox = QComboBox(self)
        sizePolicy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.comboBox.sizePolicy().hasHeightForWidth())
        self.comboBox.setSizePolicy(sizePolicy)
        self.comboBox.setMinimumSize(QSize(60, 0))
        font = QFont()
        font.setFamily(("Arial"))
        font.setBold(False)
        font.setWeight(50)
        self.comboBox.setFont(font)
        self.comboBox.setObjectName(("comboBox"))
        self.horizontalLayout_32.addWidget(self.comboBox)
        self.speedBox = QLineEdit(self)
        sizePolicy = QSizePolicy(QSizePolicy.MinimumExpanding,
                                 QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.speedBox.sizePolicy().hasHeightForWidth())
        self.speedBox.setSizePolicy(sizePolicy)
        self.speedBox.setMinimumSize(QSize(70, 0))
        self.speedBox.setMaximumSize(QSize(16777215, 16777215))
        font = QFont()
        font.setFamily(("Arial"))
        font.setBold(False)
        font.setWeight(50)
        self.speedBox.setFont(font)
        self.speedBox.setObjectName(("speedBox"))
        self.horizontalLayout_32.addWidget(self.speedBox)

        self.altitude = Altitude.NaN()
        self.customValue = Speed(30).Knots
        self.comboBox.addItems(["ICAO", "UK", "Custom"])
        self.comboBox.currentIndexChanged.connect(self.changeWindType)
        self.comboBox.setCurrentIndex(0)
        self.lblIA.setText("Wind (kts):")
        self.speedBox.setEnabled(False)

    def setAltitude(self, value):
        self.altitude = value
        self.method_5()
#     def getValue(self, SpeedUnits_0 = SpeedUnits.KTS):
#         return Speed(float(self.speedBox.text()), SpeedUnits_0)

    def method_3(self, altitude_0):
        altitude = Altitude(float(self.speedBox.text()), AltitudeUnits.FT)
        if (self.comboBox.currentIndex() != 0):
            return altitude
        return Altitude(altitude.Feet - altitude_0.Feet, AltitudeUnits.FT)

    def method_5(self):
        if self.comboBox.currentIndex() == 0:
            self.speedBox.setText(
                str(round(Speed.smethod_1(self.altitude).Knots, 1)))
        elif self.comboBox.currentIndex() == 1:
            self.speedBox.setText(
                str(round(Speed.smethod_2(self.altitude).Knots, 1)))
        else:
            self.speedBox.setText(str(self.customValue))
        if self.comboBox.currentIndex() != 2:
            self.speedBox.setEnabled(False)
        else:
            self.speedBox.setEnabled(True)

    def changeWindType(self):
        self.method_5()

    def method_7(self, string_0):
        # object[] string0 = new object[] { string_0, this.captionLabel.Caption, this.speedBox.ToString(), this.comboBox.Items[this.comboBox.SelectedIndex] };
        return "%s%s\t%s (%s)" % (string_0, "Wind: ", self.speedBox.text(),
                                  self.comboBox.currentText())

    def get_speed(self):
        try:
            return Speed(float(self.speedBox.text()))
        except:
            return None

    Value = property(get_speed, None, None, None)

    def get_isEmpty(self):
        try:
            num = float(self.speedBox.text())
            return False
        except:
            return True

    IsEmpty = property(get_isEmpty, None, None, None)
Exemplo n.º 5
0
class DogrulaDialog(QDialog):
    def __init__(self, ui):
        QDialog.__init__(self, ui)
        self.ui = ui
        self.resize(450, 170)
        self.setMinimumSize(QSize(450, 170))
        self.setMaximumSize(QSize(500, 200))
        self.setWindowTitle(self.trUtf8("Doğrula"))

        self.gridLayout = QGridLayout(self)

        self.neredenButton = QPushButton(self)
        self.neredenButton.setText(self.trUtf8("Nereden"))
        self.neredenButton.clicked.connect(self.nereden)
        self.gridLayout.addWidget(self.neredenButton, 0, 4, 1, 1)

        self.dogrulaButton = QPushButton(self)
        self.dogrulaButton.setText(self.trUtf8("Doğrula"))
        self.dogrulaButton.clicked.connect(self.dogrula)
        self.gridLayout.addWidget(self.dogrulaButton, 3, 4, 1, 1)

        self.neredenEdit = QLineEdit(self)
        self.neredenEdit.setReadOnly(True)
        self.gridLayout.addWidget(self.neredenEdit, 0, 0, 1, 4)

        self.hashEdit = QLineEdit(self)
        self.hashEdit.setReadOnly(True)
        self.gridLayout.addWidget(self.hashEdit, 3, 2, 1, 1)

        spacerItem = QSpacerItem(20, 15, QSizePolicy.Minimum, QSizePolicy.Fixed)
        self.gridLayout.addItem(spacerItem, 1, 1, 1, 1)
        
        self.comboBox = QComboBox(self)
        self.comboBox.setMinimumSize(QSize(100, 0))
        self.comboBox.addItem("MD5")
        self.comboBox.addItem("SHA1")
        self.gridLayout.addWidget(self.comboBox, 3, 1, 1, 1)

        self.karaWidget = KaraWidget(self, "=")
        self.karaWidget.hide()

    def nereden(self):
        dosya = QFileDialog.getOpenFileName(self, "", settings().value("Genel/Yol").toString())
        if dosya == "":
            pass
        elif QFile.exists(dosya):
            from os.path import abspath, dirname
            settings().setValue("Genel/Yol", abspath(dirname(str(dosya))))
            self.neredenEdit.setText(dosya)
        else:
            QMessageBox.warning(self, self.trUtf8("Hata!"), self.trUtf8("Böyle bir dosya mevcut değil!"))

    def dogrula(self):
        if self.neredenEdit.text() == "":
            QMessageBox.warning(self, self.trUtf8("Hata!"), self.trUtf8("Dosya seçmediniz!"))
        else:
            self.karaWidget.show()
            self.karaWidget.start()

    def keyPressEvent(self, event):
        pass

    def resizeEvent(self, event):
        self.karaWidget.setGeometry(0,0, event.size().width(), event.size().height())
Exemplo n.º 6
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)
Exemplo n.º 7
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)
Exemplo n.º 8
0
class OCAHPanel(QFrame):
    def __init__(self, parent):
        QFrame.__init__(self, parent)
        while not isinstance(parent, QDialog):
            parent = parent.parent()
        self.setObjectName("OCAHPanel" + str(len(parent.findChildren(OCAHPanel))))

#         self.frame_WindIA = QFrame(parent)
        sizePolicy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.sizePolicy().hasHeightForWidth())
        self.setSizePolicy(sizePolicy)
        self.setFrameShape(QFrame.StyledPanel)
        self.setFrameShadow(QFrame.Raised)
        self.setObjectName(("frame_WindIA"))
        self.hLayout = QHBoxLayout(self)
        self.hLayout.setSpacing(0)
        self.hLayout.setMargin(0)
        self.hLayout.setObjectName(("hLayout"))

        self.basicFrame = Frame(self, "HL")
        self.basicFrame.layoutBoxPanel.setSpacing(0)
        # self.basicFrame.layoutBoxPanel.setMargin(0)
        self.hLayout.addWidget(self.basicFrame)

        self.lblIA = QLabel(self.basicFrame)
        self.lblIA.setMinimumSize(QSize(200, 0))
        self.lblIA.setMaximumSize(QSize(200, 16777215))
        font = QFont()
        font.setFamily(("Arial"))
        font.setBold(False)
        font.setWeight(50)
        self.lblIA.setFont(font)
        self.lblIA.setObjectName(("lblIA"))
        self.basicFrame.Add = self.lblIA
        self.cmbType = QComboBox(self.basicFrame)
        self.cmbType.setMinimumSize(QSize(70, 0))
        self.cmbType.setMaximumWidth(70)
        font = QFont()
        font.setFamily(("Arial"))
        font.setBold(False)
        font.setWeight(50)
        self.cmbType.setFont(font)
        self.cmbType.setObjectName(("cmbType"))
        self.basicFrame.Add = self.cmbType



        self.txtAltitudeM = QLineEdit(self.basicFrame)
        self.txtAltitudeM.setEnabled(True)
        font = QFont()
        font.setBold(False)
        font.setWeight(50)
        self.txtAltitudeM.setFont(font)
        self.txtAltitudeM.setObjectName(self.objectName() + "_txtAltitudeM")
        self.txtAltitudeM.setText("0.0")
        self.txtAltitudeM.setMinimumWidth(70)
        self.txtAltitudeM.setMaximumWidth(70)
        self.basicFrame.Add = self.txtAltitudeM

        labelM = QLabel(self.basicFrame)
        labelM.setObjectName(("labelM"))
        labelM.setText(" m ")
        self.basicFrame.Add = labelM

        self.txtAltitude = QLineEdit(self.basicFrame)
        sizePolicy = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.txtAltitude.sizePolicy().hasHeightForWidth())
        self.txtAltitude.setSizePolicy(sizePolicy)
        self.txtAltitude.setMinimumSize(QSize(70, 0))
        self.txtAltitude.setMaximumSize(QSize(70, 16777215))
        font = QFont()
        font.setFamily(("Arial"))
        font.setBold(False)
        font.setWeight(50)
        self.txtAltitude.setFont(font)
        self.txtAltitude.setObjectName(self.objectName() + "_txtAltitude")
        self.basicFrame.Add = self.txtAltitude

        labelFt = QLabel(self.basicFrame)
        labelFt.setObjectName(("labelFt"))
        labelFt.setText(" ft")
        self.basicFrame.Add = labelFt

        spacerItem = QSpacerItem(10,10,QSizePolicy.Expanding, QSizePolicy.Minimum)
        self.hLayout.addItem(spacerItem)
        
        self.altitude = Altitude.NaN()
        self.customValue = Speed(30).Knots
        self.cmbType.addItems(["OCA", "OCH"])
        # self.cmbType.currentIndexChanged.connect(self.changeType)
        self.cmbType.setCurrentIndex(0)
        self.lblIA.setText("Intermediate Segment Minimum:")
        # self.txtAltitude.setEnabled(False)
        self.txtAltitudeM.textChanged.connect(self.txtAltitudeMChanged)
        self.txtAltitude.textChanged.connect(self.txtAltitudeChanged)
        
        self.captionUnits = "ft"

        self.flag = 0
        self.txtAltitudeM.setText("0.0")
        self.txtAltitude.setText("0.0")
    def txtAltitudeChanged(self):
        try:
            test = float(self.txtAltitude.text())
            if self.flag==0:
                self.flag=1;
            if self.flag==2:
                self.flag=0;
            if self.flag==1:
                try:
                    self.txtAltitudeM.setText(str(round(Unit.ConvertFeetToMeter(float(self.txtAltitude.text())), 4)))
                except:
                    self.txtAltitudeM.setText("0.0")
                self.emit(SIGNAL("Event_0"), self)
        except:
            str0 = "You must input the float type in \"%s\"."%(self.Caption)
            QMessageBox.warning(self, "Warning" , str0)
            self.txtAltitudeM.setText("0.0")
            self.txtAltitude.setText("0.0")


    def txtAltitudeMChanged(self):
        try:
            test = float(self.txtAltitudeM.text())
            if self.flag==0:
                self.flag=2;
            if self.flag==1:
                self.flag=0;
            if self.flag==2:
                try:
                    self.txtAltitude.setText(str(round(Unit.ConvertMeterToFeet(float(self.txtAltitudeM.text())), 4)))
                except:
                    self.txtAltitude.setText("0.0")
                self.emit(SIGNAL("Event_0"), self)
        except:
            str0 = "You must input the float type in \"%s\"."%(self.Caption)
            QMessageBox.warning(self, "Warning" , str0)
            self.txtAltitude.setText("0.0")
            self.txtAltitudeM.setText("0.0")

        try:
            self.altitude = Altitude(float(self.txtAltitude.text()), AltitudeUnits.FT)
        except:
            self.altitude = Altitude.NaN()
    # def txtAltitudeChanged(self):
    #     try:
    #         self.altitude = Altitude(float(self.txtAltitude.text()), AltitudeUnits.FT)
    #     except:
    #         self.altitude = Altitude.NaN()
    # def setAltitude(self, value):
    #     self.altitude = value

#     def getValue(self, SpeedUnits_0 = SpeedUnits.KTS):    
#         return Speed(float(self.txtAltitude.text()), SpeedUnits_0)
    def method_2(self, altitude_0):
        altitude = Altitude(0)
        try:
            altitude = Altitude(float(self.txtAltitude.text()), AltitudeUnits.FT)
        except:
            altitude = Altitude(0)
        if (self.cmbType.currentIndex() == 0):
            return altitude
        return Altitude(altitude.Feet + altitude_0.Feet, AltitudeUnits.FT);

    def method_3(self, altitude_0):
        altitude = Altitude(0)
        try:
            altitude = Altitude(float(self.txtAltitude.text()), AltitudeUnits.FT)
        except:
            altitude = Altitude(0)
        if (self.cmbType.currentIndex() != 0):
            return altitude
        return Altitude(altitude.Feet - altitude_0.Feet, AltitudeUnits.FT);


    
    def changeType(self):
        pass
        
    # def get_altitude(self):
    #     return self.altitude
    # Value = property(get_altitude, setAltitude, None, None)

    def get_isEmpty(self):
        try:
            num = float(self.txtAltitude.text())
            return False
        except:
            return True
    IsEmpty = property(get_isEmpty, None, None, None)
    
    def get_CaptionUnits(self):
        return self.captionUnits
    def set_CaptionUnits(self, captionUnits):
        self.captionUnits = captionUnits
    CaptionUnits = property(get_CaptionUnits, set_CaptionUnits, None, None)

    def get_Caption(self):
        caption = self.lblIA.text()
        val = caption.left(caption.length() - 1)
        return val
    def set_Caption(self, captionStr):
        self.lblIA.setText(captionStr + ":")
    Caption = property(get_Caption, set_Caption, None, None)



    def get_Value(self):
        try:
            return Altitude(float(self.txtAltitudeM.text()))
        except:
            return Altitude(0.0)

    def set_Value(self, altitude):
        if isinstance(altitude, Altitude):
            if self.captionUnits == "m":
                self.txtAltitudeM.setText(str(altitude.Metres))
            else:
                self.txtAltitude.setText(str(altitude.Feet))
        else:
            str0 = "You must input the type \"Altitude\" in \"%s\"."%(self.Caption)
            QMessageBox.warning(self, "Warning" , str0)
            self.txtAltitudeM.setText("0.0")
    Value = property(get_Value, set_Value, None, None)

    

    def set_LabelWidth(self, width):
        self.lblIA.setMinimumSize(QSize(width, 0))
        self.lblIA.setMaximumSize(QSize(width, 16777215))
    LabelWidth = property(None, set_LabelWidth, None, None)

    def get_ReadOnly(self):
        return self.txtAltitudeM.isReadOnly()
    def set_ReadOnly(self, bool):
        self.txtAltitudeM.setReadOnly(bool)
        self.txtAltitude.setReadOnly(bool)
    ReadOnly = property(get_ReadOnly, set_ReadOnly, None, None)

    def get_Enabled(self):
        return self.txtAltitudeM.isEnabled()
    def set_Enabled(self, bool):
        self.txtAltitudeM.setEnabled(bool)
        self.txtAltitude.setEnabled(bool)
    Enabled = property(get_Enabled, set_Enabled, None, None)
Exemplo n.º 9
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)
Exemplo n.º 10
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)
Exemplo n.º 11
0
class ReferencedTableEditor(QWidget):
    referenced_table_changed = pyqtSignal(str)

    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self.setupUi()

        self.cbo_ref_table.setInsertPolicy(QComboBox.InsertAlphabetically)

        self.cbo_ref_table.currentIndexChanged[str].connect(
            self._on_ref_table_changed)

        #Tables that will be omitted from the referenced table list
        self._omit_ref_tables = []

    def add_omit_table(self, table):
        """
        Add a table name that will be omitted from the list of referenced
        tables.
        :param table: Table name that will be omitted
        :type table: str
        """
        if not table in self._omit_ref_tables:
            self._omit_ref_tables.append(table)

    def add_omit_tables(self, tables):
        """
        Add a list of tables that will be omitted from the list of referenced
        tables.
        :param tables: Table names to be omitted.
        :type tables: list
        """
        for t in tables:
            self.add_omit_table(t)

    @property
    def omit_tables(self):
        """
        :return: Returns a list of tables that are to be omitted from the
        list of referenced tables.
        """
        return self._omit_ref_tables

    def setupUi(self):
        self.setObjectName("ReferencedTableEditor")
        self.gridLayout = QGridLayout(self)
        self.gridLayout.setVerticalSpacing(10)
        self.gridLayout.setObjectName("gridLayout")
        self.label_2 = QLabel(self)
        self.label_2.setMaximumSize(QSize(100, 16777215))
        self.label_2.setObjectName("label_2")
        self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1)
        self.cbo_source_field = QComboBox(self)
        self.cbo_source_field.setMinimumSize(QSize(0, 30))
        self.cbo_source_field.setObjectName("cbo_source_field")
        self.gridLayout.addWidget(self.cbo_source_field, 2, 1, 1, 1)
        self.label = QLabel(self)
        self.label.setObjectName("label")
        self.gridLayout.addWidget(self.label, 2, 0, 1, 1)
        self.label_3 = QLabel(self)
        self.label_3.setObjectName("label_3")
        self.gridLayout.addWidget(self.label_3, 3, 0, 1, 1)
        self.cbo_referencing_col = QComboBox(self)
        self.cbo_referencing_col.setMinimumSize(QSize(0, 30))
        self.cbo_referencing_col.setObjectName("cbo_referencing_col")
        self.gridLayout.addWidget(self.cbo_referencing_col, 3, 1, 1, 1)
        self.cbo_ref_table = QComboBox(self)
        self.cbo_ref_table.setMinimumSize(QSize(0, 30))
        self.cbo_ref_table.setObjectName("cbo_ref_table")
        self.gridLayout.addWidget(self.cbo_ref_table, 1, 1, 1, 1)

        self.label_2.setText(
            QApplication.translate("ReferencedTableEditor", "References"))
        self.label.setText(
            QApplication.translate("ReferencedTableEditor",
                                   "Data source field"))
        self.label_3.setText(
            QApplication.translate("ReferencedTableEditor", "Referencing"))

        self._current_profile = current_profile()
        self._current_profile_tables = []
        if not self._current_profile is None:
            self._current_profile_tables = self._current_profile.table_names()

        #Connect signals
        QMetaObject.connectSlotsByName(self)
        self.cbo_ref_table.currentIndexChanged[str].connect(
            self._load_source_table_fields)

    @pyqtSlot(str)
    def on_data_source_changed(self, data_source_name):
        """
        Loads data source fields for the given data source name.
        """
        self.load_data_source_fields(data_source_name)

    def _on_ref_table_changed(self, table):
        """
        Raise signal when the referenced table changes.
        :param table: Selected table name.
        :type table: str
        """
        self.referenced_table_changed.emit(table)

    def properties(self):
        """
        :returns: Returns the user-defined mapping of linked table and column
        pairings.
        :rtype: LinkedTableProps
        """
        l_table = self.cbo_ref_table.currentText()
        s_field = self.cbo_source_field.currentText()
        l_field = self.cbo_referencing_col.currentText()

        return LinkedTableProps(linked_table=l_table,
                                source_field=s_field,
                                linked_field=l_field)

    def set_properties(self, table_props):
        """
        Sets the combo selection based on the text in the linked table
        object properties.
        :param table_props: Object containing the linked table information.
        :type table_props: LinkedTableProps
        """
        setComboCurrentIndexWithText(self.cbo_ref_table,
                                     table_props.linked_table)
        setComboCurrentIndexWithText(self.cbo_referencing_col,
                                     table_props.linked_field)
        setComboCurrentIndexWithText(self.cbo_source_field,
                                     table_props.source_field)

    def load_data_source_fields(self, data_source_name):
        """
        Load fields/columns of the given data source.
        """
        if data_source_name == "":
            self.clear()

            return

        columns_names = table_column_names(data_source_name)

        if len(columns_names) == 0:
            return

        self.cbo_source_field.clear()
        self.cbo_source_field.addItem("")
        self.cbo_source_field.addItems(columns_names)

    def clear(self):
        """
        Resets combo box selections.
        """
        self._reset_combo_index(self.cbo_ref_table)
        self._reset_combo_index(self.cbo_referencing_col)
        self._reset_combo_index(self.cbo_source_field)

    def _reset_combo_index(self, combo):
        if combo.count > 0:
            combo.setCurrentIndex(0)

    def reset_referenced_table(self):
        self._reset_combo_index(self.cbo_ref_table)

    def load_link_tables(self, reg_exp=None, source=TABLES | VIEWS):
        self.cbo_ref_table.clear()
        self.cbo_ref_table.addItem("")

        ref_tables = []

        #Table source
        if (TABLES & source) == TABLES:
            ref_tables.extend(pg_tables(exclude_lookups=True))

        #View source
        if (VIEWS & source) == VIEWS:
            ref_tables.extend(pg_views())

        source_tables = []
        for t in ref_tables:
            #Ensure we are dealing with tables in the current profile
            if not t in self._current_profile_tables:
                continue

            #Assert if the table is in the list of omitted tables
            if t in self._omit_ref_tables:
                continue

            if not reg_exp is None:
                if reg_exp.indexIn(t) >= 0:
                    source_tables.append(t)
            else:
                source_tables.append(t)
        source_tables = source_tables + pg_views()
        self.cbo_ref_table.addItems(source_tables)

    def _load_source_table_fields(self, sel):
        self.cbo_referencing_col.clear()

        if not sel:
            return

        columns_names = table_column_names(sel)

        self.cbo_referencing_col.clear()
        self.cbo_referencing_col.addItem("")
        self.cbo_referencing_col.addItems(columns_names)
Exemplo n.º 12
0
class ComboBoxPanel(QWidget):
    def __init__(self, parent, editable=False, spacerItemMove=False):
        QWidget.__init__(self, parent)
        while not isinstance(parent, QDialog):
            parent = parent.parent()
        self.setObjectName("ComboBoxPanel" +
                           str(len(parent.findChildren(ComboBoxPanel))))

        self.hLayoutBoxPanel = QHBoxLayout(self)
        self.hLayoutBoxPanel.setSpacing(0)
        self.hLayoutBoxPanel.setContentsMargins(0, 0, 0, 0)
        self.hLayoutBoxPanel.setObjectName(("hLayoutBoxPanel"))
        self.frameBoxPanel = QFrame(self)
        sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.frameBoxPanel.sizePolicy().hasHeightForWidth())
        self.frameBoxPanel.setSizePolicy(sizePolicy)
        self.frameBoxPanel.setFrameShape(QFrame.NoFrame)
        self.frameBoxPanel.setFrameShadow(QFrame.Raised)
        self.frameBoxPanel.setObjectName(("frameBoxPanel"))
        self.hLayoutframeBoxPanel = QHBoxLayout(self.frameBoxPanel)
        self.hLayoutframeBoxPanel.setSpacing(0)
        self.hLayoutframeBoxPanel.setMargin(0)
        self.hLayoutframeBoxPanel.setObjectName(("hLayoutframeBoxPanel"))
        self.captionLabel = QLabel(self.frameBoxPanel)
        sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.captionLabel.sizePolicy().hasHeightForWidth())
        self.captionLabel.setSizePolicy(sizePolicy)
        self.captionLabel.setMinimumSize(QSize(200, 0))
        self.captionLabel.setMaximumSize(QSize(200, 16777215))
        font = QFont()
        font.setBold(False)
        font.setWeight(50)
        self.captionLabel.setFont(font)
        self.captionLabel.setObjectName(("captionLabel"))
        self.hLayoutframeBoxPanel.addWidget(self.captionLabel)

        self.comboBox = QComboBox(self.frameBoxPanel)
        self.comboBox.setEnabled(True)
        font = QFont()
        font.setBold(False)
        font.setWeight(50)
        self.comboBox.setFont(font)
        self.comboBox.setObjectName(self.objectName() + "_comboBox")
        self.comboBox.setMinimumWidth(70)
        # self.comboBox.setMaximumWidth(70)

        # self.hLayoutframeBoxPanel.addWidget(self.lineEdit)
        self.hLayoutframeBoxPanel.addWidget(self.comboBox)

        self.imageButton = QToolButton(self.frameBoxPanel)
        self.imageButton.setText((""))
        icon = QIcon()
        icon.addPixmap(QPixmap(("Resource/convex_hull.png")), QIcon.Normal,
                       QIcon.Off)
        self.imageButton.setIcon(icon)
        self.imageButton.setObjectName(("imageButton"))
        self.imageButton.setVisible(False)
        self.hLayoutframeBoxPanel.addWidget(self.imageButton)

        self.hLayoutBoxPanel.addWidget(self.frameBoxPanel)
        if not spacerItemMove:
            spacerItem = QSpacerItem(10, 10, QSizePolicy.Expanding,
                                     QSizePolicy.Minimum)
            self.hLayoutBoxPanel.addItem(spacerItem)

        self.comboBox.currentIndexChanged.connect(self.comboBoxChanged)
        # self.comboBox.editTextChanged.connect(self.comboBoxEditTextChanged)
        self.imageButton.clicked.connect(self.imageButtonClicked)

        self.captionUnits = ""

        self.hasObject = False

        self.objectList = []
        if editable == True:
            self.lineEdit = QLineEdit(self.frameBoxPanel)
            self.lineEdit.setObjectName("lineEdit")
            self.hLayoutframeBoxPanel.insertWidget(1, self.lineEdit)
            self.comboBox.setLineEdit(self.lineEdit)
            self.lineEdit.returnPressed.connect(self.comboBoxEditTextChanged)

    def FindString(self, string):
        return self.comboBox.findText(string)

    def comboBoxEditTextChanged(self):
        self.comboBox.showPopup()

    def get_Count(self):
        return self.comboBox.count()

    Count = property(get_Count, None, None, None)

    def method_0(self):
        return self.comboBox.currentIndex(
        ) >= 0 and self.SelectedItem != None and self.SelectedItem != ""

    def method_3(self, string_0):
        return self.comboBox.findText(string_0)

    def method_11(self, string_0):
        if (self.IsEmpty):
            return "%s%s\t" % (string_0, self.Caption)
        return "%s%s\t%s %s" % (string_0, self.Caption, self.Value,
                                self.CaptionUnits)

    def comboBoxChanged(self):
        self.emit(SIGNAL("Event_0"), self)

    def IndexOf(self, item):
        if isinstance(item, str) or isinstance(item, QString):
            return self.comboBox.findText(item)
        else:
            return self.comboBox.findText(item.ToString())

    def Contains(self, item):
        compStr = None
        if isinstance(item, str):
            compStr = item
        elif isinstance(item, float) or isinstance(item, int):
            compStr = str(item)
        else:
            compStr = item.ToString()
        for i in range(self.comboBox.count()):
            comboItemstr = self.comboBox.itemText(i)
            if compStr == comboItemstr:
                return True
        return False

    def Clear(self):
        self.comboBox.clear()
        self.objectList = []
        self.hasObject = False

    def Add(self, item):
        if not isinstance(item, str) and not isinstance(item, QString):
            self.comboBox.addItem(item.ToString())
            self.objectList.append(item)
            self.hasObject = True
            return
        self.comboBox.addItem(item)
        self.hasObject = False

    def Insert(self, index, item):
        if not isinstance(item, str) and not isinstance(item, QString):
            self.comboBox.insertItem(index, item.ToString())
            self.objectList.insert(index, item)
            self.hasObject = True
            return
        self.comboBox.insertItem(index, item)
        self.hasObject = False

    def imageButtonClicked(self):
        self.emit(SIGNAL("Event_3"), self)

    def get_Caption(self):
        caption = self.captionLabel.text()
        findIndex = caption.indexOf("(")
        if findIndex > 0:
            val = caption.left(findIndex)
            return val
        return caption

    def set_Caption(self, captionStr):
        if captionStr == "":
            self.captionLabel.setText("")
            self.LabelWidth = 0
            return
        if self.CaptionUnits != "" and self.CaptionUnits != None:
            self.captionLabel.setText(captionStr + "(" +
                                      QString(self.CaptionUnits) + ")" + ":")
        else:
            self.captionLabel.setText(captionStr + ":")

    Caption = property(get_Caption, set_Caption, None, None)

    def get_CaptionUnits(self):
        return self.captionUnits

    def set_CaptionUnits(self, captionUnits):
        self.captionUnits = captionUnits

    CaptionUnits = property(get_CaptionUnits, set_CaptionUnits, None, None)

    def set_ButtonVisible(self, bool):
        self.imageButton.setVisible(bool)

    ButtonVisible = property(None, set_ButtonVisible, None, None)

    # def get_Value(self):
    #     return self.comboBox.currentIndex()

    # def set_Value(self, value):
    #     try:
    #         self.comboBox.setCurrentIndex(value)
    #     except:
    #         self.textBox.setText("")
    # Value = property(get_Value, set_Value, None, None)

    def get_IsEmpty(self):
        return self.comboBox.currentText() == "" or self.comboBox.currentIndex(
        ) == -1

    IsEmpty = property(get_IsEmpty, None, None, None)

    def get_ReadOnly(self):
        return self.textBox.isReadOnly()

    # def set_ReadOnly(self, bool):
    #     self.comboBox.setR.setReadOnly(bool)
    # ReadOnly = property(get_ReadOnly, set_ReadOnly, None, None)

    def set_LabelWidth(self, width):
        self.captionLabel.setMinimumSize(QSize(width, 0))
        self.captionLabel.setMaximumSize(QSize(width, 16777215))

    LabelWidth = property(None, set_LabelWidth, None, None)

    def set_Width(self, width):
        self.comboBox.setMinimumSize(QSize(width, 0))
        self.comboBox.setMaximumSize(QSize(width, 16777215))

    Width = property(None, set_Width, None, None)

    def set_Button(self, imageName):
        if imageName == None or imageName == "":
            self.imageButton.setVisible(False)
            return
        icon = QIcon()
        icon.addPixmap(QPixmap(("Resource/" + imageName)), QIcon.Normal,
                       QIcon.Off)
        self.imageButton.setIcon(icon)
        self.imageButton.setVisible(True)

    Button = property(None, set_Button, None, None)

    def get_SelectedIndex(self):
        return self.comboBox.currentIndex()

    def set_SelectedIndex(self, index):
        if self.comboBox.count() == 0:
            return
        if index > self.comboBox.count() - 1:
            self.comboBox.setCurrentIndex(0)
        else:
            self.comboBox.setCurrentIndex(index)

    SelectedIndex = property(get_SelectedIndex, set_SelectedIndex, None, None)

    def get_Value(self):
        return self.comboBox.currentIndex()

    def set_Value(self, valueStr):
        if self.comboBox.count() == 0:
            return
        if valueStr == None:
            self.SelectedIndex = -1
            return
        self.comboBox.setCurrentIndex(self.comboBox.findText(str(valueStr)))

    Value = property(get_Value, set_Value, None, None)

    def get_Items(self):
        # if self.hasObject:
        #     return self.objectList
        itemList = []
        if self.comboBox.count() > 0:
            for i in range(self.comboBox.count()):
                itemList.append(self.comboBox.itemText(i))
        return itemList

    def set_AddItems(self, strList):
        self.Clear()
        if len(strList) != 0 and (not isinstance(strList[0], str)
                                  and not isinstance(strList[0], QString)):
            for obj in strList:
                self.comboBox.addItem(obj.ToString())
                self.objectList.append(obj)
            self.hasObject = True
            return
        self.comboBox.addItems(strList)

    Items = property(get_Items, set_AddItems, None, None)

    def get_Enabled(self):
        return self.comboBox.isEnabled()

    def set_Enabled(self, bool):
        self.comboBox.setEnabled(bool)

    Enabled = property(get_Enabled, set_Enabled, None, None)

    def get_Visible(self):
        return self.isVisible()

    def set_Visible(self, bool):
        self.setVisible(bool)

    Visible = property(get_Visible, set_Visible, None, None)

    def get_Editable(self):
        return self.comboBox.isEditable()

    def set_Editable(self, bool):
        self.comboBox.setEditable(bool)

    Editable = property(get_Editable, set_Editable, None, None)

    def get_SelectedItem(self):
        if self.comboBox.count() == 0:
            return None
        if self.hasObject:
            return self.objectList[self.SelectedIndex]
        return self.comboBox.currentText()

    def set_SelectedItem(self, val):
        index = self.comboBox.findText(val)
        self.comboBox.setCurrentIndex(index)

    SelectedItem = property(get_SelectedItem, set_SelectedItem, None, None)