77from serial .tools import list_ports
88from pyqtgraph .Qt import QtGui , QtCore , QtWidgets
99
10- from config .paths import dirs
11- from config .gui_settings import VERSION , ui_font_size
10+ from config .settings import VERSION , dirs , get_setting
1211from gui .run_task_tab import Run_task_tab
13- from gui .dialogs import Board_config_dialog , Keyboard_shortcuts_dialog , Paths_dialog
12+ from gui .dialogs import Board_config_dialog , Keyboard_shortcuts_dialog , Settings_dialog
1413from gui .configure_experiment_tab import Configure_experiment_tab
1514from gui .run_experiment_tab import Run_experiment_tab
1615from gui .setups_tab import Setups_tab
@@ -37,15 +36,15 @@ def __init__(self,app):
3736 self .available_tasks_changed = False
3837 self .available_experiments_changed = False
3938 self .available_ports_changed = False
39+ self .task_directory = get_setting ("folders" ,"tasks" )
4040 self .data_dir_changed = False
4141 self .current_tab_ind = 0 # Which tab is currently selected.
4242 self .app = app
4343
4444 # Dialogs.
45-
4645 self .config_dialog = Board_config_dialog (parent = self )
4746 self .shortcuts_dialog = Keyboard_shortcuts_dialog (parent = self )
48- self .paths_dialog = Paths_dialog (parent = self )
47+ self .settings_dialog = Settings_dialog (parent = self )
4948
5049 # Widgets.
5150 self .tab_widget = QtWidgets .QTabWidget (self )
@@ -68,7 +67,6 @@ def __init__(self,app):
6867 self .tab_widget .currentChanged .connect (self .tab_changed )
6968
7069 # Timers
71-
7270 self .refresh_timer = QtCore .QTimer () # Timer to regularly call refresh() when not running.
7371 self .refresh_timer .timeout .connect (self .refresh )
7472 self .refresh_timer .start (self .refresh_interval )
@@ -93,8 +91,8 @@ def __init__(self,app):
9391 ## --------Settings menu--------
9492 settings_menu = main_menu .addMenu ('Settings' )
9593 # Folder paths
96- paths_action = QtGui .QAction ("&Folder paths " , self )
97- paths_action .triggered .connect (self .paths_dialog .exec )
94+ paths_action = QtGui .QAction ("&Edit settings " , self )
95+ paths_action .triggered .connect (self .settings_dialog .exec )
9896 settings_menu .addAction (paths_action )
9997 # ---------Help menu----------
10098 help_menu = main_menu .addMenu ('Help' )
@@ -122,10 +120,10 @@ def __init__(self,app):
122120 self .show ()
123121
124122 def go_to_data (self ):
125- QtGui .QDesktopServices .openUrl (QtCore .QUrl .fromLocalFile (dirs [ ' data' ] ))
123+ QtGui .QDesktopServices .openUrl (QtCore .QUrl .fromLocalFile (get_setting ( "folders" , " data" ) ))
126124
127125 def go_to_tasks (self ):
128- QtGui .QDesktopServices .openUrl (QtCore .QUrl .fromLocalFile (dirs [ ' tasks' ] ))
126+ QtGui .QDesktopServices .openUrl (QtCore .QUrl .fromLocalFile (get_setting ( "folders" , " tasks" ) ))
129127
130128 def view_docs (self ):
131129 QtGui .QDesktopServices .openUrl (QtCore .QUrl ("https://pycontrol.readthedocs.io/en/latest/" ))
@@ -140,8 +138,11 @@ def get_task_file_list(self):
140138 '''Return list of .py files in tasks folder and subfolders in format:
141139 subdir_1/subdir_2/task_file_name.py'''
142140 task_files = []
143- for (dirpath , dirnames , filenames ) in os .walk (dirs ['tasks' ]):
144- task_files += [os .path .join (dirpath , file ).split (dirs ['tasks' ])[1 ][1 :- 3 ]
141+ # this function gets called every second. Normally we would use get_setting("folder","tasks")
142+ # but there no need to constantly be rereading the user_settings.json file that isn't changing
143+ # so we use this self.task_directory variable that is only updated when a new user settting is saved
144+ for (dirpath , dirnames , filenames ) in os .walk (self .task_directory ):
145+ task_files += [os .path .join (dirpath , file ).split (self .task_directory )[1 ][1 :- 3 ]
145146 for file in filenames if file .endswith ('.py' )]
146147 return task_files
147148
@@ -150,12 +151,12 @@ def refresh(self):
150151 # Scan task folder.
151152 tasks = self .get_task_file_list ()
152153 self .available_tasks_changed = tasks != self .available_tasks
153- if self .available_tasks_changed :
154+ if self .available_tasks_changed :
154155 self .available_tasks = tasks
155156 # Scan experiments folder.
156157 experiments = [t .split ('.' )[0 ] for t in os .listdir (dirs ['experiments' ]) if t [- 4 :] == '.pcx' ]
157158 self .available_experiments_changed = experiments != self .available_experiments
158- if self .available_experiments_changed :
159+ if self .available_experiments_changed :
159160 self .available_experiments = experiments
160161 # Scan serial ports.
161162 ports = set ([c [0 ] for c in list_ports .comports ()
@@ -196,7 +197,7 @@ def launch_GUI():
196197 app .setStyle ('Fusion' )
197198 app .setWindowIcon (QtGui .QIcon ("gui/icons/logo.svg" ))
198199 font = QtGui .QFont ()
199- font .setPixelSize (ui_font_size )
200+ font .setPixelSize (get_setting ( "GUI" ,( " ui_font_size" )) )
200201 app .setFont (font )
201202 gui_main = GUI_main (app )
202203 sys .excepthook = gui_main .excepthook
0 commit comments