import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QTableWidgetItem
import add_product_to_catalogue
# Абсолютный путь временное решевние
sys.path.append('C:/Python project/test')
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1000, 800)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName("verticalLayout")
self.catalogue_table = QtWidgets.QTableWidget(self.centralwidget)
self.catalogue_table.setObjectName("catalogue_table")
self.catalogue_table.setColumnCount(5)
self.catalogue_table.setRowCount(0)
item = QtWidgets.QTableWidgetItem()
item.setText("Штрих код")
font = QtGui.QFont()
font.setBold(False)
font.setItalic(False)
font.setUnderline(False)
font.setWeight(50)
font.setStrikeOut(False)
font.setKerning(True)
font.setStyleStrategy(QtGui.QFont.NoAntialias)
item.setFont(font)
self.catalogue_table.setHorizontalHeaderItem(0, item)
item = QtWidgets.QTableWidgetItem()
self.catalogue_table.setHorizontalHeaderItem(1, item)
item = QtWidgets.QTableWidgetItem()
self.catalogue_table.setHorizontalHeaderItem(2, item)
item = QtWidgets.QTableWidgetItem()
self.catalogue_table.setHorizontalHeaderItem(3, item)
item = QtWidgets.QTableWidgetItem()
self.catalogue_table.setHorizontalHeaderItem(4, item)
self.catalogue_table.horizontalHeader().setCascadingSectionResizes(False)
self.verticalLayout.addWidget(self.catalogue_table)
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.button_create = QtWidgets.QPushButton(self.centralwidget)
self.button_create.setObjectName("button_create")
self.horizontalLayout.addWidget(self.button_create)
self.button_edit = QtWidgets.QPushButton(self.centralwidget)
self.button_edit.setObjectName("button_edit")
self.horizontalLayout.addWidget(self.button_edit)
self.button_delete = QtWidgets.QPushButton(self.centralwidget)
self.button_delete.setObjectName("button_delete")
self.horizontalLayout.addWidget(self.button_delete)
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem)
self.verticalLayout.addLayout(self.horizontalLayout)
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Каталог товаров"))
item = self.catalogue_table.horizontalHeaderItem(1)
item.setText(_translate("MainWindow", "Тип товара"))
item = self.catalogue_table.horizontalHeaderItem(2)
item.setText(_translate("MainWindow", "Название товара"))
item = self.catalogue_table.horizontalHeaderItem(3)
item.setText(_translate("MainWindow", "Цена закупки"))
item = self.catalogue_table.horizontalHeaderItem(4)
item.setText(_translate("MainWindow", "Описание"))
self.button_create.setText(_translate("MainWindow", "Открыть другое окно"))
self.button_edit.setText(_translate("MainWindow", "Редактировать"))
self.button_delete.setText(_translate("MainWindow", "Удалить"))
class Widget(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(Widget, self).__init__(parent)
self.setupUi(self)
self.output_data_in_table()
self.catalogue_table.resizeColumnsToContents()
# Блокируем возможность редактирования таблицы
self.catalogue_table.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
self.button_delete.clicked.connect(self.delete_row)
self.button_create.clicked.connect(self.open_window)
def output_data_in_table(self):
pass
def delete_row(self):
""" Удаление выделеной строки """
index_row = self.catalogue_table.currentIndex().row()
bar_code = self.catalogue_table.item(index_row, 0).text()
self.catalogue_table.removeRow(index_row)
print('строка удалена')
def open_window(self):
""" Открыть 2 окно """
new_window = add_product_to_catalogue()
new_window.show()
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
w = Widget()
w.show()
sys.exit(app.exec_())