-
Notifications
You must be signed in to change notification settings - Fork 2
/
mainwindow.py
578 lines (470 loc) · 26.4 KB
/
mainwindow.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#/***************************************************************************
#* Copyright (C) 2011 by Miguel Chavez Gamboa *
#* [email protected] *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU General Public License as published by *
#* the Free Software Foundation; either version 2 of the License, or *
#* (at your option) any later version. *
#* *
#* This program is distributed in the hope that it will be useful, *
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
#* GNU General Public License for more details. *
#* *
#* You should have received a copy of the GNU General Public License *
#* along with this program; if not, write to the *
#* Free Software Foundation, Inc., *
#* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
#***************************************************************************/
from PySide import QtCore, QtGui
from ui_mainview import *
import decimal
from decimal import *
#our components
from widgets.cmPasswordDialog import *
from widgets.cmAboutDialog import *
from widgets.cmLoginWindow import *
from widgets.cmFloatPanel import *
from widgets.cmTipPanel import *
from widgets.cmLineEdit import *
#django imports
import os, sys
#from django.utils.translation import ugettext as _
from gettext import gettext as _
#if 'DJANGO_SETTINGS_MODULE' not in os.environ:
# os.environ['DJANGO_SETTINGS_MODULE']='settings'
#from django.contrib.auth import authenticate
#from django.contrib.auth.models import User
#from backend.models import *
class MainWindow(QtGui.QMainWindow, Ui_mainForm):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
#NOTE: Next code is for django to know where settings.py is.
#if 'DJANGO_SETTINGS_MODULE' not in os.environ:
# os.environ['DJANGO_SETTINGS_MODULE']='settings'
## and to add to the sys path the path where this app is. not needed now.
##sys.path+= [os.path.split(os.path.split(os.path.abspath(__file__))[0])[0]]
self.setupUi(self)
self.editItemCode.setEmptyMessage(_("Enter code or qty*code. <Enter> or <+> Keys to enter the tendered amount."))
self.editItemCode.setToolTip(_("Enter code or qty*code. <Enter> or <+> Keys to enter the tendered amount."))
self.editTendered.setEmptyMessage(_("Enter the amount..."))
self.setCentralWidget(self.mainWidget)
#NOTE: I dont know if this is a bug, but i need to include a QWidget container which is parent of all widgets and its layouts
# to be able to set this "mainWidget" as the central widget. If i dont use this, im not able to set one widget as central
# and all the widgets to be displayed in the main window. And if i do not assign a central widget then all widgets appear
# at the left,top corner with the default size without any layout (size of widgets according to window size). This does not
# happens on the C++ side of Qt.
# Also note that im a beginner with PySide and Python.
#self.readSettings() FIXME: Just remember to uncomment later
self.setUnifiedTitleAndToolBarOnMac(True)
# go fullscreen
self.showFullScreen() #TODO:Add an option to not show fullscreen.
self.clearWidgets()
self.setupInputFilters()
self.createActions()
self.createToolBars()
#TODO: Decide which method use to get payment options.
# By default is CASH, a button to launch a dialog to get debit/credit card data. Another payment method?
self.groupPayment.setVisible(False) #reparent this to the dialog -use mibit dialogs when ported to python.
#flags setup
self.loggedUser = None #This will be a django model instance.
self.config = None #This will be a django model instance.
self.products = None #This will be a django model instance.
self.saleInProgress = False;
self.totalSum = Decimal()
self.subtotal = Decimal()
self.taxes = Decimal()
self.drawerCreated = False #TODO: investigate about open a device -same as qt....
self.currentBalanceId = 0
self.operationStarted = False
self.rowOver = -1 #used to track the cell where the mouse is over. to inc/dec buttons for tableSale.
#Create timer for the clock/date
self.timerClock = QtCore.QTimer(self)
self.timerClock.setInterval(1000)
self.timerClock.timeout.connect(self.updateClock)
self.timerClock.start()
self.updateDate()
self.lblStatusCashier.setText("Unattended")
QtCore.QTimer.singleShot(1000, self.setupSalesWidget) #wait some time to let the widget take its final size.
#Lock Password Dialog
self.lockDialog = cmPasswordDialog(self, ":/icons/images/dialog.svg", "Screen Locked.", ":/icons/images/lemon-lock-screen.png")
self.lockDialog.setTextColor("white")
self.lockDialog.setSize(300,150)
self.lockDialog.editPassword.returnPressed.connect(self.unlockScreen)
#About box
self.aboutBox = cmAboutDialog(self, ":/icons/images/about.svg",
_("<b>LemonPy v 0.0</b> <br><i>©2011 Miguel Chavez Gamboa.<br>[email protected]</i><br>" \
"<a href='http://www.lemonpos.org/'>http://www.lemonpos.org/</a>, <br>"\
"<a href='http://sourceforge.net/apps/mediawiki/lemonpos/index.php?title=Main_Page'>The Wiki</a><br><br>" \
"<b>LemonPy</b> is an <i>open source</i> Point of Sale software targeted for micro, small and medium businesses.<br><br>" \
"Licensed under the <a href='http://www.gnu.org/licenses/old-licenses/gpl-2.0.html'>GNU General Public License</a>" \
))
self.aboutBox.setTextColor("white")
self.aboutBox.setSize(350,350)
self.aboutBox.button.clicked.connect(self.aboutBox.hideDialog)
#login window
self.loginWindow = cmLoginWindow(self, ":/icons/images/about.svg")
self.loginWindow.setSize(350, 350)
self.loginWindow.btnLogin.clicked.connect(self.doAuth)
self.loginWindow.editUsername.returnPressed.connect(self.loginWindow.editPassword.setFocus)
self.loginWindow.editPassword.returnPressed.connect(self.doAuth)
self.loginWindow.btnExit.clicked.connect(self.close)
#the payment options panel
self.paymentOptionsPanel = cmFloatPanel(self.groupTotals, ":/icons/images/panel_top.svg", PanelPosition.Top, self.groupTotals.width(),150)
self.paymentOptionsPanel.addWidget(self.groupPayment)
self.paymentOptionsPanel.setMode(PanelMode.Manual)
self.paymentOptionsPanel.setPosition(PanelPosition.Top)
self.paymentOptionsPanel.setHiddenCompletely(True)
self.paymentOptionsPanel.hide()
self.groupPayment.setVisible(True)
#a tip panel FIXME: Only a test
self.tipPanel = cmTipPanel(self.mainWidget, self.editItemCode, ":/icons/images/tip.svg", ":/icons/images/lemon-barcode.png", TipPosition.Below)
self.editItemCode.returnPressed.connect(self.showTip)
#Launch login-dialog
QtCore.QTimer.singleShot(800, self.login)
def showTip(self):
self.tipPanel.showTip("Hey, this is a test!", 4000)
def closeEvent(self, event):
#TODO: Can we close? Is there any sale in process? Ask the user to really exit and discard the sale?
self.writeSettings()
event.accept()
def about(self):
self.aboutBox.showDialog()
def setupInputFilters(self):
#Amount Validator
amountExpr = QtCore.QRegExp("[0-9]*[//.]{0,1}[0-9]{0,5}")
amountValidator = QtGui.QRegExpValidator(amountExpr, self)
self.editTendered.setValidator(amountValidator)
#Code validator.
codeExpr = QtCore.QRegExp("[0-9]*[//.]{0,1}[0-9]{0,5}[//*]{0,1}[0-9]*[A-Za-z_0-9\\\\/\\-]{0,30}")
codeValidator = QtGui.QRegExpValidator(codeExpr, self)
self.editItemCode.setValidator(codeValidator)
#TODO: Card number validators. and more payment options when implemented.
def clearWidgets(self):
self.editItemCode.clear()
self.editTendered.clear()
self.tableSale.clearContents()
self.tableSale.setRowCount(0)
def createActions(self):
print 'creating actions...'
self.exitAction = QtGui.QAction(_("E&xit (Ctrl+Q)"), self, shortcut="Ctrl+Q", triggered=self.close)
self.aboutAction = QtGui.QAction(_("&About"), self, statusTip=_("About"), triggered=self.about)
self.showPaymentOptionsAction = QtGui.QAction(_("Show Payment Options (Ctrl+P)"), self, shortcut="Ctrl+P", triggered=self.showPaymentOptions)
self.balanceAction = QtGui.QAction(_("Balance (Ctrl+B)"), self, shortcut="Ctrl+B", triggered=self.balance )
self.loginAction = QtGui.QAction(_("Login (Ctrl+L)"), self, shortcut="Ctrl+L", triggered=self.login )
self.codeFocusAction = QtGui.QAction(_("Enter Code (F2)"), self, shortcut="F2", triggered=self.editItemCode.setFocus )
self.searchAction = QtGui.QAction(_("Search Products (F3)"), self, shortcut="F3", triggered=self.showSearch )
self.removeItemAction = QtGui.QAction(_("Remove Item"), self, triggered=self.removeSelectedItem )
self.finishTransactionAction = QtGui.QAction(_("Finish Transaction (F12)"), self, shortcut="F12", triggered=self.finishTransaction )
self.cancelTransactionAction = QtGui.QAction(_("Cancel Transaction (F10)"), self, shortcut="F10", triggered=self.cancelTransaction )
self.cancelTicketAction = QtGui.QAction(_("Cancel Ticket (F11)"), self, shortcut="F11", triggered=self.cancelTicket )
self.startOperationsAction = QtGui.QAction(_("Start Operations (Ctrl+N)"), self, shortcut="Ctrl+N", triggered=self.startOperations ) #FIXME: QKeySequence::New
self.goPayAction = QtGui.QAction(_("Enter Payment (F4)"), self, shortcut="F4", triggered=self.editTendered.setFocus )
self.priceCheckerAction = QtGui.QAction(_("Price Checker (F9)"), self, shortcut="F9", triggered=self.showPriceChecker )
self.reprintTicketAction = QtGui.QAction(_("Reprint Ticket (F5)"), self, shortcut="F5", triggered=self.reprintTicket )
self.cashInAction = QtGui.QAction(_("Cash In (F8)"), self, shortcut="F8", triggered=self.cashIn )
self.cashOutAction = QtGui.QAction(_("Cash Out (F7)"), self, shortcut="F7", triggered=self.cashOut )
self.cashAvailableAction = QtGui.QAction(_("Cash Available (F6)"), self, shortcut="F6", triggered=self.cashAvailable )
self.endOfDayAction = QtGui.QAction(_("End Of Day (Ctrl+W)"), self, shortcut="Ctrl+W", triggered=self.endOfDay ) #FIXME: QKeySequence::Close
self.lockScreenAction = QtGui.QAction(_("Lock Screen (Ctrl+Space)"), self, shortcut="Ctrl+Space", triggered=self.lockScreen ) #FIXME: Qt::CTRL+Qt::Key_Space
self.suspendSaleAction = QtGui.QAction(_("Suspend Sale (Ctrl+Backspace)"), self, shortcut="Ctrl+Backspace", triggered=self.suspendSale ) #FIXME: Qt::CTRL+Qt::Key_Backspace
self.discountAction = QtGui.QAction(_("Apply Discount (Ctrl+D)"), self, shortcut="Ctrl+D", triggered=self.applyDiscount )
self.resumeSaleAction = QtGui.QAction(_("Resume Sale (Ctrl+R)"), self, shortcut="Ctrl+R", triggered=self.resumeSale )
self.currencyConversionAction = QtGui.QAction(_("Currency Conversion"), self, triggered=self.showCurrencyConv )
self.configAction = QtGui.QAction(_("Configure Lemon"), self, triggered=self.config )
self.exitAction.setIcon(QtGui.QIcon(":/icons/images/lemon-exit.png"))
self.aboutAction.setIcon(QtGui.QIcon(":/icons/images/lemon-tag.png"))
self.showPaymentOptionsAction.setIcon(QtGui.QIcon(":/icons/images/card.png"))
self.loginAction.setIcon(QtGui.QIcon(":/icons/images/lemon-user.png"))
self.balanceAction.setIcon(QtGui.QIcon(":/icons/images/lemon-balance.png"))
self.codeFocusAction.setIcon(QtGui.QIcon(":/icons/images/lemon-barcode.png"))
self.searchAction.setIcon(QtGui.QIcon(":/icons/images/lemon-search.png"))
self.removeItemAction.setIcon(QtGui.QIcon(":/icons/images/lemon-eraser.png"))
self.finishTransactionAction.setIcon(QtGui.QIcon(":/icons/images/lemon-transaction-accept.png"))
self.cancelTransactionAction.setIcon(QtGui.QIcon(":/icons/images/lemon-transaction-cancel.png"))
self.cancelTicketAction.setIcon(QtGui.QIcon(":/icons/images/lemon-ticket-cancel.png"))
self.startOperationsAction.setIcon(QtGui.QIcon(":/icons/images/lemon-start.png"))
self.goPayAction.setIcon(QtGui.QIcon(":/icons/images/lemon-pay.png"))
self.priceCheckerAction.setIcon(QtGui.QIcon(":/icons/images/lemon-price-checker.png"))
self.reprintTicketAction.setIcon(QtGui.QIcon(":/icons/images/lemon-print-ticket.png"))
self.cashInAction.setIcon(QtGui.QIcon(":/icons/images/lemon-cashin.png"))
self.cashOutAction.setIcon(QtGui.QIcon(":/icons/images/lemon-cashout.png"))
self.cashAvailableAction.setIcon(QtGui.QIcon(":/icons/images/lemon-money.png"))
self.endOfDayAction.setIcon(QtGui.QIcon(":/icons/images/lemon-calendar-small.png"))
self.lockScreenAction.setIcon(QtGui.QIcon(":/icons/images/lemon-lock-screen.png"))
self.suspendSaleAction.setIcon(QtGui.QIcon(":/icons/images/lemon-inbox.png"))
self.discountAction.setIcon(QtGui.QIcon(":/icons/images/lemon-discount.png"))
self.resumeSaleAction.setIcon(QtGui.QIcon(":/icons/images/lemon-outbox.png"))
self.currencyConversionAction.setIcon(QtGui.QIcon(":/icons/images/lemon-currency.png"))
self.configAction.setIcon(QtGui.QIcon(":/icons/images/lemon-configure.png"))
def createToolBars(self):
#Adding the left toolbar. non-movable.
self.toolBarLeft = QtGui.QToolBar("Left Toolbar")
self.toolBarLeft.setMovable(False)
self.addToolBar(QtCore.Qt.LeftToolBarArea, self.toolBarLeft)
self.toolBarLeft.addAction(self.aboutAction)
self.toolBarLeft.addAction(self.loginAction)
self.toolBarLeft.addAction(self.startOperationsAction)
self.toolBarLeft.addAction(self.balanceAction)
self.toolBarLeft.addAction(self.endOfDayAction)
self.toolBarLeft.addAction(self.lockScreenAction)
self.toolBarLeft.addAction(self.suspendSaleAction)
self.toolBarLeft.addAction(self.resumeSaleAction)
self.toolBarLeft.addAction(self.configAction)
self.toolBarLeft.addAction(self.exitAction)
#NOTE: Why the shortcuts dont work if the actions are not visible in the ui via a toolbar or menubar?
#Adding the top toolbar, non-movable for some important actions. This toolbar is not on the toolbarArea, it is aside the code input box.
self.toolBarTop = QtGui.QToolBar("Top Toolbar", self.toolWidget)
self.toolBarTop.setMovable(False)
self.toolBarTop.addAction(self.codeFocusAction)
self.toolBarTop.addAction(self.removeItemAction)
self.toolBarTop.addAction(self.goPayAction)
self.toolBarTop.addAction(self.discountAction)
self.toolBarTop.addAction(self.finishTransactionAction)
self.toolBarTop.addAction(self.cancelTransactionAction)
self.toolBarTop.addAction(self.cancelTicketAction)
self.toolBarTop.addAction(self.reprintTicketAction)
self.toolBarTop.addAction(self.cashInAction)
self.toolBarTop.addAction(self.cashOutAction)
self.toolBarTop.addAction(self.cashAvailableAction)
self.toolBarTop.addAction(self.priceCheckerAction)
self.toolWidgetLayout.addWidget(self.toolBarTop)
#Adding the tendered widget toolbar.
self.tenderedToolBar = QtGui.QToolBar("Tendered Toolbar", self.tenderedWidget)
self.tenderedToolBar.setMovable(False)
self.tenderedToolBar.addAction(self.showPaymentOptionsAction)
self.tenderedToolBar.addAction(self.currencyConversionAction)
self.tenderedWidgetLayout.addWidget(self.tenderedToolBar)
self.toolBarTop.setIconSize(QtCore.QSize(32,32))
self.toolBarLeft.setIconSize(QtCore.QSize(32,32))
########################## METHODS ###########################
def updateRowOver(self, row, col):
self.rowOver = row
self.tableSale.setCurrentCell(row, col)
#When a button is clicked, later the row over event is not fired in a consistent way :(
def setupSalesWidget(self):
'''
Adjust sizes of the table columns
'''
tableSize = self.tableSale.size()
piece = tableSize.width()/10
self.tableSale.horizontalHeader().setResizeMode(QtGui.QHeaderView.Interactive)
self.tableSale.horizontalHeader().resizeSection(0, piece/2)
self.tableSale.horizontalHeader().resizeSection(1, piece*5*0.98)
self.tableSale.horizontalHeader().resizeSection(2, piece*1.5)
self.tableSale.horizontalHeader().resizeSection(3, piece*1.5)
self.tableSale.horizontalHeader().resizeSection(4, piece*1.5)
#Next to enable the mouse tracking and know where the mouse is in the table (which cell) for the +/- buttons to work!
#the problem would be when using a touchscreen.
self.tableSale.setMouseTracking(True)
self.tableSale.cellEntered[int,int].connect(self.updateRowOver)
def addItem(self):
#now it is proof of concept for buttons inside CELLS.
insertedAt = self.tableSale.rowCount()
# + Qty - buttons
text = QtGui.QLabel("3")
addQtyBtn = QtGui.QPushButton("+")
remQtyBtn = QtGui.QPushButton("-")
wid = QtGui.QWidget()
layout = QtGui.QHBoxLayout()
wid.setLayout(layout)
layout.addWidget(remQtyBtn)
layout.addWidget(text)
layout.addWidget(addQtyBtn)
addQtyBtn.clicked.connect(self.incItem)
remQtyBtn.clicked.connect(self.decItem)
remQtyBtn.setMouseTracking(True) #this is important!
addQtyBtn.setMouseTracking(True) #this is important!
text.setMouseTracking(True) #this is important!
wid.setMouseTracking(True) #this is important!
#Remove item button and Article name
removeBtn = QtGui.QPushButton()
removeBtn.setIcon(QtGui.QIcon(":/icons/images/lemon-eraser.png"))
removeBtn.clicked.connect(self.removeItem)
removeBtn.setMouseTracking(True)
removeBtn.setMaximumWidth(32)
removeBtn.setToolTip(_("Remove this article"))
textA = QtGui.QLabel("An Article")
widR = QtGui.QWidget()
widR.setMouseTracking(True)
layR = QtGui.QHBoxLayout()
widR.setLayout(layR)
layR.addWidget(removeBtn)
layR.addWidget(textA)
self.tableSale.insertRow(insertedAt)
self.tableSale.setCellWidget(insertedAt, 0, wid)
self.tableSale.setCellWidget(insertedAt, 1, widR)
#self.tableSale.setItem(insertedAt, 1, QtGui.QTableWidgetItem("An article"))
self.tableSale.setItem(insertedAt, 2, QtGui.QTableWidgetItem("2.99"))
self.tableSale.setItem(insertedAt, 3, QtGui.QTableWidgetItem("0.0"))
self.tableSale.setItem(insertedAt, 4, QtGui.QTableWidgetItem("2.99"))
def incItem(self):
#first investigate in which row the button is.
#NOTE: The problem here is that the buttons can be clicked without selecting a row, so we cannot know where is it easily.
# To fix this, we connect the table's cellEntered signal to a method to save the row over. Also we select such row.
# Later i discovered that when one button is clicked, the onOver event is not reported in a consistent way, some times it fails.
row = self.tableSale.currentRow()
if row == -1:
row = self.rowOver
#now change the qty cell at row row.
text = QtGui.QLabel("1") #here the text is random because we still do not have the facilities to get such data (products hash) or increment a variable.
addQtyBtn = QtGui.QPushButton("+")
remQtyBtn = QtGui.QPushButton("-")
wid = QtGui.QWidget()
layout = QtGui.QHBoxLayout()
wid.setLayout(layout)
layout.addWidget(remQtyBtn)
layout.addWidget(text)
layout.addWidget(addQtyBtn)
addQtyBtn.clicked.connect(self.incItem)
#remQtyBtn.clicked.connect(self.remItem)
self.tableSale.setCellWidget(row, 0, wid) # column 0 is the Qty colum.
#Recalculate totals... TODO!
def decItem(self):
self.incItem()
def removeItem(self):
pass
def showPaymentOptions(self):
#Not coded yet...
self.paymentOptionsPanel.showPanel()
def login(self):
self.loginWindow.showDialog()
def balance(self):
pass
def showSearch(self):
pass
def removeSelectedItem(self):
pass
def finishTransaction(self):
pass
def cancelTransaction(self):
pass
def cancelTicket(self):
pass
def startOperations(self):
pass
def showPriceChecker(self):
pass
def reprintTicket(self):
pass
def cashIn(self):
pass
def cashOut(self):
pass
def cashAvailable(self):
pass
def endOfDay(self):
pass
def lockScreen(self):
#first disable the actions and ui.
self.disableActions()
self.disableUi()
self.lockDialog.showDialog(_("<b>This terminal is locked.</b> <br><i>Please enter the user's password to unlock it</i>."))
#now update balance and transaction.
#self.updateTransaction() #FIXME: I think this is not ui related, so it must be out of this class!
def unlockScreen(self):
if self.authenticateUser( self.loggedUser, self.lockDialog.getPassword(), False ):
self.enableUi()
self.enableActions()
self.lockDialog.hideDialog()
self.editItemCode.setFocus()
else:
self.lockDialog.shake()
def suspendSale(self):
pass
def applyDiscount(self):
pass
def resumeSale(self):
pass
def showCurrencyConv(self):
pass
def config(self):
pass
def toogleActions(self, status):
self.exitAction.setEnabled(status)
self.aboutAction.setEnabled(status)
self.showPaymentOptionsAction.setEnabled(status)
self.loginAction.setEnabled(status)
self.balanceAction.setEnabled(status)
self.codeFocusAction.setEnabled(status)
self.searchAction.setEnabled(status)
self.removeItemAction.setEnabled(status)
self.finishTransactionAction.setEnabled(status)
self.cancelTransactionAction.setEnabled(status)
self.cancelTicketAction.setEnabled(status)
self.startOperationsAction.setEnabled(status)
self.goPayAction.setEnabled(status)
self.priceCheckerAction.setEnabled(status)
self.reprintTicketAction.setEnabled(status)
self.cashInAction.setEnabled(status)
self.cashOutAction.setEnabled(status)
self.cashAvailableAction.setEnabled(status)
self.endOfDayAction.setEnabled(status)
self.lockScreenAction.setEnabled(status)
self.suspendSaleAction.setEnabled(status)
self.discountAction.setEnabled(status)
self.resumeSaleAction.setEnabled(status)
self.currencyConversionAction.setEnabled(status)
self.configAction.setEnabled(status)
def disableUi(self):
self.mainWidget.setEnabled(False)
def enableUi(self):
self.mainWidget.setEnabled(True)
def enableActions(self):
self.toogleActions(True)
def disableActions(self):
self.toogleActions(False)
def updateClock(self):
time = QtCore.QTime.currentTime()
timeString = time.toString("hh:mm")
if time.second() % 2 == 0:
timeString = timeString.replace(':', '.')
else:
timeString = timeString.replace('.',':')
self.lblStatusTime.setText(timeString)
if time.hour() == 0 and time.minute() == 0 and (time.second() == 0 or time.second() == 1 ):
updateDate()
def updateDate(self):
date = QtCore.QDate.currentDate()
dateString = date.toString("dddd MMM d")
self.lblStatusDate.setText(dateString)
def doAuth(self):
if self.authenticateUser(self.loginWindow.getUserName(), self.loginWindow.getPassword(), True ):
self.loginWindow.hideDialog()
#display = '%s %s (%s)'%(self.loggedUser.first_name, self.loggedUser.last_name, self.loggedUser.username) removed code from django auth.
#self.lblStatusCashier.setText(display)
self.lblStatusCashier.setText("An user logged in. DEMO MODE")
#FIXME: remove this!... only demo
self.addItem()
self.addItem()
self.addItem()
else:
self.loginWindow.shake()
def authenticateUser(self, user, passwd, cleanUser):
#return a random value [True, False] just for demo.
import random
val = random.sample([True, False], 1)
return val[0] #removed code is using django Auth module.
#user = authenticate(username=user, password=passwd)
#if user is not None and user.is_active and (user.is_staff or user.is_superuser):
# self.loggedUser = user
# return True
#else:
# if cleanUser:
# self.loggedUser = None
# return False
def readSettings(self):
#settings = QtCore.QSettings("codea.me", "lemonPy") # This is to read a settings file. But, dont we want that almost every setting lives at database?
pass
#pos = settings.value("pos", QtCore.QPoint(200, 200))
#size = settings.value("size", QtCore.QSize(400, 400))
#self.resize(size)
#self.move(pos)
def writeSettings(self):
pass
#settings = QtCore.QSettings("codea.me", "lemonPy")
#settings.setValue("pos", self.pos())
#settings.setValue("size", self.size())