예제 #1
0
 def add(self):
     self.data = view_data("products")
     if len(self.name_input_edit.text()) > 40 or self.name_input_edit.text(
     ) in [row[1] for row in self.data]:
         return
     if self.price_sell_input.text() == "0,00":
         return
     if len(self.category_input_edit.text()
            ) != 3 or self.category_input_edit.text().isupper() is not True:
         return
     try:
         int(self.quantity_input.text())
         price = self.price_sell_input.text()
         price = price.replace(",", ".")
         float(price.replace(",", "."))
     except ValueError:
         return
     price = self.price_sell_input.text()
     if "," in price:
         price = price.replace(",", ".")
     insert_product([
         self.name_input_edit.text(),
         self.quantity_input.text(), price,
         self.category_input_edit.text()
     ])
     self.close()
     self.parent().search_products()
예제 #2
0
    def __init__(self, parent):
        super(QWidget, self).__init__(parent)

        self.data = view_data("products")
        self.setAutoFillBackground(True)

        self.layout = QGridLayout()
        self.layout.setRowStretch(1, 6)
        self.layout.setColumnStretch(1, 2)

        self.name_label = QLabel("Name")
        self.name_input = QComboBox()
        self.name_input.addItems(set([row[1] for row in self.data]))
        self.name_input_edit = QLineEdit()
        self.name_input.setLineEdit(self.name_input_edit)

        self.layout.addWidget(self.name_label, 1, 0)
        self.layout.addWidget(self.name_input, 1, 1)

        self.quantity_label = QLabel("Quantity")
        self.quantity_input = QSpinBox()
        self.quantity_input.setMaximum(100000)
        self.layout.addWidget(self.quantity_label, 2, 0)
        self.layout.addWidget(self.quantity_input, 2, 1)

        self.price_sell_label = QLabel("Selling price")
        self.price_sell_input = QDoubleSpinBox()
        self.price_sell_input.setMaximum(100000)
        self.layout.addWidget(self.price_sell_label, 3, 0)
        self.layout.addWidget(self.price_sell_input, 3, 1)

        self.category_label = QLabel("Category")
        self.category_input = QComboBox()
        self.category_input.addItems(set([row[4] for row in self.data]))
        self.category_input_edit = QLineEdit()
        self.category_input.setLineEdit(self.category_input_edit)

        self.layout.addWidget(self.category_label, 4, 0)
        self.layout.addWidget(self.category_input, 4, 1)

        self.update_item_button = QPushButton("Update item")
        self.layout.addWidget(self.update_item_button, 5, 0)

        self.update_item_button.clicked.connect(self.update)

        self.cancel_button = QPushButton("Cancel")
        self.layout.addWidget(self.cancel_button, 5, 1)
        self.cancel_button.clicked.connect(self.close)

        self.reset_button = QPushButton("Reset to default")
        self.layout.addWidget(self.reset_button, 5, 2)
        self.reset_button.clicked.connect(self.reset_to_default)

        self.setLayout(self.layout)

        self.reset_to_default()
        self.show()
예제 #3
0
    def __init__(self):
        super(QWidget, self).__init__()
        self.layout = QGridLayout(self)

        self.data = view_data("products")

        self.add_button = QPushButton("Add new product", self)
        self.add_button.setToolTip("Add an item which is not in the list yet")
        self.add_button.clicked.connect(self.add_item)

        self.update_button = QPushButton("Update product", self)
        self.update_button.setToolTip("Update selected product")
        self.update_button.clicked.connect(self.update_item)

        self.delete_button = QPushButton("Delete product", self)
        self.delete_button.setToolTip("Delete selected product")
        self.delete_button.clicked.connect(self.delete_item)

        self.products_table = ProductsTable(parent=self)

        self.search_label = QLabel("Search by:")
        self.dropdownlist_search = QComboBox()
        categories = [
            column for index, column in enumerate(
                self.products_table.products_column_names)
            if index in (0, 1, 4)
        ]
        categories.insert(0, "All")
        self.dropdownlist_search.addItems(categories)

        self.search_field = QLineEdit()
        self.search_field.textChanged.connect(self.search_products)

        header = self.products_table.horizontalHeader()
        header.setSectionResizeMode(0, QHeaderView.ResizeToContents)
        header.setSectionResizeMode(1, QHeaderView.Stretch)
        header.setSectionResizeMode(2, QHeaderView.ResizeToContents)
        header.setSectionResizeMode(3, QHeaderView.ResizeToContents)
        header.setSectionResizeMode(4, QHeaderView.ResizeToContents)

        self.layout.addWidget(self.add_button, 0, 0)
        self.layout.addWidget(self.delete_button, 0, 1)
        self.layout.addWidget(self.update_button, 0, 2)
        self.layout.addWidget(self.search_label, 1, 0)
        self.layout.addWidget(self.dropdownlist_search, 1, 1)
        self.layout.addWidget(self.search_field, 1, 2)
        self.layout.addWidget(self.products_table, 2, 0, 1, 3)
        self.setLayout(self.layout)
