def __init__(self, table_prototype, parent): super(QuickPrototypedFilter, self).__init__(parent) self.list_model = PrototypedModelView(table_prototype, self) self.list_model_filtered = FilteringModel(self) self.list_model_filtered.setSourceModel(self.list_model) self.line_in = FilterLineEdit() self.line_in.key_down.connect(self._focus_on_list) self.line_in.textChanged.connect(self._filter_changed) self.list_view = PrototypedQuickView(table_prototype, self) self.list_view.setTabKeyNavigation(False) self.list_view.horizontalHeader().hide() self.list_view.verticalHeader().hide() self.list_view.horizontalHeader().setStretchLastSection(True) self.list_view.setModel(self.list_model_filtered) vlayout = QVBoxLayout() vlayout.setContentsMargins(0, 0, 0, 0) vlayout.addWidget(self.line_in) vlayout.addWidget(self.list_view) self.setLayout(vlayout) self.list_view.selectionModel().currentChanged.connect( self._selected_item_changed) # FIXME Clear ownership issue self.last_selected_object = None self.line_in.setFocus() QWidget.setTabOrder(self.line_in, self.list_view)
def __init__(self, parent=None): QWidget.__init__(self, parent) self.setLayout(QVBoxLayout(self)) self.text_display = QPlainTextEdit(self) self.text_display.setReadOnly(True) self.layout().addWidget(self.text_display) self.text_input = QLineEdit(self) self.text_input.returnPressed.connect(self.send_text) self.layout().addWidget(self.text_input) QWidget.setTabOrder(self.text_input, self.text_display) self.setEnabled(False) self.message.emit('Not connected') self._connection = None
def __init__(self,parent,dialog_title,list_title,form_title,mapped_klass,table_prototype,form_prototype,sort_criterion,index_builder): """ sort_criterion is a SQLAlchemy colum used when querying the list of edited objects to sort it. index_builder : a function that takes an object of the mapped class and returns a string suitable for index building. """ super(MetaFormDialog,self).__init__(parent) self.index_builder = index_builder self.sort_criterion = sort_criterion self.form_prototype = form_prototype self.mapped_klass = mapped_klass # Locate the primary key # this will work only with a one-field PK pk_column = list(filter( lambda c:c.primary_key, self.mapped_klass.__table__.columns))[0] self.key_field = pk_column.name self.in_save = False # The current item is the one currently shown in the # form. If it's None, then the form contains data # for a soon-to-be created item. Else, it's a frozen # copy. Since we work on frozen stuff, we can carry # the object around safely self.current_item = None self.list_model = PrototypedModelView(table_prototype, self) self.list_model_filtered = FilteringModel(self) self.list_model_filtered.setSourceModel(self.list_model) self.line_in = FilterLineEdit() self.line_in.key_down.connect(self._focus_on_list) self.line_in.textChanged.connect(self._filter_changed) self.list_view = PrototypedQuickView(table_prototype, self) self.list_view.setTabKeyNavigation(False) self.setWindowTitle(dialog_title) self.title_widget = TitleWidget(dialog_title,self) self.list_view.setModel(self.list_model_filtered) self.list_view.horizontalHeader().hide() self.list_view.verticalHeader().hide() self.list_view.horizontalHeader().setStretchLastSection(True) blayout = QVBoxLayout() b = QPushButton(_("New")) b.setObjectName("newButton") b.clicked.connect(self.create_action) blayout.addWidget(b) b = QPushButton(_("Save")) b.setObjectName("saveButton") b.clicked.connect(self.save_action) blayout.addWidget(b) b = QPushButton(_("Delete")) b.setObjectName("deleteButton") b.clicked.connect(self.delete_action) blayout.addWidget(b) blayout.addStretch() self.buttons = QDialogButtonBox() self.buttons.addButton( QDialogButtonBox.Ok) # BUG According to QLayout, the layout takes ownership of the widget # therefore, we have to pay attention when deleting... form_layout = QFormLayout() for p in self.form_prototype: w = p.edit_widget(self) w.setEnabled(p.is_editable) w.setObjectName("form_" + p.field) form_layout.addRow( p.title, w) top_layout = QVBoxLayout() top_layout.addWidget(self.title_widget) hl = QHBoxLayout() vlayout = QVBoxLayout() vlayout.addWidget(self.line_in) vlayout.addWidget(self.list_view) # gbox = QGroupBox(list_title,self) # gbox.setLayout(vlayout) gbox = SubFrame(list_title,vlayout,self) hl.addWidget(gbox) # gbox = QGroupBox(form_title,self) # gbox.setLayout(form_layout) gbox = SubFrame(form_title,form_layout,self) hl.addWidget(gbox) hl.addLayout(blayout) # hl.setStretch(0,0.3) # hl.setStretch(1,0.7) # hl.setStretch(2,0) top_layout.addLayout(hl) top_layout.addWidget(self.buttons) self.setLayout(top_layout) # QWidget takes ownership of the layout self.buttons.accepted.connect(self.reject) QWidget.setTabOrder(self.line_in, self.list_view) nb_objs = self._refresh_list() self.line_in.setFocus() self.list_view.selectionModel().currentChanged.connect(self.selected_item_changed) # FIXME Clear ownership issue if nb_objs > 0: self.list_view.selectRow(0) else: # Special case to automaticaly enter creation mode when # the list is empty self.create_action()
class WasteDish(): """Dish waste management tab""" global logger def __init__(self): ### logger.info('Inside WasteDish') self.wastedetail_tab_1 = QWidget() self.wastedetail_tab_1.setObjectName("wastedetail_tab_1") self.verticalLayout_9 = QVBoxLayout(self.wastedetail_tab_1) self.verticalLayout_9.setObjectName("verticalLayout_9") self.verticalLayout_8 = QVBoxLayout() self.verticalLayout_8.setObjectName("verticalLayout_8") self.horizontalLayout_12 = QHBoxLayout() self.horizontalLayout_12.setObjectName("horizontalLayout_12") self.waste_fromdate_label = QLabel(self.wastedetail_tab_1) self.waste_fromdate_label.setObjectName('waste_fromdate_label') self.horizontalLayout_12.addWidget(self.waste_fromdate_label) self.waste_fromdate_dateedit = QDateEdit(self.wastedetail_tab_1) self.waste_fromdate_dateedit.setCalendarPopup(True) self.waste_fromdate_dateedit.setObjectName("waste_fromdate_dateedit") self.horizontalLayout_12.addWidget(self.waste_fromdate_dateedit) self.waste_todate_label = QLabel(self.wastedetail_tab_1) self.waste_todate_label.setObjectName('waste_todate_label') self.horizontalLayout_12.addWidget(self.waste_todate_label) self.waste_todate_dateedit = QDateEdit(self.wastedetail_tab_1) self.waste_todate_dateedit.setCalendarPopup(True) self.waste_todate_dateedit.setObjectName("waste_todate_dateedit") self.waste_todate_dateedit.setMaximumDate(QDate.currentDate()) self.horizontalLayout_12.addWidget(self.waste_todate_dateedit) spacerItem28 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_12.addItem(spacerItem28) self.waste_table_search_button = QPushButton(self.wastedetail_tab_1) self.waste_table_search_button.setObjectName( "waste_table_search_button") self.horizontalLayout_12.addWidget(self.waste_table_search_button) self.verticalLayout_8.addLayout(self.horizontalLayout_12) self.waste_table = QTableWidget(self.wastedetail_tab_1) self.waste_table.setObjectName("waste_table") self.waste_table.setColumnCount(5) self.waste_table.setRowCount(0) item = QTableWidgetItem() self.waste_table.setHorizontalHeaderItem(0, item) item = QTableWidgetItem() self.waste_table.setHorizontalHeaderItem(1, item) item = QTableWidgetItem() self.waste_table.setHorizontalHeaderItem(2, item) item = QTableWidgetItem() self.waste_table.setHorizontalHeaderItem(3, item) item = QTableWidgetItem() self.waste_table.setHorizontalHeaderItem(4, item) self.waste_table.horizontalHeader().setCascadingSectionResizes(False) self.waste_table.horizontalHeader().setStretchLastSection(True) self.waste_table.verticalHeader().setVisible(False) self.waste_table.verticalHeader().setCascadingSectionResizes(False) self.waste_table.setSortingEnabled(True) self.verticalLayout_8.addWidget(self.waste_table) self.horizontalLayout_13 = QHBoxLayout() self.horizontalLayout_13.setObjectName("horizontalLayout_13") self.waste_table_newrow_button = QPushButton(self.wastedetail_tab_1) self.waste_table_newrow_button.setObjectName( "waste_table_newrow_button") self.horizontalLayout_13.addWidget(self.waste_table_newrow_button) spacerItem29 = QSpacerItem(612, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_13.addItem(spacerItem29) self.waste_table_discard_button = QPushButton(self.wastedetail_tab_1) self.waste_table_discard_button.setObjectName( "waste_table_discard_button") self.horizontalLayout_13.addWidget(self.waste_table_discard_button) self.verticalLayout_8.addLayout(self.horizontalLayout_13) self.verticalLayout_9.addLayout(self.verticalLayout_8) ##retranslate self.waste_fromdate_label.setText( QApplication.translate("MainWindow", "From Date", None, QApplication.UnicodeUTF8)) self.waste_fromdate_dateedit.setDisplayFormat( QApplication.translate("MainWindow", "dd/MM/yyyy", None, QApplication.UnicodeUTF8)) self.waste_todate_label.setText( QApplication.translate("MainWindow", "To Date", None, QApplication.UnicodeUTF8)) self.waste_todate_dateedit.setDisplayFormat( QApplication.translate("MainWindow", "dd/MM/yyyy", None, QApplication.UnicodeUTF8)) self.waste_table_search_button.setText( QApplication.translate("MainWindow", "Search", None, QApplication.UnicodeUTF8)) self.waste_table.horizontalHeaderItem(0).setText( QApplication.translate("MainWindow", "Code", None, QApplication.UnicodeUTF8)) self.waste_table.horizontalHeaderItem(1).setText( QApplication.translate("MainWindow", "Item", None, QApplication.UnicodeUTF8)) self.waste_table.horizontalHeaderItem(2).setText( QApplication.translate("MainWindow", "Category", None, QApplication.UnicodeUTF8)) self.waste_table.horizontalHeaderItem(3).setText( QApplication.translate("MainWindow", "Quantity", None, QApplication.UnicodeUTF8)) self.waste_table.horizontalHeaderItem(4).setText( QApplication.translate("MainWindow", "Reason", None, QApplication.UnicodeUTF8)) self.waste_table_newrow_button.setText( QApplication.translate("MainWindow", "New Row", None, QApplication.UnicodeUTF8)) self.waste_table_discard_button.setText( QApplication.translate("MainWindow", "Discard Item", None, QApplication.UnicodeUTF8)) self.wastedetail_tab_1.setTabOrder(self.waste_fromdate_dateedit, self.waste_todate_dateedit) self.wastedetail_tab_1.setTabOrder(self.waste_todate_dateedit, self.waste_table_search_button) ###signals and slots && other stuffs # self.mainwindow = Ui_MainWindow # just for the ease of finding the attributes in pycharm self.schedule = SchedulePurchase() self.suplier = BusinessParty(category='Supplier') self.add = AddStockInventory() self.item = WasteMenu() self.waste_fromdate_dateedit.setDate(QDate.currentDate()) self.waste_todate_dateedit.setDate(QDate.currentDate()) self.waste_table.setEditTriggers(QAbstractItemView.NoEditTriggers) self.waste_table_newrow_button.clicked.connect(self.add_new_blank_rows) self.waste_table_discard_button.clicked.connect(self.discard) self.waste_table_search_button.clicked.connect(self.search_discard) self.wastedetail_tab_1.setFocusPolicy(Qt.StrongFocus) self.wastedetail_tab_1.focusInEvent = self.load_rows def load_rows(self, event=None): pass def add_new_blank_rows(self): """ deletes the schedules in the database """ table = self.waste_table item = table.item(0, 0) if item: message = QMessageBox.critical(QMessageBox(), 'Warning!', 'This will remove all the entries', QMessageBox.Ok | QMessageBox.Cancel) if message == QMessageBox.Ok: table.setRowCount(0) table.clearContents() self.add_row_to_table('new') self.waste_table_discard_button.setVisible(True) elif not item: self.waste_table_discard_button.setVisible(True) self.add_row_to_table('new') def add_row_to_table(self, *args): """ complex stuff of auto complete to be added to each combo box :return: """ table = self.waste_table if args: if args[0] != 'new': table.clearContents() table.setRowCount(0) table.setRowCount(len(args)) for i, j in enumerate(args): code = QTableWidgetItem(j['code']) table.setItem(i, 0, code) item = QTableWidgetItem(j['item']) table.setItem(i, 1, item) category = QTableWidgetItem(j['category']) table.setItem(i, 2, category) quantity = QTableWidgetItem(str(j['quantity'])) table.setItem(i, 3, quantity) reason = QTableWidgetItem(j['reason_for_discard']) table.setItem(i, 4, reason) if args[0] == 'new': row = table.rowCount() + 1 table.setRowCount(row) codeline = QLineEdit() codeline.editingFinished.connect( lambda: self.get_details_of_code(row)) table.setCellWidget(row - 1, 0, codeline) itemcombo = QComboBox() self.fill_item_list(itemcombo) itemcombo.currentIndexChanged.connect( lambda: self.get_details_of_item(row)) table.setCellWidget(row - 1, 1, itemcombo) category = QTableWidgetItem() table.setItem(row - 1, 2, category) quantity = QLineEdit() table.setCellWidget(row - 1, 3, quantity) combo = QComboBox() combo.addItem("Cancelled") combo.addItem("Mishandling") combo.addItem("Excess") table.setCellWidget(row - 1, 4, combo) table.setColumnWidth(0, (table.width() / 5)) table.setColumnWidth(1, (table.width() / 5)) table.setColumnWidth(2, (table.width() / 5)) table.setColumnWidth(3, (table.width() / 5)) table.horizontalHeader().setStretchLastSection( True ) # important to resize last section else blank space after last column def fill_item_list(self, combo): """ fill the item combo box :param combo: the combobox object :return: none """ itemfield = combo itemfield.setStyleSheet("QAbstractItemView{" "background: #4B77BE;" "}") self.item.populate_item(itemfield) def get_details_of_code(self, rowcount): """ fills the item, category and units based on the code :param rowcount: the row count :return: none """ row = rowcount - 1 table = self.waste_table codeline = table.cellWidget(row, 0) data = self.item.get_details_of_code(codeline.text()) item = table.cellWidget(row, 1) index = item.findText(data['item']) item.setCurrentIndex(index) category = table.item(row, 2) category.setText(data['category']) def get_details_of_item(self, rowcount): """ fills the code, category and units based on the item :param rowcount: the row count :return: none """ row = rowcount - 1 table = self.waste_table itemcombo = table.cellWidget(row, 1) data = self.item.get_details_of_item(itemcombo.currentText()) code = table.cellWidget(row, 0) code.setText(data['code']) category = table.item(row, 2) category.setText(data['category']) def discard(self): """ saves the details in db before printing """ logger.info('WasteDish discard initiated') table = self.waste_table data = self.get_data() if data: for i in data: status = self.item.discard(i) if status: model_index = table.indexFromItem(i['model_item']) row = model_index.row() table.removeRow(row) else: msg = QMessageBox.critical(QMessageBox(), "Error!!", "The item cannot be discarded", QMessageBox.Ok) if msg == QMessageBox.Ok: return False def search_discard(self): """ searches the discard from_date and to_date :return:none """ table = self.waste_table item = table.cellWidget(0, 0) if item: msg = QMessageBox.critical(QMessageBox(), 'Warning!', 'This will delete all the rows added', QMessageBox.Ok | QMessageBox.Cancel) if msg == QMessageBox.Cancel: return False f_date = self.waste_fromdate_dateedit.text() from_date = datetime.strptime(f_date, '%d/%m/%Y') t_date = self.waste_todate_dateedit.text() to_date = datetime.strptime(t_date, '%d/%m/%Y') to_date = to_date + timedelta(hours=23, minutes=59, seconds=59) dataobj = self.item.find_itemdiscard(from_date=from_date, to_date=to_date) self.add_row_to_table(*dataobj) self.waste_table_discard_button.setVisible(False) def get_data(self): """ :return: fetches all the data for printing """ table = self.waste_table rows = table.rowCount() dataobj = [] for i in range(rows): dictionary = {} item = table.cellWidget(i, 0) if table.cellWidget( i, 0) is not None else table.item(i, 0) dictionary['code'] = item.text() if dictionary['code'] == '': break item = table.cellWidget(i, 1).currentText() if table.cellWidget( i, 1) is not None else table.item(i, 1).text() dictionary['item'] = item item = table.cellWidget(i, 2) if table.cellWidget( i, 2) is not None else table.item(i, 2) dictionary['category'] = item.text() item = table.cellWidget(i, 3) if table.cellWidget( i, 3) is not None else table.item(i, 3) dictionary['quantity'] = item.text() if dictionary['quantity'] == '': self.show_error('Quantity') return False item = table.cellWidget(i, 4).currentText() if table.cellWidget( i, 4) is not None else table.item(i, 4).text() dictionary['reason_for_discard'] = item dictionary['model_item'] = table.item(i, 2) dataobj.append(dictionary) return dataobj def show_error(self, text): """ :return: pops up an error """ QMessageBox.critical(QMessageBox(), "Fail!!", "Please Enter %s properly" % text, QMessageBox.Ok)