|
@@ -124,19 +124,6 @@ class NoTabCheckBox(urwid.CheckBox):
|
|
else:
|
|
else:
|
|
return super().keypress(size, key)
|
|
return super().keypress(size, key)
|
|
|
|
|
|
-def _set_focus_path(container, path):
|
|
|
|
- try:
|
|
|
|
- container.set_focus_path(path)
|
|
|
|
- return
|
|
|
|
- except IndexError:
|
|
|
|
- pass
|
|
|
|
-
|
|
|
|
- if path[-1] == 0 and len(path) > 1:
|
|
|
|
- _set_focus_path(container, path[:-1])
|
|
|
|
- return
|
|
|
|
-
|
|
|
|
- raise IndexError
|
|
|
|
-
|
|
|
|
class GroceryTransactionEditor(urwid.WidgetPlaceholder):
|
|
class GroceryTransactionEditor(urwid.WidgetPlaceholder):
|
|
def __init__(self, activity_manager, cur, log):
|
|
def __init__(self, activity_manager, cur, log):
|
|
super().__init__(urwid.SolidFill(u'/'))
|
|
super().__init__(urwid.SolidFill(u'/'))
|
|
@@ -201,25 +188,52 @@ class GroceryTransactionEditor(urwid.WidgetPlaceholder):
|
|
self.log.write(statement)
|
|
self.log.write(statement)
|
|
self.cur.execute(statement)
|
|
self.cur.execute(statement)
|
|
|
|
|
|
-class TransactionEditor(urwid.WidgetPlaceholder):
|
|
|
|
|
|
+class FocusWidget(urwid.WidgetPlaceholder):
|
|
|
|
+
|
|
|
|
+ def __init__(self, initial_focus, skip_focus):
|
|
|
|
+ super().__init__(urwid.SolidFill(u'/'))
|
|
|
|
+ self._initial_focus = tuple([ i for i in initial_focus ])
|
|
|
|
+ self._skip_focus = tuple([ i for i in skip_focus ])
|
|
|
|
+
|
|
|
|
+ @property
|
|
|
|
+ def skip_focus(self):
|
|
|
|
+ return self._skip_focus
|
|
|
|
+
|
|
|
|
+ @property
|
|
|
|
+ def initial_focus(self):
|
|
|
|
+ return list(self._initial_focus)
|
|
|
|
+
|
|
|
|
+ @property
|
|
|
|
+ def container(self):
|
|
|
|
+ return self.original_widget.original_widget.original_widget
|
|
|
|
+
|
|
|
|
+ def _set_focus_path(self, path):
|
|
|
|
+ try:
|
|
|
|
+ self.container.set_focus_path(path)
|
|
|
|
+ return
|
|
|
|
+ except IndexError:
|
|
|
|
+ pass
|
|
|
|
+
|
|
|
|
+ if path[-1] == 0 and len(path) > 1:
|
|
|
|
+ self._set_focus_path(path[:-1])
|
|
|
|
+ return
|
|
|
|
+
|
|
|
|
+ raise IndexError
|
|
|
|
|
|
def iter_focus_paths(self):
|
|
def iter_focus_paths(self):
|
|
- initial = [2,0,0,0]
|
|
|
|
- container = self.original_widget.original_widget.original_widget
|
|
|
|
- _set_focus_path(container, initial)
|
|
|
|
|
|
+ self._set_focus_path(self.initial_focus)
|
|
while True:
|
|
while True:
|
|
- path = container.get_focus_path()
|
|
|
|
|
|
+ path = self.container.get_focus_path()
|
|
yield path
|
|
yield path
|
|
self.advance_focus()
|
|
self.advance_focus()
|
|
- path = container.get_focus_path()
|
|
|
|
- if path == initial:
|
|
|
|
- self.advance_focus()
|
|
|
|
|
|
+ path = self.container.get_focus_path()
|
|
|
|
+ if path == self.initial_focus:
|
|
break
|
|
break
|
|
|
|
|
|
def advance_focus(self, reverse=False):
|
|
def advance_focus(self, reverse=False):
|
|
- container = self.original_widget.original_widget.original_widget
|
|
|
|
|
|
|
|
- path = container.get_focus_path()
|
|
|
|
|
|
+ path = self.container.get_focus_path()
|
|
|
|
+
|
|
if reverse:
|
|
if reverse:
|
|
paths = [ i for i in self.iter_focus_paths() ]
|
|
paths = [ i for i in self.iter_focus_paths() ]
|
|
zipped_paths = zip(paths, [
|
|
zipped_paths = zip(paths, [
|
|
@@ -229,7 +243,8 @@ class TransactionEditor(urwid.WidgetPlaceholder):
|
|
lambda x: x[1] == path,
|
|
lambda x: x[1] == path,
|
|
zipped_paths
|
|
zipped_paths
|
|
))
|
|
))
|
|
- _set_focus_path(container, next(prev_path))
|
|
|
|
|
|
+ p = next(prev_path)
|
|
|
|
+ self._set_focus_path(p)
|
|
return
|
|
return
|
|
|
|
|
|
_iter = [ i for i in enumerate(path) ][::-1]
|
|
_iter = [ i for i in enumerate(path) ][::-1]
|
|
@@ -242,14 +257,16 @@ class TransactionEditor(urwid.WidgetPlaceholder):
|
|
p[idx] += 1
|
|
p[idx] += 1
|
|
|
|
|
|
try:
|
|
try:
|
|
- _set_focus_path(container, p)
|
|
|
|
- if path == [3]:
|
|
|
|
|
|
+ self._set_focus_path(p)
|
|
|
|
+ if p in self.skip_focus:
|
|
self.advance_focus(reverse=reverse)
|
|
self.advance_focus(reverse=reverse)
|
|
return
|
|
return
|
|
except IndexError:
|
|
except IndexError:
|
|
path[idx] = 0
|
|
path[idx] = 0
|
|
-
|
|
|
|
- container.set_focus_path([2,0,0,0])
|
|
|
|
|
|
+
|
|
|
|
+ self.container.set_focus_path(self.initial_focus)
|
|
|
|
+
|
|
|
|
+class TransactionEditor(FocusWidget):
|
|
|
|
|
|
def keypress(self, size, key):
|
|
def keypress(self, size, key):
|
|
if isinstance(key, tuple):
|
|
if isinstance(key, tuple):
|
|
@@ -316,7 +333,11 @@ class TransactionEditor(urwid.WidgetPlaceholder):
|
|
def __init__(self, query_manager, fields,
|
|
def __init__(self, query_manager, fields,
|
|
layout, side_pane, bottom_pane,
|
|
layout, side_pane, bottom_pane,
|
|
save_and_clear_cb, autocomplete_cb):
|
|
save_and_clear_cb, autocomplete_cb):
|
|
- super().__init__(urwid.SolidFill(u'/'))
|
|
|
|
|
|
+ super().__init__([2,0,0,0], [
|
|
|
|
+ [4,],
|
|
|
|
+ [5,],
|
|
|
|
+ [7,],
|
|
|
|
+ ])
|
|
self.organic_checkbox = NoTabCheckBox(
|
|
self.organic_checkbox = NoTabCheckBox(
|
|
u"Organic",
|
|
u"Organic",
|
|
on_state_change=self.apply_organic_state
|
|
on_state_change=self.apply_organic_state
|