-
Notifications
You must be signed in to change notification settings - Fork 0
/
processhall.py
executable file
·367 lines (292 loc) · 12.2 KB
/
processhall.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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
import os
from PyQt5.QtWidgets import (QFrame, QDesktopWidget, QMainWindow, QAction, QWidget, qApp, QGridLayout,
QPushButton, QApplication, QVBoxLayout,QHBoxLayout, QLabel, QLineEdit, QComboBox, QCalendarWidget)
from PyQt5.QtCore import Qt, QBasicTimer, pyqtSignal, QRect, pyqtSlot
from PyQt5.QtGui import (QIcon, QFont, QPainter, QBrush, QColor, QKeyEvent)
import yaml
# Submodules
from scale.scale import Scale
from labelwriter.labelwriter import Labelwriter
# Product list used to populate fields
GLOBAL_PRODUCTS = None
with open("products.yml", 'r') as ymlfile:
GLOBAL_PRODUCTS = yaml.safe_load(ymlfile)
# customers.yml needs to be updated
# products.yml needs to be updated
GLOBAL_CUSTOMERS = None
with open("customers.yml", 'r') as ymlfile:
GLOBAL_CUSTOMERS = yaml.safe_load(ymlfile)
class ScaleFrame(QFrame):
def __init__(self, parent):
super(ScaleFrame, self).__init__(parent)
self.parent = parent
print('ScaleFrame: my parent is',self.parent)
self.initFrame()
def initFrame(self):
self.commaweight = ''
self.timer = QBasicTimer()
self.myscale = Scale(10202)
self.lbl_weight = QLabel(self)
self.lbl_weight.setObjectName('lbl_weight')
self.lbl_weight.setText("0.000")
self.lbl_weight.resize(500, 100)
self.lbl_weight.move(50, 50)
lbl_unit = QLabel(self)
lbl_unit.setObjectName('lbl_unit')
lbl_unit.setText("kg")
lbl_unit.resize(100, 120)
lbl_unit.move(350, 40)
self.setObjectName('ScaleFrame')
self.setStyleSheet("""
#ScaleFrame {
background-color: #cfcfcf;
}
.QLabel#lbl_weight {
font-size:100pt;
color: #ff0000;
}
.QLabel#lbl_unit {
font-size:100pt;
color: #000000;
}
.QLabel {
font-size:22pt;
color: #000000;
}
""")
self.start_timer()
def start_timer(self):
self.timer.start(100, self)
def timerEvent(self, event):
'''handles timer event'''
if event.timerId() == self.timer.timerId():
time_last_received, weight = self.myscale.return_last_weight()
self.window().statusbar.showMessage(F"Last received: {time_last_received}")
self.commaweight = str(F"{weight:.2f}").replace('.',',') # HACK HACK
self.lbl_weight.setText(F"{weight:.3f}")
else:
super(Board, self).timerEvent(event)
class LabelFrame(QWidget):
#asignal = pyqtSignal(str)
def __init__(self, parent):
global GLOBAL_PRODUCTS
super(LabelFrame, self).__init__(parent)
self.parent = parent
print('LabelFrame: my parent is',self.parent)
self.initFrame()
def initFrame(self):
self.mylabelwriter = Labelwriter('127.0.0.1', 9100)
self.mylabelwriter.beep()
self.productindexselected = 0
#mylabelwriter.print_label(**kwarg_partial)
self.setFixedWidth(500)
layout = QGridLayout()
lbl_product = QLabel('Product')
self.input_product = QComboBox(self)
for product in GLOBAL_PRODUCTS:
self.input_product.addItem(GLOBAL_PRODUCTS[product]['friendlyname']['NOR'])
lbl_language = QLabel('Language')
self.input_language = QComboBox(self)
self.input_language.addItems(['NOR - Norwegian', 'ENG - English', 'SPA - Spanish', 'NLD - Dutch', 'FRA - French'])
lbl_grade = QLabel('Grade')
self.input_grade = QComboBox(self)
self.input_grade.addItem('Select a product')
self.lbl_pcskg = QLabel('pcskg')
lbl_processing = QLabel('Processing')
self.input_processing = QComboBox(self)
self.input_processing.addItem('Select a product')
lbl_batch = QLabel('Batch')
self.input_batch = QLineEdit(self)
self.input_batch.setText('000001')
lbl_harvest_date = QLabel('Harvest date')
self.input_harvest_date = QCalendarWidget(self)
self.input_harvest_date.resize(100,50)
lbl_customer = QLabel('Customer')
self.input_customer = QComboBox(self)
self.input_customer.setEditable(True)
self.input_customer.addItem('CUSTOMER - You can edit this field if you want')
for customer in GLOBAL_CUSTOMERS:
self.input_customer.addItem(GLOBAL_CUSTOMERS[customer]['printablename'])
self.btn_print_label = QPushButton('Print Label', self)
self.btn_print_label.setFixedHeight(50)
self.input_printhack = QLineEdit(self)
self.input_printhack.setText('')
self.input_printhack.setPlaceholderText('++++++')
layout.setSpacing(10)
layout.addWidget(lbl_language, 1, 0)
layout.addWidget(self.input_language, 1, 1)
layout.addWidget(lbl_product, 2, 0)
layout.addWidget(self.input_product, 2, 1)
layout.addWidget(lbl_grade, 3, 0)
layout.addWidget(self.input_grade, 3, 1)
layout.addWidget(self.lbl_pcskg, 4, 1)
layout.addWidget(lbl_processing, 5, 0)
layout.addWidget(self.input_processing, 5, 1)
layout.addWidget(lbl_batch, 6, 0)
layout.addWidget(self.input_batch, 6, 1)
layout.addWidget(lbl_harvest_date, 7, 0)
layout.addWidget(self.input_harvest_date, 7, 1)
layout.addWidget(lbl_customer, 8, 0)
layout.addWidget(self.input_customer, 8, 1)
layout.addWidget(self.input_printhack, 9, 0)
layout.addWidget(self.btn_print_label, 9, 1)
self.setLayout(layout)
# Set up signals
self.input_product.currentIndexChanged[int].connect(self.on_product_combo_currentIndexChanged)
self.input_grade.currentIndexChanged[int].connect(self.on_grade_combo_currentIndexChanged)
self.input_language.activated[str].connect(self.on_language_combo_activated)
self.btn_print_label.clicked.connect(self.on_print_label_clicked)
self.input_printhack.textEdited[str].connect(self.on_printhack_edited)
@pyqtSlot()
def on_print_label_clicked(self):
print('PRINTING LABEL')
langhack = self.input_language.currentText()[0:3] # Not very smart...
productindex = self.input_product.currentIndex() # So much hack, very profit.
friendlyname = GLOBAL_PRODUCTS[productindex]['friendlyname'][langhack]
scientificname = GLOBAL_PRODUCTS[productindex]['scientificname']
productionmethod = self.input_processing.currentText()
grade = self.input_grade.currentText()
customer = self.input_customer.currentText()
batchno = self.input_batch.text()
# http://zetcode.com/gui/pyqt5/datetime/
catchdate = self.input_harvest_date.selectedDate().toString(format = Qt.ISODate)
print(grade)
pcskg = self.lbl_pcskg.text()
#print(pcskg)
#for i, grade in enumerate(GLOBAL_PRODUCTS[index]['grades']): # A dictionary
# print(grade)
# self.input_grade.addItem(grade[i])
if langhack == 'NOR':
productinthirdlanguage = ''
elif langhack == 'ENG':
productinthirdlanguage = ''
elif langhack == 'SPA':
productinthirdlanguage = 'Nombre del producto'
elif langhack == 'FRA':
productinthirdlanguage = 'Nom du produit'
elif langhack == 'NLD':
productinthirdlanguage = 'Productnaam'
else:
productinthirdlanguage = ''
print(friendlyname)
kwarg_partial = {
'friendlyname':friendlyname,
'scientificname':scientificname,
'productinthirdlanguage':productinthirdlanguage,
'gtin':GLOBAL_PRODUCTS[productindex]['gtin'],#
'processingmethod':productionmethod,
'weight':self.parent.scaleframe.commaweight,
'grade':grade,
'customer':customer,
'batchno':batchno,
'catchdate':catchdate,
'pcskg':pcskg
}
print(kwarg_partial)
#print(self.parent.scaleframe.lbl_weight.text())
self.mylabelwriter.print_label(**kwarg_partial)
@pyqtSlot(str)
def on_printhack_edited(self, text):
print(text)
if len(text) > 0:
if text[-1] == '+':
print('pluss')
self.on_print_label_clicked()
# Acitvate label print
def on_language_combo_activated(self, text):
print(text)
#self.asignal.emit('selected', text)
def on_product_combo_currentIndexChanged(self, index):
self.input_grade.clear()
print('index', index)
self.productindexselected = index
#product = text
for i, grade in enumerate(GLOBAL_PRODUCTS[index]['grades']): # A dictionary
print(grade)
self.input_grade.addItem(grade[i])
self.input_processing.clear()
print('index', index)
#product = text
for i, process in enumerate(GLOBAL_PRODUCTS[index]['processing']): # A dictionary
print(process)
self.input_processing.addItem(process)
def on_grade_combo_currentIndexChanged(self, index):
if index == -1:
return
pcskg = GLOBAL_PRODUCTS[self.productindexselected]['grades'][index]['pcs']
print(pcskg)
self.lbl_pcskg.setText(pcskg)
#self.lbl_pcskg.setText(GLOBAL_PRODUCTS[index]['grades'][index])
#print(self.productsfile)
#print(text)
class CentralFrame(QFrame):
def __init__(self, parent):
super(CentralFrame, self).__init__(parent)
self.parent = parent
print('CentralFrame: my parent is',self.parent)
self.initFrame()
def initFrame(self):
layout = QHBoxLayout()
#printbtn = QPushButton('Print Label', self)
#printbtn.clicked.connect(QApplication.instance().quit)
#printbtn.resize(printbtn.sizeHint())
self.labelframe = LabelFrame(self)
self.scaleframe = ScaleFrame(self)
layout.addWidget(self.labelframe)
layout.addWidget(self.scaleframe)
#layout.addWidget(printbtn)
self.setLayout(layout)
class MainWindow(QMainWindow):
def __init__(self, parent):
super(MainWindow, self).__init__(parent)
self.parent = parent
print('MainWindow: my parent is',self.parent)
self.initUI()
def initUI(self):
centralframe = CentralFrame(self)
self.setCentralWidget(centralframe)
#self.centralframe.labelframe.asignal.connect(self.widgetB.on_procStart)
exitAct = QAction(QIcon('exit.png'), '&Exit', self)
exitAct.setShortcut('Ctrl+Q')
exitAct.setMenuRole(QAction.NoRole)
exitAct.setStatusTip('Exit application')
exitAct.triggered.connect(qApp.quit)
self.statusbar = self.statusBar()
self.statusbar.showMessage('Ready')
menubar = self.menuBar()
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(exitAct)
path = os.path.join(os.path.dirname(sys.modules[__name__].__file__), 'icon.png')
self.setWindowIcon(QIcon(path))
self.setGeometry(1000, 600, 1000, 600)
self.center()
self.setWindowTitle('Statsnail AS - Seafood Labelling Software')
self.show()
def center(self):
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
#https://www.riverbankcomputing.com/static/Docs/PyQt4/qevent.html
def keyPressEvent(self, event: QKeyEvent) -> None:
try:
print(event.type())
if event.key() in (Qt.Key_Plus):
print('key plus pressed, ignore')
ev.ignore()
return True
except:
pass
@pyqtSlot() # https://stackoverflow.com/questions/49480437/pyqt5-qcombobox-how-do-i-use-the-selected-value-of-the-user-to-execute-a-specif
def on_click(self):
print('Clicked self?')
def onActivated(self, text):
self.lbl_customer = text
if __name__ == '__main__':
app = QApplication(sys.argv)
parent = QMainWindow()
mainwindow = MainWindow(parent)
sys.exit(app.exec_())