def __init__(self): super().__init__() self.setWindowTitle('Автооценка') self.model.setTable('auto_marks_data') self.model.setRelation(4, QSqlRelation("car_data", "car_data_id", "car_mark")) self.model.setRelation(5, QSqlRelation("car_data", "car_data_id", "car_reg_number")) self.model.setRelation(6, QSqlRelation("counter_agents", "counter_agent_id", "manager")) self.model.setRelation(7, QSqlRelation("counter_agents", "counter_agent_id", "manager")) self.model.setRelation(8, QSqlRelation('workers_info', 'worker_info_id', 'FIO')) self.model.select() self.model.setHeaderData(0, Qt.Horizontal, "id") 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.model.setHeaderData(7, Qt.Horizontal, "Заказчик") self.model.setHeaderData(8, Qt.Horizontal, "Оценщик") self.view.resizeColumnsToContents() self.view.setItemDelegateForColumn(4, QSqlRelationalDelegate(self.view)) self.view.setItemDelegateForColumn(6, QSqlRelationalDelegate(self.view)) self.view.setItemDelegateForColumn(7, QSqlRelationalDelegate(self.view)) self.view.setItemDelegateForColumn(8, QSqlRelationalDelegate(self.view)) self.view.setItemDelegate(ProductDelegate(1)) self.view.setItemDelegateForColumn(5, QSqlRelationalDelegate(self.view))
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())
def update_table(self) -> None: self.table_model = QSqlRelationalTableModel() tablename = self.combo_box.currentText() self.table_model.setTable(tablename) # foreign key logic if tablename == "goods": self.table_model.setRelation(2, QSqlRelation("units", "id", "unit")) self.table_model.setRelation( 3, QSqlRelation("categories", "id", "name")) elif tablename == "employees": self.table_model.setRelation( 2, QSqlRelation("positions", "id", "position")) elif tablename == "vendors": self.table_model.setRelation( 2, QSqlRelation("ownerships", "id", "ownership")) self.table_model.select() self.table_model.setEditStrategy(QSqlTableModel.OnManualSubmit) self.table_view.setModel(self.table_model) self.table_view.setItemDelegate(QSqlRelationalDelegate( self.table_view)) # define header width self.table_view.horizontalHeader().setStretchLastSection(False) self.table_view.resizeColumnsToContents() self.table_view.horizontalHeader().setMinimumSectionSize(50) self.table_view.horizontalHeader().setStretchLastSection(True)
def createView(title, model): view = QTableView() view.setModel(model) view.setItemDelegate(QSqlRelationalDelegate(view)) view.setWindowTitle(title) return view
def __init__(self): super().__init__() container = QWidget() layout = QVBoxLayout() self.search = QLineEdit() self.search.textChanged.connect(self.update_filter) self.table = QTableView() layout.addWidget(self.search) layout.addWidget(self.table) container.setLayout(layout) self.model = QSqlRelationalTableModel(db=db) self.table.setModel(self.model) self.model.setTable("Track") self.model.setRelation(2, QSqlRelation("Album", "AlbumId", "Title")) self.model.setRelation(3, QSqlRelation("MediaType", "MediaTypeId", "Name")) self.model.setRelation(4, QSqlRelation("Genre", "GenreId", "Name")) delegate = QSqlRelationalDelegate(self.table) self.table.setItemDelegate(delegate) self.model.select() self.setMinimumSize(QSize(1024, 600)) self.setCentralWidget(container)
def setDelegatesTableView(self): self.defaultDelegates = [ self.dataTableView.itemDelegateForColumn(column) for column in range(6) ] self.dataTableView.setItemDelegate( QSqlRelationalDelegate(self.dataTableView))
def initUi(self): self.setObjectName("Main window") self.resize(370, 300) self.setWindowTitle("Материалы") self.btn_add = QPushButton(self) self.btn_add.setObjectName("btn_add") self.btn_add.setText("Добавить") self.btn_delete = QPushButton(self) self.btn_delete.setObjectName("btn_delete") self.btn_delete.setText("Удалить") self.btn_exit = QPushButton(self) self.btn_exit.setObjectName("btn_exit") self.btn_exit.setText("Выход") self.btn_refresh = QPushButton(self) self.btn_refresh.setText("Обновить") self.db = QSqlDatabase.addDatabase('QSQLITE') self.db.setDatabaseName('ocenka.db') self.db.open() self.model = QSqlRelationalTableModel(self) self.model.setTable("v_materials") self.model.setEditStrategy(QSqlRelationalTableModel.OnFieldChange) self.model.setJoinMode(QSqlRelationalTableModel.LeftJoin) self.model.setHeaderData(0, Qt.Horizontal, "Идентификатор") 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.proxyModel = QSortFilterProxyModel(self) #self.proxyModel.setSourceModel(self.model) self.view = QTableView(self) self.view.setSortingEnabled(True) self.view.setModel(self.model) self.view.resizeColumnsToContents() self.view.hideColumn(0) self.view.horizontalHeader().setStretchLastSection(True) #self.view.hideColumn(1) self.view.setItemDelegate(QSqlRelationalDelegate(self.model)) self.model.select() self.layout = QHBoxLayout() self.layout.addWidget(self.btn_add) self.layout.addWidget(self.btn_delete) self.layout.addWidget(self.btn_exit) self.layout.addWidget(self.btn_refresh) vlayout = QVBoxLayout() vlayout.addWidget(self.view) vlayout.addLayout(self.layout) self.setLayout(vlayout) self.show() self.view.clicked.connect(self.findrow) self.btn_add.clicked.connect(self.addrow) self.btn_delete.clicked.connect(lambda: self.model.removeRow(self.view.currentIndex().row())) self.btn_exit.clicked.connect(self.close_event) self.btn_refresh.clicked.connect(lambda: self.model.select())
def _create_table_view(self, model): view = QTableView() view.setModel(model) view.setItemDelegate(QSqlRelationalDelegate()) view.resizeColumnsToContents() view.setSortingEnabled(True) view.setEditTriggers(QAbstractItemView.NoEditTriggers) return view
def __init__(self, parent): self.view = QTableView() self.parent = parent self.cnmodel = models.Components(self.parent.connection) self.view.setModel(self.cnmodel.getModel()) self.view.setItemDelegate(QSqlRelationalDelegate(self.view)) self._formatTable() super().__init__(self.view)
def loadData(self): self.lineEdit.clear() self.lineEdit.setFocus() # สร้าง model เรียก data จาก database # ใช้ QSqlRelationalTableModel สำหรับตารางที่มีคีย์นอก self.model = QSqlRelationalTableModel() self.model.setTable('queue') self.model.setEditStrategy(QSqlTableModel.OnFieldChange) self.model.setHeaderData(0, Qt.Horizontal, 'ID') 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, "Option") # ให้ column#5 เป็นคีย์นอกดึงตารางนอกมาแสดง self.model.setRelation( 5, QSqlRelation("destination", "des_id", "des_name")) # เรียกใช้ model เรียกใช้ได้จากทุกที่ใน class ไม่ต้องเรียก loadData() self.model.select() # ให้ tableView เลือก data จาก model ไปแสดง self.tableView.setModel(self.model) self.tableView.setItemDelegate(QSqlRelationalDelegate(self.tableView)) self.tableView.setColumnHidden(0, True) self.tableView.setCornerButtonEnabled(False) self.tableView.setSortingEnabled(True) self.tableView.setColumnWidth(1, 210) # เรียก fetchData เพื่อ fetch data เข้ามาใน model ให้หมด self.fetchData() # เมื่อ click ให้เลือกทั้งแถว self.tableView.setSelectionBehavior(QAbstractItemView.SelectRows) # สร้าง model เรียกตาราง destination แล้วยัดเข้า combobox self.desModel = QSqlQueryModel() selectQuery = QSqlQuery() selectQuery.prepare('SELECT des_name FROM destination') # print('QUERY = ' + str(selectQuery.lastQuery())) if selectQuery.exec(): self.desModel.setQuery(selectQuery) # print('SELECT des_name COMPLETE') self.comboBox.setModel(self.desModel) else: print('SELECT FALSE = ' + selectQuery.lastError().text()) # สร้าง obj ของ destination setting ไว้รอเรียก self.desDialog = QtWidgets.QDialog() self.ui = destination2.Ui_Dialog() self.ui.setupUi(self.desDialog) self.tableView.selectRow(0)
def setupWidgets(self): """ Create instances of widgets, the table view and set layouts. """ icons_path = "icons" title = QLabel("Account Management System") title.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) title.setStyleSheet("font: bold 24px") add_product_button = QPushButton("Add Employee") add_product_button.setIcon(QIcon(os.path.join(icons_path, "add_user.png"))) add_product_button.setStyleSheet("padding: 10px") add_product_button.clicked.connect(self.addItem) del_product_button = QPushButton("Delete") del_product_button.setIcon(QIcon(os.path.join(icons_path, "trash_can.png"))) del_product_button.setStyleSheet("padding: 10px") del_product_button.clicked.connect(self.deleteItem) # Set up sorting combobox sorting_options = ["Sort by ID", "Sort by Employee ID", "Sort by First Name", "Sort by Last Name", "Sort by Department", "Sort by Country"] sort_name_cb = QComboBox() sort_name_cb.addItems(sorting_options) sort_name_cb.currentTextChanged.connect(self.setSortingOrder) buttons_h_box = QHBoxLayout() buttons_h_box.addWidget(add_product_button) buttons_h_box.addWidget(del_product_button) buttons_h_box.addStretch() buttons_h_box.addWidget(sort_name_cb) # Widget to contain editing buttons edit_buttons = QWidget() edit_buttons.setLayout(buttons_h_box) # Create table view and set model self.table_view = QTableView() self.table_view.setModel(self.model) self.table_view.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) self.table_view.verticalHeader().setSectionResizeMode(QHeaderView.Stretch) self.table_view.setSelectionMode(QTableView.SingleSelection) self.table_view.setSelectionBehavior(QTableView.SelectRows) # Instantiate the delegate delegate = QSqlRelationalDelegate(self.table_view) self.table_view.setItemDelegate(delegate) # Main layout main_v_box = QVBoxLayout() main_v_box.addWidget(title, Qt.AlignLeft) main_v_box.addWidget(edit_buttons) main_v_box.addWidget(self.table_view) self.setLayout(main_v_box)
def __init__(self, parent=None): super().__init__(parent) self.setWindowTitle("QTableView Example") self.resize(800, 600) # Set up the model self.model = QSqlRelationalTableModel(self) self.model.setTable("queue") self.model.setEditStrategy(QSqlTableModel.OnFieldChange) self.model.setHeaderData(0, Qt.Horizontal, "ID") self.model.setHeaderData(1, Qt.Horizontal, "Number") self.model.setHeaderData(2, Qt.Horizontal, "Enter Time") self.model.setHeaderData(3, Qt.Horizontal, "Call Time") self.model.setHeaderData(4, Qt.Horizontal, "Status") self.model.setHeaderData(5, Qt.Horizontal, "Destination") # ใช้ QSqlRelation อ่านคีย์นอกจากในตาราง queue แล้ว maps เข้ากับตาราง destination เลือก index กับ text ที่ต้องการแสดงในตาราง queue self.model.setRelation( 5, QSqlRelation("destination", "des_id", "des_name")) self.model.select() # Set up the view self.view = QTableView() self.view.setModel(self.model) self.view.setItemDelegate(QSqlRelationalDelegate(self.view)) self.view.setColumnHidden(0, True) self.view.setCornerButtonEnabled(False) #self.view.setEditTriggers(QAbstractItemView()) #self.headerView = QHeaderView() #self.view.setHorizontalHeader() #print(str(self.view.editTriggers())) self.view.resizeColumnsToContents() # self.cbxModel = QSqlQueryModel(self) # self.cbxModel.setQuery = "SELECT des_name FROM destination" # self.cbxModel.query() # สร้าง comboboxmodel ดึงข้อมูลจาก ex1.destination #self.cbxModel = QSqlTableModel(self) #self.cbxModel.setTable("destination") #self.cbxModel.select() # สร้าง comboboxview #self.cbxView = QComboBox() #self.cbxView.setModel(self.cbxModel) # เลือก column ที่จะมาแสดง #self.cbxView.setModelColumn(1) # วาด comboboxview ลงบน tableview ติดปัญหา comboboxview จะวาดลงใน record สุดท้ายเสมอ # for i in range(self.model.rowCount()): # i = self.view.model().index(1, 5) # self.view.setIndexWidget(i,self.cbxView) self.setCentralWidget(self.view)
def __openTable(self): ##打开数据表 self.tabModel = QSqlRelationalTableModel(self, self.DB) #数据表 self.tabModel.setTable("studInfo") #设置数据表 self.tabModel.setEditStrategy(QSqlTableModel.OnManualSubmit ) #数据保存方式,OnManualSubmit , OnRowChange self.tabModel.setSort(self.tabModel.fieldIndex("studID"), Qt.AscendingOrder) #排序 if (self.tabModel.select() == False): #查询数据失败 QMessageBox.critical( self, "错误信息", "打开数据表错误,错误信息\n" + self.tabModel.lastError().text()) return self.__getFieldNames() #获取字段名和序号 ##字段显示名 self.tabModel.setHeaderData(self.fldNum["studID"], Qt.Horizontal, "学号") self.tabModel.setHeaderData(self.fldNum["name"], Qt.Horizontal, "姓名") self.tabModel.setHeaderData(self.fldNum["gender"], Qt.Horizontal, "性别") self.tabModel.setHeaderData(self.fldNum["departID"], Qt.Horizontal, "学院") self.tabModel.setHeaderData(self.fldNum["majorID"], Qt.Horizontal, "专业") ## 设置代码字段的查询关系数据表 self.tabModel.setRelation(self.fldNum["departID"], QSqlRelation("departments", "departID", "department")) #学院 self.tabModel.setRelation(self.fldNum["majorID"], QSqlRelation("majors", "majorID", "major")) #专业 self.selModel = QItemSelectionModel(self.tabModel) #关联选择模型 ##selModel当前项变化时触发currentChanged信号 self.selModel.currentChanged.connect(self.do_currentChanged) ##选择行变化时 ## self.selModel.currentRowChanged.connect(self.do_currentRowChanged) self.ui.tableView.setModel(self.tabModel) #设置数据模型 self.ui.tableView.setSelectionModel(self.selModel) #设置选择模型 delgate = QSqlRelationalDelegate(self.ui.tableView) self.ui.tableView.setItemDelegate(delgate) #为关系型字段设置缺省代理组件 self.tabModel.select() #必须重新查询数据 ##更新actions和界面组件的使能状态 self.ui.actOpenDB.setEnabled(False) self.ui.actRecAppend.setEnabled(True) self.ui.actRecInsert.setEnabled(True) self.ui.actRecDelete.setEnabled(True) self.ui.actFields.setEnabled(True)
def createView(self, title, model): self.model = model self.title = title view = QTableView(self) view.setModel(self.model) view.setWindowTitle(self.title) view.resizeColumnsToContents() view.setGeometry(25, 25, 380, 200) view.hideColumn(0) view.setItemDelegate(QSqlRelationalDelegate(view)) return view
def __init__(self, parent): self.view = QTableView() self.parent = parent self.cnmodel = models.CustomNetwork(self.parent.connection) self.view.setModel(self.cnmodel.getModel()) self.view.setItemDelegate(QSqlRelationalDelegate(self.view)) self.view.selectionModel().selectionChanged.connect(self.selChanged) self.view.doubleClicked.connect(self.manageDoubleClick) self._formatTable() self.dependantView = parent.cncview self.customnetwork_id = -1 super().__init__(self.view)
def show_table(self): self.table_model = QSqlRelationalTableModel() if self.table_name: table = self.table_name else: table = [str(self.ui.tablesListView.item(i).text()) for i in range(self.ui.tablesListView.count())][0] self.table_model.setTable(table) self.table_model.select() self.table_model.setEditStrategy(QSqlTableModel.OnManualSubmit) view = self.ui.tableViewerTableView view.setModel(self.table_model) view.setItemDelegate(QSqlRelationalDelegate(view))
def insertwidget(self): """ create table """ # table view and create sql model and set sql mode has table view mode title = QLabel("Items") title.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) title.setStyleSheet("font: bold 24px") self.items_view = QTableView() self.items_view.setModel(self.itemTable) self.items_view.horizontalHeader().setSectionResizeMode( QHeaderView.Stretch) # set the selection mode and behavior for item_view self.items_view.setSelectionMode(QTableView.SingleSelection) self.items_view.setSelectionBehavior(QTableView.SelectRows) # create delegate for item_view delegate = QSqlRelationalDelegate(self.items_view) self.items_view.setItemDelegate(delegate) # push button # add row button additem_button = QPushButton("Add item") additem_button.setIcon(QIcon("icons/007-download.png")) additem_button.setIconSize(QSize(10, 10)) additem_button.clicked.connect(self.additem) # delete row push button deleteitem_bt = QPushButton("delete item") deleteitem_bt.setIcon(QIcon("icons/005-cancel.png")) deleteitem_bt.setIconSize(QSize(10, 10)) deleteitem_bt.clicked.connect(self.deleteitem) # create vertical layout for push button push_layout = QHBoxLayout() push_layout.addWidget(additem_button) push_layout.addStretch() push_layout.addWidget(deleteitem_bt) # create horizontal layout for table and push button tab_layout = QVBoxLayout() tab_layout.addWidget(title, Qt.AlignCenter) push_w = QWidget() push_w.setLayout(push_layout) tab_layout.addWidget(push_w) tab_layout.addWidget(self.items_view) # set tab layout as tab widget layout self.insert_tab.setLayout(tab_layout)
def show_table(self): self.table_model = QSqlRelationalTableModel() table = self.ui.comboBox.currentText() if table == 'goods': self.create_goods_table_model() elif table == 'employees': self.create_employees_table_model() else: self.table_model.setTable(table) self.table_model.select() self.table_model.setEditStrategy(QSqlTableModel.OnManualSubmit) view = self.ui.tableView view.setModel(self.table_model) view.setItemDelegate(QSqlRelationalDelegate(view))
def __openTable(self): self.tabModel = QSqlRelationalTableModel(self, self.DB) self.tabModel.setTable("studInfo") self.tabModel.setEditStrategy(QSqlTableModel.OnManualSubmit) self.tabModel.setSort(self.tabModel.fieldIndex("studID"), Qt.AscendingOrder) if (self.tabModel.select() == False): QMessageBox.critical( self, "错误信息", "打开数据表错误,错误信息\n" + self.tabModel.lastError().text()) return self.__getFieldNames() self.tabModel.setHeaderData(self.fldNum["studID"], Qt.Horizontal, "学号") self.tabModel.setHeaderData(self.fldNum["name"], Qt.Horizontal, "姓名") self.tabModel.setHeaderData(self.fldNum["gender"], Qt.Horizontal, "性别") self.tabModel.setHeaderData(self.fldNum["departID"], Qt.Horizontal, "学院") self.tabModel.setHeaderData(self.fldNum["majorID"], Qt.Horizontal, "专业") self.tabModel.setRelation( self.fldNum["departID"], QSqlRelation("departments", "departID", "department")) self.tabModel.setRelation(self.fldNum["majorID"], QSqlRelation("majors", "majorID", "major")) self.selModel = QItemSelectionModel(self.tabModel) self.selModel.currentChanged.connect(self.do_currentChanged) self.ui.tableView.setModel(self.tabModel) self.ui.tableView.setSelectionModel(self.selModel) delgate = QSqlRelationalDelegate(self.ui.tableView) self.ui.tableView.setItemDelegate(delgate) self.tabModel.select() self.ui.actOpenDB.setEnabled(False) self.ui.actRecAppend.setEnabled(True) self.ui.actRecInsert.setEnabled(True) self.ui.actRecDelete.setEnabled(True) self.ui.actFields.setEnabled(True)
def show_table(self): self.table_model = QSqlRelationalTableModel() table = self.ui.comboBox.currentText() if table == 'Товары': self.create_goods_table_model() elif table == 'Персонал': self.create_employees_table_model() else: if table == 'Единица измерения': table = 'units' elif table == 'Категории': table = 'categories' elif table == 'Должности': table = 'positions' elif table == 'Поставщики': table = 'vendors' self.table_model.setTable(table) self.table_model.select() self.table_model.setEditStrategy(QSqlTableModel.OnManualSubmit) view = self.ui.tableView view.setModel(self.table_model) view.setItemDelegate(QSqlRelationalDelegate(view))
def show_table(self): self.table_model = QSqlRelationalTableModel() table = self.ui.tablelist.currentText() if table == 'goods': self.create_goods_table_model() elif table == 'employees': self.create_employees_table_model() elif table == 'units': self.create_units_table_model() elif table == 'vendors': self.create_vendors_table_model() elif table == 'positions': self.create_positions_table_model() elif table == 'categories': self.create_categories_table_model() else: self.table_model.setTable(table) self.table_model.select() self.table_model.setEditStrategy(QSqlTableModel.OnManualSubmit) view = self.ui.tableView view.setModel(self.table_model) view.hideColumn(0) view.setItemDelegate(QSqlRelationalDelegate(view))
def init_best_before(self): model = QSqlRelationalTableModel() model.setTable("best_before") model.setEditStrategy(QSqlRelationalTableModel.OnManualSubmit) model.setRelation(1, QSqlRelation('nutrition', 'ndbno', 'desc')) model.select() #Nutrition table needs to be populated since otherwise only 256 rows are read #And all inserts with ndbno > 100169 fail since they aren't found in nutrition #table nutri_model = model.relationModel(1) while nutri_model.canFetchMore(): nutri_model.fetchMore() self.bb_model = model nutri_model = self.lv_keys.model() #nutri_model = QSqlTableModel() #nutri_model.setTable("nutrition") ##nutri_model.setRelation(2, QSqlRelation('nutrition', 'ndbno', 'desc')) #nutri_model.setEditStrategy(QSqlRelationalTableModel.OnManualSubmit) #nutri_model.setSort(1,Qt.AscendingOrder) #nutri_model.select() self.cb_bb_item.setModel(nutri_model) self.cb_bb_item.setModelColumn(0) self.best_before_model = model self.tv_best_before.setModel(model) self.tv_best_before.setSortingEnabled(True) self.tv_best_before.sortByColumn(2, Qt.AscendingOrder) self.tv_best_before.setItemDelegate(QSqlRelationalDelegate(self.tv_best_before)) self.tv_best_before.show() #From Price self.cb_price_item.setModel(nutri_model) self.cb_price_item.setModelColumn(0) #From Tag self.cb_item_tag.setModel(nutri_model) self.cb_item_tag.setModelColumn(0) """Updates Best before table""" def update_bb(): print ("Updating Best Before") if not self.bb_model.submitAll(): QMessageBox.critical(None, "Error updating Best Before", "Couldn't update model: " + self.bb_model.lastError().text()) """Adds new data to best before table update_bb also needs to be called""" def add_bb(): print("Adding to BB") ndbno = self._get_selected_ndbno(self.cb_bb_item.model() \ .record(self.cb_bb_item.currentIndex())) print ("IDX:", self.cb_bb_item.currentIndex(), ndbno) row = self.bb_model.rowCount() self.bb_model.insertRow(row) #print ("NDBNO INDEX:", self.bb_model.fieldIndex("desc")) r = self.bb_model.record() #for i in range(r.count()): #print ("{} => {}".format(i,r.fieldName(i))) #for i in range(100000,100194): #out_ndbno = self.bb_model.setData(self.bb_model.createIndex(row, #self.bb_model.fieldIndex("desc")), i, #Qt.EditRole) #print ("{}? = {}".format(out_ndbno, i)) out_ndbno = self.bb_model.setData(self.bb_model.createIndex(row, self.bb_model.fieldIndex("desc")), ndbno, Qt.EditRole) out_time = self.bb_model.setData(self.bb_model.createIndex(row, self.bb_model.fieldIndex("time")), self.de_bb.date(), Qt.EditRole) print ("NDBNO:", out_ndbno, "TIME:", out_time) self.update_bb = update_bb self.add_bb = add_bb self.buttonBox_3.button(QDialogButtonBox.SaveAll).clicked.connect(self.update_bb) self.buttonBox_3.button(QDialogButtonBox.Apply).clicked.connect(self.add_bb)
def init_tag(self): #Selected tags when item is selected self.selected_tags = set() tag_model = QSqlTableModel() tag_model.setTable("tag") tag_model.setEditStrategy(QSqlTableModel.OnRowChange) #It can't be sorted otherwise wrong tags are selected when item is selected #tag_model.setSort(1, Qt.AscendingOrder) tag_model.select() #Added proxy model which is sorted on name tag_proxy_model = QSortFilterProxyModel(self) tag_proxy_model.setSourceModel(tag_model) tag_proxy_model.sort(1, Qt.AscendingOrder) self.tag_proxy_model = tag_proxy_model self.tag_model = tag_model tag_item_model = QSqlRelationalTableModel() tag_item_model.setTable("tag_item") #tag_item_model.setRelation(1, QSqlRelation('nutrition', 'ndbno', 'desc')) #tag_item_model.setRelation(2, QSqlRelation('tag', 'id', 'name')) tag_item_model.setEditStrategy(QSqlTableModel.OnManualSubmit) #tag_item_model.select() self.tag_item_model = tag_item_model tag_hier_model = QSqlRelationalTableModel() tag_hier_model.setTable("tag_hierarchy") tag_hier_model.setRelation(0, QSqlRelation('tag', 'id', 'name')) tag_hier_model.setRelation(1, QSqlRelation('tag', 'id', 'name')) tag_hier_model.setSort(0, Qt.AscendingOrder) tag_hier_model.setEditStrategy(QSqlTableModel.OnManualSubmit) tag_hier_model.select() #From add food self.cb_tag_select.setModel(tag_proxy_model) self.cb_tag_select.setModelColumn(1) self.tv_tag.setModel(tag_model) #self.tv_tag_item.setModel(tag_item_model) self.tv_tag_hierarchy.setModel(tag_hier_model) #ListView to choose which tags have nutrition self.lv_tag.setModel(tag_proxy_model) self.lv_tag.setModelColumn(1) #self.tv_tag_item.setItemDelegate(QSqlRelationalDelegate(self.tv_tag_item)) self.tv_tag_hierarchy.setItemDelegate( QSqlRelationalDelegate(self.tv_tag_hierarchy)) def add_tag(): print("Adding tag:") row = self.tv_tag.model().rowCount() self.tv_tag.model().insertRow(row) def add_hier(): print("Adding hier:") row = self.tv_tag_hierarchy.model().rowCount() self.tv_tag_hierarchy.model().insertRow(row) def add_item_tag(): print("Adding item_tag:") row = self.tv_tag_item.model().rowCount() self.tv_tag_item.model().insertRow(row) def save_hier(): print("Saving hier") self.tv_tag_hierarchy.model().submitAll() def select_nutri_tag(selectedIndex): ndbno = self._get_selected_ndbno(self.cb_item_tag.model() \ .record(self.cb_item_tag.currentIndex())) print("Item:", self.cb_item_tag.currentText(), ndbno) tags = self.session.query(TagItem) \ .filter(TagItem.ndbno==ndbno) \ .order_by(TagItem.tag_id) if self.lv_tag.selectionModel(): self.lv_tag.selectionModel().clearSelection() self.selected_tags.clear() for tag in tags: #print (tag.tag.name, tag.tag_id) orig_index = tag_model.createIndex(tag.tag_id, 1) index = tag_proxy_model.mapFromSource(orig_index) if index.isValid(): print("Valid index") self.lv_tag.selectionModel().select(index, QItemSelectionModel.Select) data = self.lv_tag.model().data(index) self.selected_tags.add(tag.tag_id) #print(data) def save_tag_item(): print("Saving tag item") selected_tags_now = set() for index in self.lv_tag.selectedIndexes(): mapped = self.lv_tag.model().mapToSource(index) record = tag_model.record(mapped.row()) selected_tags_now.add(record.field("id").value()) print( str(record.field("id").value()) + " - " + record.field("name").value()) added_tag_ids = selected_tags_now.difference(self.selected_tags) removed_tag_ids = self.selected_tags.difference(selected_tags_now) #print ("Unselected tags:" + ", ".join(map(lambda x: str(x), #removed_tag_ids))) #print ("New selected tags:" + ", ".join(map(lambda x: str(x), #added_tag_ids))) ndbno = self._get_selected_ndbno(self.cb_item_tag.model() \ .record(self.cb_item_tag.currentIndex())) print("Item:", self.cb_item_tag.currentText(), ndbno) query = QSqlQuery() ret = query.prepare( "DELETE FROM tag_item WHERE ndbno = :ndbno and tag_id = :tag_id") if not ret: print("Failed to prepare query") for tag_id in added_tag_ids: row = self.tag_item_model.rowCount() self.tag_item_model.insertRow(row) self.tag_item_model.setData( self.tag_item_model.createIndex(row, 0), ndbno, Qt.EditRole) self.tag_item_model.setData( self.tag_item_model.createIndex(row, 1), tag_id, Qt.EditRole) print("Adding tag id:", tag_id) #print (record.field("name").value(), record.field("id").value()) #self.tv_tag_item.model().submitAll() if not self.tag_item_model.submitAll(): QMessageBox.critical( None, "Error submitting", "Couldn't update model: " + self.tag_item_model.lastError().text()) self.tag_item_model.revertAll() query.bindValue(":ndbno", ndbno) for tag_id in removed_tag_ids: query.bindValue(":tag_id", tag_id) print("Removing tag_id:", tag_id) if not query.exec_(): print("Failed to executr query") #print (query.executedQuery()) self.pb_add_tag.pressed.connect(add_tag) self.pb_add_item_tag.pressed.connect(add_item_tag) self.pb_add_hier.pressed.connect(add_hier) self.pb_save_hier.pressed.connect(save_hier) self.pb_save_tag_item.pressed.connect(save_tag_item) self.cb_item_tag.currentIndexChanged.connect(select_nutri_tag)
def __init__(self, parent=None): super(PhoneLogDlg, self).__init__(parent) callerLabel = QLabel("&Caller:") self.callerEdit = QLineEdit() callerLabel.setBuddy(self.callerEdit) today = QDate.currentDate() startLabel = QLabel("&Start:") self.startDateTime = QDateTimeEdit() startLabel.setBuddy(self.startDateTime) self.startDateTime.setDateRange(today, today) self.startDateTime.setDisplayFormat(DATETIME_FORMAT) endLabel = QLabel("&End:") self.endDateTime = QDateTimeEdit() endLabel.setBuddy(self.endDateTime) self.endDateTime.setDateRange(today, today) self.endDateTime.setDisplayFormat(DATETIME_FORMAT) topicLabel = QLabel("&Topic:") topicEdit = QLineEdit() topicLabel.setBuddy(topicEdit) outcomeLabel = QLabel("&Outcome:") self.outcomeComboBox = QComboBox() outcomeLabel.setBuddy(self.outcomeComboBox) firstButton = QPushButton() firstButton.setIcon(QIcon(":/first.png")) prevButton = QPushButton() prevButton.setIcon(QIcon(":/prev.png")) nextButton = QPushButton() nextButton.setIcon(QIcon(":/next.png")) lastButton = QPushButton() lastButton.setIcon(QIcon(":/last.png")) addButton = QPushButton("&Add") addButton.setIcon(QIcon(":/add.png")) deleteButton = QPushButton("&Delete") deleteButton.setIcon(QIcon(":/delete.png")) quitButton = QPushButton("&Quit") quitButton.setIcon(QIcon(":/quit.png")) if not MAC: addButton.setFocusPolicy(Qt.NoFocus) deleteButton.setFocusPolicy(Qt.NoFocus) fieldLayout = QGridLayout() fieldLayout.addWidget(callerLabel, 0, 0) fieldLayout.addWidget(self.callerEdit, 0, 1, 1, 3) fieldLayout.addWidget(startLabel, 1, 0) fieldLayout.addWidget(self.startDateTime, 1, 1) fieldLayout.addWidget(endLabel, 1, 2) fieldLayout.addWidget(self.endDateTime, 1, 3) fieldLayout.addWidget(topicLabel, 2, 0) fieldLayout.addWidget(topicEdit, 2, 1, 1, 3) fieldLayout.addWidget(outcomeLabel, 3, 0) fieldLayout.addWidget(self.outcomeComboBox, 3, 1, 1, 3) navigationLayout = QHBoxLayout() navigationLayout.addWidget(firstButton) navigationLayout.addWidget(prevButton) navigationLayout.addWidget(nextButton) navigationLayout.addWidget(lastButton) fieldLayout.addLayout(navigationLayout, 4, 0, 1, 2) buttonLayout = QVBoxLayout() buttonLayout.addWidget(addButton) buttonLayout.addWidget(deleteButton) buttonLayout.addStretch() buttonLayout.addWidget(quitButton) layout = QHBoxLayout() layout.addLayout(fieldLayout) layout.addLayout(buttonLayout) self.setLayout(layout) self.model = QSqlRelationalTableModel(self) self.model.setTable("calls") self.model.setRelation(OUTCOMEID, QSqlRelation("outcomes", "id", "name")) self.model.setSort(STARTTIME, Qt.AscendingOrder) self.model.select() self.mapper = QDataWidgetMapper(self) self.mapper.setSubmitPolicy(QDataWidgetMapper.ManualSubmit) self.mapper.setModel(self.model) self.mapper.setItemDelegate(QSqlRelationalDelegate(self)) self.mapper.addMapping(self.callerEdit, CALLER) self.mapper.addMapping(self.startDateTime, STARTTIME) self.mapper.addMapping(self.endDateTime, ENDTIME) self.mapper.addMapping(topicEdit, TOPIC) relationModel = self.model.relationModel(OUTCOMEID) self.outcomeComboBox.setModel(relationModel) self.outcomeComboBox.setModelColumn(relationModel.fieldIndex("name")) self.mapper.addMapping(self.outcomeComboBox, OUTCOMEID) self.mapper.toFirst() firstButton.clicked.connect(lambda: self.saveRecord(PhoneLogDlg.FIRST)) prevButton.clicked.connect(lambda: self.saveRecord(PhoneLogDlg.PREV)) nextButton.clicked.connect(lambda: self.saveRecord(PhoneLogDlg.NEXT)) lastButton.clicked.connect(lambda: self.saveRecord(PhoneLogDlg.LAST)) addButton.clicked.connect(self.addRecord) deleteButton.clicked.connect(self.deleteRecord) quitButton.clicked.connect(self.done) self.setWindowTitle("Phone Log")
def refresh(self): self.model.select() self.tableView.setModel(self.model) self.tableView.setItemDelegate(QSqlRelationalDelegate(self.tableView))
def __init__(self, parent: any = None) -> None: """ Функция инициализации окна штатного расписания :param parent: Родительский виджет (окно) """ super().__init__(parent) self.filters = ['Номер', 'Подразделение', 'Должность', 'Количество', 'Тариф', 'Оклад', 'ФИО', 'Декрет', 'История', 'Оклад замещающего работника', 'Вид позиции', ] self.setObjectName("ShtatWindow") self.resize(1380, 886) self.centralwidget = QtWidgets.QWidget(self) self.centralwidget.setObjectName("centralwidget") self.view = QTableView(self.centralwidget) self.view.setGeometry(QRect(0, 0, 1381, 821)) self.view.setObjectName("shtat_table_view") self.view.setSortingEnabled(True) self.filter_combo_box = QtWidgets.QComboBox(self.centralwidget) self.filter_combo_box.setGeometry(QRect(250, 840, 231, 31)) self.filter_combo_box.setObjectName("filter_combo_box") self.filter_input = QtWidgets.QLineEdit(self.centralwidget) self.filter_input.setGeometry(QRect(500, 840, 281, 31)) self.filter_input.setObjectName("filter_input") self.filter_label = QtWidgets.QLabel(self.centralwidget) self.filter_label.setGeometry(QRect(10, 840, 221, 31)) font = QFont() font.setFamily("Times New Roman") font.setPointSize(12) self.filter_label.setFont(font) self.filter_label.setObjectName("filter_label") self.filter_button = QtWidgets.QPushButton(self.centralwidget) self.filter_button.setGeometry(QRect(800, 840, 171, 31)) self.save_shtat_button = QtWidgets.QPushButton(self.centralwidget) self.save_shtat_button.setGeometry(QRect(1000, 840, 225, 31)) self.filter_button.setFont(font) self.save_shtat_button.setFont(font) self.filter_button.setObjectName("filter_button") self.setCentralWidget(self.centralwidget) _translate = QCoreApplication.translate self.setWindowTitle(_translate("ShtatWindow", "Работа со штатным расписанием")) self.filter_label.setText(_translate("ShtatWindow", "Фильтровать по столбцу:")) self.filter_button.setText(_translate("ShtatWindow", "Поиск")) self.save_shtat_button.setText(_translate("ShtatWindow", "Выгрузить штатное расписание")) self.model = QSqlRelationalTableModel(self.view) self.model.setTable('salaries') self.model.setEditStrategy(QSqlRelationalTableModel.OnFieldChange) self.model.setRelation(1, QSqlRelation("departments", "code", "department")) self.model.setRelation(10, QSqlRelation("positions", "position_code", "position_name")) for i in range(0, len(self.filters)): self.model.setHeaderData(i, Qt.Horizontal, self.filters[i]) self.model.select() self.proxyModelContact = QSortFilterProxyModel(self) self.proxyModelContact.setSourceModel(self.model) self.view.setModel(self.proxyModelContact) self.view.resizeColumnsToContents() self.view.setItemDelegate(QSqlRelationalDelegate(self.view)) self.filter_combo_box.addItems(self.filters) self.filter_button.clicked.connect(self.use_filter_button) self.save_shtat_button.clicked.connect(self.use_save_shtat_button) self.view.setItemDelegate(QSqlRelationalDelegate(self.view))
R_T_MODEL.setSort(1, QtCore.Qt.AscendingOrder) # Задаем для поля категории связь с таблицей списка категорий R_T_MODEL.setRelation(1, QSqlRelation('category', 'id', 'name')) # 'category', 'id', 'category' (имя первичной таблицы, # имя поля первичного ключа, имя поля, выводящегося на экран) R_T_MODEL.select() R_T_MODEL.setHeaderData(1, QtCore.Qt.Horizontal, 'Категория товара') R_T_MODEL.setHeaderData(2, QtCore.Qt.Horizontal, 'Название товара') R_T_MODEL.dataChanged.connect(R_T_MODEL.submitAll) # Размещаем объекты VBOX_OBJ = QVBoxLayout() TV_OBJ = QTableView() TV_OBJ.setModel(R_T_MODEL) TV_OBJ.setItemDelegateForColumn(1, QSqlRelationalDelegate(TV_OBJ)) TV_OBJ.hideColumn(0) TV_OBJ.setColumnWidth(1, 150) TV_OBJ.setColumnWidth(2, 150) VBOX_OBJ.addWidget(TV_OBJ) # Добавляем кнопки BTN_ADD = QPushButton("&Добавить запись") BTN_ADD.clicked.connect(add_record) VBOX_OBJ.addWidget(BTN_ADD) BTN_DEL = QPushButton("&Удалить запись") BTN_DEL.clicked.connect(del_record) VBOX_OBJ.addWidget(BTN_DEL) # Формируем итоговое окно W_OBJ.setLayout(VBOX_OBJ)
def init_price(self): currencies = {"EUR": u"€", "HRK": u"kn"} model = QSqlTableModel() model.setTable("shop") model.setEditStrategy(QSqlRelationalTableModel.OnManualSubmit) model.select() self.shop_model = model price_model = QSqlRelationalTableModel() price_model.setTable("price") price_model.setEditStrategy(QSqlRelationalTableModel.OnManualSubmit) price_model.setRelation(1, QSqlRelation('nutrition', 'ndbno', 'desc')) price_model.setRelation(2, QSqlRelation('shop', 'id', 'name')) #Nutrition table needs to be populated since otherwise only 256 rows are read #And all inserts with ndbno > 100169 fail since they aren't found in nutrition #table nutri_model = price_model.relationModel(1) while nutri_model.canFetchMore(): nutri_model.fetchMore() self.price_model = price_model self.price_model.select() self.tv_price.setModel(price_model) self.tv_price.setSortingEnabled(True) self.tv_price.sortByColumn(1, Qt.AscendingOrder) self.tv_price.setItemDelegate(QSqlRelationalDelegate(self.tv_price)) price_sort_model = QSqlQueryModel() price_sort_model.setQuery( "SELECT nutrition.ndbno, nutrition.desc, shop.name, " + "last_updated, price, price/nutrition.package_weight*1000 as " + " price_kg, nutrition.kcal/price as kcal_price_100, " + "nutrition.protein/price as protein_price_100," + " (nutrition.kcal*nutrition.package_weight/100)/price as " + " kcal_price_package, " + " (nutrition.protein*nutrition.package_weight/100)/price " + " as protein_price_package, " + "lowered_price, lowered_untill, " + "currency,comment, temporary FROM price " + " JOIN shop ON shop.id == price.shop_id " + " JOIN nutrition ON price.ndbno = nutrition.ndbno " + " WHERE currency = 'EUR' " " ORDER BY nutrition.desc, price") proxy_model = QSortFilterProxyModel(self) proxy_model.setSourceModel(price_sort_model) proxy_model.setFilterKeyColumn(0) self.price_proxy = proxy_model #print (price_sort_model.lastError().text()) #print (price_sort_model.query().executedQuery()) self.tv_price_view.setModel(proxy_model) self.tv_price_view.setSortingEnabled(True) self.tv_price_view.horizontalHeader().setToolTip("protein/kcal_price " "higher is better") self.cb_shop.setModel(model) self.cb_shop.setModelColumn(1) #self.cb_shop.lineEdit().editingFinished.connect(self.add_shop) model_currency = QStringListModel() model_currency.setStringList(["EUR", "HRK"]) self.cb_currency.setModel(model_currency) self.de_last_updated.setMaximumDate(QDate.currentDate()) self.de_last_updated.setDateTime(QDateTime.currentDateTime()) def update_price(): print("Updating price info") if not price_model.submitAll(): QMessageBox.critical( None, "Error updating price:", "Couldn't update model: " + price_model.lastError().text()) def reset_price(): print("Resetting price info") price_model.revertAll() """Sets suffix symbols for prices based on currency""" def currency_changed(currency): symbol = currencies[currency] self.dsp_price.setSuffix(symbol) self.dsp_low_price.setSuffix(symbol) """Adds new Shop to DB""" def add_shop(): print(self.cb_shop.currentText()) row = self.shop_model.rowCount() self.shop_model.insertRow(row) self.shop_model.setData(self.shop_model.createIndex(row, 1), self.cb_shop.currentText(), Qt.EditRole) self.shop_model.submitAll() def add_price(): shop_id = self.shop_model.record(self.cb_shop.currentIndex()) \ .field("id").value() print("Shop ID:", shop_id, self.cb_shop.currentText()) record = self.cb_price_item.model() \ .record(self.cb_price_item.currentIndex()) ndbno = self._get_selected_ndbno(record) package_weight = record.field("package_weight").value() slices = record.field("num_of_slices").value() last_updated = self.de_last_updated.date() price = self.dsp_price.value() lowered_price = self.dsp_low_price.value() if \ self.dsp_low_price.value() > 0 else None lowered_untill = self.de_low_untill.date() if \ self.de_low_untill.date() > QDate.currentDate() else None currency = self.cb_currency.currentText() comment = self.le_comment.text() if \ len(self.le_comment.text()) > 3 else None temporary = self.cb_temporary.isChecked() print("ITEM:", self.cb_price_item.currentText(), ndbno) print("Weight:", package_weight, " Slices: ", slices) print("LU:", last_updated) print("PRICE:", price, " Low Price:", lowered_price) print("LOWU:", lowered_untill) print("CU:", currency) print("COMMENT:", comment) print("Temp:", temporary) print("NDBNO:", ndbno, type(ndbno)) print("SHOP ID:", shop_id, type(shop_id)) row = self.price_model.rowCount() #print ("ROW:", row, self.price_model.relationModel(1).rowCount()) self.price_model.insertRow(row) def add_data(idx, data): return self.price_model.setData( self.price_model.createIndex(row, idx), data, Qt.EditRole) #for i in range(100000,100194): #for i in self.session.query(LocalNutrition.ndbno).filter(LocalNutrition.ndbno #< 100000).order_by(LocalNutrition.ndbno): #out_ndbno = add_data(1, QVariant(i[0])) #print ("{}? = {}".format(out_ndbno, i[0])) #for i in range(100000,100194): ##for i in self.session.query(LocalNutrition.ndbno).filter(LocalNutrition.ndbno ##< 100000).order_by(LocalNutrition.ndbno): #out_ndbno = add_data(1, QVariant(i)) #print ("{}? = {}".format(out_ndbno, i)) #FIXME: Why is ndbno found in nutrtition only if it lower then 100169 #relation = self.price_model.relation(1) #print(relation, relation.displayColumn(), relation.indexColumn()) #print (relation.dictionary.contains(ndbno)) #return add_data(1, ndbno) add_data(2, shop_id) add_data(3, last_updated) add_data(4, price) if lowered_price is not None and lowered_untill is not None: add_data(5, lowered_price) add_data(6, lowered_untill) add_data(7, currency) if comment is not None: add_data(8, comment) add_data(9, temporary) self.price_model.submitAll() self.update_price = update_price self.reset_price = reset_price self.currency_changed = currency_changed self.buttonBox_4.button(QDialogButtonBox.SaveAll).clicked.connect( self.update_price) self.buttonBox_4.button(QDialogButtonBox.Reset).clicked.connect( self.reset_price) self.cb_currency.currentTextChanged.connect(self.currency_changed) self.pb_add_shop.pressed.connect(add_shop) self.pb_add_price.pressed.connect(add_price)