|
@@ -26,9 +26,9 @@ class AutoCompleteEdit(urwid.Edit):
|
|
|
self.name = name
|
|
|
title = name.title()
|
|
|
passthrough = u' ' if name.lower() == 'unit' else u''
|
|
|
-
|
|
|
+
|
|
|
super().__init__(passthrough, *args, **kwargs)
|
|
|
-
|
|
|
+
|
|
|
def keypress(self, size, key):
|
|
|
if key == 'enter':
|
|
|
self._emit('apply', self.name)
|
|
@@ -36,7 +36,7 @@ class AutoCompleteEdit(urwid.Edit):
|
|
|
elif key == 'delete':
|
|
|
self.set_edit_text('')
|
|
|
return
|
|
|
-
|
|
|
+
|
|
|
return super().keypress(size, key)
|
|
|
|
|
|
class AutoCompleteFloatEdit(numedit.FloatEdit):
|
|
@@ -54,9 +54,9 @@ class AutoCompleteFloatEdit(numedit.FloatEdit):
|
|
|
self.name = name
|
|
|
title = name.title()
|
|
|
passthrough = title
|
|
|
-
|
|
|
+
|
|
|
super().__init__(passthrough, *args, **kwargs)
|
|
|
-
|
|
|
+
|
|
|
def update_caption(self):
|
|
|
if self.pallete is not None:
|
|
|
self.set_caption((self.pallete, f'{self.op} '))
|
|
@@ -68,7 +68,7 @@ class AutoCompleteFloatEdit(numedit.FloatEdit):
|
|
|
self.last_val = self.value()
|
|
|
self.set_edit_text('')
|
|
|
self.update_caption()
|
|
|
-
|
|
|
+
|
|
|
def calc(self):
|
|
|
x = self.last_val
|
|
|
op = self.op
|
|
@@ -87,7 +87,7 @@ class AutoCompleteFloatEdit(numedit.FloatEdit):
|
|
|
else:
|
|
|
y = self.value() or Decimal(0.0)
|
|
|
z = y
|
|
|
-
|
|
|
+
|
|
|
self.op = '='
|
|
|
self.update_caption()
|
|
|
self.set_edit_text(f'{z:.2f}')
|
|
@@ -122,7 +122,7 @@ class AutoCompleteFloatEdit(numedit.FloatEdit):
|
|
|
class NoTabCheckBox(urwid.CheckBox):
|
|
|
def keypress(self, size, key):
|
|
|
if not isinstance(key, tuple) and key == 'tab':
|
|
|
- return
|
|
|
+ return
|
|
|
else:
|
|
|
return super().keypress(size, key)
|
|
|
|
|
@@ -135,11 +135,11 @@ class FocusWidget(urwid.WidgetWrap):
|
|
|
for w, p in self.iter_focus_paths():
|
|
|
if w is self._focus_widgets[0]:
|
|
|
self.container.set_focus_path(p)
|
|
|
-
|
|
|
+
|
|
|
@property
|
|
|
def container(self):
|
|
|
return self._w.original_widget.original_widget
|
|
|
-
|
|
|
+
|
|
|
def find_widget(self, widget=None):
|
|
|
if widget in self._focus_widgets:
|
|
|
return widget
|
|
@@ -149,7 +149,7 @@ class FocusWidget(urwid.WidgetWrap):
|
|
|
return
|
|
|
if _w1 is not None:
|
|
|
return self.find_widget(widget=_w1)
|
|
|
-
|
|
|
+
|
|
|
def iter_containers(self, path=None, widget=None):
|
|
|
widget = widget or self.container
|
|
|
path = path or []
|
|
@@ -160,11 +160,18 @@ class FocusWidget(urwid.WidgetWrap):
|
|
|
yield widget, path
|
|
|
for idx, c in enumerate(_w2):
|
|
|
_chain.append(self.iter_containers(path=[*path, idx], widget=c[0]))
|
|
|
-
|
|
|
+
|
|
|
if _w1 is not None:
|
|
|
_chain.append(self.iter_containers(path=[*path], widget=_w1))
|
|
|
yield from chain(*_chain)
|
|
|
|
|
|
+ def focus_on(self, w):
|
|
|
+ _, p = next(filter(lambda x: x[0] is w, self.iter_focus_paths()))
|
|
|
+ path = self.container.get_focus_path()
|
|
|
+ while path != p:
|
|
|
+ self.advance_focus()
|
|
|
+ path = self.container.get_focus_path()
|
|
|
+
|
|
|
def iter_focus_paths(self):
|
|
|
for c, path in self.iter_containers():
|
|
|
for idx, w in enumerate(c.contents):
|
|
@@ -213,7 +220,7 @@ class AutoCompletePopUp(PopUpLauncher):
|
|
|
)
|
|
|
if 0 < len(options) - height < max_height//3:
|
|
|
height = 4 * max_height // 6
|
|
|
-
|
|
|
+
|
|
|
self._pop_up_parameters = dict(**self._default_pop_up_parameters)
|
|
|
self._pop_up_parameters.update({
|
|
|
'overlay_width': max(
|
|
@@ -224,7 +231,7 @@ class AutoCompletePopUp(PopUpLauncher):
|
|
|
'overlay_height': height+2,
|
|
|
})
|
|
|
self.open_pop_up()
|
|
|
-
|
|
|
+
|
|
|
def _close_pop_up(self):
|
|
|
self.close_pop_up()
|
|
|
self.close_cb()
|
|
@@ -241,7 +248,7 @@ class AutoCompletePopUp(PopUpLauncher):
|
|
|
return self._pop_up_parameters
|
|
|
|
|
|
class SuggestionPopup(urwid.WidgetWrap):
|
|
|
-
|
|
|
+
|
|
|
signals = ['close']
|
|
|
|
|
|
def __init__(self,
|
|
@@ -263,8 +270,8 @@ class SuggestionPopup(urwid.WidgetWrap):
|
|
|
bottomBar_endCovered_prop=("▼ {} more ▼", None, None),
|
|
|
bottomBar_endExposed_prop=(f"─── {len(options)} ───", None, None),
|
|
|
), 'popup'))
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
def keypress(self, size, key):
|
|
|
if key == 'esc':
|
|
|
self._emit("close")
|
|
@@ -280,10 +287,10 @@ class FlowBarGraph(urwid.BarGraph):
|
|
|
def __init__(self, height, *args, **kwargs):
|
|
|
super().__init__(*args, **kwargs)
|
|
|
self.height = height
|
|
|
-
|
|
|
+
|
|
|
def rows(self, size, focus=False):
|
|
|
return self.height
|
|
|
-
|
|
|
+
|
|
|
def render(self, size, focus=False):
|
|
|
_size = (size[0], self.rows(size))
|
|
|
return super().render(_size,focus=focus)
|
|
@@ -293,17 +300,17 @@ class FlowGraphVScale(urwid.GraphVScale):
|
|
|
def __init__(self, graph, *args, **kwargs):
|
|
|
super().__init__(*args, **kwargs)
|
|
|
self.graph = graph
|
|
|
-
|
|
|
+
|
|
|
def rows(self, size, focus=False):
|
|
|
return self.graph.rows(size)
|
|
|
-
|
|
|
+
|
|
|
def render(self, size, focus=False):
|
|
|
_size = (size[0], self.rows(size))
|
|
|
return super().render(_size,focus=focus)
|
|
|
-
|
|
|
+
|
|
|
class FlowBarGraphWithVScale(urwid.Columns):
|
|
|
ignore_focus = True
|
|
|
-
|
|
|
+
|
|
|
@property
|
|
|
def total_width(self):
|
|
|
return self._total_width
|
|
@@ -311,24 +318,24 @@ class FlowBarGraphWithVScale(urwid.Columns):
|
|
|
@property
|
|
|
def canvas_width(self):
|
|
|
return self._canvas_width
|
|
|
-
|
|
|
+
|
|
|
@property
|
|
|
def height(self):
|
|
|
return self.graph.height
|
|
|
-
|
|
|
+
|
|
|
@height.setter
|
|
|
def height(self, value):
|
|
|
self._invalidate
|
|
|
self.graph._invalidate
|
|
|
self.graph_vscale._invalidate
|
|
|
self.graph.height = value
|
|
|
-
|
|
|
+
|
|
|
def set_bar_width(self, width):
|
|
|
self.graph.set_bar_width(width)
|
|
|
-
|
|
|
+
|
|
|
def set_caption(self, text):
|
|
|
self.graph_caption.set_text(text)
|
|
|
-
|
|
|
+
|
|
|
def set_data(self, data, _max, vscale=None, caption=None):
|
|
|
labels = vscale or []
|
|
|
caption = caption or u''
|
|
@@ -342,7 +349,7 @@ class FlowBarGraphWithVScale(urwid.Columns):
|
|
|
((x*top)//scale, f'{x:>5.2f} ') for x in labels
|
|
|
], top)
|
|
|
self.graph_caption.set_text(caption)
|
|
|
-
|
|
|
+
|
|
|
def __init__(self, cols, rows, attr, *args, hatt=None, **kwargs):
|
|
|
self._total_width = cols
|
|
|
assert cols > 6
|
|
@@ -358,4 +365,4 @@ class FlowBarGraphWithVScale(urwid.Columns):
|
|
|
self.graph_caption
|
|
|
]))
|
|
|
], *args, **kwargs)
|
|
|
-
|
|
|
+
|