Commit 97256a11 authored by Martin Schrön's avatar Martin Schrön
Browse files

GUI rewrote print output piping, improved colors, new events

parent 2a25cc91
......@@ -85,45 +85,98 @@ import os
import re
from functools import partial
import instantPASDy
_corny_print = instantPASDy.print
# pos where instanpasdy was imported
_orig_print = print
_corny_print = print
#print('(%5.2f) Finished imports.' % timer())
re_file_out = re.compile('^< (.+) saved to (.+\.\w+) \((.+)\)')
@mainthread
def print(*args, **kwargs):
_corny_print(*args, flush=True, **kwargs)
if hasattr(Root,'logwin'):
app = App.get_running_app()
#if hasattr(Root, 'logwin'):
if hasattr(app, 'data'):
if 'end' in kwargs:
end = kwargs['end']
else:
end = "\n"
text = " ".join(map(str, args))
#text = str(args[0])
text = re.sub(r'^.*\[\d+m', '(skipped colored input)', text)
if text.startswith(r'\\033'):
#if text.index('[3')>0:
text = text[1+text.index('m'):]
Root.logwin.insert_text(text + end)
app = App.get_running_app()
if app.log_line_hold:
app.update_log(text)
#Root.logwin.insert_text(text + end)
#Root.logwin.reset_undo()
#Root.logwin.do_undo()
if end=='\r':
app.update_log(text, whole_line=True)
else:
app.add_log(text)
if app.log_line_hold:
app.update_log(text)
else:
app.add_log(text)
if len(text)>0: # and app.root.update_progressbar_on_print:
if text[0] == '[':
#app.make_plot(3)
#Clock.schedule_once(lambda x: app.make_plot(4))
pass
elif text[0] == '=':
Root.update_progressbar(app.root, 0)
#app.make_plot(4)
elif text[0] == '<':
match = re_file_out.search(text)
if match:
Exec_button = ExecuteFileButton(text='%s (%s)' % (match.group(1), match.group(3)))
Exec_button.file_source = match.group(2)
if Exec_button.file_source.endswith('csv'):
Exec_button.icon = 'microsoft-excel' # file-delimited-outline
if match.group(1) == 'Data':
#app.make_plot(3.51) #Clock.schedule_once(lambda x: )
# Make plot
Root.output_csv_df = pandas.read_csv(match.group(2),
parse_dates=True, index_col=0, skipinitialspace = True)
Root.fill_dd_items(app.root)
Root.set_dd_item(app.root, 'moisture')
#app.make_plot(3.52)
elif Exec_button.file_source.endswith('pdf'):
Exec_button.icon = 'file-chart-outline'
#app.make_plot(3.6)
elif Exec_button.file_source.endswith('kml'):
Exec_button.icon = 'file-marker-outline'
#app.make_plot(3.7)
Root.create_map(app.root, match.group(2))
elif Exec_button.file_source.endswith('cfg'):
Exec_button.icon = 'file-cog-outline'
elif Exec_button.file_source.endswith('dat'):
Exec_button.icon = 'file-table-outline'
elif Exec_button.file_source.endswith('geojson'):
pass
#app.make_plot(3.9)
app.root.Tab_export_box.add_widget(Exec_button)
Root.update_progressbar(app.root, 0, diff=1)
else:
Root.update_progressbar(app.root, 0, diff=1)
if end=='':
app.log_line_hold = True
else:
app.log_line_hold = False
if len(text)>0:
if text[0] == '[':
Root.Pb.value += 15
Root.Pblbl.text = '%s ...' % text[1:-1] #' '.join(text.strip().split(' ', 2)[0:1])
elif text[0] == '=':
Root.Pb.value += 100
Root.Pblbl.text = 'Done.'
#print(app.root.update_progressbar_on_print)
# if args and not args[0].startswith(' '):
# #global progress
# self.progress += 1
......@@ -131,9 +184,6 @@ def print(*args, **kwargs):
# self.Pb.value = self.progress
# self.Pblbl.text = args[0].strip().split(' ', 1)[0]
instantPASDy.print = print # pipes print hereto
#instantPASDy.corny.io = print # pipes print hereto
redirect = dict(print=print) # set to ever function call
def RunCorny(*args):
......@@ -141,6 +191,12 @@ def RunCorny(*args):
#f = io.StringIO()
#with io.StringIO() as buf, contextlib.redirect_stdout(buf):
#with contextlib.redirect_stdout(f):
import instantPASDy
_corny_print = instantPASDy.print
instantPASDy.print = print # pipes print hereto
#instantPASDy.corny.io = print # pipes print hereto
instantPASDy.main(*args)
#print(buf.getvalue())
#output = f.getvalue()
......@@ -293,12 +349,15 @@ class CornyApp(App):
#'bgcolor': bgcolor
})
def update_log(self, dt):
def update_log(self, dt, whole_line=False):
"""Produce random text to append in the log, with the date, we don't
want to forget when we babbled incoherently.
"""
if len(self.data)>0:
self.data[-1]['text'] += dt
if whole_line:
self.data[-1]['text'] = dt
else:
self.data[-1]['text'] += dt
else:
self.add_log(dt)
......
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