mirror of
https://github.com/markqvist/NomadNet.git
synced 2025-01-11 15:19:26 -05:00
Input field rendering
This commit is contained in:
parent
4f483e482a
commit
eb6dd1729b
@ -6,6 +6,9 @@ from urwid.util import is_mouse_press
|
|||||||
from urwid.text_layout import calc_coords
|
from urwid.text_layout import calc_coords
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
# TODO: remove
|
||||||
|
import RNS
|
||||||
|
|
||||||
DEFAULT_FG_DARK = "ddd"
|
DEFAULT_FG_DARK = "ddd"
|
||||||
DEFAULT_FG_LIGHT = "222"
|
DEFAULT_FG_LIGHT = "222"
|
||||||
DEFAULT_BG = "default"
|
DEFAULT_BG = "default"
|
||||||
@ -63,11 +66,12 @@ def markup_to_attrmaps(markup, url_delegate = None):
|
|||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if len(line) > 0:
|
if len(line) > 0:
|
||||||
display_widget = parse_line(line, state, url_delegate)
|
display_widgets = parse_line(line, state, url_delegate)
|
||||||
else:
|
else:
|
||||||
display_widget = urwid.Text("")
|
display_widgets = [urwid.Text("")]
|
||||||
|
|
||||||
if display_widget != None:
|
if display_widgets != None and len(display_widgets) != 0:
|
||||||
|
for display_widget in display_widgets:
|
||||||
attrmap = urwid.AttrMap(display_widget, make_style(state))
|
attrmap = urwid.AttrMap(display_widget, make_style(state))
|
||||||
attrmaps.append(attrmap)
|
attrmaps.append(attrmap)
|
||||||
|
|
||||||
@ -125,7 +129,7 @@ def parse_line(line, state, url_delegate):
|
|||||||
|
|
||||||
heading_style = first_style
|
heading_style = first_style
|
||||||
output.insert(0, " "*left_indent(state))
|
output.insert(0, " "*left_indent(state))
|
||||||
return urwid.AttrMap(urwid.Text(output, align=state["align"]), heading_style)
|
return [urwid.AttrMap(urwid.Text(output, align=state["align"]), heading_style)]
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
@ -138,22 +142,54 @@ def parse_line(line, state, url_delegate):
|
|||||||
else:
|
else:
|
||||||
divider_char = "\u2500"
|
divider_char = "\u2500"
|
||||||
if state["depth"] == 0:
|
if state["depth"] == 0:
|
||||||
return urwid.Divider(divider_char)
|
return [urwid.Divider(divider_char)]
|
||||||
else:
|
else:
|
||||||
return urwid.Padding(urwid.Divider(divider_char), left=left_indent(state), right=right_indent(state))
|
return [urwid.Padding(urwid.Divider(divider_char), left=left_indent(state), right=right_indent(state))]
|
||||||
|
|
||||||
output = make_output(state, line, url_delegate)
|
output = make_output(state, line, url_delegate)
|
||||||
|
|
||||||
if output != None:
|
if output != None:
|
||||||
|
text_only = True
|
||||||
|
for o in output:
|
||||||
|
if not isinstance(o, tuple):
|
||||||
|
text_only = False
|
||||||
|
break
|
||||||
|
|
||||||
|
if not text_only:
|
||||||
|
widgets = []
|
||||||
|
for o in output:
|
||||||
|
if isinstance(o, tuple):
|
||||||
|
if url_delegate != None:
|
||||||
|
tw = LinkableText(o, align=state["align"], delegate=url_delegate)
|
||||||
|
else:
|
||||||
|
tw = urwid.Text(o, align=state["align"])
|
||||||
|
|
||||||
|
widgets.append(("pack", tw))
|
||||||
|
else:
|
||||||
|
if o["type"] == "field":
|
||||||
|
fw = 32
|
||||||
|
fd = o["data"]
|
||||||
|
fn = o["name"]
|
||||||
|
fs = o["style"]
|
||||||
|
f = urwid.Edit(caption="", edit_text=fd, align=state["align"], multiline=True)
|
||||||
|
f.field_name = fn
|
||||||
|
fa = urwid.AttrMap(f, fs)
|
||||||
|
widgets.append((fw, fa))
|
||||||
|
|
||||||
|
columns_widget = urwid.Columns(widgets, dividechars=0)
|
||||||
|
text_widget = columns_widget
|
||||||
|
# text_widget = urwid.Text("<"+output+">", align=state["align"])
|
||||||
|
|
||||||
|
else:
|
||||||
if url_delegate != None:
|
if url_delegate != None:
|
||||||
text_widget = LinkableText(output, align=state["align"], delegate=url_delegate)
|
text_widget = LinkableText(output, align=state["align"], delegate=url_delegate)
|
||||||
else:
|
else:
|
||||||
text_widget = urwid.Text(output, align=state["align"])
|
text_widget = urwid.Text(output, align=state["align"])
|
||||||
|
|
||||||
if state["depth"] == 0:
|
if state["depth"] == 0:
|
||||||
return text_widget
|
return [text_widget]
|
||||||
else:
|
else:
|
||||||
return urwid.Padding(text_widget, left=left_indent(state), right=right_indent(state))
|
return [urwid.Padding(text_widget, left=left_indent(state), right=right_indent(state))]
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
@ -425,8 +461,6 @@ def make_output(state, line, url_delegate):
|
|||||||
state["align"] = state["default_align"]
|
state["align"] = state["default_align"]
|
||||||
|
|
||||||
elif c == "<":
|
elif c == "<":
|
||||||
# TODO: remove
|
|
||||||
import RNS
|
|
||||||
field_name = None
|
field_name = None
|
||||||
field_name_end = line[i:].find("`")
|
field_name_end = line[i:].find("`")
|
||||||
if field_name_end == -1:
|
if field_name_end == -1:
|
||||||
@ -448,7 +482,7 @@ def make_output(state, line, url_delegate):
|
|||||||
field_data = lr[1:endpos].replace(rsg, "\\>")
|
field_data = lr[1:endpos].replace(rsg, "\\>")
|
||||||
skip = len(field_data)+len(field_name)+2
|
skip = len(field_data)+len(field_name)+2
|
||||||
field_data = field_data.replace("\\>", ">")
|
field_data = field_data.replace("\\>", ">")
|
||||||
RNS.log("Field "+str(field_name)+": "+str(field_data))
|
output.append({"type":"field", "name": field_name, "data": field_data, "style": make_style(state)})
|
||||||
|
|
||||||
elif c == "[":
|
elif c == "[":
|
||||||
endpos = line[i:].find("]")
|
endpos = line[i:].find("]")
|
||||||
|
Loading…
Reference in New Issue
Block a user