예제 #4
0
    def __init__(self):
        super(QTableWidget, self).__init__()

        self.orders_column_names = view_column_names("orders_items_view")
        self.orders_data = view_data("orders_items_view")
        self.single_order_view = QTableWidget()
        self.setColumnCount(len(self.orders_column_names))
        self.setHorizontalHeaderLabels(self.orders_column_names)

        self.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.setSelectionMode(QAbstractItemView.SingleSelection)
        self.refresh_order()

        self.setSortingEnabled(True)
        self.resizeRowsToContents()
        self.horizontalHeader().sortIndicatorChanged.connect(
            self.resizeRowsToContents)
예제 #5
0
 def refresh_products(self):
     self.rows = [row[1:] for row in view_data("temp")]
     self.setRowCount(len(self.rows))
     for row_id, row in enumerate(self.rows):
         for column_id, cell in enumerate(row):
             if column_id not in (2, 3):
                 self.setItem(row_id, column_id,
                              QTableWidgetItem(str(cell)))
             else:
                 editable = QDoubleSpinBox()
                 editable.setSingleStep(1)
                 if column_id == 2:
                     self.quantity_list.append(editable)
                     editable.setMinimum(1)
                     editable.setMaximum(cell)
                     editable.setDecimals(0)
                     editable.setValue(1)
                 if column_id == 3:
                     self.price_list.append(editable)
                     editable.setMinimum(0.01)
                     editable.setMaximum(100000)
                     editable.setDecimals(2)
                     editable.setValue(cell)
                 self.setCellWidget(row_id, column_id, editable)
예제 #6
0
    def __init__(self, parent):
        super(QWidget, self).__init__(parent)

        self.data = view_data("customers")

        self.layout = QGridLayout()
        self.layout.setRowStretch(1, 6)
        self.layout.setColumnStretch(1, 2)
        self.setAutoFillBackground(True)

        self.name_label = QLabel("Name")
        self.name_input = QComboBox()
        self.name_input.addItems(set([item_id[1] for item_id in self.data]))
        self.name_input_edit = QLineEdit()
        self.name_input.setLineEdit(self.name_input_edit)
        self.layout.addWidget(self.name_label, 1, 0)
        self.layout.addWidget(self.name_input, 1, 1)

        self.city_label = QLabel("City")
        self.city_input = QComboBox()
        self.city_input.addItems(set([item_id[2] for item_id in self.data]))
        self.city_input_edit = QLineEdit()

        self.city_input.setLineEdit(self.city_input_edit)
        self.layout.addWidget(self.city_label, 2, 0)
        self.layout.addWidget(self.city_input, 2, 1)

        self.street_label = QLabel("Street")
        self.street_input = QComboBox()
        self.street_input.addItems(set([item_id[3] for item_id in self.data]))
        self.street_input_edit = QLineEdit()

        self.street_input.setLineEdit(self.street_input_edit)
        self.layout.addWidget(self.street_label, 4, 0)
        self.layout.addWidget(self.street_input, 4, 1)

        self.house_label = QLabel("House Number")
        self.house_input = QLineEdit()
        self.layout.addWidget(self.house_label, 5, 0)
        self.layout.addWidget(self.house_input, 5, 1)

        self.zipcode_label = QLabel("Zip Code")
        self.zipcode_input = QComboBox()
        self.zipcode_input.addItems(set([item_id[5] for item_id in self.data]))
        self.zipcode_input_edit = QLineEdit()

        self.zipcode_input.setLineEdit(self.zipcode_input_edit)
        self.layout.addWidget(self.zipcode_label, 6, 0)
        self.layout.addWidget(self.zipcode_input, 6, 1)

        self.update_customer_button = QPushButton("Update customer")
        self.layout.addWidget(self.update_customer_button, 7, 0)
        self.update_customer_button.clicked.connect(self.update)

        self.cancel_button = QPushButton("Cancel")
        self.layout.addWidget(self.cancel_button, 7, 1)
        self.cancel_button.clicked.connect(self.close)

        self.reset_button = QPushButton("Reset to default")
        self.layout.addWidget(self.reset_button, 7, 2)
        self.reset_button.clicked.connect(self.reset_to_default)

        self.reset_to_default()
        self.setLayout(self.layout)
        self.show()
예제 #7
0
 def refresh_order(self):
     self.orders_data = view_data("orders_items_view")
     self.setRowCount(len(self.orders_data))
     for row_id, row in enumerate(self.orders_data):
         for column_id, cell in enumerate(row):
             self.setItem(row_id, column_id, QTableWidgetItem(str(cell)))