Commit 31e92179 authored by Michael Rudolf's avatar Michael Rudolf
Browse files

New path checking resolves #6.

parent d9bcdf73
......@@ -235,8 +235,10 @@ class RST_pick_GUI(tk.Tk):
self.entry_projname.delete(0, 'end')
pname = f_path.split('/')[-1]
self.entry_projname.insert(0, pname)
self.path_cfg.set(f_path + '/' + pname + '.cfg')
self.refresh_entries_from_cfg(path=f_path + '/' + pname + '.cfg')
self.path_cfg.set(
os.path.join(f_path, pname + '.cfg')
)
self.refresh_entries_from_cfg(path=self.path_cfg)
elif event.widget._name == '!button2': # Output path
self.entry_output.delete(0, 'end')
self.entry_output.insert(0, f_path + '/')
......@@ -295,12 +297,26 @@ class RST_pick_GUI(tk.Tk):
text=self.cfg['units'][item[0]])
opt_dlg.label_unit.grid(column=2, row=i + 1, sticky='w')
def set_data(self):
def set_data(self, init=False):
''' Set contents of fields and variables according to config '''
self.projectname.set(self.cfg['paths']['projectname'])
self.path_in.set(self.cfg['paths']['path_in'])
self.path_out.set(self.cfg['paths']['path_out'])
self.path_cfg.set(self.cfg['paths']['path_cfg'])
if init:
self.path_in.set(self.cfg['paths']['path_in'])
self.path_out.set(self.cfg['paths']['path_out'])
self.path_cfg.set(self.cfg['paths']['path_cfg'])
else:
if os.path.exists(self.cfg['paths']['path_in']):
self.path_in.set(self.cfg['paths']['path_in'])
else:
print('Replaced invalid path for input folder.')
if os.path.exists(self.cfg['paths']['path_out']):
self.path_out.set(self.cfg['paths']['path_out'])
else:
print('Replaced invalid path for output folder.')
if os.path.exists(self.cfg['paths']['path_cfg']):
self.path_cfg.set(self.cfg['paths']['path_cfg'])
else:
print('Replaced invalid path for config file.')
self.plot_ts.set(self.cfg.getint('options', 'plot_ts'))
self.save_ts.set(self.cfg.getint('options', 'save_ts'))
......@@ -337,13 +353,17 @@ class RST_pick_GUI(tk.Tk):
# Check if config path points to the correct directory otherwise create
# a new config in the project folder.
if not os.path.exists(self.path_cfg.get()):
self.path_cfg.set(
os.path.join(
self.path_in.get(),
self.projectname.get() + '.cfg'
)
if (
not os.path.exists(self.path_cfg.get()) or
self.path_cfg.get() != self.cfg['paths']['path_cfg']
):
print('Updated config path.')
new_config_path = os.path.join(
self.path_in.get(),
self.projectname.get() + '.cfg'
)
self.cfg['paths']['path_cfg'] = new_config_path
self.path_cfg.set(new_config_path)
with open(self.path_cfg.get(), 'w') as f:
self.cfg.write(f)
......@@ -374,7 +394,7 @@ class RST_pick_GUI(tk.Tk):
self.cfg.read(self.path_cfg.get())
print('created project config')
self.set_data()
self.set_data(init=init)
def create_default_config(self, path=None):
"""Creates default config in the given path"""
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment