def add_critical_holder(self): single_holder_layout = QtWidgets.QHBoxLayout() component_field = AutocapField("Componente...") component_field.setFixedWidth(175) component_field.setFocus() single_holder_layout.addWidget(component_field) value_field = StockNumberField("Valor...") value_field.setFixedWidth(65) single_holder_layout.addWidget(value_field) close_button = QtWidgets.QPushButton("×") close_button.setFixedWidth(20) single_holder_layout.addWidget(close_button) close_button.clicked.connect(self.remove_critical_holder) self.criticals_holder_layout.addLayout(single_holder_layout) for l in self.criticals_holder_layout.children(): each_component_field = l.itemAt(0).widget() each_component_field.set_completer(source="comps in stock")
def add_line(self): single_line_section = QtWidgets.QHBoxLayout() component_field = AutocapField("Componente...") component_field.setFixedWidth(200) component_field.setFocus() component_field.set_completer(source="comps in stock") value_field = StockNumberField("Cantidad...") value_field.setFixedWidth(80) close_button = LineItemCloseButton(holder=self.comps_holder_section) single_line_section.addWidget(component_field) single_line_section.addWidget(value_field) single_line_section.addWidget(close_button) self.comps_holder_section.addLayout(single_line_section)
def add_line_item(self): product_field = AutocapField("Producto...") product_field.setFixedWidth(120) product_field.set_completer(source="recipes") product_field.setFocus() value_field = StockNumberField("Cantidad...") value_field.setFixedWidth(80) close_button = LineItemCloseButton(holder=self.products_holder_section) single_line_section = QtWidgets.QHBoxLayout() single_line_section.addWidget(product_field) single_line_section.addWidget(value_field) single_line_section.addWidget(close_button) self.products_holder_section.addLayout(single_line_section)
def add_recipe_item_line(self): searchbar_recipe_component = AutocapField("Componente...") searchbar_recipe_component.setFixedWidth(130) searchbar_recipe_component.set_completer(source="comps in stock") searchbar_recipe_amount = StockNumberField("Cantidad...") searchbar_recipe_amount.setFixedWidth(85) close_button = QtWidgets.QPushButton("×") close_button.setFixedWidth(20) close_button.clicked.connect(self.remove_recipe_item_via_close_button) recipe_item_line_layout = QtWidgets.QHBoxLayout() recipe_item_line_layout.addWidget(searchbar_recipe_component) recipe_item_line_layout.addWidget(searchbar_recipe_amount) recipe_item_line_layout.addWidget(close_button) self.comps_holder_section.addLayout(recipe_item_line_layout)
def __init__(self, parent=None): super(CreateComponentDialog, self).__init__(parent) self.setWindowFlags(QtCore.Qt.Dialog | QtCore.Qt.CustomizeWindowHint | QtCore.Qt.WindowCloseButtonHint) title = QtWidgets.QLabel("Crear componente") title.setAlignment(QtCore.Qt.AlignCenter) title.setStyleSheet(generic_title_style) self.compname_field = AutocapField("Componente a crear...") self.compname_field.setFixedWidth(150) self.compname_field.setFocus() self.initstock_field = StockNumberField("Stock inicial...") self.initstock_field.setFixedWidth(80) back_button = QtWidgets.QPushButton("« Volver") back_button.setShortcut("Alt+v") self.execute_button = QtWidgets.QPushButton("Ejecutar »") self.execute_button.setDefault(True) line_edits_layout = QtWidgets.QHBoxLayout() line_edits_layout.addWidget(self.compname_field) line_edits_layout.addWidget(self.initstock_field) bottom_section = QtWidgets.QHBoxLayout() bottom_section.addWidget(back_button) bottom_section.addWidget(self.execute_button) layout = QtWidgets.QVBoxLayout() layout.addWidget(title) layout.addLayout(line_edits_layout) layout.addLayout(bottom_section) self.setLayout(layout) back_button.clicked.connect(self.close) self.execute_button.clicked.connect(self.create_component)
class CreateComponentDialog(QtWidgets.QDialog): def __init__(self, parent=None): super(CreateComponentDialog, self).__init__(parent) self.setWindowFlags(QtCore.Qt.Dialog | QtCore.Qt.CustomizeWindowHint | QtCore.Qt.WindowCloseButtonHint) title = QtWidgets.QLabel("Crear componente") title.setAlignment(QtCore.Qt.AlignCenter) title.setStyleSheet(generic_title_style) self.compname_field = AutocapField("Componente a crear...") self.compname_field.setFixedWidth(150) self.compname_field.setFocus() self.initstock_field = StockNumberField("Stock inicial...") self.initstock_field.setFixedWidth(80) back_button = QtWidgets.QPushButton("« Volver") back_button.setShortcut("Alt+v") self.execute_button = QtWidgets.QPushButton("Ejecutar »") self.execute_button.setDefault(True) line_edits_layout = QtWidgets.QHBoxLayout() line_edits_layout.addWidget(self.compname_field) line_edits_layout.addWidget(self.initstock_field) bottom_section = QtWidgets.QHBoxLayout() bottom_section.addWidget(back_button) bottom_section.addWidget(self.execute_button) layout = QtWidgets.QVBoxLayout() layout.addWidget(title) layout.addLayout(line_edits_layout) layout.addLayout(bottom_section) self.setLayout(layout) back_button.clicked.connect(self.close) self.execute_button.clicked.connect(self.create_component) def create_component(self): if self.compname_field.text() == "": message_boxes.WarningBox( "Sin nombre", "Dar nombre al componente\nantes de ejecutar.").exec_() self.compname_field.setFocus() return db = db_manager.DB_Manager() component_names_display = db.get_all_display_names_for_components() if self.compname_field.text() in component_names_display: message_boxes.WarningBox( "Nombre ya existente", "El nombre tiene que ser\ndiferente de los existentes.", ).exec_() self.compname_field.clear() self.compname_field.setFocus() return newcomp_display_name = self.compname_field.text() newcomp_sql_name = utils.format_display_name_into_sql_name( newcomp_display_name) initstock = 0 if self.initstock_field.text() != "": initstock = utils.format_number_for_calculation( self.initstock_field.text()) db.create_new_component(newcomp_sql_name, newcomp_display_name, initstock) db.log_new_config_record(config="Creación de componente", details=newcomp_display_name) db.close_connection() admin_window = self.parent().parent().parent() admin_window.statusbar.show_quick_message("Componente creado: " + newcomp_display_name) admin_window.start_screen.rebuild_main_section() QtWidgets.QApplication.processEvents() # enables scrolling table = admin_window.start_screen.main_section.table utils.scroll_to_row_in_table(table, newcomp_display_name) self.compname_field.clear() self.initstock_field.clear() self.close()