-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_root_gui_v2.py
More file actions
1880 lines (1547 loc) · 94.3 KB
/
Copy pathread_root_gui_v2.py
File metadata and controls
1880 lines (1547 loc) · 94.3 KB
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
#----------------------------------------------------------------------------
# Created by : Chloé Legué
# Current version date : 2024/04/12
# Version = 2.5.12
#----------------------------------------------------------------------------
"""
This code was made for the coincidence experiment at McGill University.
The code allows the user to choose a folder containing the results saved from the CoMPASS software from CAEN. This code should be used with the CAEN DT5751, or any other digitizer from CAEN that work in the same way.
This code is able to reproduce the important graphs that the CoMPASS software makes like MCS Graph, Energy Histogram and TOF Histogram. Other graphs can be added if needed.
"""
#----------------------------------------------------------------------------
# Imports
import os as os
import sys as sys
#----------------------------------------------------------------------------
# Other imports from ReadROOT
# Import the root reader API:
from . import read_root
root_reader = read_root.root_reader_v2
# Import the XML file parsing and info parsing (used for the CoMPASS tab):
from . import XML_Parser
InfoParser = XML_Parser.InfoParser
XMLParser = XML_Parser.XMLParser
# Import QtClasses for extra widgets (used for the GUI):
from . import QtClasses
IconLabel = QtClasses.IconLabel
Seperator = QtClasses.Seperator
SelectionBox = QtClasses.SelectionBox
Selecter = QtClasses.Selecter
Logger = QtClasses.Logger
bcolors = QtClasses.bcolors
# Import the Merger (Fast TOF calculations):
from . import merge
Merger = merge.Merger
Merger.unfilter_data = True
Converter = merge.Converter
#----------------------------------------------------------------------------
# General libraries imports
import spinmob as s #type: ignore
import spinmob.egg as egg #type: ignore
import numpy as np
# import tkinter.filedialog as fd
import pyqtgraph as pg #type: ignore
import ctypes as ct
import pyqtgraph.exporters as export #type: ignore
import darkdetect as dd #type: ignore
from PyQt5 import QtGui, QtCore, QtWidgets
import superqt, datetime
import pyautogui as p
#----------------------------------------------------------------------------
g = egg.gui
Horizontal = QtCore.Qt.Orientation.Horizontal
Vertical = QtCore.Qt.Orientation.Vertical
parameters_xml_aliases = {"INPUT":{"Enable":"SRV_PARAM_CH_ENABLED",
"Record length":"SRV_PARAM_RECLEN",
"Pre-trigger":"SRV_PARAM_CH_PRETRG",
"Polarity":"SRV_PARAM_CH_POLARITY",
"N samples baseline":"SRV_PARAM_CH_BLINE_NSMEAN",
"Fixed baseline value":"SRV_PARAM_CH_BLINE_FIXED",
"DC Offset":"SRV_PARAM_CH_BLINE_DCOFFSET",
"Calibrate ADC":"SRV_PARAM_ADCCALIB_ONSTART_ENABLE",
"Input dynamic":"SRV_PARAM_CH_INDYN",
"Analog Traces Fine Resolution":"SRV_PARAM_ANALOGTR_FINERES_ENABLE"},
"DISCRIMINATOR":{"Discriminator mode":"SRV_PARAM_CH_DISCR_MODE",
"Threshold":"SRV_PARAM_CH_THRESHOLD",
"Trigger holdoff":"SRV_PARAM_CH_TRG_HOLDOFF",
"CFD delay":"SRV_PARAM_CH_CFD_DELAY",
"CFD fraction":"SRV_PARAM_CH_CFD_FRACTION"},
"QDC":{"Energy coarse gain":"SRV_PARAM_CH_ENERGY_COARSE_GAIN",
"Gate":"SRV_PARAM_CH_GATE",
"Short gate":"SRV_PARAM_CH_GATESHORT",
"Pre-gate":"SRV_PARAM_CH_GATEPRE",
"Charge pedestal":"SRV_PARAM_CH_PEDESTAL_EN"},
"SPECTRA":{"Energy N channels":"SRV_PARAM_CH_SPECTRUM_NBINS",
"PSD N channels":"SW_PARAMETER_PSDBINCOUNT",
"Time intervals N channels":"SW_PARAMETER_DISTRIBUTION_BINCOUNT",
"Time intervals Tmin":"SW_PARAMETER_TIME_DISTRIBUTION_CH_T0",
"Time intervals Tmax":"SW_PARAMETER_TIME_DISTRIBUTION_CH_T1",
"Start-stop Δt N channels":"SW_PARAMETER_DIFFERENCE_BINCOUNT",
"Start-stop Δt Tmin":"SW_PARAMETER_TIME_DIFFERENCE_CH_T0",
"Start-stop Δt Tmax":"SW_PARAMETER_TIME_DIFFERENCE_CH_T1",
"2D Energy N channels":"SW_PARAMETER_E2D_BINCOUNT",
"2D PSD N channels":"SW_PARAMETER_PSD2D_BINCOUNT",
"2D Δt N channels":"SW_PARAMETER_TOF2D_BINCOUNT"},
"REJECTIONS":{"Saturation rejection":"SW_PARAM_CH_SATURATION_REJECTION_ENABLE",
"Pileup rejection":"SW_PARAM_CH_PUR_ENABLE",
"E low cut":"SW_PARAMETER_CH_ENERGYLOWCUT",
"E high cut":"SW_PARAMETER_CH_ENERGYHIGHCUT",
"E cut enable":"SW_PARAMETER_CH_ENERGYCUTENABLE",
"PSD low cut":"SW_PARAMETER_CH_PSDLOWCUT",
"PSD high cut":"SW_PARAMETER_CH_PSDHIGHCUT",
"PSD cut enable":"SW_PARAMETER_CH_PSDCUTENABLE",
"Time intervals low cut":"SW_PARAMETER_CH_TIMELOWCUT",
"Time intervals high cut":"SW_PARAMETER_CH_TIMEHIGHCUT",
"Time intervals cut enable":"SW_PARAMETER_CH_TIMECUTENABLE"},
"ENERGY CALIBRATION":{"C0":"SW_PARAMETER_CH_ENERGY_CALIBRATION_P0",
"C1":"SW_PARAMETER_CH_ENERGY_CALIBRATION_P1",
"C2":"SW_PARAMETER_CH_ENERGY_CALIBRATION_P2",
"Units":"SW_PARAMETER_CH_ENERGY_CALIBRATION_UDM"},
"SYNC":{"External clock source":"SRV_PARAM_DT_EXT_CLOCK",
"Start mode":"SRV_PARAM_START_MODE",
"TRG OUT-GPO mode":"SRV_PARAM_TRGOUT_MODE",
"Start delay":"SRV_PARAM_START_DELAY",
"Channel time offset":"SRV_PARAM_CH_TIME_OFFSET"},
"ONBOARD COINCIDENCES":{"Coincidence mode":"SRV_PARAM_COINC_MODE",
"Coincidence window":"SRV_PARAM_COINC_TRGOUT"},
"MISC":{"Label":"SW_PARAMETER_CH_LABEL",
"FPIO type":"SRV_PARAM_IOLEVEL",
"Rate optimization":"SRV_PARAM_EVENTAGGR"}}
parameters_types = {"INPUT":{"Enable":'bool',
"Record length":'float',
"Pre-trigger":'float',
"Polarity":'str',
"N samples baseline":'str',
"Fixed baseline value":'str',
"DC Offset":'float',
"Calibrate ADC":'bool',
"Input dynamic":'float',
"Analog Traces Fine Resolution":'bool'},
"DISCRIMINATOR":{"Discriminator mode":'str',
"Threshold":'float',
"Trigger holdoff":'float',
"CFD delay":'float',
"CFD fraction":'float'},
"QDC":{"Energy coarse gain":'str',
"Gate":'float',
"Short gate":'float',
"Pre-gate":'float',
"Charge pedestal":'bool'},
"SPECTRA":{"Energy N channels":'str',
"PSD N channels":'str',
"Time intervals N channels":'str',
"Time intervals Tmin":'float',
"Time intervals Tmax":'float',
"Start-stop Δt N channels":'str',
"Start-stop Δt Tmin":'float',
"Start-stop Δt Tmax":'float',
"2D Energy N channels":'str',
"2D PSD N channels":'str',
"2D Δt N channels":'str'},
"REJECTIONS":{"Saturation rejection":'bool',
"Pileup rejection":'bool',
"E low cut":'str',
"E high cut":'str',
"E cut enable":'bool',
"PSD low cut":'str',
"PSD high cut":'str',
"PSD cut enable":'bool',
"Time intervals low cut":'str',
"Time intervals high cut":'str',
"Time intervals cut enable":'bool'},
"ENERGY CALIBRATION":{"C0":'float',
"C1":'float',
"C2":'float',
"Units":'str'},
"SYNC":{"External clock source":'bool',
"Start mode":'str',
"TRG OUT-GPO mode":'str',
"Start delay":'float',
"Channel time offset":'float'},
"ONBOARD COINCIDENCES":{"Coincidence mode":'str',
"Coincidence window":'float'},
"MISC":{"Label":'str',
"FPIO type":'str',
"Rate optimization":'float'}}
parameters_units = {"INPUT":{"Record length":'s',
"Pre-trigger":'s',
"DC Offset":'%',
"Input dynamic":'Vpp'},
"DISCRIMINATOR":{"Threshold":'lsb',
"Trigger holdoff":'s',
"CFD delay":'s',
"CFD fraction":'%'},
"QDC":{"Gate":'s',
"Short gate":'s',
"Pre-gate":'s'},
"SPECTRA":{"Time intervals Tmin":'s',
"Time intervals Tmax":'s',
"Start-stop Δt Tmin":'s',
"Start-stop Δt Tmax":'s'},
"ONBOARD COINCIDENCES":{"Coincidence window":'s'}}
def add_color(tree_dict:g.TreeDictionary, name: str, parent: bool, default: QtGui.QColor = None):
"""Adds a color picker item to the selected `TreeDictionary`
Parameters
----------
tree_dict : g.TreeDictionary
The `TreeDictionary` to which we want to add a color picker
name : str
The name of the variable for the color picker
parent : bool
Whether the color picker will have a parent or not.
default : tuple
RGBA default value given to the color picker
"""
if not parent:
widget = tree_dict._widget
param = pg.parametertree.Parameter.create(name=name,type="color",default=default, value=default) if default is not None else pg.parametertree.Parameter.create(name=name,type="color", value=default)
widget.addParameters(param)
tree_dict.connect_any_signal_changed(tree_dict.autosave)
else:
s = name.split('/')
name = s.pop(-1)
branch = tree_dict._find_parameter(s, create_missing=True)
param = pg.parametertree.Parameter.create(name=name, type="color",default=default, value=default) if default is not None else pg.parametertree.Parameter.create(name=name,type="color", value=default)
branch.addChild(param)
def removeItem(combo_box: g.ComboBox, name: str):
"""Removes an item from a `ComboBox`
Parameters
----------
combo_box : g.ComboBox
Selected `ComboBox`
name : str
Item to remove
"""
index_to_remove = combo_box.get_index(name)
combo_box.remove_item(index_to_remove)
class GUIv2():
"""Class `GUIv2` : Creates a GUIv2 instance that the user can interact with.
Parameters
----------
name : str, optional
Name of the window, by default `"GUIv2"`
window_size : list, optional
Default window size, by default `[1000,500]`
show : bool, optional
Shows the GUI to the user, by default `True`
block : bool, optional
Blocks the command line, by default `False`
ratio : float, optional
Scale factor of the GUI, by default `None` and will be fetched if possible (defaults to 1 otherwise)
full_screen : bool, optional
Shows the GUI in fullscreen, by default `True`
dark_theme : bool, optional
Forces the GUI into its dark mode or light mode (if `False`), by default `None` and will be fetched to match the user's default theme.
compress : bool, optional
Chooses the compression type of the `.csv` files saved by the GUI, by default `True` which turns on `bz2` compression.
"""
def __init__(self, name="GUIv2", window_size=[1000,500], show: bool = True, block: bool = False, ratio: float = None, full_screen: bool = True, dark_theme: bool = None, compress: bool = True):
os.chdir(os.path.dirname(os.path.abspath(__file__)))
self.ratio = self.get_scale_factor() if ratio is None else ratio #This is used to scale the GUI on different screen resolutions. Note that this will only work on Windows.
self.dark_theme_on = dd.isDark() if dark_theme is None else dark_theme
Converter.compress = compress
self.colormap = pg.colormap.getFromMatplotlib("black_turbo") if self.dark_theme_on else pg.colormap.getFromMatplotlib("white_turbo")
self.margins = int(10/3*self.ratio)
width, height = self.get_screen_resolution()
width = int(window_size[0]/1680*width)
height = int(window_size[1]/1050*height)
IconLabel.IconSize = IconLabel.new_icon_size(int(35/3*self.ratio))
primary, secondary, accent = self.create_colors()
window = g.Window(name, size=[width, height], autosettings_path=name+"_window.txt")
window._window.setWindowIcon(QtGui.QIcon("Images/CoMPASS/icon64x64.png"))
if sys.platform.startswith("win"): #This will set the icon to the taskbar. Will only work on windows, I have no idea how this should be done on MacOs.
myappid = 'mycompany.myproduct.subproduct.version' # arbitrary string
ct.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
self.TopGrid = window.place_object(g.GridLayout(True)).set_height(int(52*self.ratio))#.set_width(1273*self.ratio)
window.new_autorow()
self.BotGrid = window.place_object(g.GridLayout(True), alignment=0)
#Change the top grid's color.
self.TopGrid._widget.setAutoFillBackground(True)
temp_palette = self.TopGrid._widget.palette()
temp_palette.setColor(self.TopGrid._widget.backgroundRole(), accent)
self.TopGrid._widget.setPalette(temp_palette)
self.TopGrid.set_column_stretch(1,1)
#Set the margins for the top and bottom grid.
self.TopGrid.set_margins(self.margins)
self.BotGrid.set_margins(self.margins)
#This is for the lines, pens, brushes, graph types and root data.
self.lines = {"No lines for now.":None} # This is to show the lines in the graph tab.
self.pens = {}
self.brushes = {}
self.graph_info = {}
self.previous_line = None
self.data = {}
#Generate the top grid
self.generate_top_grid()
#Qt Style sheets for changing the TreeDictionary colors
self.dark_tree = """
QTreeView {
background-color: rgb(23, 35, 38);
selection-background-color: rgb(32, 81, 96);
}
QTreeView::disabled{
background-color: rgb(29,29,29);
selection-background-color: rgb(72,72,72);
}
"""
self.light_tree = """
QTreeView {
background-color: rgb(208, 244, 254);
selection-background-color: rgb(165, 230, 248);
alternate-background-color: white;
}
QTreeView::disabled{
background-color: rgb(185,185,185);
selection-background-color: rgb(175,175,175);
alternate-background-color: white;
}
"""
#Qt Style sheets for changing the ComboBox colors
self.dark_combo = """
QComboBox {
background-color: rgb(32, 81, 96);
selection-background-color: rgb(24, 132, 165);
}
QComboBox::disabled {
background-color: rgb(72,72,72);
selection-background-color: rgb(111,111,111);
}
"""
self.light_combo = """
QComboBox {
background-color: rgb(61, 145, 169);
selection-background-color: rgb(111, 205, 231);
}
QComboBox::disabled {
background-color: rgb(121,121,121);
selection-background-color: rgb(158,158,158);
}
"""
#Qt Style sheets for sliders:
self.QSS_dark = """
QSlider::groove:horizontal{
""" + f"height:{int(20/3*self.ratio)}px;" + """
}
QRangeSlider{
qproperty-barColor: qlineargradient(x1:0, y1:0, x2: 1, y2: 1, stop:0 rgb(120,225,252), stop:1 #77a);
}
QSlider::handle{
background-color: rgb(61,61,61);
border: 2px solid rgb(40,40,40);
""" + f"border-radius: {int(22/3*self.ratio)}px;" + """
}
QSlider::handle:horizontal:hover{
""" + f"border-radius: {int(10/3*self.ratio)}px;" + """
}
"""
self.QSS_light = """
QSlider::groove:horizontal{
""" + f"height:{int(20/3*self.ratio)}px;" + """
}
QRangeSlider{
qproperty-barColor: qlineargradient(x1:0, y1:0, x2: 1, y2: 1, stop:0 rgb(120,225,252), stop:1 #77a);
}
QSlider::handle{
background-color: white;
border: 2px solid rgb(193,193,193);
""" + f"border-radius: {int(22/3*self.ratio)}px;" + """
}
QSlider::handle:horizontal:hover{
""" + f"border-radius: {int(10/3*self.ratio)}px;" + """
}
"""
#Change the color and icons of tree dictionary for the ROOT type
temp_widget = self.root_dict._widget
temp_widget.setStyleSheet(self.dark_tree) if self.dark_theme_on else temp_widget.setStyleSheet(self.light_tree)
a = self.root_dict.get_widget("ROOT Types")
a.setIcon(0,QtGui.QIcon("Images/file_config.png"))
#Generate the bot grid
self.generate_bot_grid()
#Change the color and icons of tree dictionary for the run info
temp_widget = self.run_dict._widget
temp_widget.setStyleSheet(self.dark_tree) if self.dark_theme_on else temp_widget.setStyleSheet(self.light_tree)
a = self.run_dict.get_widget("Run Info")
a.setIcon(0,QtGui.QIcon("Images/info.png"))
#Change the color and icons of tree dictionaries for the board info
temp_widget = self.board_dict_1._widget
temp_widget.setStyleSheet(self.dark_tree) if self.dark_theme_on else temp_widget.setStyleSheet(self.light_tree)
a = self.board_dict_1.get_widget("Board Info")
a.setIcon(0,QtGui.QIcon("Images/info.png"))
temp_widget = self.board_dict_2._widget
temp_widget.setStyleSheet(self.dark_tree) if self.dark_theme_on else temp_widget.setStyleSheet(self.light_tree)
temp_widget = self.board_dict_3._widget
temp_widget.setStyleSheet(self.dark_tree) if self.dark_theme_on else temp_widget.setStyleSheet(self.light_tree)
#Change the color and icons of tree dictionary for the plot settings
temp_widget = self.plot_settings_dict._widget
temp_widget.setStyleSheet(self.dark_tree) if self.dark_theme_on else temp_widget.setStyleSheet(self.light_tree)
a = self.plot_settings_dict.get_widget("General Settings")
a.setIcon(0,QtGui.QIcon("Images/settings.png"))
a = self.plot_settings_dict.get_widget("Axis")
a.setIcon(0,QtGui.QIcon("Images/axis.png"))
a = self.plot_settings_dict.get_widget("Grid")
a.setIcon(0,QtGui.QIcon("Images/grid.png"))
a = self.plot_settings_dict.get_widget("Line")
a.setIcon(0,QtGui.QIcon("Images/line.png"))
a = self.plot_settings_dict.get_widget("Histogram")
a.setIcon(0,QtGui.QIcon("Images/histogram.png"))
#Make the grid layout for the plot buttons another color:
self.inner_left._widget.setAutoFillBackground(True)
temp_palette = self.inner_left._widget.palette()
temp_palette.setColor(self.inner_left._widget.backgroundRole(), accent)
self.inner_left._widget.setPalette(temp_palette)
#Load all the settings for the graphs:
self.load_graph_options()
s.settings["dark_theme_qt"] = self.dark_theme_on
if full_screen: window._window.showMaximized()
if show: window.show(block)
def get_screen_resolution(self) -> tuple[int, int]:
"""Gets the resolution of a screen
Returns
-------
tuple[int, int]
Output tuple containing the width and height of the screen.
"""
screen_size = p.size()
return (screen_size.width, screen_size.height)
def get_scale_factor(self) -> float:
"""Gets the scale factor of your screen. This will only work on Windows machines.
Returns
-------
scale_factor : float
Scale factor of your device.
"""
if sys.platform.startswith("win"):
#Works only for Windows since we are working with dll.
return float(ct.windll.shcore.GetScaleFactorForDevice(0)/100)
else:
return 1
def generate_top_grid(self):
"""Generates the top grid with the buttons of the GUI"""
#For the channel buttons:
self.previous_btn = None
#Search folder button
search_folder_btn = self.TopGrid.place_object(g.Button(" ",tip="Search a folder!")).set_width(int(45*self.ratio)).set_height(int(45*self.ratio))
search_folder_btn.set_style_unchecked(style="image: url(Images/OpenFolder.png)")
search_folder_btn.signal_clicked.connect(self.search_folder)
#File type (Raw, unfiltered, filtered)
self.root_dict = self.TopGrid.place_object(g.TreeDictionary(), alignment=0).set_width(int(245*self.ratio)).set_height(int(40*self.ratio))
self.root_dict.add_parameter("ROOT Types/Type chosen",values=["RAW","UNFILTERED","FILTERED"])#.set_width(150*self.ratio)
self.root_dict.connect_signal_changed("ROOT Types/Type chosen", self.changing_tree)
self.root_dict._widget.setHeaderLabels(["Parameters long","Value"])
#Label to show what file was selected
self.folder_label = self.TopGrid.place_object(g.Label("No folder selected!"))
#Channel Buttons
self.ch0_btn = self.make_channel_btn(self.TopGrid, "0", 45, self.channel_toggling)
self.ch1_btn = self.make_channel_btn(self.TopGrid, "1", 45, self.channel_toggling)
self.ch2_btn = self.make_channel_btn(self.TopGrid, "2", 45, self.channel_toggling)
self.ch3_btn = self.make_channel_btn(self.TopGrid, "3", 45, self.channel_toggling)
self.TopGrid.place_object(g.GridLayout()).set_width(int(680*self.ratio))
def generate_bot_grid(self):
"""Generates the bottom grid of the GUI. This contains most of the GUI, like the CoMPASS and Graph tabs,"""
main_tab_area = self.BotGrid.place_object(g.TabArea(), alignment=0)
main_tab_area._widget.setTabsClosable(False) #To not pop out the tabs by accident. This removes the icons if done.
self.compass_tab = main_tab_area.add_tab("CoMPASS")
self.graph_tab = main_tab_area.add_tab("GRAPH")
#Add the icons
main_tab_area._widget.setTabIcon(0, QtGui.QIcon("Images/CoMPASS/icon64x64.ico"))
main_tab_area._widget.setTabIcon(1, QtGui.QIcon("Images/CoMPASS/OpenGraph.png"))
self.generate_compass_tab()
self.generate_graph_tab()
Logger.text_width = int(1265*self.ratio)
self.logs = Logger(main_tab_area)
main_tab_area.set_current_tab(0)
def generate_compass_tab(self):
"""Generates the CoMPASS tab with all of the `TreeDictionary` containing the information of the `.xml` file saved by CoMPASS. All the run settings will also be loaded such that the user can read and note the values used for a specific run."""
self.run_dict = self.compass_tab.place_object(g.TreeDictionary(),alignment=0,column_span=3).set_height(int(100*self.ratio))
self.run_dict._widget.setHeaderLabels(["Parameters long","Value"])
self.run_dict.add_parameter("Run Info/Run ID", value=" ", readonly=True,tip="Run ID name set in CoMPASS/Folder name in which files are saved.")
self.run_dict.add_parameter("Run Info/Start Time", value=" ", readonly=True, tip="Time at which the acquisition started.")
self.run_dict.add_parameter("Run Info/Stop Time", value=" ", readonly=True, tip="Time at which the acquisition stopped.")
self.run_dict.add_parameter("Run Info/Run Time", value=" ", readonly=True, tip="Amount of time the acquisition ran for.")
self.compass_tab.new_autorow()
self.board_dict_1 = self.compass_tab.place_object(g.TreeDictionary(),alignment=0).set_height(int(100*self.ratio))
self.board_dict_1._widget.setHeaderLabels(["Parameters Long","Value"])
self.board_dict_1.add_parameter("Board Info/Name", value=" ", readonly=True, tip="Name of the digitizer in use.")
self.board_dict_1.add_parameter("Board Info/ADC bits", value=" ", readonly=True, tip="Number of binary digits used to represent digital data from the digitizer.")
self.board_dict_1.add_parameter("Board Info/ROC firmware", value=" ", readonly=True)
self.board_dict_1.add_parameter("Board Info/Link", value=" ", readonly=True)
self.board_dict_2 = self.compass_tab.place_object(g.TreeDictionary(),alignment=0).set_height(int(100*self.ratio))
self.board_dict_2._widget.setHeaderLabels(["Parameters Long","Value"])
self.board_dict_2.add_parameter(" /ID", value=" ", readonly=True)
self.board_dict_2.add_parameter(" /Sampling rate", value=None, type="float", readonly=True, suffix="S/s", siPrefix=True)
self.board_dict_2.add_parameter(" /AMC firware", value=" ", readonly=True)
self.board_dict_3 = self.compass_tab.place_object(g.TreeDictionary(),alignment=0).set_height(int(100*self.ratio))
self.board_dict_3._widget.setHeaderLabels(["Parameters Long","Value"])
self.board_dict_3.add_parameter(" /Model", value=" ", readonly=True, tip="Model of the digitizer in use.")
self.board_dict_3.add_parameter(" /DPP type", value=" ", readonly=True)
self.board_dict_3.add_parameter(" /Enable", value=False, readonly=True,tip="Whether the digitizer can be used or not.")
self.compass_tab.new_autorow()
embed_compass_tab_area = self.compass_tab.place_object(g.TabArea(),alignment=0,column_span=3)
embed_compass_tab_area._widget.setTabsClosable(False) #Same as before if they pop out the icons are gone.
#Create the new tabs
input_tab = embed_compass_tab_area.add_tab("INPUT")
disc_tab = embed_compass_tab_area.add_tab("DISCRIMINATOR")
qdc_tab = embed_compass_tab_area.add_tab("QDC")
spectra_tab = embed_compass_tab_area.add_tab("SPECTRA")
rejection_tab = embed_compass_tab_area.add_tab("REJECTIONS")
energy_tab = embed_compass_tab_area.add_tab("ENERGY CALIBRATION")
sync_tab = embed_compass_tab_area.add_tab("SYNC/TRG")
coincidence_tab = embed_compass_tab_area.add_tab("ONBOARD COINCIDENCES")
misc_tab = embed_compass_tab_area.add_tab("MISCELLANEOUS")
#Add the icons of those tabs
input_icon = QtGui.QIcon('Images/CoMPASS/Input.png')
disc_icon = QtGui.QIcon('Images/CoMPASS/Discriminator.png')
qdc_icon = QtGui.QIcon('Images/CoMPASS/QDC.png')
spectra_icon = QtGui.QIcon('Images/CoMPASS/Spectra.png')
rejection_icon = QtGui.QIcon('Images/CoMPASS/Rejections.png')
energy_icon = QtGui.QIcon('Images/CoMPASS/EnergyCalibration.png')
sync_icon = QtGui.QIcon('Images/CoMPASS/Sync.png')
coinc_icon = QtGui.QIcon('Images/CoMPASS/Coincidence.png')
misc_icon = QtGui.QIcon('Images/CoMPASS/Misc.png')
icon_list = [input_icon, disc_icon, qdc_icon, spectra_icon, rejection_icon, energy_icon, sync_icon, coinc_icon, misc_icon]
_w = embed_compass_tab_area._widget
[_w.setTabIcon(index, item) for index, item in enumerate(icon_list)]
embed_compass_tab_area.set_current_tab(0)
#Make the settings tab:
self.input_channel, self.input_dict = self.make_comp_settings_tab(input_tab, "INPUT")
self.disc_channel, self.disc_dict = self.make_comp_settings_tab(disc_tab, "DISCRIMINATOR")
self.qdc_channel, self.qdc_dict = self.make_comp_settings_tab(qdc_tab, "QDC")
self.spectra_channel, self.spectra_dict = self.make_comp_settings_tab(spectra_tab, "SPECTRA")
self.reject_channel, self.reject_dict = self.make_comp_settings_tab(rejection_tab, "REJECTIONS")
self.energy_channel, self.energy_dict = self.make_comp_settings_tab(energy_tab, "ENERGY CALIBRATION")
self.sync_channel, self.sync_dict = self.make_comp_settings_tab(sync_tab, "SYNC")
self.coinc_channel, self.coinc_dict = self.make_comp_settings_tab(coincidence_tab, "ONBOARD COINCIDENCES")
self.misc_channel, self.misc_dict = self.make_comp_settings_tab(misc_tab, "MISC")
[channel.signal_changed.connect(self.reload_channels) for channel in [self.input_channel, self.disc_channel, self.qdc_channel, self.spectra_channel, self.reject_channel, self.energy_channel, self.sync_channel, self.misc_channel]]
def generate_graph_tab(self):
"""Generates the Graph tab which contains the plot zone and all of the different histogram buttons and settings."""
grid_left = self.graph_tab.place_object(g.GridLayout(False), alignment=0)
grid_right = self.graph_tab.place_object(g.GridLayout(False), alignment=0).set_width(int(300*self.ratio))
#Make some grids inside the right side grid.
grid_top = grid_right.place_object(g.GridLayout(False),1,1).set_height(int(50*self.ratio))
grid_bot = grid_right.place_object(g.GridLayout(False),1,2)
#Make the line selection center:
self.line_selector = grid_top.place_object(g.ComboBox(items=list(self.lines.keys()))).set_width(int(195*self.ratio)).set_height(int(45*self.ratio))
self.line_selector._widget.setStyleSheet(self.dark_combo) if self.dark_theme_on else self.line_selector._widget.setStyleSheet(self.light_combo)
self.line_selector.signal_changed.connect(self.change_line_highlight)
save_btn = grid_top.place_object(g.Button(" ")).set_height(int(45*self.ratio)).set_width(int(45*self.ratio))
save_btn.set_style_unchecked(style="image: url(Images/save.png)")
save_btn.signal_clicked.connect(self.save_changes)
delete_btn = grid_top.place_object(g.Button(" ")).set_height(int(45*self.ratio)).set_width(int(45*self.ratio))
delete_btn.set_style_unchecked(style="image: url(Images/delete.png)")
delete_btn.signal_clicked.connect(self.delete)
#Make a collapsible zone for the plot settings
plot_collapsible = grid_bot.place_object(superqt.QCollapsible("Plot Settings",expandedIcon=QtGui.QIcon("Images/expanded.png"),collapsedIcon=QtGui.QIcon("Images/collapsed.png")))
self.make_plot_settings(plot_collapsible)
#Make a collapsible zone
grid_bot.new_autorow()
self.collapsible = grid_bot.place_object(superqt.QCollapsible("TOF Settings", expandedIcon=QtGui.QIcon("Images/expanded.png"),collapsedIcon=QtGui.QIcon("Images/collapsed.png")))
self.make_collapsible_section(self.collapsible)
#Make the plotting region
self.inner_left = grid_left.place_object(g.GridLayout(False), alignment=0).set_width(int(40*self.ratio))
inner_right = grid_left.place_object(g.GridLayout(False), alignment=0)
#Add the buttons for the different plots:
self.previous_graph_btn = None #To keep track of what was the last graph button selected.
self.energy_btn = self.make_comp_btn(self.inner_left, "New Energy Histogram", "Images/EnergyHist.png", column=1, row=1)
self.energy_btn.signal_toggled.connect(self.plot_selection)
self.psd_btn = self.make_comp_btn(self.inner_left, "New PSD Histogram", "Images/PSDHist.png", column=1, row=2)
self.psd_btn.signal_toggled.connect(self.plot_selection)
self.time_btn = self.make_comp_btn(self.inner_left, "New Time Histogram", "Images/TimeHist.png", column=1, row=3)
self.time_btn.signal_toggled.connect(self.plot_selection)
self.tof_btn = self.make_comp_btn(self.inner_left, "New TOF (Time of flight) Histogram", "Images/TOFHist.png", column=1, row=4)
self.tof_btn.signal_toggled.connect(self.tof_selection)
self.psdvse_btn = self.make_comp_btn(self.inner_left, "New PSD vs Energy Histogram", "Images/PSDvsEnergyHist.png", column=1, row=5)
self.psdvse_btn.signal_toggled.connect(self.plot_selection)
self.evse_btn = self.make_comp_btn(self.inner_left, "New Energy vs Energy Histogram", "Images/EnergyvsEnergyHist.png", column=1, row=6)
self.evse_btn.signal_toggled.connect(self.tof_selection)
self.tofvse_btn = self.make_comp_btn(self.inner_left," New TOF (Time of flight) vs Energy Histogram", "Images/TOFvsEnergyHist.png", column=1, row=7)
self.tofvse_btn.signal_toggled.connect(self.tof_selection)
self.mcs_btn = self.make_comp_btn(self.inner_left, "New MCS Graph", "Images/MCS Graph.png", column=1, row=8)
self.mcs_btn.signal_toggled.connect(self.plot_selection)
self.snapshot_btn = self.inner_left.place_object(g.Button(" ", tip="Snapshot"), alignment=0, column=1, row=9).set_height(int(35*self.ratio)).set_width(int(35*self.ratio))
self.snapshot_btn.set_style_unchecked(style="image: url(Images/SaveCompass.png)")
self.snapshot_btn.signal_clicked.connect(self.save_snapshot)
self.plot_btn = self.inner_left.place_object(g.Button(" ", tip="Plot the graph/histogram selected above"), alignment=0, column=1, row=10).set_height(int(35*self.ratio)).set_width(int(35*self.ratio))
self.plot_btn.set_style_unchecked(style="image: url(Images/PlotCompass.png)")
self.plot_btn.signal_clicked.connect(self.plot_graphs)
self.clear_btn = self.make_comp_btn(self.inner_left, "Clear plot", "Images/CompClear.png", column=1, row=11)
self.clear_btn.signal_toggled.connect(self.clear)
self.graph_buttons = [self.energy_btn, self.psd_btn, self.time_btn, self.tof_btn, self.psdvse_btn, self.evse_btn, self.tofvse_btn, self.mcs_btn]
#Adding the databox and the plot
# inner_right.new_autorow()
plot_region = inner_right.place_object(pg.PlotWidget(), alignment=0)
plot_region.setBackground("black") if self.dark_theme_on else plot_region.setBackground("white")
self.plot = plot_region.getPlotItem()
def make_plot_settings(self, parent):
"""Generates the plot settings inside of a collapsible zone"""
collapsible_grid_layout = g.GridLayout(False)
self.plot_settings_dict = collapsible_grid_layout.place_object(g.TreeDictionary(autosettings_path="GUIv2_plot_dict.txt"),alignment=0).set_width(int(275*self.ratio))
self.plot_settings_dict._widget.setHeaderLabels(["Parameters slight long","Value"])
self.plot_settings_dict.add_parameter("General Settings/Title", value=" ", tip="Title of the graph")
self.plot_settings_dict.connect_signal_changed("General Settings/Title", self.change_title)
self.plot_settings_dict.add_parameter("General Settings/Legend", value=False, tip="Shows the legend of the graph")
self.plot_settings_dict.connect_signal_changed("General Settings/Legend", self.change_legend)
self.plot_settings_dict.add_parameter("Line/Name",value=" ", tip="Name of the line")
add_color(self.plot_settings_dict, "Line/Pen Color",True, QtGui.QColor(67, 230, 110, 255))
add_color(self.plot_settings_dict, "Line/Brush Color",True, QtGui.QColor(67, 194, 230, 255))
self.plot_settings_dict.add_parameter("Grid/X Axis",value=True, tip="Shows the X-axis grid")
self.plot_settings_dict.connect_signal_changed("Grid/X Axis", self.change_grid)
self.plot_settings_dict.add_parameter("Grid/Y Axis",value=True, tip="Shows the Y-axis grid")
self.plot_settings_dict.connect_signal_changed("Grid/Y Axis", self.change_grid)
self.plot_settings_dict.add_parameter("Axis/X Label", value=" ", tip="Label of the X-axis")
self.plot_settings_dict.connect_signal_changed("Axis/X Label", self.change_labels)
self.plot_settings_dict.add_parameter("Axis/Y Label", value=" ", tip="Label of the Y-axis")
self.plot_settings_dict.connect_signal_changed("Axis/Y Label", self.change_labels)
self.plot_settings_dict.add_parameter("Axis/X Log Scale", value=False)
self.plot_settings_dict.connect_signal_changed("Axis/X Log Scale", self.change_log)
self.plot_settings_dict.add_parameter("Axis/Y Log Scale", value=False)
self.plot_settings_dict.connect_signal_changed("Axis/Y Log Scale", self.change_log)
self.plot_settings_dict.add_parameter("Axis/Min X",value=0)
self.plot_settings_dict.connect_signal_changed("Axis/Min X", self.change_min_max)
self.plot_settings_dict.add_parameter("Axis/Max X",value=100)
self.plot_settings_dict.connect_signal_changed("Axis/Max X", self.change_min_max)
self.plot_settings_dict.add_parameter("Axis/Min Y",value=0)
self.plot_settings_dict.connect_signal_changed("Axis/Min Y", self.change_min_max)
self.plot_settings_dict.add_parameter("Axis/Max Y",value=100)
self.plot_settings_dict.connect_signal_changed("Axis/Max Y", self.change_min_max)
self.plot_settings_dict.add_parameter("Histogram/X Axis bins", value=100, tip="X-axis bins")
self.plot_settings_dict.add_parameter("Histogram/Y Axis bins", value=1024, tip="Y-axis bins (for 2D histograms only)")
self.plot_settings_dict.add_parameter("Histogram/Fill Level", value=0)
self.plot_settings_dict.add_parameter("Histogram/Minimum bin", value=0, tip="For TOF and Time histograms")
self.plot_settings_dict.add_parameter("Histogram/Maximum bin", value=100, tip="For TOF and time histograms")
parent.addWidget(collapsible_grid_layout._widget)
parent.expand()
def make_collapsible_section(self, parent):
"""Generates the TOF options inside of a collapsible zone"""
collapse_grid_layout = g.GridLayout(False)
self.old_range = 500
self.old_min = 0
self.previous_start_btn = None #To keep track of what was the last start channel button selected
self.previous_stop_btn = None #To keep track of what was the last stop channel buttons selected.
# Calculate TOF button theme:
light_theme = """
QPushButton{
border: 2px solid rgb(193,193,193);
border-radius: 5px;
background-color: qlineargradient(x1:0, y1:0, x2: 1, y2: 1, stop:0 rgb(120,225,252), stop:1 rgb(119,119,170));
}
QPushButton:checked {
border: 2px solid rgb(193,193,193);
border-radius: 5px;
background-color: qlineargradient(x1:0, y1:0, x2: 1, y2: 1, stop:0 rgb(61,145,169), stop:1 rgb(78,78,128));
color: white;
}
QPushButton:hover:!pressed{
border: 2px solid rgb(193,193,193);
border-radius: 5px;
background-color: qlineargradient(x1:0, y1:0, x2: 1, y2: 1, stop:0 rgb(111,205,231), stop:1 rgb(104,104,161));
}
QPushButton:hover:checked {
border: 2px solid rgb(193,193,193);
border-radius: 5px;
background-color: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 rgb(111,205,231), stop:1 rgb(91,91,144))
color: white;
}
QPushButton:disabled{
border: 2px solid rgb(193,193,193);
border-radius: 5px;
background-color: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 rgb(159,159,159), stop:1 rgb(110,110,110));
color: white;
}
"""
dark_theme = """
QPushButton{
border: 2px solid rgb(193,193,193);
border-radius: 5px;
background-color: qlineargradient(x1:0, y1:0, x2: 1, y2: 1, stop:0 rgb(120,225,252), stop:1 rgb(119,119,170));
color: black;
}
QPushButton:checked {
border: 2px solid rgb(30,30,30);
border-radius: 5px;
background-color: qlineargradient(x1:0, y1:0, x2: 1, y2: 1, stop:0 rgb(61,145,169), stop:1 rgb(78,78,128));
color: white;
}
QPushButton:hover:!pressed{
border: 2px solid rgb(193,193,193);
border-radius: 5px;
background-color: qlineargradient(x1:0, y1:0, x2: 1, y2: 1, stop:0 rgb(111,205,231), stop:1 rgb(104,104,161));
}
QPushButton:hover:checked {
border: 2px solid rgb(193,193,193);
border-radius: 5px;
background-color: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 rgb(111,205,231), stop:1 rgb(91,91,144))
color: white;
}
QPushButton:disabled{
border: 2px solid rgb(193,193,193);
border-radius: 5px;
background-color: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 rgb(159,159,159), stop:1 rgb(110,110,110));
color: white;
}
"""
button_grid = collapse_grid_layout.place_object(g.GridLayout(False), alignment=0, column_span=2)
self.cpp_tof_btn = button_grid.place_object(g.Button("Calculate TOF", checkable=True)).set_width(int(240*self.ratio))
self.cpp_tof_btn._widget.setStyleSheet(dark_theme) if self.dark_theme_on else self.cpp_tof_btn._widget.setStyleSheet(light_theme)
self.roi_btn = self.make_channel_btn(button_grid, "SelectROI", 30, self.show_roi, tip="Show region selected by sliders")
collapse_grid_layout.new_autorow()
#MAKE SOMETHING FOR THE FILE SELECTION!
temp_grid = collapse_grid_layout.place_object(g.GridLayout(False), alignment=0, column_span=2)
self.selection = Selecter("No CSV files for now.", parent=temp_grid)
self.selection.change_button("Images/OnSelect.png","Images/OffSelect.png","Images/DisabledSelect.png",(1,196,255))
self.selection.change_combo(self.dark_combo) if self.dark_theme_on else self.selection.change_combo(self.light_combo)
self.selection.show()
self.selection.set_height(int(30*self.ratio))
self.selection.set_width(int(240*self.ratio))
collapse_grid_layout.new_autorow()
#Start label
collapse_grid_layout.place_object(IconLabel("Images/start.png","Start channel range: ", int(125*self.ratio)))
collapse_grid_layout.new_autorow()
self.start_range_hslider = collapse_grid_layout.place_object(superqt.QLabeledDoubleRangeSlider(Horizontal))
self.start_range_hslider.setMinimumWidth(int(275*self.ratio))
self.start_range_hslider.setMinimumHeight(int(40*self.ratio))
self.start_range_hslider.setStyleSheet(self.QSS_dark) if self.dark_theme_on else self.start_range_hslider.setStyleSheet(self.QSS_light)
self.start_range_hslider.setValue((0,80))
self.start_range_hslider.setRange(self.old_min,self.old_range)
self.start_range_hslider.show()
self.start_range_hslider.valueChanged.connect(self.update_roi)
collapse_grid_layout.new_autorow()
#Stop label
collapse_grid_layout.place_object(IconLabel("Images/stop.png","Stop channel range: ", int(125*self.ratio)))
collapse_grid_layout.new_autorow()
self.stop_range_hslider = collapse_grid_layout.place_object(superqt.QLabeledDoubleRangeSlider(Horizontal))
self.stop_range_hslider.setMinimumWidth(int(275*self.ratio))
self.stop_range_hslider.setMinimumHeight(int(40*self.ratio))
self.stop_range_hslider.setStyleSheet(self.QSS_dark) if self.dark_theme_on else self.stop_range_hslider.setStyleSheet(self.QSS_light)
self.stop_range_hslider.setValue((0,80))
self.stop_range_hslider.setRange(self.old_min,self.old_range)
self.stop_range_hslider.show()
self.stop_range_hslider.valueChanged.connect(self.update_roi)
collapse_grid_layout.new_autorow()
#Window label
collapse_grid_layout.place_object(IconLabel("Images/time.png","Window time: ",int(75*self.ratio)))
self.time_range = collapse_grid_layout.place_object(superqt.QQuantity("10us"))
self.time_range.setDecimals(2)
self.time_range.show()
collapse_grid_layout.new_autorow()
start_button_grid = collapse_grid_layout.place_object(g.GridLayout(False), alignment=0,column_span=2)
start_button_grid.place_object(IconLabel("Images/start.png","Start channel: ", int(75*self.ratio)))
self.ch0_start_btn = self.make_channel_btn(start_button_grid, "0", 30, self.start_channel_toggling)
self.ch1_start_btn = self.make_channel_btn(start_button_grid, "1", 30, self.start_channel_toggling)
self.ch2_start_btn = self.make_channel_btn(start_button_grid, "2", 30, self.start_channel_toggling)
self.ch3_start_btn = self.make_channel_btn(start_button_grid, "3", 30, self.start_channel_toggling)
collapse_grid_layout.new_autorow()
collapse_grid_layout.place_object(Seperator(int(125*self.ratio), int(100*self.ratio), left=int(113*self.ratio), right=int(37*self.ratio)),column_span=2)
collapse_grid_layout.new_autorow()
stop_button_grid = collapse_grid_layout.place_object(g.GridLayout(False), alignment=0, column_span=2)
stop_button_grid.place_object(IconLabel("Images/stop.png","Stop channel: ", int(75*self.ratio)))
self.ch0_stop_btn = self.make_channel_btn(stop_button_grid, "0", 30, self.stop_channel_toggling)
self.ch1_stop_btn = self.make_channel_btn(stop_button_grid, "1", 30, self.stop_channel_toggling)
self.ch2_stop_btn = self.make_channel_btn(stop_button_grid, "2", 30, self.stop_channel_toggling)
self.ch3_stop_btn = self.make_channel_btn(stop_button_grid, "3", 30, self.stop_channel_toggling)
#List of the buttons:
self.buttons_list = [self.ch0_btn, self.ch1_btn, self.ch2_btn, self.ch3_btn]
self.start_buttons_list = [self.ch0_start_btn, self.ch1_start_btn, self.ch2_start_btn, self.ch3_start_btn]
self.stop_buttons_list = [self.ch0_stop_btn, self.ch1_stop_btn, self.ch2_stop_btn, self.ch3_stop_btn]
self.start_roi = pg.LinearRegionItem(self.start_range_hslider.value(),brush=pg.mkBrush((5,255,0,50)),pen=pg.mkPen((31,88,37)),movable=False)
self.stop_roi = pg.LinearRegionItem(self.stop_range_hslider.value(),brush=pg.mkBrush((255,0,0,50)),pen=pg.mkPen((88,31,31)),movable=False)
parent.addWidget(collapse_grid_layout._widget)
def reload_csv_files(self):
"""Reloads the `.csv` files shown in the TOF options's Selecter"""
self.selection.clear()
if os.path.isdir(os.path.join(self.complete_path,"TOF Data")):
items_to_add = list(os.listdir(os.path.join(self.complete_path,"TOF Data")))
for item in items_to_add:
if item.endswith(".csv"):
split_item = item.split("_")[1:]
to_add = "_".join(split_item)
self.selection.add_item(to_add)
def make_comp_btn(self, parent, tip_text: str, url_image: str, **kwargs):
"""Makes a button with the proper disabled and pressed style sheets."""
btn = parent.place_object(g.Button(" ", checkable=True, tip=tip_text), alignment=0, **kwargs).set_height(int(35*self.ratio)).set_width(int(35*self.ratio))
btn.set_style_checked(style=f"image: url({url_image}); border: 2px solid rgb(1,196,255); background: rgb(54,54,54)") if self.dark_theme_on else btn.set_style_checked(style=f"image: url({url_image}); border: 2px solid rgb(1,196,255); background: rgb(220,220,220)")
btn.set_style_unchecked(style=f"image: url({url_image})")
return btn
def make_channel_btn(self, parent, channel_number: int, size: int, function: callable, tip: str=None, off: str=None, on:str=None, disabled:str=None):
"""Makes a channel button with the proper disabled and pressed style sheets."""
tip = f"Channel {channel_number}" if tip is None else tip
button = parent.place_object(g.Button(" ", True, tip=tip)).set_width(int(size*self.ratio)).set_height(int(size*self.ratio))
off = "Off" if off is None else off
on = "On" if on is None else on
disabled = "Disabled" if disabled is None else disabled
QSS = """
QPushButton {
""" + f"image: url(Images/{off}{channel_number}.png);" + """
}
QPushButton::checked{
""" + f"image: url(Images/{on}{channel_number}.png);" + """
border: 2px solid rgb(1,196,255);
""" + f"background: {'rgb(54,54,54)' if self.dark_theme_on else 'rgb(220,220,220)'};" + """
}
QPushButton::disabled{
""" + f"image: url(Images/{disabled}{channel_number}.png);" + """
""" + f"background: {'rgb(54,54,54)' if self.dark_theme_on else 'rgb(220,220,220)'};" + """
}
"""
button.signal_toggled.connect(function)
button._widget.setStyleSheet(QSS)
return button
def create_colors(self):
"""Returns some colors used for the GUI"""
if self.dark_theme_on:
primary_color = QtGui.QColor("#01c4ff")
secondary_color = QtGui.QColor("#0baada")
accent_color = QtGui.QColor("#205160")
else:
primary_color = QtGui.QColor("#d0f4fe")
secondary_color = QtGui.QColor("#a5e6f8")
accent_color = QtGui.QColor("#3d91a9")
return primary_color, secondary_color, accent_color
def make_comp_settings_tab(self, parent_tab, tab_type):
"""Makes a CoMPASS setting tab with the specific `TreeDictionary` entries."""
grid = parent_tab.place_object(g.GridLayout(False), alignment=0)
grid.place_object(g.Label("Channel :"))
channel_selector = grid.place_object(g.ComboBox(items=["BOARD","CH0","CH1","CH2","CH3"])).set_width(int(1200*self.ratio))
channel_selector._widget.setStyleSheet(self.dark_combo) if self.dark_theme_on else channel_selector._widget.setStyleSheet(self.light_combo)
grid.new_autorow()
tree_dict = grid.place_object(g.TreeDictionary(), alignment=0, column_span=2)
tree_dict._widget.setHeaderLabels(["Parameters are very long so here","Values"])
tree_dict._widget.setStyleSheet(self.dark_tree) if self.dark_theme_on else tree_dict._widget.setStyleSheet(self.light_tree)
for param in list(parameters_xml_aliases[tab_type].keys()):
embed_dict = parameters_units.get(tab_type)
units = embed_dict.get(param) if embed_dict is not None else None
suffixOn = False if units is None else True
type_value = parameters_types[tab_type].get(param)
if tab_type in ["REJECTIONS","ENERGY CALIBRATION","SYNC","MISC"]:
tree_dict.add_parameter(key=param, value=None, type=type_value, readonly=True)
else:
tree_dict.add_parameter(key=param, value=None, type=type_value, suffix=units, siPrefix=suffixOn, readonly=True)
return channel_selector, tree_dict
def search_folder(self):
"""Function that asks the user to look for a CoMPASS folder and loads the files and data."""
# tkinter_result = fd.askdirectory()
tkinter_result = QtWidgets.QFileDialog.getExistingDirectory()
self.complete_path = os.path.realpath(tkinter_result)
for file in os.listdir(self.complete_path):
if file.endswith(".xml"):
self.xml_file = file
if file.endswith(".info"):
self.info_file = file
if not hasattr(self, "xml_file") and not hasattr(self, "info_file"):
self.logs.add_log("The folder searching was cancelled. Please reload a folder before using any of the GUI's functions.")
return
self.folder_label.set_text("Folder selected!")
self.reload_csv_files()
self.load_info_xml()
def load_info_xml(self):
"""Loads the information from the `.xml` and `.info` files into the CoMPASS settings and run information."""
xml_file_path = self.complete_path + "\\" + self.xml_file
info_file_path = self.complete_path + "\\" + self.info_file
info_parser = InfoParser(info_file_path)
run_information = info_parser.get_run_info()
run_dict_keys = list(self.run_dict.get_keys())