-
Notifications
You must be signed in to change notification settings - Fork 16
/
pysolo_options.py
1183 lines (890 loc) · 49.2 KB
/
pysolo_options.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
# All the classes here are used in the option panel
import wx, os, cPickle
from pysolo_slices import pySoloVersion
from pysolo_path import optPath
import wx.lib.filebrowsebutton as filebrowse
from wx.lib.masked.numctrl import NumCtrl
import wx.lib.colourselect as csel
import wx.lib.masked as masked
class pySoloOption(dict):
def AddOption(self, option_name, option_type, option_checked, option_choices, option_description):
'''
Called in from the panel code, will add a new variable option_name of type option_type. Default value
will be at position option_checked of the list option_choices and option_description is used to describe
the variable in the option Frame
option_name = the name of the variable for the current panel
option_type = boolean | radio | text | multiple
option_checked = the int number indicating the position of the chosen value in option_choices. Must be 0 if option_type = text
option_choices = a list containing all the possible choices
'''
option_name = str(option_name)
ot = ['boolean', 'radio', 'text', 'multiple']
if option_type not in ot:
raise 'option_type must be one of the following: %s' % ot
if option_type == 'text':
option_checked = 0
if type(option_choices) != list: option_choices = [option_choices]
option_choices = [str(i) for i in option_choices]
self[option_name] = [option_type, option_checked, option_choices, option_description]
def GetOption(self, option_name):
'''
Retrieve Selected value of a custom Panel variable
If boolean will return True or False
If radio or check will return the value in the list option_choices
If text will return the text value as string.
'''
option_type = self[option_name][0]
option_choices = self[option_name][2]
option_checked = self[option_name][1]
if option_type == 'multiple':
value = [option_choices[v] for v in option_checked]
elif option_type == 'boolean': #for boolean first choice is always True, second choice always False
value = (int(option_checked) == 0)
elif option_type == 'text' and type(option_choices) != list:
value = option_choices
else:
value = option_choices[int(option_checked)]
return value
def GetOptionValue(self, option_name):
'''
alias of GetOption
'''
return self.GetOption(option_name)
def GetOptionType(self, option_name):
'''
return option type
'''
return self[option_name][0]
def GetOptionDescription(self, option_name):
'''
return option description
'''
return self[option_name][3]
def SetOption(self, n):
'''
'''
def LoadPreferenceFile(filename = 'pysolo.opt'):
'''
LoadPreferenceFile(filename = 'pysolo.opt')
Retrieves all user preferences from a binary file called filename
Returns three values:
PreferenceFileFound as boolean
userConfig, customUserConfig as dictionaries
'''
filename = os.path.join(optPath, filename)
try:
preferenceFile = open (filename, 'r')
userConfig, customUserConfig = cPickle.load(preferenceFile)
preferenceFile.close()
PreferenceFileFound = True
except:
#logText ('Configuration file was not found. Using default values')
userConfig = dict()
customUserConfig = dict()
#Here all the default values for all the userConfig Variables
userConfig['plotting_colors'] = ['#333333', '#0066cc', '#33cc33', '#cc0033', '#ffcc00', '#990099', '#660000', '#999999', '#99ccff', '#ccff99', '#ffcc99', '#ffff00', '#ff99cc', '#666666', '#336633', '#663366', '#ffff99', '#466086', '#ff8040', '#989e67']
userConfig['plotting_colors_name'] = ['Dark Grey', 'Blue', 'Green', 'Red', 'Yellow', 'Purple', 'Brown', 'Light Grey', 'Light Blue', 'Light Green', 'Light Pink', 'Bright Yellow', 'Pink', 'Grey', 'Dark Green', 'Dark Purple', 'Light Yellow', 'Blue Marine', 'Dark Orange', 'Olive Green']
userConfig['DAMoutput'] = '/'
userConfig['DAMinput'] = '/'
userConfig['DAMextension'] = '.txt'
userConfig['DAMtype'] = 'Channel' #Other possible choices are Monitor and Custom
userConfig['Canvas'] = 'wxmpl'
userConfig['FigureSize'] = (10, 6)#canvas size in inches
userConfig['Panels'] = dict()
userConfig['DataTypes'] = ['Regular', 'TANK', 'Video']
userConfig['RecentFiles'] = []
userConfig['crosshair'] = False
userConfig['use_std'] = True
userConfig['use_dropout'] = True
userConfig['min_sleep'] = 0
userConfig['max_sleep'] = 1400
userConfig['virtual_trikinetics'] = True
userConfig['min_distance'] = 300
userConfig['max_distance'] = 1000
userConfig['dpi'] = 250
userConfig['checkUpdate'] = False
preferenceFile = open ('pysolo.opt', 'w')
toDump = userConfig.copy(), customUserConfig.copy()
cPickle.dump (toDump, preferenceFile)
preferenceFile.close()
PreferenceFileFound = False
userConfig['option_file'] = filename
return PreferenceFileFound, userConfig, customUserConfig
PreferenceFileFound, userConfig, customUserConfig = LoadPreferenceFile()
def SavePreferenceFile(userConfig, customUserConfig):
'''
Saves all the user preferences in a binary file
the name of the file is stored in the userConfig dictionary
returns a boolean on whether the operation was successful
'''
try:
filename = userConfig['option_file']
preferenceFile = open (filename, 'w')
toDump = (userConfig, customUserConfig)
cPickle.dump (toDump, preferenceFile)
preferenceFile.close()
return True
except:
return False
class partial: #AKA curry
'''
This functions allows calling another function upon event trigger and pass arguments to it
ex buttonA.Bind (wx.EVT_BUTTON, partial(self.Print, 'Hello World!'))
'''
def __init__(self, fun, *args, **kwargs):
self.fun = fun
self.pending = args[:]
self.kwargs = kwargs.copy()
def __call__(self, *args, **kwargs):
if kwargs and self.kwargs:
kw = self.kwargs.copy()
kw.update(kwargs)
else:
kw = kwargs or self.kwargs
return self.fun(*(self.pending + args), **kw)
def CopyDict(inDict):
'''
This function is required because of a bug in the shallow copy
function of a dictionary in python.
The original copy() function would not make a shallow copy of those
dictionary keys that are of type "list"
'''
return inDict
outDict = dict()
for key in inDict:
if type(inDict[key]) == list:
outDict[key] = inDict[key][:]
elif type(inDict[key]) == dict:
outDict[key] = CopyDict(inDict[key])
else:
outDict[key] = inDict[key]
return outDict
def color_hex2dec(col_list):
'''
Takes the list of colors indicated as hex values and return
a list of colors as tuple of integer values
'''
hex_tuples = []
for color in col_list:
red, green, blue = int(color[1:3],16), int(color[3:5],16), int(color[5:],16)
hex_tuples.append((red, green, blue))
return hex_tuples
class OptionsFilesFolderPanel(wx.ScrolledWindow):
'''
Creates the panel that allow choosing general options
'''
def __init__(self, parent, user_config, customuser_config):
self.temp_userconfig = user_config
self.temp_customuserconfig = customuser_config
wx.ScrolledWindow.__init__(self, parent)
sz1 = wx.BoxSizer(wx.VERTICAL)
titleFont = wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)
items = []
items.append ( wx.StaticText(self, -1, '\nSelect the DAM Folder.') )
items[-1].SetFont(titleFont)
items.append ( wx.StaticText(self, -1, 'The folder should contain the raw data as output of the DAM monitor.\nFiles should be arranged in a hierarchy of folders of type: \\yyyy\\mm\\dd\\\n') )
items.append ( filebrowse.DirBrowseButton(self, -1, size=(400, -1), changeCallback = partial(self.dbbCallback, 'DAMinput'), startDirectory=self.temp_userconfig['DAMinput'] ))
items[-1].SetValue(self.temp_userconfig['DAMinput'])
items.append ( (wx.StaticLine(self), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5 ))
items.append ( wx.StaticText(self, -1, '\nSelect the Output Folder.') )
items[-1].SetFont(titleFont)
items.append ( wx.StaticText(self, -1, 'The folder where the .DAL and .DAD files are going to be saved.') )
items.append ( filebrowse.DirBrowseButton(self, -1, size=(400, -1), changeCallback = partial(self.dbbCallback, 'DAMoutput'), startDirectory=self.temp_userconfig['DAMoutput'] ) )
items[-1].SetValue(self.temp_userconfig['DAMoutput'])
items.append ( (wx.StaticLine(self), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5 ))
items.append ( wx.StaticText(self, -1, '\nSelect the extension of the input files.') )
items[-1].SetFont(titleFont)
items.append ( wx.StaticText(self, -1, 'What is the extension of the file containing the raw data? Default is ".txt".\nLeave blank for none.' ))
items.append ( wx.TextCtrl (self, -1, size=(100,-1), name='Select your extension' ) )
items[-1].Bind( wx.EVT_TEXT, partial(self.dbbCallback, 'DAMextension') )
items[-1].SetValue(self.temp_userconfig['DAMextension'])
items.append ( (wx.StaticLine(self), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5 ))
# Group of radio controls:
items.append ( wx.StaticText(self, -1, '\nSelect RAW Data structure.') )
items[-1].SetFont(titleFont)
items.append ( wx.StaticText(self, -1, 'Select the version of the input type file.\n') )
grid1 = wx.FlexGridSizer( 0, 1, 0, 0 )
self.DAM_version_radio = []
self.DAM_version_radio.append( wx.RadioButton( self, -1, 'Trikinetics - Channel Files', name = 'Channel', style = wx.RB_GROUP ) )
self.DAM_version_radio.append( wx.RadioButton( self, -1, 'Trikinetics - Monitor Files', name = 'Monitor' ) )
self.DAM_version_radio.append( wx.RadioButton( self, -1, 'pySolo Video - Distance', name = 'pvg_distance' ) )
self.DAM_version_radio.append( wx.RadioButton( self, -1, 'pySolo Video - Virtual Beam Split', name = 'pvg_beam' ) )
self.DAM_version_radio.append( wx.RadioButton( self, -1, 'pySolo Video - Raw Data', name = 'pvg_raw' ) )
#not active yet
#self.DAM_version_radio[-1].Enable(False)
for radio in self.DAM_version_radio:
grid1.Add( radio, 0, wx.ALIGN_LEFT|wx.LEFT|wx.RIGHT|wx.TOP, 5 )
radio.Bind(wx.EVT_RADIOBUTTON, partial(self.OnGroupSelect, 'DAMtype', bool=False ))
ck = ['Channel', 'Monitor', 'pvg_distance', 'pvg_beam', 'pvg_raw'].index(self.temp_userconfig['DAMtype'])
self.DAM_version_radio[ck].SetValue(True)
items.append (grid1)
items.append ( (wx.StaticLine(self), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5 ))
# Group of radio controls:
items.append ( wx.StaticText(self, -1, '\nAutomatically check for updates on start.') )
items[-1].SetFont(titleFont)
items.append ( wx.StaticText(self, -1, 'Do this only if your computer is always connected to the Internet.\n') )
grid1 = wx.FlexGridSizer( 0, 1, 0, 0 )
self.checkUpdate_radio = []
self.checkUpdate_radio.append( wx.RadioButton( self, -1, 'Yes', name = 'checkUpdate', style = wx.RB_GROUP ) )
self.checkUpdate_radio.append( wx.RadioButton( self, -1, 'No', name = 'no_checkUpdate' ) )
for radio in self.checkUpdate_radio:
grid1.Add( radio, 0, wx.ALIGN_LEFT|wx.LEFT|wx.RIGHT|wx.TOP, 5 )
radio.Bind(wx.EVT_RADIOBUTTON, partial(self.OnGroupSelect, 'checkUpdate', bool=True ))
ck = not self.temp_userconfig['checkUpdate']
self.checkUpdate_radio[ck].SetValue(True)
items.append (grid1)
items.append ( (wx.StaticLine(self), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5 ))
sz1.AddMany (items)
self.SetSizer(sz1)
sz1.Fit(self)
def dbbCallback(self, key, event):
self.temp_userconfig[key] = event.GetString()
def OnGroupSelect( self, key, event=None, bool=False ):
if bool:
self.temp_userconfig[key] = (event.EventObject.GetName() == key)
else:
self.temp_userconfig[key] = event.EventObject.GetName()
class OptionsVideoPanel(wx.ScrolledWindow):
'''
Create the panel to choose basic options about Video
'''
def __init__(self, parent, user_config, customuser_config):
self.temp_userconfig = user_config
self.temp_customuserconfig = customuser_config
wx.ScrolledWindow.__init__(self, parent)
sz1 = wx.BoxSizer(wx.VERTICAL)
items = []
items.append ( wx.StaticText(self, -1, '\nActivity computation system.') )
titleFont = wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)
items[-1].SetFont(titleFont)
items.append ( wx.StaticText(self, -1, 'Activity of the flies can be computed on the basis of the distance they walk\nor using a virtual TriKinetic Monitor System. In the second case, the video data will be analized counting how many times\nthe flies have crossed an imaginary line that runs in the middle of the recording area, emulating the IR system.'))
#sz1.AddMany (items)
grid1 = wx.FlexGridSizer( 0, 1, 0, 0 )
self.use_vtm_radio = []
self.use_vtm_radio.append( wx.RadioButton( self, -1, 'Use virtual Trikinetics Monitor System', name = 'virtual_trikinetics', style = wx.RB_GROUP ) )
self.use_vtm_radio.append( wx.RadioButton( self, -1, 'Use distance', name = 'no_virtual_trikinetics') )
for radio in self.use_vtm_radio:
grid1.Add( radio, 0, wx.ALIGN_LEFT|wx.LEFT|wx.RIGHT|wx.TOP, 5 )
radio.Bind(wx.EVT_RADIOBUTTON, partial(self.OnGroupSelect, 'virtual_trikinetics'))
ck = not self.temp_userconfig['virtual_trikinetics']
self.use_vtm_radio[ck].SetValue(True)
items.append (grid1)
items.append ( (wx.StaticLine(self), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5 ) )
items.append ( wx.StaticText(self, -1, '\nMinimum and Maximum distances to be called movement.') )
titleFont = wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)
items[-1].SetFont(titleFont)
items.append ( wx.StaticText(self, -1, 'Tweak the values here to define the the minimum and maximum distance (in pixel) for the movement range.\nDetected movements that will have a smaller or bigger threshold will be considered noise and ignored.\nThis setting depends on the quality of your acquisition and on your desire to detect small fly movements'))
grid2 = wx.BoxSizer(wx.HORIZONTAL)
mins = str(self.temp_userconfig['min_distance'])
maxs = str(self.temp_userconfig['max_distance'])
min_sleep = masked.TextCtrl(self , -1, mins, mask = "####")
max_sleep = masked.TextCtrl(self , -1, maxs, mask = "####")
min_sleep.Bind(wx.EVT_TEXT, partial(self.OnChangeSleepValues, 'min_distance'))
max_sleep.Bind(wx.EVT_TEXT, partial(self.OnChangeSleepValues, 'max_distance'))
grid2.Add(min_sleep, 0, wx.RIGHT, 3)
grid2.Add(max_sleep, 0, wx.LEFT, 3)
items.append(grid2)
sz1.AddMany (items)
self.SetSizer(sz1)
sz1.Fit(self)
def OnChangeSleepValues(self, key, event):
try:
self.temp_userconfig[key] = int( n )
except:
pass
def OnGroupSelect( self, key, event ):
self.temp_userconfig[key] = (event.EventObject.GetName() == key)
class OptionsSleepPanel(wx.ScrolledWindow):
'''
Create the panel to choose basic options about sleep
'''
def __init__(self, parent, user_config, customuser_config):
self.temp_userconfig = user_config
self.temp_customuserconfig = customuser_config
wx.ScrolledWindow.__init__(self, parent)
sz1 = wx.BoxSizer(wx.VERTICAL)
items = []
items.append ( wx.StaticText(self, -1, '\nUse dropout flies.') )
titleFont = wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)
items[-1].SetFont(titleFont)
items.append ( wx.StaticText(self, -1, 'A dropout fly is a fly that died during the course of the experiment, for instance during the last days.\nHere you can decide on whether you want to include in your experiments.\nNB: this option will not affect the behaviour of all the panels\n'))
#sz1.AddMany (items)
grid1 = wx.FlexGridSizer( 0, 1, 0, 0 )
self.use_dropout_radio = []
self.use_dropout_radio.append( wx.RadioButton( self, -1, 'Use dropout flies', name = 'use_dropout', style = wx.RB_GROUP ) )
self.use_dropout_radio.append( wx.RadioButton( self, -1, 'Do not use dropout flies', name = 'no_dropout' ) )
for radio in self.use_dropout_radio:
grid1.Add( radio, 0, wx.ALIGN_LEFT|wx.LEFT|wx.RIGHT|wx.TOP, 5 )
radio.Bind(wx.EVT_RADIOBUTTON, partial(self.OnGroupSelect, 'use_dropout'))
ck = not self.temp_userconfig['use_dropout']
self.use_dropout_radio[ck].SetValue(True)
items.append (grid1)
items.append ( (wx.StaticLine(self), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5 ) )
items.append ( wx.StaticText(self, -1, '\nSleep limits.') )
titleFont = wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)
items[-1].SetFont(titleFont)
items.append ( wx.StaticText(self, -1, 'Enter the min and max values that are to be used to determine which flies to use.\nOnly flies that slept more than the minimum value and less than then maximum are taken.\nValues have to be entered in minutes (24H = 1440minutes)\n'))
grid2 = wx.BoxSizer(wx.HORIZONTAL)
mins = str(self.temp_userconfig['min_sleep'])
maxs = str(self.temp_userconfig['max_sleep'])
min_sleep = masked.TextCtrl(self , -1, mins, mask = "####")
max_sleep = masked.TextCtrl(self , -1, maxs, mask = "####")
min_sleep.Bind(wx.EVT_TEXT, partial(self.OnChangeSleepValues, 'min_sleep'))
max_sleep.Bind(wx.EVT_TEXT, partial(self.OnChangeSleepValues, 'max_sleep'))
grid2.Add(min_sleep, 0, wx.RIGHT, 3)
grid2.Add(max_sleep, 0, wx.LEFT, 3)
items.append(grid2)
sz1.AddMany (items)
self.SetSizer(sz1)
sz1.Fit(self)
def OnChangeSleepValues(self, key, event):
try:
self.temp_userconfig[key] = int( event.EventObject.GetValue() )
except:
pass
def OnGroupSelect( self, key, event ):
self.temp_userconfig[key] = (event.EventObject.GetName() == key)
class OptionsGraphPanel(wx.ScrolledWindow):
'''
Create the panel to choose basic options about graphs
'''
def __init__(self, parent, user_config, customuser_config):
self.temp_userconfig = user_config
self.temp_customuserconfig = customuser_config
wx.ScrolledWindow.__init__(self, parent)
sz1 = wx.BoxSizer(wx.VERTICAL)
desc = []
desc.append ( wx.StaticText(self, -1, '\nDefault Figure size.') )
titleFont = wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)
desc[-1].SetFont(titleFont)
desc.append ( wx.StaticText(self, -1, 'Choose default size for all the figures.\nSize can be changed for every figure from their context menu.\n'))
sz1.AddMany (desc)
actual_size = self.temp_userconfig['FigureSize']
inputsizer = wx.BoxSizer(wx.HORIZONTAL)
self.fig_size_textctrl_x = NumCtrl (self, -1, size = (80,-1), value = actual_size[0], allowNegative = False, fractionWidth = 0, autoSize = False)
self.fig_size_textctrl_y = NumCtrl (self, -1, size = (80,-1), value = actual_size[1], allowNegative = False, fractionWidth = 0, autoSize = False)
self.fig_size_textctrl_x.Bind(wx.EVT_LEAVE_WINDOW, partial (self.OnUpdateSize, 'x'))
self.fig_size_textctrl_y.Bind(wx.EVT_LEAVE_WINDOW, partial (self.OnUpdateSize, 'y'))
self.fig_size_select_mu = wx.Choice(self, -1, choices = ['in', 'cm', 'mm', 'px'] )
self.fig_size_select_mu.SetSelection(0)
self.fig_size_select_mu.Bind(wx.EVT_CHOICE, self.OnChangeMeasureUnit)
inputsizer.Add (self.fig_size_textctrl_x, 0, wx.ALL, 1)
inputsizer.Add (self.fig_size_textctrl_y, 0, wx.ALL, 1)
inputsizer.Add (self.fig_size_select_mu, 0, wx.ALL, 1)
sz1.Add(inputsizer, 0, wx.ALL, 3)
sz1.Add (wx.StaticLine(self), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5 )
#Define default dpi size when exporting to file
desc = []
desc.append ( wx.StaticText(self, -1, '\nDefault dpi of exported images.') )
desc[-1].SetFont(titleFont)
desc.append ( wx.StaticText(self, -1, 'You may export images as bitmap files (tif, rgb).\nSelect here the default resolution at export time\n') )
def_dpi = str(self.temp_userconfig['dpi'])
txt_dpi = masked.TextCtrl(self , -1, def_dpi, mask = "###", name='DPI')
txt_dpi.Bind(wx.EVT_TEXT, partial(self.OnChangeDPI, 'dpi'))
desc.append(txt_dpi)
sz1.AddMany (desc)
sz1.Add (wx.StaticLine(self), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5 )
# Group of radio controls:
desc = []
desc.append ( wx.StaticText(self, -1, '\nSelect the graphical interface.') )
desc[-1].SetFont(titleFont)
desc.append ( wx.StaticText(self, -1, 'The interactive interface is the default one.\nSelect the second one only in case the first one does not work.\nA restart is needed to see changes.\n') )
grid1 = wx.FlexGridSizer( 0, 1, 0, 0 )
self.canvas_type = []
self.canvas_type.append( wx.RadioButton( self, -1, 'Interactive', name = 'wxmpl', style = wx.RB_GROUP ) )
self.canvas_type.append( wx.RadioButton( self, -1, 'Not interactive', name = 'wx' ) )
for radio in self.canvas_type:
grid1.Add( radio, 0, wx.ALIGN_LEFT|wx.LEFT|wx.RIGHT|wx.TOP, 5 )
radio.Bind(wx.EVT_RADIOBUTTON, self.OnCanvasSelect)
ck = (self.temp_userconfig['Canvas'] == 'wx')*1
self.canvas_type[ck].SetValue(True)
desc.append (grid1)
radio_sizer = wx.BoxSizer(wx.VERTICAL)
radio_sizer.AddMany(desc)
sz1.Add(radio_sizer, 0, wx.ALL, 3)
self.SetSizer(sz1)
sz1.Fit(self)
def OnChangeDPI(self, key, event):
value = event.EventObject.GetValue()
try:
self.temp_userconfig[key] = int(value)
except:
pass
def OnChangeMeasureUnit(self, event):
'''
We update the value in the textbox when we change measure unit
'''
dpi = 96
x = self.temp_userconfig['FigureSize'][0]
y = self.temp_userconfig['FigureSize'][1]
#conv_fact = (1, dpi*(1/2.54), dpi*(1/25.4), dpi)
conv_fact = (1, 2.54, 25.4, dpi) #in, cm, mm, px
fra_width = (0, 2, 0, 2)
mu = self.fig_size_select_mu.GetCurrentSelection()
self.fig_size_textctrl_x.SetFractionWidth(fra_width[mu])
self.fig_size_textctrl_y.SetFractionWidth(fra_width[mu])
self.fig_size_textctrl_x.SetValue( x * conv_fact[mu])
self.fig_size_textctrl_y.SetValue( y * conv_fact[mu] )
def OnUpdateSize(self, ax, event):
'''
Size is always stored as inches but
can be entered in different units (px, mm, cm)
'''
dpi = 96.0
#conv_fact = (1, dpi*(1/2.54), dpi*(1/25.4), dpi) #px, cm, mm, in
conv_fact = (1, 1/2.54, 1/25.4, 1/dpi) #in, cm, mm, px
mu = self.fig_size_select_mu.GetCurrentSelection()
if ax == 'x':
size = (self.fig_size_textctrl_x.GetValue() * conv_fact[mu] , self.temp_userconfig['FigureSize'][1] )
elif ax == 'y':
size = (self.temp_userconfig['FigureSize'][0], self.fig_size_textctrl_y.GetValue() * conv_fact[mu] )
self.temp_userconfig['FigureSize'] = size
def OnCanvasSelect( self, event ):
self.temp_userconfig['Canvas'] = event.EventObject.GetName()
class StyleGraphPanel(wx.ScrolledWindow):
'''
Creates the Panel for choosing the graphic style
'''
def __init__(self, parent, user_config, customuser_config):
self.temp_userconfig = user_config
self.temp_customuserconfig = customuser_config
wx.ScrolledWindow.__init__(self, parent)
sz1 = wx.BoxSizer(wx.VERTICAL)
items = []
items.append ( wx.StaticText(self, -1, '\nUse crosshair.') )
titleFont = wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)
items[-1].SetFont(titleFont)
items.append ( wx.StaticText(self, -1, 'Use a crosshair styled mouse cursor to navigate the graphs\nIt will work only in interactive mode. Restart of pySolo is required.'))
#sz1.AddMany (items)
grid1 = wx.FlexGridSizer( 0, 1, 0, 0 )
self.DAM_version_radio = []
self.DAM_version_radio.append( wx.RadioButton( self, -1, 'Use crosshair', name = 'crosshair', style = wx.RB_GROUP ) )
self.DAM_version_radio.append( wx.RadioButton( self, -1, 'Do not use crosshair', name = 'no_crosshair' ) )
for radio in self.DAM_version_radio:
grid1.Add( radio, 0, wx.ALIGN_LEFT|wx.LEFT|wx.RIGHT|wx.TOP, 5 )
radio.Bind(wx.EVT_RADIOBUTTON, partial(self.OnGroupSelect, 'crosshair'))
ck = not self.temp_userconfig['crosshair']
self.DAM_version_radio[ck].SetValue(True)
items.append (grid1)
items.append ( (wx.StaticLine(self), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5 ) )
items.append ( wx.StaticText(self, -1, '\nUse standard deviation or standard error.') )
titleFont = wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)
items[-1].SetFont(titleFont)
items.append ( wx.StaticText(self, -1, 'Here you can choose whether to display standard error\nor deviation as error bar in graphs.\nNote that it will not work on all panels but only those that support this.\n'))
#sz1.AddMany (items)
grid2 = wx.FlexGridSizer( 0, 1, 0, 0 )
self.error_kind_radio = []
self.error_kind_radio.append( wx.RadioButton( self, -1, 'Use standard deviation', name = 'use_std', style = wx.RB_GROUP ) )
self.error_kind_radio.append( wx.RadioButton( self, -1, 'Use standard error', name = 'use_stde' ) )
for radio in self.error_kind_radio:
grid2.Add( radio, 0, wx.ALIGN_LEFT|wx.LEFT|wx.RIGHT|wx.TOP, 5 )
radio.Bind(wx.EVT_RADIOBUTTON, partial(self.OnGroupSelect, 'use_std'))
ck = not self.temp_userconfig['use_std']
self.error_kind_radio[ck].SetValue(True)
items.append (grid2)
items.append ( (wx.StaticLine(self), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5 ) )
sz1.AddMany (items)
self.SetSizer(sz1)
sz1.Fit(self)
def OnGroupSelect( self, key,event ):
self.temp_userconfig[key] = (event.EventObject.GetName() == key)
class OptionsColourPanel(wx.ScrolledWindow):
'''
Creates the Panel for choosing the plotting colors and their names
'''
def __init__(self, parent, user_config, customuser_config):
self.temp_userconfig = user_config
self.temp_customuserconfig = customuser_config
wx.ScrolledWindow.__init__(self, parent)
sz1 = wx.BoxSizer(wx.VERTICAL)
items = []
items.append ( wx.StaticText(self, -1, '\nSelect the color sequence.') )
titleFont = wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)
items[-1].SetFont(titleFont)
items.append ( wx.StaticText(self, -1, 'You can pick up to 20 different colors to be used to draw independent lines on the graph.\n Please specify a name for the color too.\n'))
items.append ( (wx.StaticLine(self), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5 ) )
sz1.AddMany (items)
buttonSizer = wx.FlexGridSizer(5, 8) # sizer to contain all the example buttons
self.colourBtns = []
plotcol_dec = color_hex2dec(self.temp_userconfig['plotting_colors'])
hm = len(plotcol_dec)
label_l = self.temp_userconfig['plotting_colors_name']
color_l = plotcol_dec
size_l = [(80,-1)]*hm
name_l = range(1,hm+1)
buttonData = zip(name_l, color_l, size_l, label_l)
# build each button and save a reference to it
for name, color, size, label in buttonData:
b = csel.ColourSelect(self, -1, label, color, size = size)
b.Bind(csel.EVT_COLOURSELECT, self.OnSelectColour)
self.colourBtns.append(b)
buttonSizer.AddMany([
(wx.StaticText(self, -1, str(name)), 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL),
(b, 0, wx.ALL, 3),
])
sz1.Add(buttonSizer, 0, wx.ALL, 3)
self.SetSizer(sz1)
sz1.Fit(self)
def OnSelectColour (self, event):
'''
After we have selected a colour we need to give it a name
'''
def dec2hex(color):
red, green, blue = list(color)
red = '%X' % red
green = '%X' % green
blue = '%X' % blue
return '#' + str(red).zfill(2) + str(green).zfill(2) + str(blue).zfill(2)
color_value = dec2hex(event.GetValue())
color_name_dlg = wx.Dialog(self, wx.ID_ANY, 'Pick colour name', size=(200,160), style=wx.DEFAULT_DIALOG_STYLE )
sizer = wx.BoxSizer(wx.VERTICAL)
box = wx.BoxSizer(wx.HORIZONTAL)
btnsizer = wx.BoxSizer(wx.HORIZONTAL)
label = wx.StaticText(color_name_dlg, -1, 'Please, give a name to this colour')
sizer.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 2)
label = wx.StaticText(color_name_dlg, -1, 'Name: ')
box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 2)
txtColorName = wx.TextCtrl(color_name_dlg, -1, color_value, size=(80,-1))
box.Add(txtColorName, 1, wx.ALIGN_CENTRE|wx.ALL, 2)
sizer.Add(box, 2, wx.GROW|wx.ALL, 2)
line = wx.StaticLine(color_name_dlg, -1, size=(20,-1), style=wx.LI_HORIZONTAL)
sizer.Add(line, 0, wx.GROW|wx.RIGHT|wx.TOP, 1)
btn = wx.Button(color_name_dlg, wx.ID_OK)
btn.SetDefault()
btnsizer.Add(btn, 0)
btn = wx.Button(color_name_dlg, wx.ID_CANCEL)
btnsizer.Add(btn, 0)
sizer.Add(btnsizer, 1, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, 5)
color_name_dlg.SetSizer(sizer)
# this does not return until the dialog is closed.
val = color_name_dlg.ShowModal()
if val == wx.ID_OK: #identifies which button gave rise to the event
n = 0
for btn in self.colourBtns:
if btn.GetId() == event.GetId():
self.colourBtns[n].SetLabel(txtColorName.GetValue())
#The following three rows are added to correct a bug with this class
#New versions of ColourSelect should not need them anymore
bmp = self.colourBtns[n].MakeBitmap()
self.colourBtns[n].SetBitmap(bmp)
self.colourBtns[n].SetBitmapHover(bmp)
self.temp_userconfig['plotting_colors'][n] = color_value
self.temp_userconfig['plotting_colors_name'][n] = txtColorName.GetValue()
n += 1
else:
pass
color_name_dlg.Destroy()
class OptionsInformationPanel(wx.ScrolledWindow):
'''
Creates a Panel showing some information about the system
'''
def __init__(self, parent, user_config, customuser_config):
self.temp_userconfig = user_config
self.temp_customuserconfig = customuser_config
wx.ScrolledWindow.__init__(self, parent)
sz1 = wx.BoxSizer(wx.VERTICAL)
items = []
items.append ( wx.StaticText(self, -1, '\nInformation.') )
titleFont = wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)
items[-1].SetFont(titleFont)
items.append ( wx.StaticText(self, -1, 'Here some information about your system.\n'))
items.append ( (wx.StaticLine(self), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5 ) )
from os import name as os_name
from sys import version as sys_version
from wxmpl import __version__ as wxmpl_version
from matplotlib import __version__ as mpl_version
from numpy import __version__ as numpy_version
from scipy import __version__ as scipy_version
information = 'OS type: %s\n' % (os_name)
information += 'pySolo version: %s\n' % (pySoloVersion)
information += 'Python version: %s\n' % (sys_version)
information += 'wxPython version: %s\n' % (wx.__version__)
information += 'wxmpl version: %s\n' % (wxmpl_version)
information += 'matplotlib version: %s\n' % (mpl_version)
information += 'numpy version: %s\n' % (numpy_version)
information += 'scipy version: %s\n' % (scipy_version)
items.append ( (wx.TextCtrl (self, -1, information, size=(200,150), style=wx.TE_MULTILINE|wx.TE_PROCESS_ENTER), 0, wx.GROW | wx.EXPAND | wx.ALL, 10))
from pysolo_lib import GUI
items.append ( wx.StaticText(self, -1, '\nGUI variable (for debugging).') )
titleFont = wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)
items[-1].SetFont(titleFont)
items.append ( wx.StaticText(self, -1, 'Here the content of the GUI variable.\n'))
items.append ( (wx.StaticLine(self), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5 ) )
infoGui = ''
for key in GUI:
infoGui += '%s:\t%s\n' % (key, GUI[key])
items.append ( (wx.TextCtrl (self, -1, infoGui, size=(200,150), style=wx.TE_MULTILINE|wx.TE_PROCESS_ENTER), 0, wx.GROW | wx.EXPAND | wx.ALL, 10))
items.append ( wx.StaticText(self, -1, '\nuserConfig variable (for debugging).') )
titleFont = wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)
items[-1].SetFont(titleFont)
items.append ( wx.StaticText(self, -1, 'Here the content of the userConfig variable.\n'))
items.append ( (wx.StaticLine(self), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5 ) )
infoUC = ''
for key in self.temp_userconfig:
infoUC += '%s:\t%s\n' % (key, self.temp_userconfig[key])
items.append ( (wx.TextCtrl (self, -1, infoUC, size=(200,150), style=wx.TE_MULTILINE|wx.TE_PROCESS_ENTER), 0, wx.GROW | wx.EXPAND | wx.ALL, 10))
sz1.AddMany (items)
self.SetSizer(sz1)
sz1.Fit(self)
class OptionsChoicePanel(wx.ScrolledWindow):
def __init__(self, parent, user_config, customuser_config):
self.temp_userconfig = user_config
self.temp_customuserconfig = customuser_config
wx.ScrolledWindow.__init__(self, parent)
sz1 = wx.BoxSizer(wx.VERTICAL)
titleFont = wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)
items = []
items.append ( wx.StaticText(self, -1, '\nSelect order and visibility of custom Panels.') )
items[-1].SetFont(titleFont)
items.append ( wx.StaticText(self, -1, 'Here is a list of installed custom panels.\nPlease select which ones you want to visualize and their relative order.\nRestart the program to make your changes effective.') )
items.append ( (wx.StaticLine(self), 0, wx.EXPAND|wx.ALL, 5 ))
self.chkListBox = wx.CheckListBox(self, -1, choices = [])
self.UpdateCheckListBox()
self.chkListBox.Bind(wx.EVT_CHECKLISTBOX, self.OnCheckItemInListBox)
items.append ( (self.chkListBox, 0, wx.ALL, 5) )
btnSizer = wx.BoxSizer(wx.HORIZONTAL)
btnUp = wx.Button(self, -1, 'up')
btnUp.Bind(wx.EVT_BUTTON, partial(self.MoveItemInList, -1))
btnDown = wx.Button(self, -1, 'down')
btnDown.Bind(wx.EVT_BUTTON, partial(self.MoveItemInList, +1))
btnSizer.Add(btnUp, 0, wx.ALL, 1)
btnSizer.Add(btnDown, 0, wx.ALL, 1)
items.append (btnSizer)
sz1.AddMany (items)
self.SetSizer(sz1)
sz1.Fit(self)
def UpdateCheckListBox(self):
'''
Update content and order of check list box containing the list of panels
'''
customPanelList = [''] * len(self.temp_userconfig['Panels'])
checkPanelList = [False] * len(self.temp_userconfig['Panels'])
for aPanel in self.temp_userconfig['Panels']:
position = self.temp_userconfig['Panels'][aPanel][0]
customPanelList[position] = aPanel
checkPanelList[position] = self.temp_userconfig['Panels'][aPanel][1]
self.chkListBox.SetItems(customPanelList)
n = 0
for toCheck in checkPanelList:
self.chkListBox.Check(n, toCheck)
n+=1
def OnCheckItemInListBox(self, event):
'''
When we check/uncheck item in the list box set panel flag visible / invisible
'''
index_c = event.GetSelection()
items = self.chkListBox.GetItems()
check_value = event.GetEventObject().IsChecked(index_c)
self.temp_userconfig['Panels'][items[index_c]][1] = check_value
def MoveItemInList(self, pos, event):
'''
Move items in the checklistbox up or down.
'''
index = self.chkListBox.GetSelection()
items = self.chkListBox.GetItems()
if 0 <= ( index + pos ) < len(items):
selection = items[index]
target = items[index+pos]
self.temp_userconfig['Panels'][selection][0] = index+pos
self.temp_userconfig['Panels'][target][0] = index
self.UpdateCheckListBox()
self.chkListBox.SetSelection(index+pos)
class pySolo_OptionPanel(wx.Frame):
'''
This class defines the Option Frame
'''
def __init__(
self, parent, ID=-1, title='Option Panel', pos=wx.DefaultPosition,
size=(640,480), style=wx.DEFAULT_FRAME_STYLE
):
wx.Frame.__init__(self, parent, ID, title, pos, size, style)
self.temp_userconfig = CopyDict(userConfig)
self.temp_customuserconfig = CopyDict(customUserConfig)
pp = wx.Panel(self, -1)
self.optpane = wx.Treebook(pp, -1, style= wx.BK_DEFAULT)
# These are the default panels laying in a tree-like fashion
optList = [['Files and Folders'], ['Sleep options'],['Video options'], ['Graphs', 'Style', 'Colours'], ['Custom Panels Options'], ['Information']]
# Here we add to position two of the list, under Custom Panels Option, every needed customPanel
for panName in self.temp_customuserconfig:
optList[3].append(panName)
# Now make a bunch of panels for the list book
for optCategory in optList:
# The first item of the list is the main Panel
tbPanel = self.makePanel(self.optpane, optCategory[0])
self.optpane.AddPage(tbPanel, optCategory[0])
for optName in optCategory[1:]:
# All the following ones are children
tbPanel = self.makePanel(self.optpane, optName)
self.optpane.AddSubPage(tbPanel, optName)
#self.Bind(wx.EVT_TREEBOOK_PAGE_CHANGED, self.OnPageChanged)
btSave = wx.Button(pp, wx.ID_SAVE)
btCancel = wx.Button(pp, wx.ID_CANCEL)
btSave.Bind(wx.EVT_BUTTON, self.OnSaveOptions)
btCancel.Bind(wx.EVT_BUTTON, self.OnCancelOptions)
self.Bind(wx.EVT_CLOSE, self.OnCancelOptions)
btSz = wx.BoxSizer(wx.HORIZONTAL)
btSz.Add (btCancel)
btSz.Add (btSave)
sz = wx.BoxSizer(wx.VERTICAL)
sz.Add (self.optpane, 1, wx.EXPAND)
sz.Add (btSz, 0, wx.ALIGN_RIGHT | wx.ALL, 10)
pp.SetSizer(sz)
# This is a workaround for a sizing bug on Mac...
wx.FutureCall(100, self.AdjustSize)
for i in range(0,len(self.optpane.Children)-1):
self.optpane.ExpandNode(i)
def CopyUserConfigVariables(self):
'''
Makes a local copy of userConfig and customUserConfig
to be used as chached copy until we hit the Save button
'''
# self.temp_userconfig = dict()
# self.temp_customuserconfig = dict()
self.temp_userconfig = CopyDict(userConfig)
self.temp_customuserconfig = CopyDict(customUserConfig)
def AdjustSize(self):
'''
Apparently this is needed as workaround for a sizing bug on Mac.
'''
self.optpane.GetTreeCtrl().InvalidateBestSize()
self.optpane.SendSizeEvent()
def OnSaveOptions(self, event):
'''
Called when we hit the Save button
Will copy the temporary stored variables to the real one and save it
away to file
'''
customUserConfig = CopyDict(self.temp_customuserconfig)
userConfig = CopyDict(self.temp_userconfig)
try:
SavePreferenceFile(userConfig, customUserConfig)
except:
wx.MessageBox('Error writing the preference file.\nThe file could be open by another process or the disk could be full.', 'oops!', style=wx.OK|wx.ICON_EXCLAMATION)
self.Destroy()