-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
executable file
·1972 lines (1724 loc) · 90 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
import sys
import json
import os
import subprocess
import time
import threading
from threading import Thread
from multiprocessing.pool import ThreadPool
import sqlite3
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from ui_mainwindow import Ui_splashScreen
from ui_userprofile import Ui_userWindow
from ui_resetpin import Ui_resetPinWindow
from ui_finger import Ui_loginWindow
from ui_requestitem import Ui_requestItemWindow
from ui_editdetails import Ui_editDetailsWindow
from ui_inventory import Ui_inventoryWindow
from ui_cart import Ui_cartWindow
from ui_about import Ui_aboutWindow
from ui_adminpanel import Ui_adminWindow
from ui_enrol import Ui_enrolWindow
from ui_editusers import Ui_editUsersWindow
from ui_enrolfingerprint import Ui_enrolFingerWindow
from ui_archeader import Ui_arcHeader
from ui_projectsBrowser import Ui_projectsBrowserWindow
from ui_userList import Ui_userList
from ui_inventory_editor import Ui_inventoryEditor
from sql.user_details import user_info
from sql.reset_pin import resetPin
from sql.view_cart import view_cart
from sql.inventory import selectFromInventory
from sql.purchase import purchaseRequests
from sql.enrollUser import enrollUser
from sql.editUsers import editUsers
from sql.insert_data_users import db
from sql.sessions import manageSession
from sql.projectdb import projectDB
from fingerprint_sensor.finger_download import *
from fingerprint_sensor.FPS import *
database_path='./sql/'
dbs=db(database_path+'SIMS.db')
# Objects from this class are used for the active user in the application
# At a time, only one user can be logged in.
# NOTE: Make this a singleton in the future?
class userDetails():
def __init__(self, _name = "ARC-User-X", _userId = 1, _isAdmin = True, labAccess = True, inventoryAccess = True):
self._name = _name
self._userId = _userId
self._isAdmin = _isAdmin
self._hasLabAccess = labAccess
self._hasInventoryAccess = inventoryAccess
def getName(self):
return self._name
def getUserId(self):
return self._userId
def isAdmin(self):
return self._isAdmin
def hasLabAccess(self):
return self._hasLabAccess
def hasInventoryAccess(self):
return self._hasInventoryAccess
class ScrollArea(QScrollArea):
def __init__(self,parent=None):
self.widget=QWidget()
super().__init__(parent)
def addWidget(self,wid):
wid.setFixedSize(1119,629)
self.normalHeight=wid.height()
wid.setFocusPolicy(Qt.NoFocus)
wid.setParent(self.widget)
#wid.show()
#self.widget=wid
self.widget.setFixedWidth(wid.width())
self.widget.setFixedHeight(wid.height())
self.widget.setFocusPolicy(Qt.NoFocus)
self.setFocus()
self.setWidget(self.widget)
#self.setFocusPolicy(Qt.NoFocus)
self.setFrameShape(QFrame.Box)
self.setWidgetResizable(True)
self.setLineWidth(0)
self.setAlignment(Qt.AlignHCenter|Qt.AlignVCenter)
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self.verticalScrollBar().setFixedWidth(0)
QScroller.grabGesture(self.viewport(), QScroller.LeftMouseButtonGesture)
def focusInEvent(self,event):
self.widget.setFixedHeight(self.normalHeight)
#self.scroll(0,-self.verticalScrollBar().sliderPosition())
super().focusInEvent(event)
def focusOutEvent(self,event):
if type(self.focusWidget())==QLineEdit:
self.widget.setFixedHeight(1000)
super().focusOutEvent(event)
def eventFilter(self,obj,event):
#if event.type() == QEvent.MouseButtonRelease and type(obj)==QLineEdit:
#print('maximum')
#print(self.verticalScrollBar().maximum())
#print('minimum')
#print(self.verticalScrollBar().minimum())
#self.verticalScrollBar().setValue(-obj.pos().y()+80)
return super().eventFilter(obj,event)
# Event Filter
def clickable(widget):
class Filter(QObject):
clicked = pyqtSignal()
def eventFilter(self, obj, event):
if obj == widget:
if event.type() == QEvent.MouseButtonRelease:
if obj.rect().contains(event.pos()):
self.clicked.emit()
# The developer can opt for .emit(obj) to get the object within the slot.
return True
return False
filter = Filter(widget)
widget.installEventFilter(filter)
return filter.clicked
# The mainWindow class handles all the GUI widgets and logic
class mainWindow(QWidget):
userIdSignal = pyqtSignal(int)
userListChanged = pyqtSignal()
enrolFingerResult=pyqtSignal(bool)
fingerScanning=False
HeaderWidgetCreated=False
UserProfileCreated=False
FingerCreated=False
ResetPinCreated=False
RequestItemCreated=False
EditDetailsCreated=False
InventoryCreated=False
CartCreated=False
AdminCreated=False
EnrolCreated=False
EditUsersCreated=False
EnrolFingerprintCreated=False
ProjectsBrowserCreated=False
UserListWidgetCreated=False
projectInventoryCreated=False
ProjectCartCreated=False
InventoryEditorCreated=False
def __init__(self):
super(mainWindow, self).__init__()
self.loadConfig()
self.windowWidget = QWidget()
self.windowWidget.setStyleSheet("QPushButton {border-width: 1px;border-color: #339;border-style: solid;border-radius: 8;padding: 10px}\nQPushButton:pressed{background:royalblue;border-color:royalblue;border-width:2px}\nQWidget {background-color: white}\n* {font: 16pt}\n")
self.windowWidget.setWindowFlags(Qt.FramelessWindowHint)
# self.windowWidget.resize(1280, 800)
self.userId = None
self.splashScreen = QMainWindow()
self.userProfile = QDialog()
self.resetPin = QWidget()
self.resetPinScroller = ScrollArea()
self.fingerprint = QDialog()
self.requestItem = QWidget()
self.requestItemScroller = ScrollArea()
self.editDetails = QWidget()
self.editDetailsScroller = ScrollArea()
self.inventory = QMainWindow()
self.arcHeader = QWidget()
self.cart = QMainWindow()
self.finger = QDialog()
self.about = QWidget()
self.admin = QWidget()
self.enrol = QWidget()
self.enrolScroller = ScrollArea()
self.editUsers = QWidget()
self.editUsersScroller = ScrollArea()
self.enrolFingerprint = QWidget()
self.projectsBrowser=QWidget()
self.projectsBrowserScroller = ScrollArea()
self.userListWidget = QWidget()
self.projectInventory = QMainWindow()
self.projectCart = QMainWindow()
self.inventoryEditor = QMainWindow()
self.inventoryEditorScroller = ScrollArea()
self.currentPage = 0
self.previousPage = []
self.session=manageSession(self.databasePath)
self.StackWidget = QStackedWidget(self)
self.HomeWidget = QStackedWidget(self)
self.screenWidget = QWidget()
self.setupAbout()
self.setupSplashScreen()
self.scanThread = ThreadPool(processes=1)
self.setupFinger()
self.HomeWidget.addWidget(self.splashScreen)
self.HomeWidget.addWidget(self.screenWidget)
self.HomeWidget.addWidget(self.about)
self.HomeWidget.addWidget(self.finger)
vbox = QVBoxLayout()
vbox.addWidget(self.arcHeader)
vbox.addWidget(self.StackWidget)
self.screenWidget.setLayout(vbox)
windowVBox = QVBoxLayout()
windowVBox.addWidget(self.HomeWidget)
self.onAdminPage=False
self.windowWidget.setLayout(windowVBox)
self.HomeWidget.setCurrentIndex(0)
self.createStackedPages()
self.StackWidget.setCurrentIndex(0)
self.userListChanged.connect(self.updateUserList)
self.userIdSignal.connect(self.handleAction)
self.enrolFingerResult.connect(self.handleEnrolResult)
# The widget on top with the back button, ARC logo, and user options
def setupHeaderWidget(self, widget):
if not self.HeaderWidgetCreated:
Ui_arcHeader().setupUi(self.arcHeader)
arcLogo = self.arcHeader.findChild(QLabel,'label_3')
arcLogo.setPixmap(QPixmap('images/arclogo.png'))
backButton = self.arcHeader.findChild(QPushButton,'backButton')
backButton.setFocusPolicy(Qt.NoFocus)
backButton.setIcon(QIcon(self.resourceImagesPath+'locked.png'))
userWidget = self.arcHeader.findChild(QWidget,'widget')
userWidget.setFocusPolicy(Qt.NoFocus)
userIcon = self.arcHeader.findChild(QLabel,'label_4')
userImagePath = self.userImagePath + self.userImagesPrefix + \
str(self.user.getUserId()) + '.jpg'
if QFile.exists(userImagePath):
userIcon.setPixmap(QPixmap(userImagePath))
else:
userIcon.setPixmap(QPixmap('images/default_user.png'))
comboBox = self.arcHeader.findChild(QPushButton,'comboBox')
comboBox.setFocusPolicy(Qt.NoFocus)
#for i in self.user.getName().split(' '):
#if len(i)>3:
#username=i
#break
comboBox.setText('USER:'+str(self.user.getUserId()))
if not self.HeaderWidgetCreated:
backButton.clicked.connect(self.goBack)
comboBox.clicked.connect(self.handleComboBox)
self.HeaderWidgetCreated=True
hbox = self.arcHeader.findChild(QHBoxLayout,'horizontalLayout_2')
userHBox = self.arcHeader.findChild(QHBoxLayout,'horizontalLayout_3')
userHBox.addWidget(userIcon)
userHBox.addWidget(comboBox)
userWidget.setLayout(userHBox)
hbox.addWidget(backButton)
hbox.addWidget(arcLogo)
hbox.addWidget(userWidget)
hbox.setAlignment(backButton, Qt.AlignLeft|Qt.AlignTop)
hbox.setAlignment(arcLogo, Qt.AlignHCenter|Qt.AlignTop)
hbox.setAlignment(userWidget, Qt.AlignRight|Qt.AlignTop)
widget.setLayout(hbox)
widget.setStyleSheet("QPushButton {padding: 10px}\nQWidget {background-color: white}\n")
"""
hbox = QHBoxLayout()
icon = QIcon()
icon.addPixmap(QPixmap("images/back.png"), QIcon.Normal, QIcon.Off)
#setting up gui
backButton = QPushButton()
backButton.setFlat(True)
backButton.setIcon(icon)
backButton.setIconSize(QSize(48, 48))
backButton.setFocusPolicy(Qt.NoFocus)
arcLogo = QLabel()
arcLogo.setMinimumSize(QSize(0, 0))
arcLogo.setMaximumSize(QSize(117, 100))
arcLogo.setPixmap(QPixmap('images/arclogo.png'))
arcLogo.setScaledContents(True)
userWidget = QWidget()
userWidget.setFocusPolicy(Qt.NoFocus)
userHBox = QHBoxLayout()
userIcon = QLabel()
comboBox = QPushButton(self.user.getName())
comboBox.setFocusPolicy(Qt.NoFocus)
comboBox.setAttribute(Qt.WA_MouseNoMask,True)
userIcon.setMinimumSize(QSize(0, 40))
userIcon.setMaximumSize(QSize(50, 50))
userImagePath = self.userImagePath + self.userImagesPrefix + \
str(self.user.getUserId()) + '.jpg'
if QFile.exists(userImagePath):
userIcon.setPixmap(QPixmap(userImagePath))
else:
userIcon.setPixmap(QPixmap(userImagePath + self.userImagesPrefix + 'default.png'))
userIcon.setScaledContents(True)
comboBox.setMinimumSize(QSize(200, 40))
comboBox.setMaximumSize(QSize(300, 16777215))
#comboBox.addItem(self.user.getName())
#comboBox.addItem('About')
#comboBox.addItem("Admin Panel")
comboBox.clicked.connect(self.handleComboBox)
#comboBox.activated.connect(self.handleComboBox)
userHBox.addWidget(userIcon)
userHBox.addWidget(comboBox)
userWidget.setLayout(userHBox)
hbox.addWidget(backButton)
hbox.addWidget(arcLogo)
hbox.addWidget(userWidget)
hbox.setAlignment(backButton, Qt.AlignLeft|Qt.AlignTop)
hbox.setAlignment(arcLogo, Qt.AlignHCenter|Qt.AlignTop)
hbox.setAlignment(userWidget, Qt.AlignRight|Qt.AlignTop)
widget.setLayout(hbox)
widget.setStyleSheet("QPushButton {padding: 10px}\nQWidget {background-color: white}\n")
backButton.clicked.connect(self.goBack)
"""
# Config is loaded from the config.json file present in the same dir
def loadConfig(self):
with open('config.json') as data_file:
data = json.load(data_file)
self.device = data['Settings']['device']
self.fprintEnabled = data['Settings']['fingerprint']['enabled']
self.sensorPath = data['Settings']['fingerprint']['sensorPath']
self.baudRate = data['Settings']['fingerprint']['baudRate']
self.userImagePath = data['Settings']['images']['user-images-path']
self.userImagesPrefix = data['Settings']['images']['user-images-prefix']
self.inventoryImagesPath = data['Settings']['images']['inventory-images-path']
self.inventoryImagesPrefix = data['Settings']['images']['inventory-images-prefix']
self.resourceImagesPath = data['Settings']['images']['resource-images-path']
self.databasePath = data['Settings']['database']['path']
print ('Loading config from \'config.json\'')
def handleComboBox(self):
print(self.previousPage)
if (self.StackWidget.currentIndex() == 0) and self.user.isAdmin():
self.launchWindow(7)
else:
self.launchWindow(0)
# The widgets are arranged in a QStackedWidget. They are layered on
# top of one another in the order in which they are added to the StackWidget
def createStackedPages(self):
self.StackWidget.addWidget(self.userProfile)
self.StackWidget.addWidget(self.resetPinScroller)
self.StackWidget.addWidget(self.fingerprint)
self.StackWidget.addWidget(self.requestItemScroller)
self.StackWidget.addWidget(self.editDetailsScroller)
self.StackWidget.addWidget(self.inventory)
self.StackWidget.addWidget(self.cart)
self.StackWidget.addWidget(self.admin)
self.StackWidget.addWidget(self.enrolScroller)
self.StackWidget.addWidget(self.editUsersScroller)
self.StackWidget.addWidget(self.enrolFingerprint)
self.StackWidget.addWidget(self.projectsBrowserScroller)
self.StackWidget.addWidget(self.userListWidget)
self.StackWidget.addWidget(self.projectInventory)
self.StackWidget.addWidget(self.projectCart)
self.StackWidget.addWidget(self.inventoryEditorScroller)
# Each widget has a setup function which modifies the QWidget defined
# in the mainWindow class by calling the setupUi method of the autogenerated
# UI->Python files. We connect the actions of each widget through Qt's signal/slots
def setupSplashScreen(self):
Ui_splashScreen().setupUi(self.splashScreen)
self.pinEntry = False
clickable(self.splashScreen).connect(lambda: self.unlockScreen())
def setupAbout(self):
Ui_aboutWindow().setupUi(self.about)
closeButton = self.about.findChild(QPushButton, "closeButton")
closeButton.clicked.connect(lambda: self.HomeWidget.setCurrentIndex(1))
def setupFingerprint(self):
Ui_loginWindow.setupUi(self.finger)
def setupUserProfile(self):
if not self.UserProfileCreated:
Ui_userWindow().setupUi(self.userProfile)
inventoryButton = self.userProfile.findChild(QPushButton, "inventoryButton")
editDetailsButton = self.userProfile.findChild(QPushButton, "editDetailsButton")
requestButton = self.userProfile.findChild(QPushButton, "requestButton")
resetPinButton = self.userProfile.findChild(QPushButton, "resetPinButton")
cartButton = self.userProfile.findChild(QPushButton, "cartButton")
lockButton = self.userProfile.findChild(QPushButton, "lockButton")
logoutButton = self.userProfile.findChild(QPushButton, "logoutButton")
welcomeLabel = self.userProfile.findChild(QLabel, "welcomeLabel")
profilePic = self.userProfile.findChild(QLabel, "profilePic")
inventoryButton.setFocusPolicy(Qt.NoFocus)
editDetailsButton.setFocusPolicy(Qt.NoFocus)
requestButton.setFocusPolicy(Qt.NoFocus)
resetPinButton.setFocusPolicy(Qt.NoFocus)
cartButton.setFocusPolicy(Qt.NoFocus)
#lockButton.setFocusPolicy(Qt.NoFocus)
logoutButton.setFocusPolicy(Qt.NoFocus)
welcomeLabel.setFocusPolicy(Qt.NoFocus)
profilePic.setFocusPolicy(Qt.NoFocus)
if not self.UserProfileCreated:
inventoryButton.clicked.connect(lambda: self.launchWindow(5))
editDetailsButton.clicked.connect(lambda: self.launchWindow(4))
requestButton.clicked.connect(lambda: self.launchWindow(3))
resetPinButton.clicked.connect(lambda: self.launchWindow(1))
cartButton.clicked.connect(lambda: self.launchWindow(6))
logoutButton.clicked.connect(lambda:self.logoutUser())
self.UserProfileCreated=True
for i in self.user.getName().split(' '):
if len(i)>=1:
username=i
break
welcomeLabel.setText("Welcome, " + username)
#profilePic.setPixmap(QPixmap(self.userImagePath + self.userImagesPrefix + \
#str(self.user.getUserId()) + '.jpg'))
userImagePath = self.userImagePath + self.userImagesPrefix + \
str(self.user.getUserId()) + '.jpg'
if QFile.exists(userImagePath):
profilePic.setPixmap(QPixmap(userImagePath))
else:
profilePic.setPixmap(QPixmap('images/default_user.png'))
def setupResetPin(self):
if not self.ResetPinCreated:
Ui_resetPinWindow().setupUi(self.resetPin)
buttonBox = self.resetPin.findChild(QDialogButtonBox, "buttonBox")
currentPwd = self.resetPin.findChild(QLineEdit, "currentPwd")
newPwd = self.resetPin.findChild(QLineEdit, "newPwd")
currentPwd.setText("")
newPwd.setText("")
self.resetPinScroller.addWidget(self.resetPin)
if not self.ResetPinCreated:
buttonBox.accepted.connect(lambda: self.execResetPin(currentPwd.text(), newPwd.text()))
buttonBox.rejected.connect(lambda: self.launchWindow(0))
self.ResetPinCreated=True
def setupFinger(self):
if not self.FingerCreated:
Ui_loginWindow().setupUi(self.finger)
self.FingerCreated=True
fingerLabel = self.finger.findChild(QLabel, "fingerLabel")
layout = self.finger.findChild(QVBoxLayout,'verticalLayout')
layout.setAlignment(fingerLabel, Qt.AlignHCenter|Qt.AlignVCenter)
# fingerData = None
self.scanFingerprint = QMovie("images/finger-scan.gif")
self.scanFingerprint.setScaledSize(QSize(320, 240))
fingerLabel.setMovie(self.scanFingerprint)
def gotResult(self, myresult):
print(myresult)
print(threading.current_thread())
self.userIdSignal.emit(myresult)
def handleAction(self, myresult):
print(threading.current_thread())
print("THERESULT")
print(myresult)
if myresult != -1:
userInfo = user_info(self.databasePath)
userData = userInfo.get_user_info(myresult)
self.user = userDetails(userData[0], myresult, userData[5], userData[6], userData[7])
self.session.login(myresult)
self.setupWindows()
self.HomeWidget.setCurrentIndex(1)
else:
# self.finger = QWidget()
self.lock()
# Fingerprint login is supported here. We only take the sensor's word
# for whether the fingerprint provided is valid.
def unlockScreen(self):
if self.fprintEnabled == True:
print(threading.current_thread())
self.fingerprintObject = fsensor(self.sensorPath, self.baudRate)
self.scanFingerprint.start()
self.HomeWidget.setCurrentIndex(3)
self.scanThread.apply_async(self.scanFinger, callback=self.gotResult)
else:
self.HomeWidget.setCurrentIndex(1)
def scanFinger(self):
correctFingerprint = QPixmap("images/finger-correct.gif")
wrongFingerprint = QPixmap("images/finger-wrong.gif")
print(threading.current_thread())
fingerLabel = self.finger.findChild(QLabel, "fingerLabel")
# loggedIn = False
# while(loggedIn == False):
fingerId = self.fingerprintObject.Search()
if (fingerId == None):
print('NOT FOUND')
fingerLabel.setPixmap(wrongFingerprint)
time.sleep(1)
return -1
else:
print('FOUND:'+str(fingerId))
fingerLabel.setPixmap(correctFingerprint)
time.sleep(1)
userInfoObject = user_info(self.databasePath)
# loggedIn = True
self.userId = userInfoObject.identify_user(fingerId)
return self.userId
# print(fingerId)
# # fingerData = fingerId
# self.HomeWidget.setCurrentIndex(1)
def setupRequestItem(self):
if not self.RequestItemCreated:
Ui_requestItemWindow().setupUi(self.requestItem)
project = self.requestItem.findChild(QLineEdit, "project")
project.setText("")
item = self.requestItem.findChild(QLineEdit, "item")
item.setText("")
price = self.requestItem.findChild(QLineEdit, "price")
price.setText("")
requestItemButton = self.requestItem.findChild(QPushButton, "requestItemButton")
buttonBox = self.requestItem.findChild(QDialogButtonBox, "buttonBox")
self.requestItemScroller.addWidget(self.requestItem)
#self.requestItem.setFixedSize(1119,629)
#parent = QWidget()
#self.requestItem.setParent(parent)
#parent.setFixedSize(1119,1200)
#self.RequestItemScroller = QScrollArea()
#parent.setFocusPolicy(Qt.NoFocus)
#self.requestItemScroller.setFocusPolicy(Qt.NoFocus)
#self.requestItemScroller.setWidget(parent)
#self.requestItemScroller.setAlignment(Qt.AlignHCenter|Qt.AlignVCenter)
#self.requestItemScroller.setWidgetResizable(True)
#self.requestItemScroller.setFrameShape(QFrame.Box)
#self.requestItemScroller.setLineWidth(0)
#self.requestItemScroller.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
purchaseRequest = purchaseRequests(self.databasePath)
if not self.RequestItemCreated:
project.installEventFilter(self.requestItemScroller)
item.installEventFilter(self.requestItemScroller)
price.installEventFilter(self.requestItemScroller)
buttonBox.accepted.connect(lambda: (purchaseRequest.addToTable(self.user.getUserId(), \
str(project.text()), str(price.text()), \
str(item.text()), 1000),
self.showMsgBox('Request submitted!')))
buttonBox.rejected.connect(lambda: self.launchWindow(0))
self.RequestItemCreated=True
def setupEditDetails(self):
if not self.EditDetailsCreated:
Ui_editDetailsWindow().setupUi(self.editDetails)
buttonBox = self.editDetails.findChild(QDialogButtonBox, "buttonBox")
if not self.EditDetailsCreated:
buttonBox.rejected.connect(lambda: self.launchWindow(0))
buttonBox.accepted.connect(lambda: self.saveUserDetails(self.user.getUserId()))
buttonBox.accepted.connect(lambda: self.showMsgBox('Database successfully updated!'))
buttonBox.accepted.connect(lambda: self.launchWindow(0))
self.EditDetailsCreated=True
userInfo = user_info(self.databasePath)
userData = userInfo.get_user_info(self.user.getUserId())
name = self.editDetails.findChild(QLineEdit, "name")
phoneCall = self.editDetails.findChild(QLineEdit, "phoneCall")
phoneWhatsApp = self.editDetails.findChild(QLineEdit, "phoneWhatsApp")
roomNumber = self.editDetails.findChild(QLineEdit, "roomNumber")
email = self.editDetails.findChild(QLineEdit, "email")
name.setText(userData[0])
phoneCall.setText(userData[1])
phoneWhatsApp.setText(userData[2])
roomNumber.setText(userData[3])
email.setText(userData[4])
self.editDetailsScroller.addWidget(self.editDetails)
def setupInventoryEditor(self):
if not self.InventoryEditorCreated:
Ui_inventoryEditor().setupUi(self.inventoryEditor)
self.inventoryEditorScroller.addWidget(self.inventoryEditor)
self.categoryList = self.inventoryDb.getCatagories()
delete = self.inventoryEditor.findChild(QPushButton, "Delete")
categoryView = self.inventoryEditor.findChild(QListView, "categoryView")
itemView = self.inventoryEditor.findChild(QListView, "itemListView")
save = self.inventoryEditor.findChild(QPushButton, "Save")
plusButton = self.inventoryEditor.findChild(QPushButton, "plus")
minusButton = self.inventoryEditor.findChild(QPushButton, "minus")
quantity = self.inventoryEditor.findChild(QLabel, "quantity")
new = self.inventoryEditor.findChild(QPushButton, "new_2")
#partID = self.inventoryEditor.findChild(QLabel, "partID")
categoryView.setModel(self.categoryModel)
itemView.setModel(self.itemListModel)
self.updateInventoryEditorItemInfo(None)
if not self.InventoryEditorCreated:
#currentChanged signal is available for selection model of qlistview
categoryView.selectionModel().currentChanged.connect(self.updateInventoryItemList)
itemView.selectionModel().currentChanged.connect(self.updateInventoryEditorItemInfo)
categoryView.selectionModel().currentChanged.connect(lambda:itemView.setCurrentIndex(self.itemListModel.index(0,0)))
new.clicked.connect(lambda: self.newItem())
save.clicked.connect(lambda: self.saveItem())
delete.clicked.connect(lambda: self.deleteItem())
self.InventoryEditorCreated=True
categoryView.setCurrentIndex(self.categoryModel.index(0,0))
def updateInventoryEditorItemInfo(self, id,previous_id=None):
partName = self.inventoryEditor.findChild(QLineEdit, "partName")
partCategory = self.inventoryEditor.findChild(QLineEdit, "partCategory")
partID = self.inventoryEditor.findChild(QLabel, "partID")
partShelf = self.inventoryEditor.findChild(QLineEdit, "partShelf")
partBox = self.inventoryEditor.findChild(QLineEdit, "partBox")
partImage = self.inventoryEditor.findChild(QLabel, "partImage")
plusButton = self.inventoryEditor.findChild(QPushButton, "plus")
minusButton = self.inventoryEditor.findChild(QPushButton, "minus")
quantity = self.inventoryEditor.findChild(QLabel, "quantity")
categoryView = self.inventoryEditor.findChild(QListView, "categoryView")
rfid = self.inventoryEditor.findChild(QLineEdit, "rfid")
if not self.InventoryEditorCreated:
plusButton.clicked.connect(lambda: self.updateTotalQuantity(quantity,True))
minusButton.clicked.connect(lambda: self.updateTotalQuantity(quantity,False))
if id==None:
partName.setText("")
partCategory.setText("")
partID.setText("")
partShelf.setText("")
partBox.setText("")
quantity.setText(" ")
rfid.setText("")
partImage.setPixmap(QPixmap(self.inventoryImagesPath+self.inventoryImagesPrefix +'./../default_item.png'))
return
self.inventoryDb.getItems(categoryView.currentIndex().row())
itemDetails = self.inventoryDb.getItemInfo(id.row())
partName.setText(itemDetails[1])
rfid.setText(itemDetails[2])
partCategory.setText(itemDetails[5])
partID.setText(str(itemDetails[0]))
partShelf.setText(str(itemDetails[3]))
partBox.setText(str(itemDetails[4]))
quantity.setText(" "+str(itemDetails[6])+" ")
itemImage=self.inventoryImagesPath+self.inventoryImagesPrefix + \
str(itemDetails[0])+'.png'
if QFile.exists(itemImage):
partImage.setPixmap(QPixmap(itemImage))
else:
partImage.setPixmap(QPixmap(self.inventoryImagesPath+self.inventoryImagesPrefix +'./../default_item.png'))
def updateTotalQuantity(self,label, increase):
categoryView = self.inventoryEditor.findChild(QListView, "categoryView")
itemView = self.inventoryEditor.findChild(QListView, "itemListView")
if itemView.currentIndex().row()==None:
print(itemView.currentIndex().row())
return
#self.inventoryDb.getItems(categoryView.currentIndex().row())
#itemDetails = self.inventoryDb.getItemInfo(itemView.currentIndex().row())
#maxquantity=int(itemDetails[7])
if increase:
label.setText(" "+str(int(label.text())+1)+" ")
label.update()
else:
label.setText(" "+str(max(int(label.text())-1,0))+" ")
label.update()
def newItem(self):
partName = self.inventoryEditor.findChild(QLineEdit, "partName")
partCategory = self.inventoryEditor.findChild(QLineEdit, "partCategory")
partID = self.inventoryEditor.findChild(QLabel, "partID")
partShelf = self.inventoryEditor.findChild(QLineEdit, "partShelf")
partBox = self.inventoryEditor.findChild(QLineEdit, "partBox")
rfid = self.inventoryEditor.findChild(QLineEdit, "rfid")
partImage = self.inventoryEditor.findChild(QLabel, "partImage")
quantity = self.inventoryEditor.findChild(QLabel, "quantity")
partName.setText("")
partCategory.setText("")
partID.setText(str(self.inventoryDb.maxID()+1))
partShelf.setText("")
partBox.setText("")
quantity.setText(" 0 ")
rfid.setText("")
partImage.setPixmap(QPixmap(self.inventoryImagesPath+self.inventoryImagesPrefix +'./../default_item.png'))
def saveItem(self):
msg = QMessageBox()
msg.setIcon(QMessageBox.Information)
msg.setText('Save Changes to Item?')
msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
ret = msg.exec_()
if not ret:
return
categoryView = self.inventoryEditor.findChild(QListView, "categoryView")
itemView = self.inventoryEditor.findChild(QListView, "itemListView")
partName = self.inventoryEditor.findChild(QLineEdit, "partName")
partCategory = self.inventoryEditor.findChild(QLineEdit, "partCategory")
partID = self.inventoryEditor.findChild(QLabel, "partID")
partShelf = self.inventoryEditor.findChild(QLineEdit, "partShelf")
rfid = self.inventoryEditor.findChild(QLineEdit, "rfid")
partBox = self.inventoryEditor.findChild(QLineEdit, "partBox")
partImage = self.inventoryEditor.findChild(QLabel, "partImage")
quantity = self.inventoryEditor.findChild(QLabel, "quantity")
status = self.inventoryEditor.findChild(QLabel, "status")
if self.inventoryDb.updateItem(partID.text(), partName.text(), rfid.text(), partShelf.text(), partBox.text(), partCategory.text(), quantity.text()):
status.setText('<font color=\'green\'>'+'Inventory updated successfully'+'</font>')
else:
status.setText('<font color=\'red\'>Error!</font>')
Thread(target=self.clearStatus,args=(status,)).start()
self.updateInventoryCategories()
categoryView.setCurrentIndex(self.categoryModel.index(0,0))
self.updateInventoryItemList(categoryView.currentIndex())
self.updateInventoryEditorItemInfo(itemView.currentIndex())
def deleteItem(self):
msg = QMessageBox()
msg.setIcon(QMessageBox.Information)
msg.setText('Are you sure you want to delete this Item?')
msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
ret = msg.exec_()
if not ret:
return
categoryView = self.inventoryEditor.findChild(QListView, "categoryView")
itemView = self.inventoryEditor.findChild(QListView, "itemListView")
partID = self.inventoryEditor.findChild(QLabel, "partID")
status = self.inventoryEditor.findChild(QLabel, "status")
ret = self.inventoryDb.deleteItem(partID.text())
if ret==1:
status.setText('<font color=\'green\'>'+'Item Deleted'+'</font>')
elif ret==0:
status.setText('<font color=\'red\'>Item in use!</font>')
else:
status.setText('<font color=\'red\'>Error!</font>')
Thread(target=self.clearStatus,args=(status,)).start()
self.updateInventoryCategories()
categoryView.setCurrentIndex(self.categoryModel.index(0,0))
self.updateInventoryItemList(categoryView.currentIndex())
self.updateInventoryEditorItemInfo(itemView.currentIndex())
def setupProjectsBrowser(self):
if not self.ProjectsBrowserCreated:
Ui_projectsBrowserWindow().setupUi(self.projectsBrowser)
self.projectsBrowserScroller.addWidget(self.projectsBrowser)
self.projectDb = projectDB(self.databasePath)
self.updateProjectsList()
self.current_project = None
self.curent_project_lead_id = None
projectsView = self.projectsBrowser.findChild(QListView, "userView")
saveButton = self.projectsBrowser.findChild(QPushButton, "saveButton")
newButton = self.projectsBrowser.findChild(QPushButton, "new_2")
deleteButton = self.projectsBrowser.findChild(QPushButton, "deleteButton")
leadUser = self.projectsBrowser.findChild(QPushButton, "changeLeadUser")
inventory = self.projectsBrowser.findChild(QPushButton, "Inventory")
cart = self.projectsBrowser.findChild(QPushButton, "ViewCart")
self.updateUserList()
if not self.ProjectsBrowserCreated:
projectsView.clicked.connect(lambda:self.updateProjectInfo())
projectsView.clicked.connect(lambda:self.updateViewProjectCart())
saveButton.clicked.connect(lambda:self.saveProjectInfo())
newButton.clicked.connect(lambda:self.newProject())
deleteButton.clicked.connect(lambda:self.deleteProject())
leadUser.clicked.connect(lambda:self.launchWindow(12))
inventory.clicked.connect(lambda:self.launchWindow(13))
cart.clicked.connect(lambda:self.launchWindow(14))
self.ProjectsBrowserCreated = True
def setupUserListWidget(self):
if not self.UserListWidgetCreated:
Ui_userList().setupUi(self.userListWidget)
usersView = self.userListWidget.findChild(QListView, "userView")
selectButton = self.userListWidget.findChild(QPushButton, "Select")
self.updateUserList()
usersView.setModel(self.userModel)
if not self.UserListWidgetCreated:
selectButton.clicked.connect(lambda:self.updateLead())
self.UserListWidgetCreated=True
def updateLead(self):
usersView = self.userListWidget.findChild(QListView, "userView")
if usersView.currentIndex().row():
nameId = usersView.currentIndex().row()
else:
return
self.curent_project_lead_id = self.userList[nameId][0]
res = self.userInfoObject.get_user_info(self.curent_project_lead_id)
lead = self.projectsBrowser.findChild(QLabel, "lead")
lead.setText(res[0])
self.launchWindow(11)
def updateProjectsList(self):
projectsView = self.projectsBrowser.findChild(QListView, "userView")
self.projectsListModel = QStandardItemModel()
projectsView.setModel(self.projectsListModel)
projectsList = self.projectDb.getProjectsList()
for item in projectsList:
self.projectsListModel.appendRow(QStandardItem(item[1]))
def updateProjectInfo(self):
projectsView = self.projectsBrowser.findChild(QListView, "userView")
name = self.projectsBrowser.findChild(QLineEdit, "name")
lead = self.projectsBrowser.findChild(QLabel, "lead")
self.current_project = self.projectDb.project_list[projectsView.currentIndex().row()][0]
project_name = self.projectDb.project_list[projectsView.currentIndex().row()][1]
self.curent_project_lead_id = self.projectDb.project_list[projectsView.currentIndex().row()][2]
lead_name = self.userInfoObject.get_user_info(self.curent_project_lead_id)[0]
name.setText(project_name)
lead.setText(lead_name)
def saveProjectInfo(self):
projectsView = self.projectsBrowser.findChild(QListView, "userView")
if projectsView.currentIndex().row()==None:
return
name = self.projectsBrowser.findChild(QLineEdit, "name")
status = self.projectsBrowser.findChild(QLabel, "status")
if self.current_project==None:
if self.projectDb.newProject(name.text(),self.curent_project_lead_id):
status.setText('<font color=\'green\'>Project '+name.text()+' updated'+'</font>')
else:
status.setText('<font color=\'red\'>Error saving new project!</font>')
else:
if self.projectDb.updateProject(self.current_project,name.text(),self.curent_project_lead_id):
status.setText('<font color=\'green\'>Project '+name.text()+' updated'+'</font>')
else:
status.setText('<font color=\'red\'>Update Error!</font>')
Thread(target=self.clearStatus,args=(status,)).start()
self.updateProjectsList()
def newProject(self):
name = self.projectsBrowser.findChild(QLineEdit, "name")
lead = self.projectsBrowser.findChild(QLabel, "lead")
status = self.projectsBrowser.findChild(QLabel, "status")
self.current_project = None
self.curent_project_lead_id = None
name.setText('')
lead.setText('')
status.setText('Enter new project details and click Save' )
Thread(target=self.clearStatus,args=(status,)).start()
def deleteProject(self):
projectsView = self.projectsBrowser.findChild(QListView, "userView")
if projectsView.currentIndex().row()==None:
return
name = self.projectsBrowser.findChild(QLineEdit, "name")
lead = self.projectsBrowser.findChild(QLabel, "lead")
status = self.projectsBrowser.findChild(QLabel, "status")
if self.projectDb.deleteProject(self.current_project,self.curent_project_lead_id):
self.current_project = None
self.curent_project_lead_id = None
name.setText('')
lead.setText('')
self.updateProjectsList()
def setupProjectInventory(self):
if not self.projectInventoryCreated:
Ui_inventoryWindow().setupUi(self.projectInventory)
#self.inventoryDb = selectFromInventory(self.databasePath)
#self.categoryModel = QStandardItemModel()
#self.itemListModel = QStandardItemModel()
#self.categoryList = self.inventoryDb.getCatagories()
cartButton = self.projectInventory.findChild(QPushButton, "cartButton")
categoryView = self.projectInventory.findChild(QListView, "categoryView")
itemView = self.projectInventory.findChild(QListView, "itemListView")
addToCartButton = self.projectInventory.findChild(QPushButton, "addToCartButton")
plusButton = self.projectInventory.findChild(QPushButton, "plus")
minusButton = self.projectInventory.findChild(QPushButton, "minus")
quantity = self.projectInventory.findChild(QLabel, "quantity")
partQty = self.projectInventory.findChild(QLabel, "partQty")
categoryView.setModel(self.categoryModel)
itemView.setModel(self.itemListModel)
#self.categoryModel.clear()
#for item in self.categoryList:
#self.categoryModel.appendRow(QStandardItem(item))
self.updateProjectInventoryItemInfo(None)
if not self.projectInventoryCreated:
#currentChanged signal is available for selection model of qlistview
categoryView.selectionModel().currentChanged.connect(self.updateInventoryItemList)
itemView.selectionModel().currentChanged.connect(self.updateProjectInventoryItemInfo)
categoryView.selectionModel().currentChanged.connect(lambda:itemView.setCurrentIndex(self.itemListModel.index(0,0)))
#cartButton.clicked.connect(lambda: self.updateViewProjectCart())
cartButton.clicked.connect(lambda: self.launchWindow(14))
addToCartButton.clicked.connect(lambda: self.addToProjectCartAction(itemView, quantity, partQty))
self.projectInventoryCreated=True
categoryView.setCurrentIndex(self.categoryModel.index(0,0))
def updateProjectInventoryItemInfo(self, id,previous_id=None):
partName = self.projectInventory.findChild(QLabel, "partName")
partCategory = self.projectInventory.findChild(QLabel, "partCategory")
partID = self.projectInventory.findChild(QLabel, "partID")
partShelf = self.projectInventory.findChild(QLabel, "partShelf")
partBox = self.projectInventory.findChild(QLabel, "partBox")
partQty = self.projectInventory.findChild(QLabel, "partQty")
partImage = self.projectInventory.findChild(QLabel, "partImage")
plusButton = self.projectInventory.findChild(QPushButton, "plus")
minusButton = self.projectInventory.findChild(QPushButton, "minus")
quantity = self.projectInventory.findChild(QLabel, "quantity")
categoryView = self.projectInventory.findChild(QListView, "categoryView")
if not self.projectInventoryCreated:
plusButton.clicked.connect(lambda: self.updateQuantityProject(quantity,True))
minusButton.clicked.connect(lambda: self.updateQuantityProject(quantity,False))
if id==None:
partName.setText("")
partCategory.setText("")
partID.setText("")
partShelf.setText("")
partBox.setText("")
partQty.setText("")
quantity.setText(" 1 ")
partImage.setPixmap(QPixmap(self.inventoryImagesPath+self.inventoryImagesPrefix +'./../default_item.png'))
return
self.inventoryDb.getItems(categoryView.currentIndex().row())
itemDetails = self.inventoryDb.getItemInfo(id.row())
partName.setText(itemDetails[1])
partCategory.setText(itemDetails[5])
partID.setText(str(itemDetails[0]))
partShelf.setText(str(itemDetails[3]))
partBox.setText(str(itemDetails[4]))
partQty.setText(str(itemDetails[7]))
partQty.update()
quantity.setText(" 1 ")
itemImage=self.inventoryImagesPath+self.inventoryImagesPrefix + \
str(itemDetails[0])+'.png'
if QFile.exists(itemImage):
partImage.setPixmap(QPixmap(itemImage))
else:
partImage.setPixmap(QPixmap(self.inventoryImagesPath+self.inventoryImagesPrefix +'./../default_item.png'))
def updateQuantityProject(self,label, increase):
categoryView = self.projectInventory.findChild(QListView, "categoryView")
itemView = self.projectInventory.findChild(QListView, "itemListView")
if itemView.currentIndex().row()==None:
print(itemView.currentIndex().row())
return
self.inventoryDb.getItems(categoryView.currentIndex().row())
itemDetails = self.inventoryDb.getItemInfo(itemView.currentIndex().row())
maxquantity=int(itemDetails[7])
if increase:
label.setText(" "+str(min((int(label.text())+1),maxquantity))+" ")
label.update()
else:
label.setText(" "+str(max((int(label.text())-1),0))+" ")
label.update()
def addToProjectCartAction(self, itemView, qtySpinBox, partQty):