· 5 years ago · Aug 09, 2020, 10:56 AM
1from kivy.config import Config
2
3Config.set('graphics', 'resizable', False)
4
5import mysql.connector
6
7sql=mysql.connector.connect(host='localhost',user='root',passwd='password')
8cursor=sql.cursor()
9
10cursor.execute('DROP DATABASE PRACTICE')
11cursor.execute('CREATE DATABASE IF NOT EXISTS PRACTICE')
12cursor.execute('USE PRACTICE')
13
14def tablecreator():
15 cursor.execute('CREATE TABLE IF NOT EXISTS CUSTOMERS (username varchar(255), password varchar(255), customerID smallint UNSIGNED PRIMARY KEY AUTO_INCREMENT)')
16 cursor.execute('CREATE TABLE IF NOT EXISTS cpu(Name varchar(255), Type varchar(20) not null default "cpu", cpuID smallint unsigned not null primary key auto_increment, socket varchar(10) not null, wattage smallint unsigned, cost int unsigned)')
17 cursor.execute('CREATE TABLE IF NOT EXISTS cpucooler(Name varchar(255), Type varchar(20) not null default "cpucooler", coolerID smallint unsigned not null primary key auto_increment, wattage smallint unsigned, cost int unsigned)')
18 cursor.execute('CREATE TABLE IF NOT EXISTS storage(Name varchar(255), Type varchar(20) not null default "storage", storageID smallint unsigned not null primary key auto_increment, wattage smallint unsigned, cost int unsigned)')
19 cursor.execute('CREATE TABLE IF NOT EXISTS peripheral(Name varchar(255), Type varchar(20) not null default "peripheral", peripheralID smallint unsigned not null primary key auto_increment, cost int unsigned)')
20 cursor.execute('CREATE TABLE IF NOT EXISTS ram(Name varchar(255), Type varchar(20) not null default "ram", ramID smallint unsigned not null primary key auto_increment, wattage smallint unsigned, cost int unsigned, memory varchar(10) not null)')
21 cursor.execute('CREATE TABLE IF NOT EXISTS gpu(Name varchar(255), Type varchar(20) not null default "gpu", gpuID smallint unsigned not null primary key auto_increment, gpulength smallint unsigned, wattage smallint unsigned, cost int unsigned)')
22 cursor.execute('CREATE TABLE IF NOT EXISTS psu(Name varchar(255), Type varchar(20) not null default "psu", psuID smallint unsigned not null primary key auto_increment, psutype smallint unsigned, wattage smallint unsigned, cost int unsigned)')
23 cursor.execute('CREATE TABLE IF NOT EXISTS pccase(Name varchar(255), Type varchar(20) not null default "pccase", caseID smallint unsigned not null primary key auto_increment, caselength smallint unsigned, casetype varchar(20), cost int unsigned)')
24 cursor.execute('CREATE TABLE IF NOT EXISTS mobo(Name varchar(255), Type varchar(20) not null default "mobo", moboID smallint unsigned not null primary key auto_increment, mobotype varchar(20), mobosocket varchar(20), wattage smallint unsigned, cost int unsigned)')
25 cursor.execute('CREATE TABLE IF NOT EXISTS orders(Name varchar(255), producttype varchar(20), productID smallint unsigned, quantity smallint unsigned, cost int unsigned)')
26 cursor.execute('CREATE TABLE IF NOT EXISTS customerdetails (customerID smallint unsigned primary key, phno int(12) unsigned, address varchar(255), emailid varchar(50))')
27 cursor.execute('CREATE TABLE IF NOT EXISTS cart (Name varchar(255), producttype varchar(20), productID smallint unsigned, quantity smallint unsigned, cost int unsigned, currentuserID int unsigned)')
28 partinserter()
29
30def partinserter():
31 cursor.execute('INSERT INTO gpu(Name,gpuLength,Wattage,cost) values("Zotac GeForce GTX 1050 Ti OC Edition 4GB PCI Express Graphics Card",28,75,11000)')
32 cursor.execute('INSERT INTO gpu(Name,gpuLength,Wattage,cost) values("GALAX GeForce GTX 1650 EX 1-Click OC 4GB GDDR5",20,75,12000)')
33 cursor.execute('INSERT INTO gpu(Name,gpuLength,Wattage,cost) values("ZOTAC Gaming GeForce GTX 1660Ti Twin Fan 6GB GDDR6",17.3,130,23000)')
34 cursor.execute('INSERT INTO gpu(Name,gpuLength,Wattage,cost) values("ZOTAC Gaming GeForce RTX 2060 Mini 6GB GDDR6",21,160,30000)')
35 cursor.execute('INSERT INTO gpu(Name,gpuLength,Wattage,cost) values("GIGABYTE GeForce RTX 2070 DirectX 12 8GB 256-Bit GDDR6",26,200,45000)')
36 cursor.execute('INSERT INTO mobo(Name,mobotype,mobosocket,wattage,cost) values("Gigabyte GA-A320M-H","ATX","AM4",50,4200)')
37 cursor.execute('INSERT INTO mobo(Name,mobotype,mobosocket,wattage,cost) values("ASRock B450M-HDV","MATX","AM4",50,7500)')
38 cursor.execute('INSERT INTO mobo(Name,mobotype,mobosocket,wattage,cost) values("ASRock B450M Steel legend","MATX","AM4",50,12000)')
39 cursor.execute('INSERT INTO mobo(Name,mobotype,mobosocket,wattage,cost) values("ASUS Prime H310-CS 2.0","MATX","LGA1151",50,5200)')
40 cursor.execute('INSERT INTO mobo(Name,mobotype,mobosocket,wattage,cost) values("ASUS ROG Strix B-365","ATX","LGA1155",50,13000)')
41 cursor.execute('INSERT INTO mobo(Name,mobotype,mobosocket,wattage,cost) values("ASUS ROG Maximus XI Extreme Z390","EATX","LGA1151",50,40000)')
42 cursor.execute('INSERT INTO ram(name,wattage,cost,memory) values("HyperX Fury 4GB 2400MHz DDR4",1,2300,"2400Mhz")')
43 cursor.execute('INSERT INTO ram(name,wattage,cost,memory) values("Corsair Vengeance LPX 8GB DDR4",1,3500,"3000Mhz")')
44 cursor.execute('INSERT INTO ram(name,wattage,cost,memory) values("G.SKILL FBA4719692004970 Ripjaws V Series 16GB (2 x 8GB) 288-Pin DDR4 ",1,10000,"3200Mhz")')
45 cursor.execute('INSERT INTO ram(name,wattage,cost,memory) values("Corsair 16 GB Vengeance LPX DDR4 3000MHz C16 XMP 2.0 Desktop Memory - Black",1,6000,"3200Mhz")')
46 cursor.execute('INSERT INTO ram(name,wattage,cost,memory) values("TEAMGROUP T-Force Delta RGB DDR4 16GB (2x8GB) 3200MHz",2,9800,"3200Mhz")')
47 cursor.execute('INSERT INTO pccase(Name,caselength,casetype,cost) values("BBC 8865",50,"MIDTOWER",2100)')
48 cursor.execute('INSERT INTO pccase(Name,caselength,casetype,cost) values("Ant Esports ICE-400TG",43,"MIDTOWER",4500)')
49 cursor.execute('INSERT INTO pccase(Name,caselength,casetype,cost) values("Antec NX 310",53,"MIDTOWER",3600)')
50 cursor.execute('INSERT INTO pccase(Name,caselength,casetype,cost) values("Corsair Carbide SPEC-06 ",46,"MIDTOWER",8500)')
51 cursor.execute('INSERT INTO pccase(Name,caselength,casetype,cost) values("NZXT H510i",42,"MIDTOWER",10500)')
52 cursor.execute('INSERT INTO pccase(Name,caselength,casetype,cost) values("Corsair Graphite 780T CC-9011063-WW",60,"FULLTOWER",16500)')
53 cursor.execute('INSERT INTO pccase(Name,caselength,casetype,cost) values("iBall Baby 342",50,"MINITOWER",3200)')
54 cursor.execute('INSERT INTO cpu(Name,Socket,Wattage,cost) value("AMD Athlon 3000 Dual Core","AM4",35,4500)')
55 cursor.execute('INSERT INTO cpu(Name,Socket,Wattage,cost) value("AMD Ryzen 5 3500 Octa Core","AM4",65,11000)')
56 cursor.execute('INSERT INTO cpu(Name,Socket,Wattage,cost) value("AMD Ryzen 7 2700 Octa Core","AM4",65,17500)')
57 cursor.execute('INSERT INTO cpu(Name,Socket,Wattage,cost) value("Intel Core i5 9400F Hexa Core","LGA1151",65,13500)')
58 cursor.execute('INSERT INTO cpu(Name,Socket,Wattage,cost) value("Intel Core i7 9700K Octa Core","LGA1151",95,32500)')
59 sql.commit()
60
61tablecreator()
62
63from kivy.core.window import Window
64Window.size = (450,520)
65
66from kivy.metrics import dp
67from kivymd.uix.datatables import MDDataTable
68from kivy.core.text import LabelBase
69from kivy.uix.image import Image
70from kivymd.app import MDApp
71from kivy.uix.gridlayout import GridLayout
72from kivy.uix.floatlayout import FloatLayout
73from kivy.lang.builder import Builder
74from kivy.uix.screenmanager import ScreenManager, Screen
75from kivy.properties import ObjectProperty
76#to connect widgets in kv file to py
77# username = ObjectProperty(None) is a way to connect username from kv file to property
78# you can use self.username then to refer to username in the class
79
80LabelBase.register(name='OpenSans', fn_regular='OpenSans-Light.ttf')
81
82class LoginScreen(Screen):
83
84 def upderrordispl1(self):
85 self.ids.errordispl.text = ''
86
87 def upderrordispl2(self):
88 self.ids.errordispl.text = '[color=fb403b]Wrong Credentials[/color]'
89 self.ids.uname.text = ''
90 self.ids.passw.text = ''
91
92 def createaccount(self):
93 uname = self.ids.uname.text
94 passw = self.ids.passw.text
95 cursor.execute('SELECT * FROM customers where username="'+uname+'"')
96 a = tuple(cursor)
97 if len(a) == 0:
98 if len(passw) >= 8:
99 cursor.execute('INSERT INTO customers (username, password) values(%s,%s)',(uname,passw))
100 sql.commit()
101 self.ids.errordispl.text = '[color=000000]Login now.[/color]'
102 if len(passw) < 8:
103 self.ids.errordispl.text = '[color=fb403b]Your password is too short[/color]'
104 else:
105 self.ids.errordispl.text = '[color=fb403b]User already exists[/color]'
106
107 def logincheck(self):
108 uname = self.ids.uname.text
109 passw = self.ids.passw.text
110 cursor.execute('SELECT * FROM customers where username = "'+uname+'"')
111 a = tuple(cursor)
112 if len(a) == 0:
113 self.upderrordispl2()
114 for i in a:
115 if passw in i:
116 self.upderrordispl1()
117 cursor.execute('SELECT customerID from customers where username = "'+uname+'"')
118 for i in tuple(cursor):
119 for j in i:
120 global curruser
121 curruser = j
122 print(curruser)
123 self.ids.uname.text = ''
124 self.ids.passw.text = ''
125 self.ids.errordispl.theme_text_color = 'Primary'
126 sm.current = 'main'
127 else:
128 self.upderrordispl2()
129
130class MainScreen(Screen):
131 pass
132
133class BudgetScreen(Screen):
134 def setbudgetandchangescreen(self):
135 global budget
136 try:
137 budget = int(self.ids.budget.text)
138 except ValueError:
139 budget = None
140 Window.size = (1080,700)
141
142class GCaseScreen(Screen):
143 def firsttable(self):
144 global collistone
145 self.collistone = []
146 cursor.execute('desc pccase')
147 for i in tuple(cursor):
148 collistone.append(tuple([i[0],dp(30)]))
149 global rowlistone
150 self.rowlistone = []
151 cursor.execute('select * from pccase')
152 for i in tuple(cursor):
153 rowlistone.append(i)
154
155
156class DemoApp(MDApp):
157 def build(self):
158
159 table1 = MDDataTable(size_hint=(0.9,0.6),
160 pos_hint={'center_x':0.5,'center_y':0.5},
161 column_data=GCaseScreen.collistone,
162 row_data=GCaseScreen.rowlistone)
163
164 self.theme_cls.primary_palette = "LightBlue"
165 self.theme_cls.primary_hue = "800"
166 self.theme_cls.accent_palette = 'LightBlue'
167 self.theme_cls.theme_style = "Light"
168 global sm
169 sm = ScreenManager()
170 sm.add_widget(LoginScreen(name='login'))
171 sm.add_widget(MainScreen(name='main'))
172 sm.add_widget(BudgetScreen(name='budgetscreen'))
173 sm.add_widget(GCaseScreen(name='gcase'))
174 return sm
175
176 def open_table(self):
177 self.table1.open()
178
179if __name__ == '__main__':
180 DemoApp().run()
181
182
183
184------------
185
186KV File:
187
188ScreenManager:
189 LoginScreen:
190 MainScreen:
191
192<MDTextField>:
193 mode: "rectangle"
194 size_hint: (None,None)
195 height: 30
196 text_color: (1,1,1,1)
197 width: 250
198
199<MDRectangleFlatButton>:
200 size_hint: (None, None)
201 size: (140,33)
202 pos_hint: {'center_x':0.5, 'center_y':0.5}
203
204
205<LoginScreen>:
206 name: 'login'
207
208 FloatLayout:
209
210 MDTextField:
211 id: uname
212 hint_text: "Username"
213 pos_hint: {'center_x': 0.5, 'center_y': 0.725}
214 multiline: False
215
216 MDTextField:
217 id: passw
218 password: True
219 hint_text: 'Password'
220 helper_text: "Make your password at least 8 characters long. "
221 helper_text_mode: "on_focus"
222 pos_hint: {'center_x': 0.5, 'center_y': 0.62}
223 multiline: False
224
225 Label:
226 id: errordispl
227 font_name: 'OpenSans'
228 pos_hint: {'center_x': 0.47, 'center_y': 0.3}
229 markup: True
230 text: '[color=000000][/color]'
231
232 MDRectangleFlatButton:
233 pos_hint: {'center_x': 0.295, 'center_y': 0.46}
234 text: 'Login'
235 on_release:
236 root.logincheck()
237 #background_color: (0.157,0.455,0.753,1)
238 #background_normal: ''
239
240 MDRectangleFlatButton:
241 pos_hint: {'center_x': 0.669, 'center_y': 0.46}
242 #background_color: (0.157,0.455,0.753,1)
243 #background_normal: ''
244 text: 'Create Account'
245 on_release:
246 root.createaccount()
247
248<MainScreen>:
249 name: 'main'
250
251 FloatLayout:
252 MDLabel:
253 font_name: 'OpenSans'
254 text: "Want us to help you pick all your parts while \n making sure they're compatible? Pick the guided \n part builder. Want to pick your own parts? Click the \n Free button. Want to add information to your Account \n or view your orders? That's the last button for you."
255 #pos_hint: {'center_x': 0.6, 'center_y': 0.7}
256 halign: 'center'
257 pos_hint: {'center_y': 0.7}
258 MDRectangleFlatButton:
259 text: 'Guide me'
260 pos_hint: {'center_x': 0.2, 'center_y': 0.4}
261 on_release:
262 root.manager.current = 'budgetscreen'
263 MDRectangleFlatButton:
264 text: 'Free me'
265 pos_hint: {'center_x': 0.49, 'center_y': 0.4}
266 MDRectangleFlatButton:
267 text: 'My Account'
268 pos_hint: {'center_x': 0.8, 'center_y': 0.4}
269 MDRectangleFlatButton:
270 pos_hint: {'center_x': 0.49, 'center_y': 0.2}
271 text: "Logout"
272 on_release:
273 root.manager.current = 'login'
274 curruser = None
275
276<BudgetScreen>:
277 name: 'budgetscreen'
278
279 FloatLayout:
280 MDTextField:
281 id: budget
282 hint_text: "Enter a budget in rupees if you want one"
283 pos_hint: {'center_x': 0.5, 'center_y': 0.6}
284 width: 280
285 height: 26
286 MDRectangleFlatButton:
287 pos_hint: {'center_x': 0.3, 'center_y': 0.4}
288 text: 'Continue'
289 on_release:
290 root.setbudgetandchangescreen()
291 root.manager.current = 'gcase'
292 MDRectangleFlatButton:
293 pos_hint: {'center_x': 0.69, 'center_y': 0.4}
294 text: 'Go Back'
295 on_release:
296 root.manager.current = 'main'
297
298<GCaseScreen>:
299 name: 'gcase'
300
301 FloatLayout:
302