-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathScopePy_preferences.py
More file actions
1205 lines (800 loc) · 34.8 KB
/
ScopePy_preferences.py
File metadata and controls
1205 lines (800 loc) · 34.8 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
# -*- coding: utf-8 -*-
"""
Created on Sat May 16 18:51:34 2015
@author: john
Version
==============================================================================
$Revision:: 43 $
$Date:: 2015-05-23 09:25:13 -0400 (Sat, 2#$
$Author:: john $
==============================================================================
ScopePy Preferences
-------------------
Module for handling Preferences for ScopePy
Defines a class for storing preferences and a dialog box for setting them.
The Preferences class is then used by other parts of ScopePy as a central
location.
"""
#==============================================================================
#%% License
#==============================================================================
"""
Copyright 2015 John Bainbridge
This file is part of ScopePy.
ScopePy 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.
ScopePy 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 ScopePy. If not, see <http://www.gnu.org/licenses/>.
"""
#==============================================================================
#%% Imports
#==============================================================================
# Standard library
import os,logging
import configparser
# Third party libraries
from PyQt4.QtCore import *
from PyQt4.QtGui import *
# My libraries
import ScopePy_keyboard as kbd
from ScopePy_utilities import minidir
#==============================================================================
#%% Logger
#==============================================================================
# create logger
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
# Add do nothing handler
logger.addHandler(logging.NullHandler())
# create console handler and set level to debug
con = logging.StreamHandler()
con.setLevel(logging.DEBUG)
# create formatter
formatter = logging.Formatter('[%(asctime)s:%(name)s:%(levelname)s]: %(message)s')
# add formatter to ch
con.setFormatter(formatter)
# add ch to logger
logger.addHandler(con)
#==============================================================================
#%% Constants
#==============================================================================
DEFAULT_PREFS_FILE = os.path.join(os.path.expanduser('~'),'.ScopePy','preferences.ini')
BASEPATH, dummy = os.path.split(os.path.abspath(__file__))
#==============================================================================
#%% Functions
#==============================================================================
def getPathsFromList(ListWidget):
"""
Extract the lines of text from a QListWidget
Inputs
--------
ListWidget: QListWidget
Outputs
--------
list of paths: list of str
"""
# Get list of QListWidget items
nItems = len(ListWidget)
if nItems == 0:
return
list_of_paths = []
for index in range(nItems):
list_of_paths.append(ListWidget.item(index).text())
return list_of_paths
def addPathsToList(ListWidget,list_of_paths):
"""
Add a list of paths to a QListWidget
Input
-------
list_of_paths : list of str
"""
if list_of_paths == [] or list_of_paths is None:
return
for path in list_of_paths:
if path:
ListWidget.addItem(path)
#==============================================================================
#%% Preferences class
#==============================================================================
class Preferences():
"""
Holds all the Preferences for ScopePy and handles storing and loading
"""
def __init__(self):
self.basepath = BASEPATH
# Paths
# ============================
# Panel paths
self.panelPaths = []
# Script paths
self.scriptPaths = []
# Transformer paths
self.transformerPaths = []
# Math functions paths
self.mathFunctionPaths = []
# Macro paths
self.macroPaths = []
# Data sources path
self.dataSourcePaths = []
# Store last path
self.lastPath = os.path.expanduser('~')
# Recent files
# =====================
self.recentFiles = []
# Themes
# ==========================
self.theme_css = os.path.join(self.basepath,'themes/default/default.css')
self.theme = 'default'
self.themePaths = []
# Preferences location
# ==========================
self.prefs_filename = DEFAULT_PREFS_FILE
# Keyboard shortcuts
# =========================
self.keyboard = kbd.makeDefaultKeyboardShortcuts()
def save(self):
"""
Save Preferences to default location
"""
def isListEmpty(a_list):
return a_list==[] or a_list is None
# Check existence of saving directory
# -------------------------------------
path, filename = os.path.split(self.prefs_filename)
# Create directory if needed
if not os.path.exists(path):
os.makedirs(path,exist_ok=True)
# Make the preferences file format
# -----------------------------------
config = configparser.ConfigParser()
config['PATHS'] = {}
if not isListEmpty(self.panelPaths):
config['PATHS']['PANELS'] = ";".join(self.panelPaths)
if not isListEmpty(self.scriptPaths):
config['PATHS']['SCRIPTS'] = ";".join(self.scriptPaths)
if not isListEmpty(self.transformerPaths):
config['PATHS']['TRANSFORMERS'] = ";".join(self.transformerPaths)
if not isListEmpty(self.macroPaths):
config['PATHS']['MACROS'] = ";".join(self.macroPaths)
if not isListEmpty(self.dataSourcePaths):
config['PATHS']['DATASOURCES'] = ";".join(self.dataSourcePaths)
if not isListEmpty(self.themePaths):
config['PATHS']['THEMES'] = ";".join(self.themePaths)
if not isListEmpty(self.mathFunctionPaths):
config['PATHS']['MATHFUNCTIONS'] = ";".join(self.mathFunctionPaths)
config['PATHS']['LAST_PATH'] = self.lastPath
if not isListEmpty(self.recentFiles):
config['PATHS']['RECENTFILES'] = ";".join(self.recentFiles)
config['THEME'] = {}
if self.theme:
config['THEME']['SELECTED'] = self.theme
# TODO : add keyboard shortcuts
# Store the file
# ----------------
with open(self.prefs_filename, 'w') as configfile:
config.write(configfile)
def load(self,basepath=BASEPATH):
"""
Load preferences from default location
"""
self.basepath = basepath
# Function for reading from config
def readIfExists(a_dict,key,default=''):
if key in a_dict:
return a_dict[key]
else:
return default
# Check file exists
# --------------------
if not os.path.exists(self.prefs_filename):
logger.debug('Preferences: Cannot find preferences file [%s]' % self.prefs_filename)
return
logger.debug('Preferences: Loading from preferences file [%s]' % self.prefs_filename)
# Load file
# -------------
config = configparser.ConfigParser()
out = config.read(self.prefs_filename)
if not out:
logger.debug('Preferences:Error with loading preferences file [%s]' % self.prefs_filename)
return
# Extract the preferences data
# -----------------------------
self.panelPaths = readIfExists(config['PATHS'],'PANELS').split(';')
self.scriptPaths = readIfExists(config['PATHS'],'SCRIPTS').split(';')
self.transformerPaths = readIfExists(config['PATHS'],'TRANSFORMERS').split(';')
self.macroPaths = readIfExists(config['PATHS'],'MACROS').split(';')
self.themePaths = readIfExists(config['PATHS'],'THEMES').split(';')
self.mathFunctionPaths = readIfExists(config['PATHS'],'MATHFUNCTIONS').split(';')
self.lastPath = config['PATHS']['LAST_PATH']
self.recentFiles = readIfExists(config['PATHS'],'RECENTFILES').split(';')
if 'THEME' in config:
self.theme = readIfExists(config['THEME'],'SELECTED','default')
#==============================================================================
#%% Preference dialog class
#==============================================================================
class PreferencesDialog(QDialog):
"""
ScopePy preferences
"""
def __init__(self,parent=None,prefs=Preferences()):
# Initialise base class
super(PreferencesDialog,self).__init__(parent)
self.setWindowTitle("ScopePy Preferences")
# Setup Preferences data
# ============================
self.prefs = prefs
# Setup widgets
# =========================
# Panels tab
self.panelsPath = QLineEdit()
self.panelsList = QListWidget()
panelsBrowseButton = QPushButton("Browse...")
panelsAddButton = QPushButton("Add")
panelsRemoveButton = QPushButton("Remove")
# scripts tab
self.scriptsPath = QLineEdit()
self.scriptsList = QListWidget()
scriptsBrowseButton = QPushButton("Browse...")
scriptsAddButton = QPushButton("Add")
scriptsRemoveButton = QPushButton("Remove")
# transformers tab
self.transPath = QLineEdit()
self.transList = QListWidget()
transAddButton = QPushButton("Add")
transBrowseButton = QPushButton("Browse...")
transRemoveButton = QPushButton("Remove")
# maths functions tab
self.mathsPath = QLineEdit()
self.mathsList = QListWidget()
mathsAddButton = QPushButton("Add")
mathsBrowseButton = QPushButton("Browse...")
mathsRemoveButton = QPushButton("Remove")
# macros tab
self.macroPath = QLineEdit()
self.macroList = QListWidget()
macroAddButton = QPushButton("Add")
macroBrowseButton = QPushButton("Browse...")
macroRemoveButton = QPushButton("Remove")
# Themes tab
self.currentThemePath = QLineEdit()
#themeDefaultButton = QPushButton("Set to Default theme")
self.themePath = QLineEdit()
self.themeList = QListWidget()
themeAddButton = QPushButton("Add")
themeBrowseButton = QPushButton("Browse...")
themeRemoveButton = QPushButton("Remove")
# OK/Cancel buttons
buttonBox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
buttonBox.button(QDialogButtonBox.Ok).setDefault(True)
# Frame to go around tabs
# Use this to define the size of the dialog
mainFrame = QFrame()
mainFrame.setFrameStyle(QFrame.Panel | QFrame.Raised)
mainFrame.setLineWidth(3)
mainFrame.setMinimumSize(QSize(600,300))
mainFrame.setMaximumSize(QSize(600,500))
mainFrame.setSizePolicy(QSizePolicy.Preferred,QSizePolicy.Preferred)
# Frame to go around buttons
buttonFrame = QFrame()
buttonFrame.setFrameStyle(QFrame.Panel | QFrame.Raised)
buttonFrame.setLineWidth(3)
# Setup connections
# ===========================
# Panel buttons
self.connect(panelsBrowseButton,SIGNAL("clicked()"),self.browseForPanelPath)
self.connect(panelsAddButton,SIGNAL("clicked()"),self.addPanelPath)
self.connect(panelsRemoveButton,SIGNAL("clicked()"),self.removePanelPath)
# Script buttons
self.connect(scriptsBrowseButton,SIGNAL("clicked()"),self.browseForScriptPath)
self.connect(scriptsAddButton,SIGNAL("clicked()"),self.addScriptPath)
self.connect(scriptsRemoveButton,SIGNAL("clicked()"),self.removeScriptPath)
# Transformer buttons
self.connect(transBrowseButton,SIGNAL("clicked()"),self.browseForTransformerPath)
self.connect(transAddButton,SIGNAL("clicked()"),self.addTransformerPath)
self.connect(transRemoveButton,SIGNAL("clicked()"),self.removeTransformerPath)
# Macro buttons
self.connect(macroBrowseButton,SIGNAL("clicked()"),self.browseForMacroPath)
self.connect(macroAddButton,SIGNAL("clicked()"),self.addMacroPath)
self.connect(macroRemoveButton,SIGNAL("clicked()"),self.removeMacroPath)
# Maths buttons
self.connect(mathsBrowseButton,SIGNAL("clicked()"),self.browseForMathFunctionPath)
self.connect(mathsAddButton,SIGNAL("clicked()"),self.addMathFunctionPath)
self.connect(mathsRemoveButton,SIGNAL("clicked()"),self.removeMathFunctionPath)
# Theme buttons
self.connect(themeBrowseButton,SIGNAL("clicked()"),self.browseForThemePath)
#self.connect(themeDefaultButton,SIGNAL("clicked()"),self.setDefaultThemePath)
self.connect(themeAddButton,SIGNAL("clicked()"),self.addThemePath)
self.connect(themeRemoveButton,SIGNAL("clicked()"),self.removeThemePath)
# Exit buttons
self.connect(buttonBox,SIGNAL("accepted()"),self.exitDialog)
self.connect(buttonBox,SIGNAL("rejected()"),self,SLOT("reject()"))
# Layout the dialog
# ==============================
# Tab widget for different preferences categories
prefsTab = QTabWidget()
# Panels tab
# ------------------------------------------
panelsLayout = QGridLayout()
row=0
panelsLayout.addWidget(QLabel("Add/Remove paths where Panel classes are stored"),row,0)
row+=1
panelsLayout.addWidget(self.panelsPath,row,0)
panelsLayout.addWidget(panelsBrowseButton,row,1)
row+=1
# Col 0, rows 1-3
panelsLayout.addWidget(self.panelsList,row,0,3,1)
panelsLayout.setColumnStretch(0,3)
# Col 1, row 1
panelsLayout.addWidget(panelsAddButton,row,1,1,1)
row+=1
# Col 1, row 2
panelsLayout.addWidget(panelsRemoveButton,row,1,1,1)
# Col 1, row 3
panelsWidget = QWidget()
panelsWidget.setLayout(panelsLayout)
prefsTab.addTab(panelsWidget,"Panels paths")
# Scripts tab
# ------------------------------------------
scriptsLayout = QGridLayout()
row=0
scriptsLayout.addWidget(QLabel("Add/Remove paths where Scripts are stored"),row,0)
row+=1
scriptsLayout.addWidget(self.scriptsPath,row,0)
scriptsLayout.addWidget(scriptsBrowseButton,row,1)
row+=1
# Col 0, rows 1-3
scriptsLayout.addWidget(self.scriptsList,row,0,3,1)
scriptsLayout.setColumnStretch(0,3)
# Col 1, row 1
scriptsLayout.addWidget(scriptsAddButton,row,1,1,1)
row+=1
# Col 1, row 2
scriptsLayout.addWidget(scriptsRemoveButton,row,1,1,1)
# Col 1, row 3
scriptsWidget = QWidget()
scriptsWidget.setLayout(scriptsLayout)
prefsTab.addTab(scriptsWidget,"Scripts paths")
# trans tab
# ------------------------------------------
transLayout = QGridLayout()
row=0
transLayout.addWidget(QLabel("Add/Remove paths where transformer classes are stored"),row,0)
row+=1
transLayout.addWidget(self.transPath,row,0)
transLayout.addWidget(transBrowseButton,row,1)
row+=1
# Col 0, rows 1-3
transLayout.addWidget(self.transList,row,0,3,1)
transLayout.setColumnStretch(0,3)
# Col 1, row 1
transLayout.addWidget(transAddButton,row,1,1,1)
row+=1
# Col 1, row 2
transLayout.addWidget(transRemoveButton,row,1,1,1)
# Col 1, row 3
transWidget = QWidget()
transWidget.setLayout(transLayout)
prefsTab.addTab(transWidget,"Transformer paths")
# maths function tab
# ------------------------------------------
mathsLayout = QGridLayout()
row=0
mathsLayout.addWidget(QLabel("Add/Remove paths where Maths functions are stored"),row,0)
row+=1
mathsLayout.addWidget(self.mathsPath,row,0)
mathsLayout.addWidget(mathsBrowseButton,row,1)
row+=1
# Col 0, rows 1-3
mathsLayout.addWidget(self.mathsList,row,0,3,1)
mathsLayout.setColumnStretch(0,3)
# Col 1, row 1
mathsLayout.addWidget(mathsAddButton,row,1,1,1)
row+=1
# Col 1, row 2
mathsLayout.addWidget(mathsRemoveButton,row,1,1,1)
# Col 1, row 3
mathsWidget = QWidget()
mathsWidget.setLayout(mathsLayout)
prefsTab.addTab(mathsWidget,"Maths function paths")
# Macro tab
# ------------------------------------------
macroLayout = QGridLayout()
row=0
macroLayout.addWidget(QLabel("Add/Remove paths where Macro scripts are stored"),row,0)
row+=1
macroLayout.addWidget(self.macroPath,row,0)
macroLayout.addWidget(macroBrowseButton,row,1)
row+=1
# Col 0, rows 1-3
macroLayout.addWidget(self.macroList,row,0,3,1)
macroLayout.setColumnStretch(0,3)
# Col 1, row 1
macroLayout.addWidget(macroAddButton,row,1,1,1)
row+=1
# Col 1, row 2
macroLayout.addWidget(macroRemoveButton,row,1,1,1)
# Col 1, row 3
macroWidget = QWidget()
macroWidget.setLayout(macroLayout)
prefsTab.addTab(macroWidget,"Macro paths")
# Themes tab
# -------------------
themeLayout = QGridLayout()
# themeLayout.addWidget(QLabel('<H2><b>Themes</b></H2>'))
# themeLayout.addWidget(self.currentThemePath)
# themeLayout.addWidget(themeBrowseButton)
# themeLayout.addWidget(themeDefaultButton)
row=0
themeLayout.addWidget(QLabel("Add/Remove paths where Themes are stored"),row,0)
row+=1
themeLayout.addWidget(self.themePath,row,0)
themeLayout.addWidget(themeBrowseButton,row,1)
row+=1
# Col 0, rows 1-3
themeLayout.addWidget(self.themeList,row,0,3,1)
themeLayout.setColumnStretch(0,3)
# Col 1, row 1
themeLayout.addWidget(themeAddButton,row,1,1,1)
row+=1
# Col 1, row 2
themeLayout.addWidget(themeRemoveButton,row,1,1,1)
# Col 1, row 3
themeWidget = QWidget()
themeWidget.setLayout(themeLayout)
prefsTab.addTab(themeWidget,"Themes")
# Add Tab bar to mainFrame
# --------------------------
mainFrameLayout = QVBoxLayout()
mainFrameLayout.addWidget(prefsTab)
mainFrame.setLayout(mainFrameLayout)
# Add button box to buttonFrame
# -------------------------------
buttonFrameLayout = QVBoxLayout()
buttonFrameLayout.addWidget(buttonBox)
buttonFrame.setLayout(buttonFrameLayout)
# Layout for all the dialog
# -------------------------
dialogLayout = QVBoxLayout()
dialogLayout.addWidget(mainFrame)
dialogLayout.addWidget(buttonFrame)
self.setLayout(dialogLayout)
# Fill in the dialog fields
self.populate()
# -----------------------------------------------------------------------
# Exiting dialog
# -----------------------------------------------------------------------
def exitDialog(self):
"""
Function to execute when the OK button is clicked.
It extracts all the paths into list variables so the caller can
extract them.
"""
# Get Panels paths
# -----------------
self.prefs.panelPaths = getPathsFromList(self.panelsList)
# Get Scripts paths
# -----------------
self.prefs.scriptPaths = getPathsFromList(self.scriptsList)
# Get transformer paths
# -----------------
self.prefs.transformerPaths = getPathsFromList(self.transList)
# Get maths functions paths
# -----------------
self.prefs.mathFunctionPaths = getPathsFromList(self.mathsList)
# Get Macro paths
# -----------------
self.prefs.macroPaths = getPathsFromList(self.macroList)
# Get theme paths
# -------------------
self.prefs.theme_css = self.currentThemePath.text()
self.prefs.themePaths = getPathsFromList(self.themeList)
# Exit dialog
self.accept()
# -----------------------------------------------------------------------
# Populate dialog
# -----------------------------------------------------------------------
def populate(self):
"""
Populate the fields of the dialog box from the Preferences class
"""
# Paths
# ---------
self.setPanelPaths(self.prefs.panelPaths)
self.setScriptPaths(self.prefs.scriptPaths)
self.setTransformerPaths(self.prefs.transformerPaths)
self.setMacroPaths(self.prefs.macroPaths)
self.currentThemePath.setText(self.prefs.theme_css)
# -----------------------------------------------------------------------
# Panel Preferences
# -----------------------------------------------------------------------
def setPanelPaths(self,list_of_paths):
"""
Set the panel paths directly
Input
---------
list_of_paths : list of str
"""
addPathsToList(self.panelsList,list_of_paths)
def addPanelPath(self):
"""
Add the path in the Panel line edit to the Panel path list box.
Checking that the path exists.
"""
# Get path
newPath = self.panelsPath.text()
# Check if path exists
if not os.path.exists(newPath):
QMessageBox.warning(self,"Unknown path","Cannot find path [%s]" % newPath)
return
# add new path to list
self.panelsList.addItem(newPath)
def browseForPanelPath(self):
"""
Open file dialog and get a new path
"""
newPath = self.getPath("Select path containing panels")
if newPath:
self.panelsPath.setText(newPath)
def removePanelPath(self):
"""
Remove currently selected paths.
Usually called by clicking 'Remove' button
"""
selectedItems = self.panelsList.selectedItems()
if selectedItems == []:
return
for item in selectedItems:
self.panelsList.takeItem(self.panelsList.row(item))
# -----------------------------------------------------------------------
# Script Preferences
# -----------------------------------------------------------------------
def setScriptPaths(self,list_of_paths):
"""
Set the panel paths directly
Input
---------
list_of_paths : list of str
"""
addPathsToList(self.scriptsList,list_of_paths)
def addScriptPath(self):
"""
Add the path in the Script line edit to the Script path list box.
Checking that the path exists.
"""
# Get path
newPath = self.scriptsPath.text()
# Check if path exists
if not os.path.exists(newPath):
QMessageBox.warning(self,"Unknown path","Cannot find path [%s]" % newPath)
return
# add new path to list
self.scriptsList.addItem(newPath)
def browseForScriptPath(self):
"""
Open file dialog and get a new path
"""
newPath = self.getPath("Select path containing scripts")
if newPath:
self.scriptsPath.setText(newPath)
def removeScriptPath(self):
"""
Remove currently selected paths.
Usually called by clicking 'Remove' button
"""
selectedItems = self.scriptsList.selectedItems()
if selectedItems == []:
return
for item in selectedItems:
self.scriptsList.takeItem(self.scriptsList.row(item))
# -----------------------------------------------------------------------
# Transformer Preferences
# -----------------------------------------------------------------------
def setTransformerPaths(self,list_of_paths):
"""
Set the panel paths directly
Input
---------
list_of_paths : list of str
"""
addPathsToList(self.transList,list_of_paths)
def addTransformerPath(self):
"""
Add the path in the Transformer line edit to the Transformer path list box.
Checking that the path exists.
"""
# Get path
newPath = self.transPath.text()
# Check if path exists
if not os.path.exists(newPath):
QMessageBox.warning(self,"Unknown path","Cannot find path [%s]" % newPath)
return
# add new path to list
self.transList.addItem(newPath)
def browseForTransformerPath(self):
"""
Open file dialog and get a new path
"""
newPath = self.getPath("Select path containing transformers")
if newPath:
self.transPath.setText(newPath)
def removeTransformerPath(self):
"""
Remove currently selected paths.
Usually called by clicking 'Remove' button
"""
selectedItems = self.transList.selectedItems()
if selectedItems == []:
return
for item in selectedItems:
self.transList.takeItem(self.transList.row(item))
# -----------------------------------------------------------------------
# MathFunction Preferences
# -----------------------------------------------------------------------
def setMathFunctionPaths(self,list_of_paths):
"""
Set the panel paths directly
Input
---------
list_of_paths : list of str
"""
addPathsToList(self.mathsList,list_of_paths)
def addMathFunctionPath(self):
"""
Add the path in the MathFunction line edit to the MathFunction path list box.
Checking that the path exists.
"""
# Get path
newPath = self.mathsPath.text()
# Check if path exists
if not os.path.exists(newPath):
QMessageBox.warning(self,"Unknown path","Cannot find path [%s]" % newPath)
return
# add new path to list
self.mathsList.addItem(newPath)
def browseForMathFunctionPath(self):
"""
Open file dialog and get a new path
"""
newPath = self.getPath("Select path containing MathFunctions")
if newPath:
self.mathsPath.setText(newPath)
def removeMathFunctionPath(self):
"""
Remove currently selected paths.
Usually called by clicking 'Remove' button
"""
selectedItems = self.mathsList.selectedItems()
if selectedItems == []:
return
for item in selectedItems:
self.mathsList.takeItem(self.mathsList.row(item))