Commit 8021bfa5 authored by Martin Schrön's avatar Martin Schrön
Browse files

Improved Config treatment: now default.cfg is basis, incl auto-update

parent b765bfcb
......@@ -84,6 +84,7 @@ import pandas
import os
import re
from functools import partial
import configparser
# pos where instanpasdy was imported
_orig_print = print
......@@ -819,6 +820,17 @@ class Root(BoxLayout):
# Clear existing Tabs
for tab in self.Tb_config.get_tab_list():
self.Tb_config.remove_widget(tab)
# Get substantial config from file:
self.config_filename = self.Ti_config.text
print('> Reading %s ...' % self.config_filename)
self.__config = configparser.ConfigParser()
temp = self.__config.read(self.config_filename, encoding='utf-8')
# Default config
self.config_default = script_path + 'default.cfg'
#Thr = Thread(target=self.load_config) #, args=(self.get_running_app().root))
#Thr.setDaemon(True)
#Thr.start()
......@@ -848,9 +860,7 @@ class Root(BoxLayout):
#self.fig = MDTabs()
#self.fig.clear_widgets()
#self.fig.clear_tabs()
self.config_filename = self.Ti_config.text
print('> Reading %s ...' % self.config_filename)
file_config = open(self.config_filename, 'r', encoding="utf-8")
file_config = open(self.config_default, 'r', encoding="utf-8")
self.config_lines = []
self.config_keys = dict()
......@@ -983,10 +993,10 @@ class Root(BoxLayout):
if match: self.__item_type = 'selectone'
match = re_selectany.search(line)
if match: self.__item_type = 'selectany'
match = re_multiline.search(line)
if match and self.__multiline_attach:
self.__gr.file_input.text += line.strip() + "\n"
if line.strip() != '':
self.__gr.file_input.text += line.strip()# + "\n"
match = re_keyval.search(line)
if match:
......@@ -1014,6 +1024,8 @@ class Root(BoxLayout):
self.__gr.label2.size_hint = (1, 0.2)
self.__gr.label2.halign='left'
self.__gr.file_input = TextInputMD(label=key, units='', multiline=True, text=val, size_hint=(1, 0.8))
if key in self.__config[self.__current_section]:
self.__gr.file_input.text = self.__config[self.__current_section][key]
self.__gr.height = 150
self.__gr.add_widget(self.__gr.file_input)
self.__multiline_attach = True
......@@ -1023,6 +1035,9 @@ class Root(BoxLayout):
"""
(yes/no) -> Chips_xor
"""
if key in self.__config[self.__current_section]:
val = self.__config[self.__current_section][key]
self.__gr.file_input = SelectChip_xor(text='yes', active=True if val=='yes' else False)
self.__gr.file_input2 = SelectChip_xor_no(text='no', active=True if (val=='no' or val=='') else False)
......@@ -1036,6 +1051,9 @@ class Root(BoxLayout):
"""
(select one) -> Chips_or
"""
if key in self.__config[self.__current_section]:
val = self.__config[self.__current_section][key]
self.__gr.select_container = MDStackLayout(size_hint=(0.6, 1)) #size_hint=(1, None))
for i in range(len(self.__selectitems)):
#print(i, self.__selectitems[i])
......@@ -1086,6 +1104,9 @@ class Root(BoxLayout):
"""
... -> TextField
"""
if key in self.__config[self.__current_section]:
val = self.__config[self.__current_section][key]
self.__gr = TextInputMD(label=key, units=self.__units, multiline=False, text=val, size_hint=(1, None))
self.config_keys[key] = self.__gr #.file_input
self.__units = '' # reset units
......@@ -1129,10 +1150,13 @@ class Root(BoxLayout):
text = ''
obj = self.config_keys[k]
no_linebreak = False
if isinstance(obj, TextInputMD):
text = obj.text
if obj.multiline:
text = "\n " + text.replace("\n", "\n ").strip()
no_linebreak = True
#if "\n" in text:
#text = "\n"+text
#text = text.replace("\n", "\n ")
......@@ -1157,8 +1181,11 @@ class Root(BoxLayout):
else:
print('Unknown', k, type(obj))
continue
file.write('%s = %s\n' % (k, text))
if no_linebreak:
file.write('%s = %s' % (k, text))
else:
file.write('%s = %s\n' % (k, text))
else:
file.write(k)
print(' OK.') #'' %s.' % new_config_filename)
......
This diff is collapsed.
......@@ -108,7 +108,7 @@ bbox =
# Exclude certain areas (e.g. tunnels or buildings). Make sure to add spaces before each line (table):
# Table: lat, lon, radius (m)
exclude_table =
## Temporal aggregation
......@@ -447,7 +447,7 @@ measured_sm = 0.20
# Table: name, lat, lon, radius (m)
poi_table =
river_plain, 51.877578, 12.244764, 50
road_junction, 51.877191, 12.237821, 100
road_junction, 51.877191, 12.237821, 100
# Spatial weighting method of the average (select one):
# - equal # equal weight, i.e. simple average over all points
......
This diff is collapsed.
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