Closed philipstarkey closed 7 years ago
Original comment by Jan Werkmann (Bitbucket: PhyNerd, GitHub: PhyNerd).
I noticed that under file in the menu there allready are options for loading configuration and saving them, but they do nothing at all. This proposed change would be great especially, when managing very many different special scripts and a small set of 'default scripts'
Original comment by Jan Werkmann (Bitbucket: PhyNerd, GitHub: PhyNerd).
We could add something like this:
add to Lyse class:
#!python
def save_configuration(self):
import pprint
save_file = os.path.join(os.path.dirname(os.path.realpath(__file__)),"config.ini")
lyse_config = LabConfig(save_file)
save_data = {}
save_data['SingleShot'] = [routine.filepath for routine in self.singleshot_routinebox.routines]
save_data['LastSingleShotFolder'] = self.singleshot_routinebox.last_opened_routine_folder
save_data['MultiShot'] = [routine.filepath for routine in self.multishot_routinebox.routines]
save_data['LastMultiShotFolder'] = self.multishot_routinebox.last_opened_routine_folder
save_data['LastFileBoxFolder'] = self.filebox.last_opened_shots_folder
for key, value in save_data.items():
lyse_config.set('lyse_state', key, pprint.pformat(value))
def load_configuration(self):
import ast
save_file = os.path.join(os.path.dirname(os.path.realpath(__file__)),"config.ini")
lyse_config = LabConfig(save_file)
try:
self.singleshot_routinebox.add_rotines(ast.literal_eval(lyse_config.get('lyse_state', 'SingleShot')))
self.singleshot_routinebox.last_opened_routine_folder = ast.literal_eval(lyse_config.get('lyse_state', 'LastSingleShotFolder'))
self.multishot_routinebox.add_rotines(ast.literal_eval(lyse_config.get('lyse_state', 'MultiShot')))
self.multishot_routinebox.last_opened_routine_folder = ast.literal_eval(lyse_config.get('lyse_state', 'LastMultiShotFolder'))
self.filebox.last_opened_shots_folder = ast.literal_eval(lyse_config.get('lyse_state', 'LastFileBoxFolder'))
except:
pass
and to Lyse.init():
#!python
self.ui.actionLoad_configuration.triggered.connect(self.load_configuration)
self.ui.actionSave_configuration.triggered.connect(self.save_configuration)
and add to/modify in RoutineBox:
#!python
def on_add_routines_clicked(self):
routine_files = QtGui.QFileDialog.getOpenFileNames(self.ui,
'Select analysis routines',
self.last_opened_routine_folder,
"Python scripts (*.py)")
if not routine_files:
# User cancelled selection
return
# Convert to standard platform specific path, otherwise Qt likes forward slashes:
routine_files = [os.path.abspath(routine_file) for routine_file in routine_files]
# Save the containing folder for use next time we open the dialog box:
self.last_opened_routine_folder = os.path.dirname(routine_files[0])
self.add_rotines(routine_files)
def add_rotines(self, routine_files):
# Queue the files to be opened:
for filepath in routine_files:
if filepath in [routine.filepath for routine in self.routines]:
app.output_box.output('Warning: Ignoring duplicate analysis routine %s\n'%filepath, red=True)
continue
routine = AnalysisRoutine(filepath, self.model, self.output_box_port)
self.routines.append(routine)
self.update_select_all_checkstate()
Original comment by Chris Billington (Bitbucket: cbillington, GitHub: chrisjbillington).
Fixed in pull request #18
Original report (archived issue) by Shaun Johnstone (Bitbucket: shjohnst, GitHub: shjohnst).
It would make sense for lyse to have a configuration file similar to runmanager's, where you can set default analysis scripts to load when you start the program. As with runmanager, there should then be options to load/revert/save the configuration.