Exemplo n.º 1
0
    def __init__(self, tag_number):
        super().__init__()
        print('processing query...')
        qry = QSqlQuery(db)
        query = 'SELECT name, ename, startno, starttime FROM name WHERE ecard = %i OR ecard2 = %i' % (
            tag_number, tag_number)
        qry.prepare(query)
        qry.exec()

        model = QSqlQueryModel()
        model.setQuery(qry)
        print(model.rowCount())
        mapper = QDataWidgetMapper()
        form = QFormLayout()
        layout = QVBoxLayout()

        first_name = QLineEdit()
        start_number = QLineEdit()
        form.addRow(QLabel("Startnummer"), start_number)
        form.addRow(QLabel("Fornavn"), first_name)
        mapper.setModel(model)
        mapper.addMapping(first_name, 0)
        mapper.addMapping(start_number, 2)
        mapper.toFirst()
        layout.addLayout(form)
        widget = QWidget()
        widget.setLayout(layout)
        self.setCentralWidget(widget)
        #controls = QHBoxLayout()
        '''
Exemplo n.º 2
0
    def _create_form_groupbox(self):
        imageLabel = QLabel("Name:")
        self.image = imageEdit = QLineEdit()
        imageLabel.setBuddy(imageEdit)

        commandLabel = QLabel("Service:")
        commandEdit = QLineEdit()
        commandLabel.setBuddy(commandEdit)

        environmentLabel = QLabel("Options:")
        environmentEdit = QLineEdit()
        environmentLabel.setBuddy(environmentEdit)

        self.mapper = mapper = QDataWidgetMapper(self)
        mapper.setSubmitPolicy(QDataWidgetMapper.AutoSubmit)
        mapper.setModel(self.model)
        mapper.addMapping(imageEdit, StepItem.Cols.IMAGE.value)
        mapper.addMapping(commandEdit, StepItem.Cols.COMMAND.value)
        mapper.addMapping(environmentEdit, StepItem.Cols.ENVIRONMENT.value)

        self.groupbox = config = QGroupBox()
        config_layout = QGridLayout()
        config_layout.addWidget(imageLabel, 0, 0)
        config_layout.addWidget(imageEdit, 0, 1)
        config_layout.addWidget(commandLabel, 1, 0)
        config_layout.addWidget(commandEdit, 1, 1)
        config_layout.addWidget(environmentLabel, 2, 0)
        config_layout.addWidget(environmentEdit, 2, 1)
        config.setLayout(config_layout)

        self.all_fields = [
            imageEdit,
            commandEdit,
            environmentEdit,
        ]
Exemplo n.º 3
0
def schema_ui_map(schema, model, form):
    """Construct a QDataWidgetMapper from the given ``schema`` class.
    (Function 4)

    :param schema: The schema to create field-to-widget mappings from.
    :param model: The model that the QDataWidgetMapper observes.
    :param form: The UI widget containing stuff to bind to. It is also set as
                 the parent for the widget mapper.
    """
    assert isinstance(model, QAbstractItemModel)
    mapper = QDataWidgetMapper(form)
    mapper.setModel(model)

    s = schema()

    for i, (name, field) in enumerate(s.fields.items()):
        try:
            widget_classes = _widget_type(type(field))
            widget = form.findChild(widget_classes, name)
            if not widget:
                raise ValueError
            prop = _widget_property(type(widget))
            log.debug("adding map from (`%s', col = %d) to %s (prop = `%s')",
                      name, i, widget, prop)
            mapper.addMapping(widget, i, bytes(prop, encoding='utf8'))
            assert mapper.mappedWidgetAt(i) == widget
        except KeyError:
            log.error("unknown field type %s", type(field))
        except ValueError:  # FIXME: is this the correct exception type?
            log.error("failed to find widget for field `%s'", name)

    mapper.toFirst()
    return mapper
Exemplo n.º 4
0
    def _biaocaozuo(self):
        self.model = QtSql.QSqlTableModel()
        self.model.setTable('BookData')

        self.model.setEditStrategy(QSqlTableModel.OnManualSubmit)  # 设置保存策略

        self.table_view.setModel(self.model)
        self.model.select()
        self.model.setHeaderData(0, Qt.Horizontal, 'ISBN')
        self.model.setHeaderData(1, Qt.Horizontal, '书名')
        self.model.setHeaderData(2, Qt.Horizontal, '作者')
        self.model.setHeaderData(3, Qt.Horizontal, '出版社')
        self.model.setHeaderData(4, Qt.Horizontal, '出版日期')
        self.model.setHeaderData(5, Qt.Horizontal, '评分')
        self.model.setHeaderData(6, Qt.Horizontal, '照片')
        self.table_view.setColumnHidden(6, True)

        self.mapper = QDataWidgetMapper()
        self.mapper.setModel(self.model)
        self.mapper.setSubmitPolicy(QDataWidgetMapper.AutoSubmit)

        self.mapper.addMapping(self.lineEdit_ISBN, 0)
        self.mapper.addMapping(self.lineEdit_shuming, 1)
        self.mapper.addMapping(self.lineEdit_zuozhe, 2)
        self.mapper.addMapping(self.lineEdit_chubanshe, 3)
        self.mapper.addMapping(self.lineEdit_chubanriqi, 4)
        self.mapper.addMapping(self.lineEdit_pingfen, 5)
        self.mapper.toFirst()

        self.selModel = QItemSelectionModel(self.model)  # 选择模型
        self.table_view.setSelectionModel(self.selModel)
        self.selModel.currentChanged.connect(
            self.do_currentChanged)  # 当前项变化时触发
        self.selModel.currentRowChanged.connect(
            self.do_currentRowChanged)  # 选择行变化时
Exemplo n.º 5
0
 def threadSizeInit(self, index = 0):
     self.sizeMapper = QDataWidgetMapper(self)
     self.sizeModel = QSqlQueryModel(self)
     form = self.threadFormLbl.text()
     threadClass = self.threadClassLbl.text()
     sizeSelect = "SELECT size, pitch, major_dia, \
         min_major_dia, max_minor_dia, min_minor_dia, \
         max_pitch_dia, min_pitch_dia FROM internal_threads WHERE form \
         = '{}' AND class = '{}'".format(form, threadClass)
     self.sizeModel.setQuery(sizeSelect)
     self.sizeMapper.setModel(self.sizeModel)
     self.sizeMapper.addMapping(self.threadSizeLbl, 0, b'text')
     self.sizeMapper.addMapping(self.threadTPILbl, 1, b'text')
     self.sizeMapper.addMapping(self.threadMajorDiaLbl, 2, b'text')
     self.sizeMapper.addMapping(self.minMajorDiaLbl, 3, b'text')
     self.sizeMapper.addMapping(self.maxMinorDiaLbl, 4, b'text')
     self.sizeMapper.addMapping(self.minMinorDiaLbl, 5, b'text')
     self.sizeMapper.addMapping(self.maxPitchDiaLbl, 6, b'text')
     self.sizeMapper.addMapping(self.minPitchDiaLbl, 7, b'text')
     self.sizeMapper.toLast()
     self.sizeLast = self.sizeMapper.currentIndex()
     self.sizeMapper.setCurrentIndex(index)
     self.drillSizeInit()
     self.threadSizeCalc()
     self.numPassesCalc()
     self.threadHeightCalc()
Exemplo n.º 6
0
 def __init__(self,
              parent: QWidget,
              tableName: str,
              filter: str = None,
              db=QtSql.QSqlDatabase()):
     '''用于窗体模式进行数据编辑时的主窗体数据模型。\n
     会自动增加数据映射器,但是外键字段要使用addComboBoxData方法增加列表文字。
     最后要调用tofirst()方法定位编辑的记录。\n
     注:数据映射器不能增删记录,只能编辑
     '''
     super().__init__(parent=parent, db=db)
     self.parent = parent
     self.setTable(tableName)
     if filter:
         self.setFilter(filter)
     self.select()
     rec = self.record()
     self.mapper = QDataWidgetMapper(parent)
     self.mapper.setModel(self)
     self.mapper.setItemDelegate(_JPRelationalDelegate(parent, self.mapper))
     self.mapper.setSubmitPolicy(QDataWidgetMapper.ManualSubmit)
     for i in range(rec.count()):
         widget = parent.findChild(self._tp, rec.fieldName(i))
         if widget:
             if not isinstance(widget, QComboBox):
                 self.mapper.addMapping(widget, i)
Exemplo n.º 7
0
 def setup_treemodel(self, treerootNode=None, treetype='FsTree'):
     if treetype=='FsTree':
         treemodel = FsTreeModel(treerootNode)
     else:
         treemodel = VnTreeModel(treerootNode)
     self.setModel(treemodel)
     self.dataMapper = QDataWidgetMapper()
     self.dataMapper.setModel(treemodel)
Exemplo n.º 8
0
 def __init__(self, employee_model, employee_controller, main_window):
     super().__init__()
     self.setupUi(self)
     self.employee_model: EmployeeModel = employee_model
     self.employee_controller: EmployeeController = employee_controller
     self.main_window: MainWindowView = main_window
     self.mapper = QDataWidgetMapper()
     self.set_employee_editor()
Exemplo n.º 9
0
 def __init__(self, student_model, student_controller, main_window):
     super().__init__()
     self.setupUi(self)
     self.student_model: StudentModel = student_model
     self.student_controller: StudentController = student_controller
     self.main_window: MainWindowView = main_window
     self.mapper = QDataWidgetMapper()
     self.set_student_editor()
Exemplo n.º 10
0
    def __init__(self, parent):
        super(MasternodeOutputsTab, self).__init__(parent)
        self.dialog = parent
        self.manager = parent.manager

        include_frozen_checkbox = QCheckBox(_('Include frozen addresses'))
        include_frozen_checkbox.setChecked(False)
        self.scan_outputs_button = QPushButton(_('Scan For Masternode Outputs'))
        def on_scan_outputs():
            """Call scan_for_outputs() with whether to include frozen addresses."""
            self.scan_for_outputs(include_frozen_checkbox.isChecked())
        self.scan_outputs_button.clicked.connect(on_scan_outputs)

        self.status_edit = QLineEdit()
        self.status_edit.setReadOnly(True)
        self.valid_outputs_list = MasternodeOutputsWidget()
        self.valid_outputs_list.outputSelected.connect(self.set_output)

        self.collateral_edit = PrevOutWidget()
        self.collateral_edit.setReadOnly(True)

        self.mapper = QDataWidgetMapper()
        self.mapper.setSubmitPolicy(QDataWidgetMapper.ManualSubmit)
        self.mapper.setModel(self.dialog.masternodes_widget.proxy_model)

        model = self.dialog.masternodes_widget.model
        self.mapper.addMapping(self.collateral_edit, model.VIN, b'string')

        self.save_output_button = QPushButton(_('Save'))
        self.save_output_button.setEnabled(False)
        self.save_output_button.clicked.connect(self.save_output)


        vbox = QVBoxLayout()

        desc = ' '.join(['Use this tab to scan for and choose a collateral payment for your masternode.',
            'A valid collateral payment is exactly 1000 AXE.'])
        desc = QLabel(_(desc))
        desc.setWordWrap(True)
        vbox.addWidget(desc)

        status_box = QHBoxLayout()
        status_box.setContentsMargins(0, 0, 0, 0)
        status_box.addWidget(QLabel(_('Status:')))
        status_box.addWidget(self.status_edit, stretch=1)
        vbox.addLayout(status_box)

        valid_outputs_box = QVBoxLayout()
        valid_outputs_box.setContentsMargins(0, 0, 0, 0)
        valid_outputs_box.addWidget(QLabel(_('Masternode Outputs:')))
        valid_outputs_box.addWidget(self.valid_outputs_list)

        vbox.addLayout(util.Buttons(include_frozen_checkbox, self.scan_outputs_button))
        vbox.addLayout(valid_outputs_box)

        vbox.addWidget(self.collateral_edit)
        vbox.addLayout(util.Buttons(self.save_output_button))
        self.setLayout(vbox)
Exemplo n.º 11
0
 def setUpMapper(self):
     self.mapper = QDataWidgetMapper(self)
     self.mapper.setModel(self.model)
     # self.mapper.addMapping(self.table,1,b'currentIndex')
     self.mapper.addMapping(self.table, 1)
     # self.mapper.addMapping(self.combo,0,b'currentIndex')
     self.mapper.addMapping(self.combo, 0)
     self.mapper.currentIndexChanged.connect(self.updateButtons)
     self.mapper.toFirst()
Exemplo n.º 12
0
    def __init__(self, current_index, model):
        super().__init__()
        # uic.loadUi('editForm.ui', self)
        self.setupUi(self)
        # self.db = database

        self.db_map = QDataWidgetMapper(self)
        self.db_map.setModel(model)
        self.db_map.setSubmitPolicy(QDataWidgetMapper.ManualSubmit)
        self.db_map.addMapping(self.lineEdit_name, 1)
        self.db_map.addMapping(self.lineEdit_inv_number, 2)
        self.db_map.addMapping(self.textEdit_comments, 3)
        self.db_map.addMapping(self.checkBox_on_balance,
                               model.fieldIndex('is_on_balance'))

        relModel_status = model.relationModel(5)
        self.comboBox_status.setModel(relModel_status)
        self.comboBox_status.setModelColumn(
            relModel_status.fieldIndex("status_name"))
        self.db_map.setItemDelegate(QSqlRelationalDelegate(self))
        self.db_map.addMapping(self.comboBox_status, 5)

        relModel_type = model.relationModel(6)
        self.comboBox_type.setModel(relModel_type)
        self.comboBox_type.setModelColumn(
            relModel_type.fieldIndex("goods_type_name"))
        self.db_map.setItemDelegate(QSqlRelationalDelegate(self))
        self.db_map.addMapping(self.comboBox_type, 6)

        relModel_subtype = model.relationModel(7)
        self.comboBox_subtype.setModel(relModel_subtype)
        self.comboBox_subtype.setModelColumn(
            relModel_subtype.fieldIndex("goods_subtype_name"))
        self.db_map.setItemDelegate(QSqlRelationalDelegate(self))
        self.db_map.addMapping(self.comboBox_subtype, 7)

        relModel_location = model.relationModel(8)
        self.comboBox_location.setModel(relModel_location)
        self.comboBox_location.setModelColumn(
            relModel_location.fieldIndex("location_name"))
        self.db_map.setItemDelegate(QSqlRelationalDelegate(self))
        self.db_map.addMapping(self.comboBox_location, 8)

        relModel_responsible = model.relationModel(9)
        self.comboBox_responsible.setModel(relModel_responsible)
        self.comboBox_responsible.setModelColumn(
            relModel_responsible.fieldIndex("FIO"))
        self.db_map.setItemDelegate(QSqlRelationalDelegate(self))
        self.db_map.addMapping(self.comboBox_responsible, 9)

        self.pushBtn_save.clicked.connect(self.save_item)
        self.pushBtn_cancel.clicked.connect(self.cancel)
        self.pushBtn_next.clicked.connect(self.db_map.toNext)
        self.pushBtn_prev.clicked.connect(self.db_map.toPrevious)
        self.pushBtn_close.clicked.connect(self.close)

        self.db_map.setCurrentIndex(current_index.row())
Exemplo n.º 13
0
    def plot(self, modelIndex):
        self.mapper = QDataWidgetMapper(self)
        self.mapper.setModel(self.imageListModel)
        self.mapper.addMapping(self.ui.lineEditFile, 1)
        self.mapper.addMapping(self.ui.lineEditHash, 2)
        self.mapper.addMapping(self.ui.lineEditTarget, 3)
        self.mapper.addMapping(self.ui.lineEditFrame, 4)
        self.mapper.addMapping(self.ui.lineEditFilter, 5)
        self.mapper.addMapping(self.ui.lineEditExposure, 6)
        self.mapper.addMapping(self.ui.lineEditTemp, 7)
        self.mapper.addMapping(self.ui.lineEditXbinning, 8)
        self.mapper.addMapping(self.ui.lineEditYbinning, 9)
        self.mapper.addMapping(self.ui.lineEditSiteLat, 10)
        self.mapper.addMapping(self.ui.lineEditSiteLong, 11)
        self.mapper.addMapping(self.ui.lineEditRa, 12)
        self.mapper.addMapping(self.ui.lineEditDec, 13)
        self.mapper.addMapping(self.ui.lineEditAlt, 14)
        self.mapper.addMapping(self.ui.lineEditAz, 15)
        self.mapper.addMapping(self.ui.lineEditDate, 16)
        self.mapper.addMapping(self.ui.lineEditGain, 17)
        self.mapper.addMapping(self.ui.lineEditOffset, 18)
        self.mapper.addMapping(self.ui.lineEditSubframeScale, 19)
        self.mapper.addMapping(self.ui.lineEditCameraGain, 20)
        self.mapper.addMapping(self.ui.lineEditCameraResolution, 21)
        self.mapper.addMapping(self.ui.lineEditScaleUnit, 22)
        self.mapper.addMapping(self.ui.lineEditDataUnit, 23)
        self.mapper.addMapping(self.ui.lineEditCsvFile, 24)
        self.mapper.addMapping(self.ui.lineEditFwhm, 25)
        self.mapper.addMapping(self.ui.lineEditEccentricity, 26)
        self.mapper.addMapping(self.ui.lineEditSnrWeight, 27)
        self.mapper.addMapping(self.ui.lineEditNoise, 28)
        self.mapper.setCurrentIndex(modelIndex.row())
        self.ui.lineEditRaF.setText(
            self.convertCoord(self.ui.lineEditRa.text(), "hms"))
        self.ui.lineEditDecF.setText(
            self.convertCoord(self.ui.lineEditDec.text(), "dms"))
        self.ui.lineEditSiteLatF.setText(
            self.convertCoord(self.ui.lineEditSiteLat.text(), "lat"))
        self.ui.lineEditSiteLongF.setText(
            self.convertCoord(self.ui.lineEditSiteLong.text(), "long"))
        self.ui.lineEditAltF.setText(
            self.convertCoord(self.ui.lineEditAlt.text(), "dms"))
        self.ui.lineEditAzF.setText(
            self.convertCoord(self.ui.lineEditAz.text(), "dms"))

        cr = self.imageListModel.index(modelIndex.row(), 1)
        t = self.imageListModel.data(cr, QtCore.Qt.DisplayRole)
        self.mplwidget = MatplotlibWidget(self.ui.MplWidget)
        self.mplwidget.setFileName(t)
        self.mplwidget.plot()
        try:
            self.resize(self.app.settings.value("sizeDetailW"))
            self.move(self.app.settings.value("posDetailW"))
        except Exception as e:
            self.logger.error(f"{e}")

        self.show()
Exemplo n.º 14
0
 def __init__(self, parent=None):
     super().__init__(parent)
     self.setupUi(self)
     self.model = None
     self.parts_tree_model = ArmorSetTreeModel()
     self.skill_model = SkillTranslationModel()
     self.armor_item_mapper = QDataWidgetMapper(self)
     self.armor_item_mapper.setItemDelegate(ItemDelegate())
     self.armor_item_mapper.setModel(self.parts_tree_model)
     self.parts_tree_view.setModel(self.parts_tree_model)
     self.parts_tree_view.activated.connect(
         self.handle_parts_tree_activated)
     self.import_export_manager = ImportExportManager(self.parts_tree_view)
     self.import_export_manager.connect_custom_context_menu()
     for it in ("set_skill1_value", "set_skill2_value", "skill1_value",
                "skill2_value", "skill3_value"):
         getattr(self, it).setModel(self.skill_model)
     mappings = [
         (self.id_value, Column.id, b"text"),
         (self.name_value, Column.gmd_name_index, b"text"),
         (self.description_value, Column.gmd_desc_index, b"text"),
         (self.setid_value, Column.set_id),
         (self.set_group_value, Column.set_group),
         (self.type_value, Column.type, b"currentIndex"),
         (self.order_value, Column.order),
         (self.variant_value, Column.variant, b"currentIndex"),
         (self.equip_slot_value, Column.equip_slot, b"currentIndex"),
         (self.gender_value, Column.gender, b"currentIndex"),
         (self.mdl_main_id_value, Column.mdl_main_id),
         (self.mdl_secondary_id_value, Column.mdl_secondary_id),
         (self.icon_color_value, Column.icon_color),
         (self.defense_value, Column.defense),
         (self.rarity_value, Column.rarity),
         (self.cost_value, Column.cost),
         (self.fire_res_value, Column.fire_res),
         (self.water_res_value, Column.water_res),
         (self.thunder_res_value, Column.thunder_res),
         (self.ice_res_value, Column.ice_res),
         (self.dragon_res_value, Column.dragon_res),
         (self.set_skill1_value, Column.set_skill1),
         (self.set_skill1_lvl_value, Column.set_skill1_lvl),
         (self.set_skill2_value, Column.set_skill2),
         (self.set_skill2_lvl_value, Column.set_skill2_lvl),
         (self.skill1_value, Column.skill1),
         (self.skill1_lvl_value, Column.skill1_lvl),
         (self.skill2_value, Column.skill2),
         (self.skill2_lvl_value, Column.skill2_lvl),
         (self.skill3_value, Column.skill3),
         (self.skill3_lvl_value, Column.skill3_lvl),
         (self.num_gem_slots, Column.num_gem_slots),
         (self.gem_slot1_lvl_value, Column.gem_slot1_lvl),
         (self.gem_slot2_lvl_value, Column.gem_slot2_lvl),
         (self.gem_slot3_lvl_value, Column.gem_slot3_lvl),
     ]
     for mapping in mappings:
         self.armor_item_mapper.addMapping(*mapping)
Exemplo n.º 15
0
 def __init__(self, parent=None):
     super().__init__(parent)
     self.setupUi(self)
     self.model = None
     self.skill_model = SkillTranslationModel()
     self.table_model = WpDatTableModel(self)
     self.weapon_tree_view.activated.connect(
         self.handle_weapon_tree_view_activated)
     self.kire_widget.set_model(KireGaugeModelEntryAdapter())
     self.mapper = QDataWidgetMapper(self)
     self.mapper.setItemDelegate(ItemDelegate())
     self.mapper.setModel(self.table_model)
     self.skill_id_value.setModel(self.skill_model)
     self.import_export_manager = ImportExportManager(self.weapon_tree_view)
     self.import_export_manager.connect_custom_context_menu()
     mappings = [
         (self.id_value, WpDatEntry.id.index, b"text"),
         (self.name_value, WpDatEntry.gmd_name_index.index, b"text"),
         (self.description_value, WpDatEntry.gmd_description_index.index,
          b"text"),
         (self.order_value, WpDatEntry.order.index),
         (self.tree_id_value, WpDatEntry.tree_id.index),
         (self.tree_position_value, WpDatEntry.tree_position.index),
         (self.is_fixed_upgrade_value, WpDatEntry.is_fixed_upgrade.index,
          b"checked"),
         (self.base_model_id_value, WpDatEntry.base_model_id.index),
         (self.part1_id_value, WpDatEntry.part1_id.index),
         (self.part2_id_value, WpDatEntry.part2_id.index),
         (self.color_value, WpDatEntry.color.index),
         (self.rarity_value, WpDatEntry.rarity.index),
         (self.cost_value, WpDatEntry.crafting_cost.index),
         (self.raw_damage_value, WpDatEntry.raw_damage.index),
         (self.affinity_value, WpDatEntry.affinity.index),
         (self.defense_value, WpDatEntry.defense.index),
         (self.handicraft_value, WpDatEntry.handicraft.index,
          b"currentIndex"),
         (self.element_id_value, WpDatEntry.element_id.index,
          b"currentIndex"),
         (self.element_damage_value, WpDatEntry.element_damage.index),
         (self.hidden_element_id_value, WpDatEntry.hidden_element_id.index,
          b"currentIndex"),
         (self.hidden_element_damage_value,
          WpDatEntry.hidden_element_damage.index),
         (self.elderseal_value, WpDatEntry.elderseal.index,
          b"currentIndex"),
         (self.num_gem_slots, WpDatEntry.num_gem_slots.index),
         (self.gem_slot1_lvl_value, WpDatEntry.gem_slot1_lvl.index),
         (self.gem_slot2_lvl_value, WpDatEntry.gem_slot2_lvl.index),
         (self.gem_slot3_lvl_value, WpDatEntry.gem_slot3_lvl.index),
         (self.skill_id_value, WpDatEntry.skill_id.index),
         (self.wep1_id_value, WpDatEntry.wep1_id.index),
         (self.wep2_id_value, WpDatEntry.wep2_id.index),
         (self.kire_widget, WpDatEntry.kire_id.index),
     ]
     for mapping in mappings:
         self.mapper.addMapping(*mapping)
Exemplo n.º 16
0
    def __init__(self, model=None, ui_file: str = None) -> None:
        super().__init__()
        loadUi(ui_file or self.ui_file, self)

        self.row = None
        self.record = None

        self.new_record = False
        self.parent_view = None
        self.sub_views = []

        if self.window_title:
            self.setWindowTitle(self.window_title)

        if self.window_icon:
            self.setWindowIcon(QIcon(self.window_icon))

        # allow passing a model class or instances
        model = model or self.model
        if inspect.isclass(model):
            self.data_model = model()
        else:
            self.data_model = model

        # update subviews on row change
        self.data_mapper = QDataWidgetMapper()
        self.data_mapper.setModel(self.data_model)
        self.data_mapper.currentIndexChanged.connect(self._update_subviews)

        # auto map fields to db columns
        for field in self.data_model.fields:
            if hasattr(self, field.name):
                self.data_mapper.addMapping(getattr(self, field.name),
                                            field.index)

        # setup subviews
        for view_name, view_cls in self.subviews.items():
            placeholder_name = '{0}_placeholder'.format(view_name)
            try:
                placeholder = getattr(self, placeholder_name)
            except AttributeError:
                raise ImproperlyConfigured(
                    'Unable to find subview placeholder ' + placeholder_name)

            view = view_cls()
            self.sub_views.append(view)
            view.set_parent_view(self)
            layout = placeholder.layout()
            if not layout:
                layout = QVBoxLayout(placeholder)
            layout.setContentsMargins(0, 0, 0, 0)
            layout.addWidget(view)
            setattr(self, view_name, view)

        if hasattr(self, 'setup_ui'):
            self.setup_ui()
Exemplo n.º 17
0
def materialInit(parent):
    parent.materialMapper = QDataWidgetMapper(parent)
    parent.materialModel = QSqlQueryModel(parent)
    parent.materialModel.setQuery('SELECT DISTINCT material FROM cut_chart')
    parent.materialMapper.setModel(parent.materialModel)
    parent.materialMapper.addMapping(parent.materialLbl, 0, b'text')
    parent.materialMapper.toLast()
    parent.materialLast = parent.materialMapper.currentIndex()
    parent.materialMapper.toFirst()
    thicknessInit(parent)
Exemplo n.º 18
0
def threadFormInit(parent):
    parent.formMapper = QDataWidgetMapper(parent)
    parent.formModel = QSqlQueryModel(parent)
    parent.formModel.setQuery('SELECT DISTINCT form FROM internal_threads')
    parent.formMapper.setModel(parent.formModel)
    parent.formMapper.addMapping(parent.threadFormLbl, 0, b'text')
    parent.formMapper.toLast()
    parent.formsLast = parent.formMapper.currentIndex()
    parent.formMapper.toFirst()
    threadClassInit(parent)
Exemplo n.º 19
0
def toolTypeInit(parent):
    parent.toolTypeMapper = QDataWidgetMapper(parent)
    parent.toolTypeModel = QSqlQueryModel(parent)
    parent.toolTypeModel.setQuery('SELECT DISTINCT material FROM end_mills')
    parent.toolTypeMapper.setModel(parent.toolTypeModel)
    parent.toolTypeMapper.addMapping(parent.endMillMaterialLbl, 0, b'text')
    parent.toolTypeMapper.toLast()
    parent.toolTypeLast = parent.toolTypeMapper.currentIndex()
    print('current index {}'.format(parent.toolTypeMapper.currentIndex()))
    parent.toolTypeMapper.toFirst()
Exemplo n.º 20
0
    def init_model(self, model):
        self.__model = model

        self.__mapper = QDataWidgetMapper(self)
        self.__mapper.setModel(self.__model)

        self.__mapper.setSubmitPolicy(QDataWidgetMapper.ManualSubmit)
        self.__mapper.addMapping(self.titleEdit, 1)
        self.__mapper.addMapping(self.plannedDateTimeEdit, 2)
        self.__mapper.addMapping(self.contentEdit, 3)
Exemplo n.º 21
0
 def threadFormInit(self):
     self.formMapper = QDataWidgetMapper(self)
     self.formModel = QSqlQueryModel(self)
     self.formModel.setQuery('SELECT DISTINCT form FROM internal_threads')
     self.formMapper.setModel(self.formModel)
     self.formMapper.addMapping(self.threadFormLbl, 0, b'text')
     self.formMapper.toLast()
     self.formsLast = self.formMapper.currentIndex()
     self.formMapper.toFirst()
     self.threadClassInit()
Exemplo n.º 22
0
def rtFormInit(parent):
    parent.rtFormMapper = QDataWidgetMapper(parent)
    parent.rtFormModel = QSqlQueryModel(parent)
    parent.rtFormModel.setQuery('SELECT DISTINCT form FROM tap')
    parent.rtFormMapper.setModel(parent.rtFormModel)
    parent.rtFormMapper.addMapping(parent.rtFormLbl, 0, b'text')
    parent.rtFormMapper.toLast()
    parent.rtFormLast = parent.rtFormMapper.currentIndex()
    parent.rtFormMapper.toFirst()
    rtSizeInit(parent)
Exemplo n.º 23
0
def nozzleInit(parent):
    parent.nozzleMapper = QDataWidgetMapper(parent)
    parent.nozzleModel = QSqlQueryModel(parent)
    thickness = parent.thicknessLbl.text()
    parent.nozzleModel.setQuery("SELECT DISTINCT nozzle FROM cut_chart \
        WHERE thickness = '{}'".format(thickness))
    parent.nozzleMapper.setModel(parent.nozzleModel)
    parent.nozzleMapper.addMapping(parent.nozzleLbl, 0, b'text')
    parent.nozzleMapper.toLast()
    parent.nozzleLast = parent.nozzleMapper.currentIndex()
    parent.nozzleMapper.toFirst()
Exemplo n.º 24
0
    def __init__(self, main_widget, parent=None):
        super(ProposalEditor, self).__init__(parent)
        self.main_widget = main_widget

        self.name_edit = QLineEdit()
        self.url_edit = QLineEdit()
        self.start_block_edit = QLineEdit()
        self.end_block_edit = QLineEdit()
        self.amount_edit = QLineEdit()
        self.address_edit = QLineEdit()
        self.txid_edit = QLineEdit()
        for i in [
                self.name_edit, self.url_edit, self.start_block_edit,
                self.end_block_edit, self.amount_edit, self.address_edit,
                self.txid_edit
        ]:
            i.setReadOnly(True)

        self.mapper = QDataWidgetMapper()
        self.mapper.setModel(self.main_widget.proxy_model)
        self.mapper.setSubmitPolicy(QDataWidgetMapper.ManualSubmit)

        self.mapper.addMapping(self.name_edit, ProposalsModel.NAME)
        self.mapper.addMapping(self.url_edit, ProposalsModel.URL)
        self.mapper.addMapping(self.start_block_edit,
                               ProposalsModel.START_BLOCK)
        self.mapper.addMapping(self.end_block_edit, ProposalsModel.END_BLOCK)
        self.mapper.addMapping(self.amount_edit, ProposalsModel.AMOUNT)
        self.mapper.addMapping(self.address_edit, ProposalsModel.ADDRESS)
        self.mapper.addMapping(self.txid_edit, ProposalsModel.TXID)

        block_hbox = QHBoxLayout()
        block_hbox.addWidget(self.start_block_edit)
        block_hbox.addWidget(QLabel(' - '))
        block_hbox.addWidget(self.end_block_edit)

        self.vote_combo = QComboBox()
        self.vote_combo.addItem(_('Yes'))
        self.vote_combo.addItem(_('No'))
        self.vote_button = QPushButton(_('Vote'))
        self.vote_button.clicked.connect(self.cast_vote)

        vote_hbox = util.Buttons(self.vote_combo, self.vote_button)

        form = QFormLayout()
        form.addRow(_('Name:'), self.name_edit)
        form.addRow(_('URL:'), self.url_edit)
        form.addRow(_('Blocks:'), block_hbox)
        form.addRow(_('Monthly Payment:'), self.amount_edit)
        form.addRow(_('Payment Address:'), self.address_edit)
        form.addRow(_('Fee TxID:'), self.txid_edit)

        form.addRow(_('Vote:'), vote_hbox)
        self.setLayout(form)
Exemplo n.º 25
0
def thicknessInit(parent):
    parent.thicknessMapper = QDataWidgetMapper(parent)
    parent.thicknessModel = QSqlQueryModel(parent)
    material = parent.materialLbl.text()
    parent.thicknessModel.setQuery("SELECT DISTINCT gauge FROM cut_chart \
        WHERE material = '{}'".format(material))
    parent.thicknessMapper.setModel(parent.thicknessModel)
    parent.thicknessMapper.addMapping(parent.thicknessLbl, 0, b'text')
    parent.thicknessMapper.toLast()
    parent.thicknessLast = parent.thicknessMapper.currentIndex()
    parent.thicknessMapper.toFirst()
    nozzleInit(parent)
Exemplo n.º 26
0
 def formModelInit(self):
     self.formMapper = QDataWidgetMapper(self)
     self.formModel = QSqlQueryModel(self)
     self.formModel.setQuery('SELECT DISTINCT form FROM threads')
     self.formMapper.setModel(self.formModel)
     self.formMapper.addMapping(self.formLbl, 0, b'text')
     self.formMapper.currentIndexChanged.connect(self.formChanged)
     self.formMapper.toLast()
     self.formsLast = self.formMapper.currentIndex()
     self.formMapper.toFirst()
     self.formIndexLbl.setText('{}'.format(self.formMapper.currentIndex()))
     self.classModelInit()
Exemplo n.º 27
0
def rtSizeInit(parent):
    parent.rtSizeMapper = QDataWidgetMapper(parent)
    parent.rtSizeModel = QSqlQueryModel(parent)
    form = parent.rtFormLbl.text()
    classSelect = "SELECT DISTINCT size FROM tap \
        WHERE form = '{}'".format(form)
    parent.rtSizeModel.setQuery(classSelect)
    parent.rtSizeMapper.setModel(parent.rtSizeModel)
    parent.rtSizeMapper.addMapping(parent.rtSizeLbl, 0, b'text')
    parent.rtSizeMapper.toLast()
    parent.rtSizeLast = parent.rtSizeMapper.currentIndex()
    parent.rtSizeMapper.toFirst()
    rtInfoInit(parent)
Exemplo n.º 28
0
    def __init__(self, contact_list_model, contact_index):
        super().__init__()
        ui_file = BASE_UI_PATH / "edit_contact_window.ui"
        uic.loadUi(ui_file, self)
        self.gender_editbox.addItems(GENDER_LIST)

        contact = contact_list_model.contact_by_index(contact_index)

        mapper = QDataWidgetMapper(self)
        mapper.setModel(contact_list_model)
        for section, name in enumerate(contact.field_names()):
            mapper.addMapping(getattr(self, f"{name}_editbox"), section)
        mapper.setCurrentIndex(contact_index)
Exemplo n.º 29
0
 def threadClassInit(self):
     self.classMapper = QDataWidgetMapper(self)
     self.classModel = QSqlQueryModel(self)
     form = self.threadFormLbl.text()
     classSelect = "SELECT DISTINCT class FROM internal_threads \
         WHERE form = '{}'".format(form)
     self.classModel.setQuery(classSelect)
     self.classMapper.setModel(self.classModel)
     self.classMapper.addMapping(self.threadClassLbl, 0, b'text')
     self.classMapper.toLast()
     self.classLast = self.classMapper.currentIndex()
     self.classMapper.toFirst()
     self.threadSizeInit()
Exemplo n.º 30
0
    def create_view_masternode_tab(self):
        """Create the tab used to view masternodes."""
        desc = ' '.join([
            'In this tab, you can view your masternodes and fill in required data about them.',
            'The collateral payment for a masternode can be specified using the "Choose Collateral" tab.',
        ])
        desc = QLabel(_(desc))
        desc.setWordWrap(True)

        self.masternode_editor = editor = MasternodeEditor()
        model = self.masternodes_widget.proxy_model
        self.mapper = mapper = QDataWidgetMapper()

        editor.alias_edit.textChanged.connect(self.on_editor_alias_changed)

        mapper.setSubmitPolicy(QDataWidgetMapper.ManualSubmit)
        mapper.setModel(model)
        mapper.addMapping(editor.alias_edit, MasternodesModel.ALIAS)
        mapper.addMapping(editor.status_edit, MasternodesModel.STATUS)

        editor.vin_edit.setReadOnly(True)
        mapper.addMapping(editor.vin_edit, MasternodesModel.VIN, b'string')

        mapper.addMapping(editor.addr_edit, MasternodesModel.ADDR, b'string')
        mapper.addMapping(editor.delegate_key_edit, MasternodesModel.DELEGATE)
        mapper.addMapping(editor.protocol_version_edit,
                          MasternodesModel.PROTOCOL_VERSION)

        self.save_new_masternode_button = QPushButton('Save As New Masternode')
        self.save_new_masternode_button.clicked.connect(
            lambda: self.save_current_masternode(as_new=True))

        self.save_masternode_button = QPushButton(_('Save Masternode'))
        self.save_masternode_button.clicked.connect(
            self.save_current_masternode)

        self.delete_masternode_button = QPushButton(_('Delete Masternode'))
        self.delete_masternode_button.clicked.connect(
            self.delete_current_masternode)

        vbox = QVBoxLayout()
        vbox.addWidget(desc)
        vbox.addWidget(editor)
        vbox.addStretch(1)
        vbox.addLayout(
            util.Buttons(self.delete_masternode_button,
                         self.save_new_masternode_button,
                         self.save_masternode_button))
        w = QWidget()
        w.setLayout(vbox)
        return w