-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
55 lines (41 loc) · 1.55 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import sqlite3
import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QMainWindow, QApplication, QTableWidgetItem, QWidget
QUERY = 'SELECT variety_name, roast, ground_or_beans, description, price, package_size FROM coffee;'
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
uic.loadUi('main.ui', self)
self.con = sqlite3.connect('coffee.sqlite')
self.cur = self.con.cursor()
self.update_button.clicked.connect(self.update_table)
self.edit_button.clicked.connect(self.edit)
self.add_button.clicked.connect(self.add)
self.update_table()
def get_data(self):
data = self.cur.execute(QUERY).fetchall()
return data
def update_table(self):
data = self.get_data()
self.table.setColumnCount(6)
self.table.setRowCount(len(data))
self.table.setHorizontalHeaderLabels(
['Variety name', 'Roast level', 'Type', 'Description', 'Price [rub]', 'Size [kg]'])
for row in range(len(data)):
for col in range(6):
self.table.setItem(row, col, QTableWidgetItem(str(data[row][col])))
def add(self):
pass
def edit(self):
self.form = AddEditCoffeeForm()
self.form.show()
class AddEditCoffeeForm(QWidget):
def __init__(self):
super(AddEditCoffeeForm, self).__init__()
uic.loadUi('addEditCoffeeForm.ui', self)
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec())