-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSelectorWidget.py
1985 lines (1768 loc) · 100 KB
/
SelectorWidget.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
'''
Copyright José FOURNIER 2023
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 3 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, see <https://www.gnu.org/licenses/>.
'''
from SelectorWidgetBase import Ui_Selector as selself
from PyQt6.QtWidgets import QWidget,QCheckBox,QGroupBox,QPushButton,QHBoxLayout,QVBoxLayout,QLineEdit,QLabel
from PyQt6 import QtCore
from PyQt6.QtCore import Qt,QRegularExpression
from database.fermentables.fermentable_brand import all_fbrand, find_fbrand_by_name
from database.fermentables.fermentable import all_fermentable
from database.yeasts.yeast import all_ybrand
from database.yeasts.yeast import all_yeast
from database.hops.hop import all_hop
from database.miscs.misc import all_misc
from parameters import yeast_target,yeast_form
from BrewUtils import BrewUtils
from PyQt6 import QtGui
from database.hops.hop_suppliers import all_hsupplier
import re
from database.profiles.rest import Rest
from PyQt6.QtGui import QRegularExpressionValidator,QPalette
from SignalObject import SignalObject
from MyQListView import MyQListView
from parameters import raw_ingredients, fermentable_categories
from parameters import raw_ingredients, hop_forms,hop_purposes
from RecipeFermentable import RecipeFermentable
from RecipeHop import RecipeHop
from RecipeYeast import RecipeYeast
from RecipeMisc import RecipeMisc
from HelpMessage import HelpMessage
from CheckableComboBox import CheckableComboBox,MyStandardItem
from pathlib import Path
class SelectorWidget(QWidget):
def __init__(self, source_list,destination_list,what,context,parent=None):
#context may be recipe, brew or inventory
super().__init__(parent)
self.parent=parent
self.ui =selself()
self.ui.setupUi(self)
self.destination_list=destination_list
self.source_list=source_list
self.what=what
self.context=context
self.this_file_path=Path(__file__).parent
self.source_selection=None
self.destination_selection=None
#for filters-------------------
match self.what:
case "fermentable":
self.active_brands=[]
self.active_categories=[]
self.active_ingredients=[]
case "hop":
self.active_suppliers=[]
self.active_forms=[]
self.active_purposes=[]
case "yeast":
self.active_brands=[]
self.active_forms=[]
self.active_targets=[]
case "misc":
pass
#---------------------------------
self.ui.fermentableControlGroupBox.setStyleSheet('color:black; background-color: white;')
self.ui.hopControlGroupBox.setStyleSheet('color:black; background-color: white;')
self.ui.yeastControlGroupBox.setStyleSheet('color:black; background-color: white;')
self.ui.miscControlGroupBox.setStyleSheet('color:black; background-color: white;')
self.ui.restControlGroupBox.setStyleSheet('color:black; background-color: white;')
if what!='rest':
self.ui.temperatureTransitionGroupbox.setVisible(False)
self.ui.titleGroupBox.setStyleSheet('color:black; background-color:white;')
match self.what:
case 'fermentable':
self.source_model=SourceModel(what='fermentable',items=self.source_list)
self.ui.hopControlGroupBox.setVisible(False)
self.ui.yeastControlGroupBox.setVisible(False)
self.ui.miscControlGroupBox.setVisible(False)
self.ui.restControlGroupBox.setVisible(False)
self.hide_steeping_controls()
self.ui.fermentableUsageLabel.setText('Usage')
self.ui.fermentableUsageCombo.addItem('')
self.ui.fermentableUsageCombo.addItem("empâtage")
self.ui.fermentableUsageCombo.addItem("trempage")
self.ui.fermentableUsageCombo.addItem("ébullition")
case 'hop':
self.source_model=SourceModel(what='hop',items=self.source_list)
self.ui.fermentableControlGroupBox.setVisible(False)
self.ui.yeastControlGroupBox.setVisible(False)
self.ui.miscControlGroupBox.setVisible(False)
self.ui.restControlGroupBox.setVisible(False)
#self.ui.hopUsageLabel.setText('Houblonnage')
self.ui.hopUsageCombo.addItem('')
self.ui.hopUsageCombo.addItem("à l'empâtage")
self.ui.hopUsageCombo.addItem("au premier moût")
self.ui.hopUsageCombo.addItem("à l'ébullition")
self.ui.hopUsageCombo.addItem("hors flamme")
self.ui.hopUsageCombo.addItem("au fermenteur")
case 'yeast':
self.source_model=SourceModel(what='yeast',items=self.source_list)
self.ui.fermentableControlGroupBox.setVisible(False)
self.ui.hopControlGroupBox.setVisible(False)
self.ui.miscControlGroupBox.setVisible(False)
self.ui.restControlGroupBox.setVisible(False)
self.ui.yeastPitchingRateUnitLabel.setVisible(True)
case 'misc':
self.source_model=SourceModel(what='misc',items=self.source_list)
self.ui.fermentableControlGroupBox.setVisible(False)
self.ui.hopControlGroupBox.setVisible(False)
self.ui.yeastControlGroupBox.setVisible(False)
self.ui.restControlGroupBox.setVisible(False)
case 'rest':
self.source_model=SourceModel(what='rest',items=self.source_list)
self.ui.fermentableControlGroupBox.setVisible(False)
self.ui.hopControlGroupBox.setVisible(False)
self.ui.yeastControlGroupBox.setVisible(False)
self.ui.miscControlGroupBox.setVisible(False)
self.ui.temperatureMethodCombo.addItem('','')
self.ui.temperatureMethodCombo.addItem('Chauffage','Heating')
self.ui.temperatureMethodCombo.addItem('Infusion','Infusion')
self.ui.temperatureMethodCombo.addItem('Décoction','Decoction')
if self.context=='recipe':
self.hide_temperature_transition_control_group()
self.ui.thicknessReferenceCheckbox.setVisible(False)
if self.context=='brew':
self.ui.grainTemperatureEdit.setText(str(self.parent.grain_temperature))
self.ui.additionsTemperatureEdit.setText(str(self.parent.additions_temperature))
self.ui.temperatureMethodCombo.setCurrentText(self.parent.temperature_method)
self.ui.restHelpButton.setStyleSheet('background-color:green; color:White')
self.ui.restHelpButton.setToolTip("Obtenir de l'information sur les paliers d'empâtage")
#we use a derived class of QListView to take into account a click elsewhere than on an item
self.destinationList=MyQListView(name='destination')
self.destinationLayout=QVBoxLayout()
self.destinationControlLayout=QHBoxLayout()
self.destinationLayout.addWidget(self.destinationList)
self.destinationLayout.addLayout(self.destinationControlLayout)
##self.ui.horizontalLayout_6.addWidget(self.destinationList)
self.ui.groupBox_left.setLayout(self.destinationLayout)
self.sourceList=MyQListView(name='source')
self.sourceLayout=QVBoxLayout()
self.add_filters( self.what)
self.sourceLayout.addWidget(self.sourceList)
self.sourceLayout.addWidget(self.filterGroupbox)
#self.filterGroupbox.setLayout(self.filterLayout)
##self.ui.horizontalLayout_6.addLayout(self.sourceLayout)
self.ui.groupBox_right.setLayout(self.sourceLayout)
#self.ui.horizontalLayout_6.addWidget(self.ui.sourceList)
self.sourceList.setModel(self.source_model)
self.sourceList.setSpacing(6)
self.ui.importButton.setVisible(False)
#hide buttons
self.ui.deleteButton.setVisible(False)
self.ui.importButton.setText('Non actif')
#self.ui.groupBox_left.setStyleSheet('background-color:red;color: white;')
#complete GUI
match self.what:
case 'fermentable':
self.destination_model=DestinationModel(what='fermentable',context=context,items=self.destination_list)
if(context == 'recipe'):
self.ui.fermentableUnitHelpButton.setText('?')
self.ui.fermentableUnitHelpButton.setStyleSheet('background-color:green;color:white;')
else:
self.ui.fermentableUnitHelpButton.setVisible(False)
case 'hop':
self.destination_model=DestinationModel(what='hop',context=context,items=self.destination_list)
self.hide_non_permanent_hop_controls()
self.ui.looseHelpButton.setText('?')
self.ui.looseHelpButton.setStyleSheet('background-color:green;color:white;')
self.ui.multiplicatorButton.setText('?')
self.ui.multiplicatorButton.setStyleSheet('background-color:green;color:white;')
self.ui.hopStandHelpButton.setText('?')
self.ui.hopStandHelpButton.setStyleSheet('background-color:green;color:white;')
self.ui.multiplicatorButton.setVisible(False)
case 'yeast':
self.destination_model=DestinationModel(what='yeast',context=context,bw=self.parent,items=self.destination_list)
case 'misc':
self.destination_model=DestinationModel(what='misc',context=context,items=self.destination_list)
case 'rest':
self.ui.calculationHelpButton.setText('?')
self.ui.calculationHelpButton.setStyleSheet('background-color:green;color:white;')
self.ui.calculationHelpButton.setToolTip("Get help on the way the various water additions are calculated")
self.destination_model=DestinationModel(what='rest',context=context,bw=self.parent,items=self.destination_list)
self.destinationList.setModel(self.destination_model)
self.destinationList.setSpacing(6)
self.sourceList.setVisible(False)
self.toggle_tab_view()
self.ui.restTemperatureEdit.setValidator(QRegularExpressionValidator(QRegularExpression("[0-9]{0,2}[\\.][0-9]{1,2}")))
self.ui.fermentableQuantityEdit.setValidator(QRegularExpressionValidator(QRegularExpression("[0-9]{0,3}([\\.][0-9]{3}){0,1}")))
self.ui.hopQuantityEdit.setValidator(QRegularExpressionValidator(QRegularExpression("[0-9]{0,3}\\.][0-9]{1,2}")))
self.ui.hopMinutesEdit.setValidator(QRegularExpressionValidator(QRegularExpression("[0-9]{0,3}")))
self.ui.miscQuantityEdit.setValidator(QRegularExpressionValidator(QRegularExpression("[0-9]{0,3}([\\.][0-9]{3}){0,1}")))
self.ui.miscReferenceVolumeEdit.setValidator(QRegularExpressionValidator(QRegularExpression("[0-9]{0,3}([\\.][0-9]{0,2}){0,1}")))
self.ui.restDurationEdit.setValidator(QRegularExpressionValidator(QRegularExpression("[0-9]{0,3}")))
self.sourceList.setStyleSheet("QListView{border: 2px solid green;}"\
"QListView::item:selected{border: 3px solid red;color:blue;background-color:white}"\
"QListView::item{border-bottom:2px solid gray}")
self.destinationList.setStyleSheet("QListView{border: 2px solid green;}"\
"QListView::item:selected{border: 3px solid red;color:blue;background-color:white}"\
"QListView::item{border-bottom:2px solid gray}")
#set connections
self.set_connections()
for what in ['fermentable_quantity','fermentable_usage','fermentable_steeping','hop_quantity','hop_usage','hop_utilisation','hop_multiplicator','hop_days','hop_hours','hop_minutes',\
'yeast_quantity','yeast_reference_volume','misc_quantity','misc_reference_volume','rest_temperature','rest_duration']:
self.clean_edit(what)
#-----------------------------------------------------------------------------------------------------------
def remove_all_fermentables(self):
print("remove all called")
self.destination_model.items=[]
self.destination_model.layoutChanged.emit()
def receive_signal(self,obj):
print('signal received '+obj.name)
def set_connections(self):
match self.what:
case 'fermentable':
self.brandFilterCombo.closedPopup.connect(self.on_brand_closedPopup)
self.brand_checkbox.stateChanged.connect(self.toggle_brand_filter)
self.categoryFilterCombo.closedPopup.connect(self.on_category_closedPopup)
self.category_checkbox.stateChanged.connect(self.toggle_category_filter)
self.ingredientFilterCombo.closedPopup.connect(self.on_ingredient_closedPopup)
self.ingredient_checkbox.stateChanged.connect(self.toggle_ingredient_filter)
self.searchEdit.editingFinished.connect(self.search_in_name)
self.searchHelpButton.clicked.connect(lambda: self.show_contextual_help('filter_f'))
case "hop":
self.supplierFilterCombo.closedPopup.connect(self.on_supplier_closedPopup)
self.supplier_checkbox.stateChanged.connect(self.toggle_supplier_filter)
self.formFilterCombo.closedPopup.connect(self.on_form_closedPopup)
self.form_checkbox.stateChanged.connect(self.toggle_form_filter)
self.purposeFilterCombo.closedPopup.connect(self.on_purpose_closedPopup)
self.purpose_checkbox.stateChanged.connect(self.toggle_purpose_filter)
self.yearSearchEdit.editingFinished.connect(self.search_year)
self.searchEdit.editingFinished.connect(self.search_in_name)
self.searchHelpButton.clicked.connect(lambda: self.show_contextual_help('filter_h'))
case "yeast":
self.brandFilterCombo.closedPopup.connect(self.on_brand_closedPopup)
self.brand_checkbox.stateChanged.connect(self.toggle_brand_filter)
self.formFilterCombo.closedPopup.connect(self.on_form_closedPopup)
self.form_checkbox.stateChanged.connect(self.toggle_form_filter)
self.targetFilterCombo.closedPopup.connect(self.on_target_closedPopup)
self.target_checkbox.stateChanged.connect(self.toggle_target_filter)
self.searchEdit.editingFinished.connect(self.search_in_name)
self.searchHelpButton.clicked.connect(lambda: self.show_contextual_help('filter'))
#nothing for misc
case 'rest':
self.ui.temperatureMethodCombo.currentTextChanged.connect(self.temperature_method_changed)
self.ui.additionsTemperatureEdit.textChanged.connect(self.additions_temperature_changed)
self.ui.grainTemperatureEdit.textChanged.connect(self.grain_temperature_changed)
self.ui.restHelpButton.clicked.connect(lambda:self.show_contextual_help('rest'))
self.sourceList.clicked.connect(self.select_source)
self.sourceList.mysignal.connect(self.on_mysignal)
self.destinationList.clicked.connect(self.select_destination)
self.destinationList.mysignal.connect(self.on_mysignal)
self.ui.importButton.clicked.connect(self.apply_prepared_operation)
self.ui.deleteButton.clicked.connect(self.delete)
self.ui.fermentableQuantityEdit.textChanged.connect(lambda: self.clean_edit('fermentable_quantity') )
self.ui.fermentableUsageCombo.currentTextChanged.connect(lambda: self.clean_edit('fermentable_usage'))
self.ui.fermentableSteepingEdit.textChanged.connect(lambda : self.clean_edit('fermentable_steep'))
self.ui.fermentableUsageCombo.currentTextChanged.connect(self.toggle_steeping_controls)
self.ui.hopQuantityEdit.textChanged.connect(lambda: self.clean_edit('hop_quantity'))
self.ui.hopUsageCombo.currentTextChanged.connect(lambda: self.clean_edit('hop_usage'))
self.ui.hopUtilisationEdit.textChanged.connect(lambda: self.clean_edit('hop_utilisation'))
self.ui.hopMultiplicatorEdit.textChanged.connect(lambda: self.clean_edit('hop_multiplicator'))
self.ui.hopDaysEdit.textChanged.connect(lambda: self.clean_edit('hop_days'))
self.ui.hopHoursEdit.textChanged.connect(lambda: self.clean_edit('hop_hours'))
self.ui.hopMinutesEdit.textChanged.connect(lambda: self.clean_edit('hop_minutes'))
self.ui.hopTemperatureEdit.textChanged.connect(lambda : self.clean_edit('hop_temperature'))
self.ui.pitchingRateSpinBox.valueChanged.connect(lambda: self.clean_edit('yeast_pitching_rate'))
self.ui.hopUsageCombo.currentTextChanged.connect(self.adapt_hop_control_view)
self.ui.pitchingRateSpinBox.valueChanged.connect(lambda: self.clean_edit('yeast_quantity'))
#self.ui.yeastReferencVolumeEdit.textChanged.connect(lambda :self.clean_edit('yeast_reference_volume'))
self.ui.miscQuantityEdit.textChanged.connect(lambda: self.clean_edit('misc_quantity'))
self.ui.miscReferenceVolumeEdit.textChanged.connect(lambda :self.clean_edit('misc_reference_volume'))
self.ui.restTemperatureEdit.textChanged.connect(lambda :self.clean_edit('rest_temperature'))
self.ui.restDurationEdit.textChanged.connect(lambda :self.clean_edit('rest_duration'))
self.ui.toggleViewButton.clicked.connect(self.toggle_tab_view)
self.ui.steepYieldHelpButton.clicked.connect(lambda: self.show_contextual_help('steep_yield'))
self.ui.fermentableUnitHelpButton.clicked.connect(lambda: self.show_contextual_help('fermentable_unit'))
self.ui.looseHelpButton.clicked.connect(lambda: self.show_contextual_help('loose_hop'))
self.ui.hopStandHelpButton.clicked.connect(lambda : self.show_contextual_help('hop_stand'))
self.ui.multiplicatorButton.clicked.connect(lambda: self.show_contextual_help('multiplicator'))
self.ui.calculationHelpButton.clicked.connect(lambda: self.show_contextual_help('water_additions'))
#-----------------------------------------------------------------
def add_filters(self,what):
self.filterGroupbox=QGroupBox()
self.filterLayout=QHBoxLayout()
#self.filterGroupbox.setFixedHeight(100)
match what:
case "fermentable":
self.fermentableFilterLayout=QHBoxLayout()
self.brandLayout=QVBoxLayout()
self.brandFilterCombo=CheckableComboBox()
self.brands=all_fbrand()
for brand in self.brands:
item = MyStandardItem(brand.name)
item.setCheckable(True)
item.setCheckState(Qt.CheckState.Unchecked)
self.brandFilterCombo.model().appendRow(item)
self.brand_checkbox=QCheckBox('Filtrer les marques')
self.brandLayout.addWidget(self.brand_checkbox)
self.brandLayout.addWidget(self.brandFilterCombo)
self.fermentableFilterLayout.addLayout(self.brandLayout)
self.brandFilterCombo.setVisible(False)
self.categoryLayout=QVBoxLayout()
self.categoryFilterCombo=CheckableComboBox()
self.categories=fermentable_categories
for category in self.categories:
item = MyStandardItem(category)
item.setCheckable(True)
item.setCheckState(Qt.CheckState.Unchecked)
self.categoryFilterCombo.model().appendRow(item)
self.category_checkbox=QCheckBox('Filtrer les catégories')
self.categoryLayout.addWidget(self.category_checkbox)
self.categoryLayout.addWidget(self.categoryFilterCombo)
self.fermentableFilterLayout.addLayout(self.categoryLayout)
self.categoryFilterCombo.setVisible(False)
self.ingredientLayout=QVBoxLayout()
self.ingredientFilterCombo=CheckableComboBox()
self.ingredients=raw_ingredients#import from parameters
for ingredient in self.ingredients:
item = MyStandardItem(ingredient)
item.setCheckable(True)
item.setCheckState(Qt.CheckState.Unchecked)
self.ingredientFilterCombo.model().appendRow(item)
self.ingredient_checkbox= QCheckBox('Filtrer les ingrédients')
self.ingredientLayout.addWidget(self.ingredient_checkbox)
self.ingredientLayout.addWidget(self.ingredientFilterCombo)
self.fermentableFilterLayout.addLayout(self.ingredientLayout)
self.ingredientFilterCombo.setVisible(False)
self.searchEdit=QLineEdit()
self.searchEdit.setPlaceholderText('🔍Entrée en fin de saisie')
self.fermentableFilterLayout.addWidget(self.searchEdit)
#self.fermentableFilterLayout.addStretch()
#self.ui.filterGroupBox.setLayout(self.fermentableFilterLayout)
self.filterLayout.addLayout(self.fermentableFilterLayout)
case "hop":
#suppliers
self.hopFilterLayout=QHBoxLayout()
self.supplierLayout=QVBoxLayout()
self.supplierFilterCombo=CheckableComboBox()
self.suppliers=all_hsupplier()
for supplier in self.suppliers:
item = MyStandardItem(supplier.name)
item.setCheckable(True)
item.setCheckState(Qt.CheckState.Unchecked)
self.supplierFilterCombo.model().appendRow(item)
self.supplier_checkbox=QCheckBox('Filtrer fournisseurs')
self.supplierLayout.addWidget(self.supplier_checkbox)
self.supplierLayout.addWidget(self.supplierFilterCombo)
self.hopFilterLayout.addLayout(self.supplierLayout)
self.supplierFilterCombo.setVisible(False)
#forms
self.formLayout=QVBoxLayout()
self.formFilterCombo=CheckableComboBox()
self.forms=hop_forms
for form in self.forms:
item = MyStandardItem(form[1],form[0])
item.setCheckable(True)
item.setCheckState(Qt.CheckState.Unchecked)
self.formFilterCombo.model().appendRow(item)
self.form_checkbox=QCheckBox('Filtrer les formes')
self.formLayout.addWidget(self.form_checkbox)
self.formLayout.addWidget(self.formFilterCombo)
self.hopFilterLayout.addLayout(self.formLayout)
self.formFilterCombo.setVisible(False)
#purpose
self.purposeLayout=QVBoxLayout()
self.purposeFilterCombo=CheckableComboBox()
self.purposes=hop_purposes#import from parameters
for purpose in self.purposes:
item = MyStandardItem(purpose[1],purpose[0])
item.setCheckable(True)
item.setCheckState(Qt.CheckState.Unchecked)
self.purposeFilterCombo.model().appendRow(item)
self.purpose_checkbox= QCheckBox('Filtrer les buts')
self.purposeLayout.addWidget(self.purpose_checkbox)
self.purposeLayout.addWidget(self.purposeFilterCombo)
self.hopFilterLayout.addLayout(self.purposeLayout)
self.purposeFilterCombo.setVisible(False)
#year
self.yearLayout=QVBoxLayout()
self.yearSearchLabel=QLabel('Année')
self.yearSearchLabel.setFixedWidth(60)
self.yearSearchEdit=QLineEdit()
self.yearSearchEdit.setFixedWidth(60)
self.yearSearchEdit.setPlaceholderText('? ')
self.yearLayout.addWidget(self.yearSearchLabel)
self.yearLayout.addWidget(self.yearSearchEdit)
self.hopFilterLayout.addLayout(self.yearLayout)
#search
self.nameLayout=QVBoxLayout()
self.nameSearchLabel=QLabel('Chercher dans nom')
self.searchEdit=QLineEdit()
self.searchEdit.setPlaceholderText('? ')
self.nameLayout.addWidget(self.nameSearchLabel)
self.nameLayout.addWidget(self.searchEdit)
self.hopFilterLayout.addLayout(self.nameLayout)
#self.fermentableFilterLayout.addStretch()
#self.ui.filterGroupBox.setLayout(self.fermentableFilterLayout)
self.filterLayout.addLayout(self.hopFilterLayout)
case "yeast":
self.yeastFilterLayout=QHBoxLayout()
#brands
self.brandLayout=QVBoxLayout()
self.brandFilterCombo=CheckableComboBox()
self.brands=all_ybrand()
for brand in self.brands:
item = MyStandardItem(brand.name)
item.setCheckable(True)
item.setCheckState(Qt.CheckState.Unchecked)
self.brandFilterCombo.model().appendRow(item)
self.brand_checkbox=QCheckBox('Filtrer les marques')
self.brandLayout.addWidget(self.brand_checkbox)
self.brandLayout.addWidget(self.brandFilterCombo)
self.yeastFilterLayout.addLayout(self.brandLayout)
self.brandFilterCombo.setVisible(False)
#forms
self.formLayout=QVBoxLayout()
self.formFilterCombo=CheckableComboBox()
self.forms=yeast_form
for form in self.forms:
item = MyStandardItem(form)
item.setCheckable(True)
item.setCheckState(Qt.CheckState.Unchecked)
self.formFilterCombo.model().appendRow(item)
self.form_checkbox=QCheckBox('Filtrer les formes')
self.formLayout.addWidget(self.form_checkbox)
self.formLayout.addWidget(self.formFilterCombo)
self.yeastFilterLayout.addLayout(self.formLayout)
self.formFilterCombo.setVisible(False)
#target
self.targetLayout=QVBoxLayout()
self.targetFilterCombo=CheckableComboBox()
self.targets=yeast_target#import from parameters
for target in self.targets:
item = MyStandardItem(target)
item.setCheckable(True)
item.setCheckState(Qt.CheckState.Unchecked)
self.targetFilterCombo.model().appendRow(item)
self.target_checkbox= QCheckBox('Filtrer les cibles')
self.targetLayout.addWidget(self.target_checkbox)
self.targetLayout.addWidget(self.targetFilterCombo)
self.yeastFilterLayout.addLayout(self.targetLayout)
self.targetFilterCombo.setVisible(False)
self.searchEdit=QLineEdit()
self.searchEdit.setPlaceholderText('🔍Entrée en fin de saisie')
self.yeastFilterLayout.addWidget(self.searchEdit)
self.filterLayout.addLayout(self.yeastFilterLayout)
#self.yeastFilterLayout.addStretch()
case "misc":
self.miscFilterLayout=QHBoxLayout()
self.searchEdit=QLineEdit()
self.searchEdit.setPlaceholderText('🔍Entrée en fin de saisie')
self.miscFilterLayout.addWidget(self.searchEdit)
self.filterLayout.addLayout(self.miscFilterLayout)
self.searchHelpButton=QPushButton('?')
self.searchHelpButton.setFixedWidth(24)
self.searchHelpButton.setStyleSheet('background-color:green; color:White')
self.searchHelpButton.setToolTip("Obtenir de l'aide sur le filtrage et la recherche")
self.filterLayout.addWidget(self.searchHelpButton)
self.filterGroupbox.setLayout(self.filterLayout)
self.filterGroupbox.setStyleSheet("background-color:#D5F5E3")
#-------------------------------------------------------------------------
@QtCore.pyqtSlot()
def on_brand_closedPopup(self):
self.active_brands=self.brandFilterCombo.checkedItems()
self.filter_list()
#----------------------------------------------
def toggle_brand_filter(self):
if self.brand_checkbox.isChecked():
self.brandFilterCombo.setVisible(True)
else:
self.brandFilterCombo.setVisible(False)
self.filter_list()
#---------------------------------------------
@QtCore.pyqtSlot()
def on_category_closedPopup(self):
self.active_categories=self.categoryFilterCombo.checkedItems()
self.filter_list()
#----------------------------------------------
def toggle_category_filter(self):
if self.category_checkbox.isChecked():
self.categoryFilterCombo.setVisible(True)
else:
self.categoryFilterCombo.setVisible(False)
self.filter_list()
#---------------------------------------------
@QtCore.pyqtSlot()
def on_ingredient_closedPopup(self):
self.active_ingredients=self.ingredientFilterCombo.checkedItems()
self.filter_list()
#----------------------------------------------
def toggle_ingredient_filter(self):
if self.ingredient_checkbox.isChecked():
self.ingredientFilterCombo.setVisible(True)
else:
self.ingredientFilterCombo.setVisible(False)
self.filter_list()
#---------------------------------------------------------------------------
QtCore.pyqtSlot()
def on_supplier_closedPopup(self):
self.active_suppliers=self.supplierFilterCombo.checkedItems()
self.filter_list()
#----------------------------------------------
def toggle_supplier_filter(self):
if self.supplier_checkbox.isChecked():
self.supplierFilterCombo.setVisible(True)
else:
self.supplierFilterCombo.setVisible(False)
self.filter_list()
#---------------------------------------------------------------------------
QtCore.pyqtSlot()
def on_form_closedPopup(self):
self.active_forms=self.formFilterCombo.checkedItems()
self.filter_list()
#----------------------------------------------
def toggle_form_filter(self):
if self.form_checkbox.isChecked():
self.formFilterCombo.setVisible(True)
else:
self.formFilterCombo.setVisible(False)
self.filter_list()
#---------------------------------------------------------------------------
QtCore.pyqtSlot()
def on_purpose_closedPopup(self):
self.active_purposes=self.purposeFilterCombo.checkedItems()
self.filter_list()
#----------------------------------------------
def toggle_purpose_filter(self):
if self.purpose_checkbox.isChecked():
self.purposeFilterCombo.setVisible(True)
else:
self.purposeFilterCombo.setVisible(False)
self.filter_list()
@QtCore.pyqtSlot()
def on_brand_closedPopup(self):
self.active_brands=self.brandFilterCombo.checkedItems()
self.searchEdit.setText('')
self.filter_list()
#----------------------------------------------
def toggle_brand_filter(self):
if self.brand_checkbox.isChecked():
self.brandFilterCombo.setVisible(True)
else:
self.brandFilterCombo.setVisible(False)
self.filter_list()
#---------------------------------------------
@QtCore.pyqtSlot()
def on_form_closedPopup(self):
self.active_forms=self.categoryFilterCombo.checkedItems()
self.searchEdit.setText('')
self.filter_list()
#----------------------------------------------
def toggle_form_filter(self):
if self.form_checkbox.isChecked():
self.formFilterCombo.setVisible(True)
else:
self.formFilterCombo.setVisible(False)
self.filter_list()
#---------------------------------------------
@QtCore.pyqtSlot()
def on_target_closedPopup(self):
self.active_targets=self.targetFilterCombo.checkedItems()
self.searchEdit.setText('')
self.filter_list()
#----------------------------------------------
def toggle_target_filter(self):
if self.target_checkbox.isChecked():
self.targetFilterCombo.setVisible(True)
else:
self.targetFilterCombo.setVisible(False)
self.filter_list()
#-----------------------------------------------------------------------------------------------
def refresh_source(self):
match self.what:
case "fermentable":
self.source_list=all_fermentable()
self.source_list.sort(key=lambda x: (x.brand,x.name,x.version))
case "hop":
self.source_list=all_hop()
self.source_list.sort(key=lambda x: (x.supplier,x.name,x.crop_year))
case "yeast":
self.source_list=all_yeast()
self.source_list.sort(key=lambda x: (x.target,x.brand,x.name))
case "misc":
self.source_list=all_misc()
self.source_model.items=self.source_list
self.source_model.layoutChanged.emit()
#----------------------------------------------------------------------------------------------
def filter_list(self):
items=self.source_list
filtered=None
match self.what:
case "fermentable":
filtered=list(filter(lambda x:\
(x.brand in self.active_brands or not self.brand_checkbox.isChecked()) and \
(x.category in self.active_categories or not self.category_checkbox.isChecked()) and \
(x.raw_ingredient in self.active_ingredients or not self.ingredient_checkbox.isChecked())\
,items ))
filtered.sort(key=lambda x: (x.brand,x.name,x.version))
case "hop":
filtered=list(filter(lambda x:\
(x.supplier in self.active_suppliers or not self.supplier_checkbox.isChecked()) and \
(x.form in self.active_forms or not self.form_checkbox.isChecked()) and \
(x.purpose in self.active_purposes or not self.purpose_checkbox.isChecked())\
,items))
filtered.sort(key=lambda x: (x.supplier,x.name,x.crop_year))
case "yeast":
filtered=list(filter(lambda x:\
(x.brand in self.active_brands or not self.brand_checkbox.isChecked()) and \
(x.form in self.active_forms or not self.form_checkbox.isChecked()) and \
(x.target in self.active_targets or not self.target_checkbox.isChecked())\
,items ))
filtered.sort(key=lambda x: (x.target,x.brand,x.name))
self.source_model.items=filtered
self.source_model.layoutChanged.emit()
#------------------------------------------------------------------------------------------------
def search_in_name(self):
self.filter_list()#we start with the filtered list
pattern=self.searchEdit.text()
if pattern != '':
items=self.source_model.items #we search only in the filtered list
sorted_array=list(filter(lambda x: re.search(pattern, x.name,re.IGNORECASE),items))
self.source_model.items=sorted_array
self.source_model.layoutChanged.emit()
#----------------------------------------------------------------------------------------------
def search_year(self):
self.searchEdit.setText('')
self.filter_list()#we start with the filtered list
pattern=self.yearSearchEdit.text()
if pattern != '':
items=self.source_model.items #we search only in the filtered list
sorted_array=list(filter(lambda x: re.search(pattern, x.crop_year,re.IGNORECASE),items))
self.source_model.items=sorted_array
self.source_model.layoutChanged.emit()
#------------------------------------------------------------------
def show_contextual_help(self,what):
filename=(self.this_file_path/"help/Head.html").resolve()
prepend=open(filename,'r',encoding="utf-8").read()
helpPopup=HelpMessage()
match what:
case 'filter_f':
helpPopup.set_title('À propos du filtrage et de la recherche')
filename=(self.this_file_path/"help/FermentableSearchHelp.html").resolve()
text=open(filename,'r',encoding="utf-8").read()
helpPopup.set_message(prepend+text)
case 'filter_h':
helpPopup.set_title('À propos du filtrage et de la recherche')
filename=(self.this_file_path/"help/HopSearchHelp.html").resolve()
text=open(filename,'r',encoding="utf-8").read()
helpPopup.set_message(prepend+text)
case 'steep_yield':
helpPopup.set_title('À propos du rendement au trempage')
filename=(self.this_file_path/"help/SteepYieldHelp.html").resolve()
text=open(filename,'r',encoding="utf-8").read()
helpPopup.set_message(prepend+text)
case 'fermentable_unit':
helpPopup.set_title ("Pourquoi l'absence d'unité de masse de fermentable")
filename=(self.this_file_path/"help/FermentableUnitHelp.html").resolve()
text=open(filename,'r',encoding="utf-8").read()
helpPopup.set_message(prepend+text)
case 'loose_hop':
helpPopup.set_title("À quoi sert l'indicateur en vrac ?")
filename=(self.this_file_path/"help/LooseHelp.html").resolve()
text=open(filename,'r',encoding="utf-8").read()
helpPopup.set_message(prepend+text)
case 'multiplicator':
helpPopup.set_title('Le multiplicateur')
filename=(self.this_file_path/"help/Multiplicator.html").resolve()
text=open(filename,'r',encoding="utf-8").read()
helpPopup.set_message(prepend+text)
case 'hop_stand':
helpPopup.set_title('Le houblonnage Hors Flamme')
filename=(self.this_file_path/"help/Hopstand.html").resolve()
text=open(filename,'r',encoding="utf-8").read()
helpPopup.set_message(prepend+text)
case "water_additions":
helpPopup.set_title("Calcul des additions d'eau et de leur température")
filename=(self.this_file_path/"help/WaterAdditions.html").resolve()
text=open(filename,'r',encoding="utf-8").read()
helpPopup.set_message(prepend+text)
case "rest":
helpPopup.set_title("Information sur les paliers d'empâtage")
filename=(self.this_file_path/"help/Rests.html").resolve()
text=open(filename,'r',encoding="utf-8").read()
helpPopup.set_message(prepend+text)
helpPopup.exec()
#------------------------------------------------------------------------
def on_mysignal(self,obj):
#this signal is emitted from a custom class that allow to take into account a click elsewhere than on an item
#in that way, we can call self.select_destination for clearing the selection
match obj.value:
case 'source':
indexes=self.sourceList.selectedIndexes()
if indexes:
self.select_source()
else:
pass
case 'destination':
indexes=self.destinationList.selectedIndexes()
if indexes:
self.select_destination()
else:
pass
#------------------------------------------------------------------------
def additions_temperature_changed(self):
try:
self.parent.additions_temperature=round(float(self.ui.additionsTemperatureEdit.text()),1)
except:
self.parent.additions_temperature=None
self.destination_model.layoutChanged.emit()
self.signal_changes()
#-------------------------------------------------------------------------
def grain_temperature_changed(self):
try:
self.parent.grain_temperature=float(self.ui.grainTemperatureEdit.text())
except:
self.parent.grain_temperature=None
self.destination_model.layoutChanged.emit()
self.signal_changes()
def temperature_method_changed(self):
self.parent.temperature_method = self.ui.temperatureMethodCombo.currentText()
if self.what =='rest' and self.parent.temperature_method =='Chauffage':
for item in self.destination_model.items:
pass#item.thickness_reference=False
self.ui.thicknessReferenceCheckbox.setVisible(False)
else:
self.ui.thicknessReferenceCheckbox.setVisible(True)
self.destination_model.layoutChanged.emit()
self.signal_changes()
#-------------------------------------------------------------------------
def hide_non_permanent_hop_controls(self):
self.ui.hopMultiplicatorEdit.setVisible(False)
self.ui.multiplicatorButton.setVisible(False)
self.ui.hopMultiplicatorLabel.setVisible(False)
self.ui.hopUtilisationEdit.setVisible(False)
self.ui.hopUtilisationLabel.setVisible(False)
self.ui.hopDaysEdit.setVisible(False)
self.ui.hopDaysLabel.setVisible(False)
self.ui.hopHoursEdit.setVisible(False)
self.ui.hopHoursLabel.setVisible(False)
self.ui.hopMinutesEdit.setVisible(False)
self.ui.hopTemperatureEdit.setVisible(False)
self.ui.hopTemperatureLabel.setVisible(False)
self.ui.hopMinutesLabel.setVisible(False)
self.ui.hopDurationLabel.setVisible(False)
#-------------------------------------------------------------------------
def adapt_hop_control_view(self):
self.hide_non_permanent_hop_controls()
self.ui.looseCheckBox.setVisible(True)
self.ui.looseHelpButton.setVisible(True)
match self.ui.hopUsageCombo.currentText():
case "à l'empâtage":
self.ui.hopMultiplicatorEdit.setVisible(True)
self.ui.hopMultiplicatorLabel.setVisible(True)
self.ui.multiplicatorButton.setVisible(True)
self.ui.looseCheckBox.setVisible(False)
self.ui.looseHelpButton.setVisible(False)
self.ui.hopStandHelpButton.setVisible(False)
self.ui.hopTemperatureLabel.setVisible(False)
case "au premier moût" :
self.ui.hopMultiplicatorEdit.setVisible(True)
self.ui.hopMultiplicatorLabel.setVisible(True)
self.ui.multiplicatorButton.setVisible(True)
self.ui.hopTemperatureLabel.setVisible(False)
self.ui.hopStandHelpButton.setVisible(False)
case "à l'ébullition":
self.ui.hopDurationLabel.setVisible(True)
self.ui.hopMinutesEdit.setVisible(True)
self.ui.hopMinutesLabel.setVisible(True)
self.ui.hopTemperatureLabel.setVisible(False)
self.ui.hopStandHelpButton.setVisible(False)
case "hors flamme":
self.ui.hopTemperatureLabel.setVisible(True)
self.ui.hopTemperatureEdit.setVisible(True)
self.ui.hopDurationLabel.setVisible(True)
self.ui.hopMinutesLabel.setVisible(True)
self.ui.hopMinutesEdit.setVisible(True)
self.ui.hopStandHelpButton.setVisible(True)
case "au fermenteur":
self.ui.hopDurationLabel.setVisible(True)
self.ui.hopDaysEdit.setVisible(True)
self.ui.hopDaysLabel.setVisible(True)
self.ui.hopHoursEdit.setVisible(True)
self.ui.hopHoursLabel.setVisible(True)
self.ui.hopUtilisationEdit.setVisible(True)
self.ui.hopUtilisationLabel.setVisible(True)
self.ui.hopStandHelpButton.setVisible(False)
#-------------------------------------------------------------------------
def toggle_steeping_controls(self):
val=self.ui.fermentableUsageCombo.currentText()
if val == 'trempage':
self.show_steeping_controls()
return
if val == '' or val == 'empâtage' or val== 'ébullition':
self.hide_steeping_controls()
def show_steeping_controls(self):
self.ui.steepYieldHelpButton.setText('?')
self.ui.steepYieldHelpButton.setStyleSheet('background-color:green;color:white;')
self.ui.steepYieldHelpButton.setVisible(True)
self.ui.fermentableSteepingLabel.setVisible(True)
self.ui.fermentableSteepingEdit.setVisible(True)
self.ui.fermentableSteepingUnitLabel.setVisible(True)
self.ui.fermentableSteepingEdit.setToolTip("Il s'agit du rendement au trempage.Les valeurs, toujours inférieures à celle de l'empâtage, varient significativement selon les types de malt et la pratique.\
Renseignez-vous pour la valeur à utiliser en fonction du type de malt, de la température et de la durée.")
#-------------------------------------------------------------------------
def hide_steeping_controls(self):
self.ui.steepYieldHelpButton.setVisible(False)
self.ui.fermentableSteepingLabel.setVisible(False)
self.ui.fermentableSteepingEdit.setVisible(False)
self.ui.fermentableSteepingUnitLabel.setVisible(False)
#-------------------------------------------------------------------
def toggle_tab_view(self):
if(self.sourceList.isVisible()):
#self.searchEdit.setVisible(False)
#self.searchEdit.setVisible(False)
#self.searchLabel.setVisible(False)
self.ui.toggleViewButton.setText('Montrer le sélecteur')
self.sourceList.setVisible(False)
self.filterGroupbox.setVisible(False)
else:
#self.searchEdit.setVisible(True)
#self.searchLabel.setVisible(True)
self.ui.toggleViewButton.setText('Cacher le sélecteur')
self.sourceList.setVisible(True)
self.filterGroupbox.setVisible(True)
#-------------------------------------------------------------------------
def hide_source_list(self):
#contrarily to toggle_tab_view hide the selector whatever the visibility of it
self.ui.toggleViewButton.setText('Montrer le sélecteur')
self.sourceList.setVisible(False)
self.filterGroupbox.setVisible(False)
self.ui.toggleViewButton.setVisible(False)
#---------------------------------------------------------------------------
def prepare_form_for_add(self):
#prepare the form for additional values when adding an item from source list to destination list
self.ui.importButton.setText('Ajouter à la recette')
self.ui.importButton.setVisible(True)
self.ui.deleteButton.setVisible(False)
self.ui.controlGroupBox.setVisible(True)
match self.what:
case'fermentable':
#self.show_fermentable_control_group()
self.ui.fermentableQuantityEdit.setText('')
self.ui.fermentableUsageCombo.setCurrentText('')
case 'hop':
#self.show_hop_control_group()
self.ui.hopQuantityEdit.setText('')
self.ui.hopUsageCombo.setCurrentText('')
self.ui.hopUtilisationEdit.setText('')
self.ui.hopMultiplicatorEdit.setText('')
self.ui.hopDaysEdit.setText('')
self.ui.hopHoursEdit.setText('')
self.ui.hopMinutesEdit.setText('')
self.ui.hopTemperatureEdit.setText('')
self.ui.looseCheckBox.setChecked(False)
case 'misc':
self.ui.miscQuantityEdit.setText('')
self.ui.miscReferenceVolumeEdit.setText('')
self.ui.miscMassUnitLabel.setText(self.source_selection.unit)
self.ui.miscUsageEdit.setText('')
case 'yeast':
self.ui.pitchingRateSpinBox.setValue(0)
#self.ui.yeastReferencVolumeEdit.setText('')
self.ui.yeastPitchingRateUnitLabel.setText('10⁹ cel./litre/plato')
case 'rest' :
self.ui.restDurationEdit.setText(str(self.source_selection.duration))
self.ui.restTemperatureEdit.setText(str(self.source_selection.temperature))
self.ui.thicknessReferenceCheckbox.setChecked(False)
#-----------------------------------------------------------------------------------------
def prepare_form_for_update(self):
#prepare the form of additional values for update in the destination liste
self.ui.importButton.setText('Mettre à jour')
self.ui.importButton.setVisible(True)
self.ui.deleteButton.setVisible(True)
self.ui.controlGroupBox.setVisible(True)
match self.what:
case 'fermentable':
#self.show_fermentable_control_group()
self.ui.fermentableQuantityEdit.setText(str(round(self.destination_selection.quantity,3)))
self.ui.fermentableUsageCombo.setCurrentText(self.destination_selection.usage)
self.ui.fermentableSteepingEdit.setText(str(round(self.destination_selection.steep_potential)))