Commit 8b96f528 authored by Martin Schrön's avatar Martin Schrön
Browse files

Cleaned old load config function

parent 53b86bb9
......@@ -1089,410 +1089,6 @@ class Root(BoxLayout):
self.__selectitems = []
self.__item_type = ''
def load_config(self, *args):
self.is_loading = True
#self.fig = MDTabs()
#self.fig.clear_widgets()
#self.fig.clear_tabs()
self.config_filename = self.Ti_config.text
file_config = open(self.config_filename, 'r', encoding="utf-8")
re_section = re.compile(r'^\[(.+)\]')
re_commenthead = re.compile(r'^\#\# (.+)')
re_comment = re.compile(r'^\# (.+)')
re_keyval = re.compile(r'^(\w+)\s*=(.*)')
re_multiline = re.compile(r'^\s+(\w.+)')
re_table = re.compile(r'\(table\)')
re_selectone = re.compile(r'\(select one\)')
re_selectany = re.compile(r'\(select any\)')
re_selectitems = re.compile(r'^\# - (.+) \# (.+)')
re_yesno = re.compile(r'\(yes\/no\)')
self.config_lines = []
self.config_keys = dict()
section = ''
subsection = ''
sv_l = None
sv_llayout = []
item_type = ''
selectitems = []
selectitemc = []
multiline_attach = False
current_section = None
current_subsection = None
self.Ac_subsection = []
l = 0
s = -1
ss = -1
lines = file_config.readlines()
num_lines = len(lines)
for line in lines:
l += 1
self.update_progressbar(int(l/num_lines*100))
if line.strip() == '':
self.config_lines.append(line)
match = re_section.search(line)
if match:
"""
[section] -> Tab
"""
self.config_lines.append(line)
section = match.group(1)
current_section = section
s += 1
ss = -1
# make new tab
Tb_config_l = Tab(text=section.capitalize()) #TabbedPanelHeader(text=section.capitalize(), size_hint_x=None, width=20+9*len(section)) #background_color=(0.81, 0.8, 0.73, 1), background_image='',
#Tb_config_l.width=20+9*len(section) #Tb_config_l.texture_size[0]
###sv_l = ScrollView(size_hint=(1, 1), scroll_type=['bars'], bar_pos_y='left', bar_width=10, do_scroll_x=False, do_scroll_y=True) #(Window.width, Window.height -100) , size=(Tb_config.width, Tb_config.height)
sv_lcontent = MDBoxLayout(orientation='vertical', adaptive_height=True, spacing=1, padding=(20,20,5,20)) #ltrb #, size_hint_y=None, height=0, spacing=1, padding=40)
#Tb_config_l.content = sv_l
print(Tb_config_l)
Tb_config_l.add_widget(sv_lcontent)
#P_tabs.add_widget(Tb_config)
sv_llayout.append(sv_lcontent) # GridLayout(cols=1, spacing=1, size_hint_y=None)
###sv_llayout[s].bind(minimum_height=sv_llayout[s].setter('height'))
#sv_l.add_widget(sv_llayout[s])
#Tb_config_l.content = sv_llayout[s]
#Tb_config_l.add_widget(sv_llayout[s])
self.Tb_config.add_widget(Tb_config_l)
# Clear item type as no more multiline data is expected
multiline_attach = False
# ss
ss_sv_l = None
ss_sv_llayout = []
match = re_commenthead.search(line)
if match:
"""
## Comment head -> Expansion Panel
"""
self.config_lines.append(line)
commenthead = match.group(1).strip()
ss += 1
#if TbP_subsection[] is None:
# If this is the first subsection...
###if ss == 0:
### # Create an Accordeon on pos=0
### self.Ac_subsection.append(Accordion(orientation='vertical'))
### # Add it to the BoxLayout
### sv_llayout[s].add_widget(self.Ac_subsection[s])
### sv_llayout[s].height += self.Ac_subsection[s].height
### #sv_llayout[s].add_widget(self.TbP_subsection[s]) # Add TbP to BoxLayout
# make new tab
#collapse = True if ss == 0 else False
###ss_Ac_item = AccordionItem(title=commenthead.capitalize())
#ss_Ac_item.min_space = 20
#ss_Ac_item.container.padding = 0
###ss_sv_l = ScrollView(size_hint=(1, None), scroll_type=['bars'], bar_pos_y='left', bar_width=10, do_scroll_x=False, do_scroll_y=True)
###ss_sv_lcontent = BoxLayout(orientation='vertical', size_hint_y=None, height=0, spacing=15, padding=(20,10,10,10))
#ss_sv_lcontent = MDBoxLayout(orientation='vertical', adaptive_height=True, spacing=15, padding=(0,10))
ss_sv_lcontent = MDBoxLayout(orientation='vertical', adaptive_height=True, padding=(0,10), spacing=15)
###ss_Ac_item.add_widget(ss_sv_l)
ss_Ac_item = Subsection(commenthead.capitalize(), ss_sv_lcontent)
sv_llayout[s].add_widget(ss_Ac_item)
#sv_llayout[s].height += ss_Ac_item.height
###ss_sv_l.add_widget(ss_sv_lcontent)
ss_sv_llayout.append(ss_sv_lcontent)
###ss_sv_llayout[ss].bind(minimum_height=ss_sv_llayout[ss].setter('height'))
###self.Ac_subsection[s].add_widget(ss_Ac_item)
# make new label
#['Consolas','fonts/consola.ttf','fonts/consolai.ttf','fonts/consolab.ttf','fonts/consolaz.ttf']
#['Segeo UI','fonts/segoeui.ttf','fonts/segoeuii.ttf','fonts/segoeuib.ttf','fonts/segoeuiz.ttf'])
#chcontent = BoxLayout(orientation= 'vertical', size_hint = (None, 1))
#height = 120 if Root.isShownMenu else 0,
#width: 120
#opacity = 1 if Root.isShownMenu else 0)
#testlabel = WrappedLabel(text='Dies ist ein Test', color='red')
#testlabel2 = WrappedLabel(text='Dies ist ein Test', color='red')
#chcontent.add_widget(testlabel)
#chcontent.add_widget(testlabel2)
#lbl = WrappedLabel(text='[b]%s[/b]' % commenthead,
# halign='left', valign='middle', color='grey', size_hint=(1, None),
# markup=True, font_name='app/_ui/fonts/segoeuib.ttf', subbox=chcontent)
if section!='':
#sep = Separator(sep_color=[0,1,0,1], size_hint=(None, 1), height=4)
#ss_sv_llayout[ss].add_widget(sep)
#ss_sv_llayout[ss].add_widget(lbl)
#ss_sv_llayout[ss].height += sep.height + lbl.height
#ss_sv_llayout[ss].add_widget(chcontent)
pass
else:
# print to log
pass
# Clear item type as no more multiline data is expected
multiline_attach = False
# This is a copy of the old section content
#match = re_commenthead.search(line)
if False:
"""
## Comment head -> Label (old)
"""
self.config_lines.append(line)
commenthead = match.group(1).strip()
# make new label
#['Consolas','fonts/consola.ttf','fonts/consolai.ttf','fonts/consolab.ttf','fonts/consolaz.ttf']
#['Segeo UI','fonts/segoeui.ttf','fonts/segoeuii.ttf','fonts/segoeuib.ttf','fonts/segoeuiz.ttf'])
chcontent = BoxLayout(orientation= 'vertical', size_hint = (None, 1))
#height = 120 if Root.isShownMenu else 0,
#width: 120
#opacity = 1 if Root.isShownMenu else 0)
testlabel = WrappedLabel(text='Dies ist ein Test', color='red')
testlabel2 = WrappedLabel(text='Dies ist ein Test', color='red')
chcontent.add_widget(testlabel)
chcontent.add_widget(testlabel2)
lbl = WrappedLabel(text='[b]%s[/b]' % commenthead,
halign='left', valign='middle', color='grey', size_hint=(1, None),
markup=True, font_name='app/_ui/fonts/segoeuib.ttf', subbox=chcontent)
if section!='':
sep = Separator(sep_color=[0,1,0,1], size_hint=(None, 1), height=4)
sv_llayout[s].add_widget(sep)
sv_llayout[s].add_widget(lbl)
#sv_llayout[s].height += sep.height + lbl.height
sv_llayout[s].add_widget(chcontent)
else:
# print to log
pass
# Clear item type as no more multiline data is expected
multiline_attach = False
match = re_comment.search(line)
if match:
"""
# Comment -> Label
"""
self.config_lines.append(line)
match2 = re_selectitems.search(line)
if match2:
selectitems.append(match2.group(1).strip())
selectitemc.append(match2.group(2).strip())
else:
comment = match.group(1)
# make new label
#WrappedLabel(text=comment, halign='left', valign='middle', color='grey', size_hint=(1, None))
lbl = WrappedLabel(text=comment, halign='left', valign='middle', color='grey', size_hint=(1, None))
#lbl.height = 50
if section != '':
if ss < 0:
lbl.padding = (15,5)
sv_llayout[s].add_widget(lbl)
#sv_llayout[s].height += lbl.height
else:
ss_sv_llayout[ss].add_widget(lbl)
#ss_sv_llayout[ss].height += lbl.height
else:
# print to log
pass
# Clear item type as no more multiline data is expected
multiline_attach = False
match = re_table.search(line)
if match: item_type = 'multiline'
match = re_yesno.search(line)
if match: item_type = 'yesno'
match = re_selectone.search(line)
if match: item_type = 'selectone'
match = re_selectany.search(line)
if match: item_type = 'selectany'
match = re_multiline.search(line)
if match and multiline_attach:
gr.file_input.text += line.strip() + "\n"
match = re_keyval.search(line)
if match:
"""
key = value -> ...
"""
key = match.group(1).strip()
val = match.group(2).strip()
self.config_lines.append(key)
# make new grid
gr = MDGridLayout(cols=2, size_hint=(1, None), height=38, padding=5, spacing=5) #self.width/2
if ss < 0:
gr.bind(width=sv_llayout[s].setter('width'))
else:
gr.bind(width=ss_sv_llayout[ss].setter('width'))
gr.label2 = Label(text=key, halign='right', valign='top', color='black', size_hint=(0.4, 1), font_name='app/_ui/fonts/consola.ttf', padding_y=6)
gr.label2.bind(size=gr.label2.setter('text_size'))
gr.add_widget(gr.label2)
if item_type == 'multiline':
"""
(multiline) -> TextField multiline
"""
gr.cols=1
gr.label2.size_hint = (1, 0.2)
gr.label2.halign='left'
gr.file_input = TextInputMD(label=key, units='', multiline=True, text=val, size_hint=(1, 0.8))
gr.height = 150
gr.add_widget(gr.file_input)
multiline_attach = True
self.config_keys[key] = gr.file_input
elif item_type == 'yesno':
"""
(yes/no) -> Chips_xor
"""
###gr.file_input = ToggleButton(text='yes', state='down' if val=='yes' else 'normal', size_hint=(None, 1), group=key, font_name='app/_ui/fonts/consola.ttf')
###gr.file_input2 = ToggleButton(text='no', state='down' if val=='no' else 'normal', size_hint=(None, 1), group=key, font_name='app/_ui/fonts/consola.ttf')
gr.file_input = SelectChip_xor(text='yes', active=True if val=='yes' else False)
gr.file_input2 = SelectChip_xor_no(text='no', active=True if val=='no' else False)
#gr.file_input.group = True
#gr.file_input = Switch(active_norm_pos=0, active=True, size_hint=(None, 1))
gr.container = MDStackLayout(size_hint=(0.6, 1))
gr.container.add_widget(gr.file_input)
gr.container.add_widget(gr.file_input2)
gr.add_widget(gr.container)
self.config_keys[key] = gr.file_input
elif item_type == 'selectone':
"""
(select one) -> Chips_or
"""
#gr = BoxLayout(orientation='vertical', size_hint=(1, None))
#gr.key_label = Label(text=key, color='black', size_hint=(0.4, None), font_name='app/_ui/fonts/consola.ttf', padding_y=6)
#gr.key_label.bind(size=gr.key_label.setter('text_size'))
#gr.add_widget(gr.key_label)
gr.select_container = MDStackLayout(size_hint=(0.6, 1)) #size_hint=(1, None))
###gr.container = BoxLayout(orientation='vertical', size_hint=(0.6, 1))
###gr.container_row = BoxLayout(size_hint=(1, 1))
###current_container_row = gr.container_row
###text_length = 0
for i in range(len(selectitems)):
gr.file_input = SelectChip_or(text=selectitems[i], active=True if val==selectitems[i] else False)
gr.select_container.add_widget(gr.file_input)
if val==selectitems[i]:
self.config_keys[key] = gr.file_input
###text_length += len(selectitems[i])
###if text_length > 23 and i > 0:
### #print('Make new row', i, key)
### gr.container.add_widget(current_container_row)
### gr.container_row = BoxLayout(size_hint=(1, 1))
### current_container_row = gr.container_row
### gr.height += 30
#gr.file_input = Spinner(active=True, size_hint=(0.3, 1))
#gr.file_input.group = True
#gr.add_widget(gr.file_input)
###gr.file_input = ToggleButton(text=selectitems[i], state='down' if val==selectitems[i] else 'normal', group=key, font_name='app/_ui/fonts/consola.ttf')
###gr.file_input.width = gr.file_input.texture_size[0]
###current_container_row.add_widget(gr.file_input)
gr.add_widget(gr.select_container)
#gr.container.add_widget(gr.file_input2)
###gr.container.add_widget(current_container_row)
###gr.add_widget(gr.container)
#self.config_keys[key] = gr.file_input
# if len(selectitems)>0:
# gr.file_input = Spinner(text=selectitems[0], values=selectitems[1:], size_hint=(0.6, 1), font_name='fonts/consola.ttf') #, background_normal='', background_color=[1, 1, 1, 1], color='black', border=[1,1,1,1]
# gr.add_widget(gr.file_input)
# else:
# print('bad list', key, val)
elif item_type == 'selectanyx':
"""
(select any) -> Chips
"""
gr.container = BoxLayout(orientation='vertical', size_hint=(0.6, 1))
gr.container_row = BoxLayout(size_hint=(1, 1))
current_container_row = gr.container_row
text_length = 0
for i in range(len(selectitems)):
#gr.file_input = Spinner(active=True, size_hint=(0.3, 1))
#gr.file_input.group = True
#gr.add_widget(gr.file_input)
gr.file_input = ToggleButton(text=selectitems[i], font_name='fonts/consola.ttf')
#gr.file_input.bind(on_state=self.change_toggle)
#gr.file_input.bind(on_state=lambda *args: self.change_toggle('btn1', *args) )
#gr.file_input.bind(on_state=self.change_toggle) #, 'waff'))
gr.file_input.width = gr.file_input.texture_size[0]
current_container_row.add_widget(gr.file_input)
text_length += len(selectitems[i])
if text_length > 30 and i < len(selectitems):
gr.container.add_widget(current_container_row)
gr.container_row = BoxLayout(size_hint=(1, 1))
current_container_row = gr.container_row
gr.height += 30
#gr.container.add_widget(gr.file_input2)
gr.container.add_widget(current_container_row)
gr.add_widget(gr.container)
# store binding
self.config_keys[key] = gr.file_input
else:
"""
... -> TextField
"""
gr = TextInputMD(label=key, units='in m', multiline=False, text=val, size_hint=(1, None))
#gr.file_input =
#gr.add_widget(gr.file_input)
# store binding
self.config_keys[key] = gr #.file_input
if ss < 0:
sv_llayout[s].add_widget(gr)
#sv_llayout[s].height += gr.height
else:
ss_sv_llayout[ss].add_widget(gr)
#ss_sv_llayout[ss].height += gr.height
#sv_llayout[s].height += gr.height
selectitems = []
item_type = ''
# Opens first Accordion items
###for Ac in self.Ac_subsection:
### Ac.children[-1].collapse = False
#self.is_loading = False
# Overwrite print() with flush, i.e., no buffer
#window.Refresh()
#instantPASDy.corny.print = myprint
def change_toggle(self, togglebutton):
pass
#tb = togglebutton #.get_widgets('group')
......
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