|
@@ -25,13 +25,16 @@ from urwid import (
|
|
|
Edit,
|
|
|
Filler,
|
|
|
LineBox,
|
|
|
- Padding,
|
|
|
Pile,
|
|
|
Text,
|
|
|
)
|
|
|
|
|
|
-from .. import COPYRIGHT
|
|
|
from ..data.QueryManager import QueryManager
|
|
|
+from .grouped_widget_util import (
|
|
|
+ to_numbered_field,
|
|
|
+ to_unnumbered_field,
|
|
|
+ to_named_value,
|
|
|
+)
|
|
|
from ..widgets import (
|
|
|
AutoCompleteEdit,
|
|
|
AutoCompleteFloatEdit,
|
|
@@ -43,31 +46,14 @@ from ..widgets import (
|
|
|
from . import ActivityManager
|
|
|
from .Rating import Rating
|
|
|
from .NewProduct import NewProduct
|
|
|
-
|
|
|
-def to_numbered_field(x):
|
|
|
- if len(x[0].split('#', 1)) > 1:
|
|
|
- name, idx = x[0].split('#', 1)
|
|
|
- idx = int(idx)
|
|
|
- else:
|
|
|
- name, idx = x[0], 0
|
|
|
-
|
|
|
- return (name, int(idx)), x[1]
|
|
|
-
|
|
|
-def to_unnumbered_field(x):
|
|
|
- return x[0][0], x[1]
|
|
|
-
|
|
|
-def in_same_row(name):
|
|
|
- if len(name.split('#', 1)) > 1:
|
|
|
- _, row = name.split('#', 1)
|
|
|
- else:
|
|
|
- row = 0
|
|
|
- return lambda x: x[0][1] == int(row)
|
|
|
+from .Banner import banner
|
|
|
|
|
|
def unzip(_iter: List[Tuple[AutoCompleteEdit, Edit]]) -> Tuple[
|
|
|
List[AutoCompleteEdit], List[Edit]
|
|
|
]:
|
|
|
return zip(*_iter)
|
|
|
|
|
|
+
|
|
|
def extract_values(x: Union[List[AutoCompleteEdit], List[Edit]]) -> Iterable[str]:
|
|
|
if isinstance(x, (list, tuple)):
|
|
|
if len(x) == 0:
|
|
@@ -75,8 +61,6 @@ def extract_values(x: Union[List[AutoCompleteEdit], List[Edit]]) -> Iterable[str
|
|
|
return ( v.get_edit_text() for v in x )
|
|
|
raise Exception(f"Unsupported type: {type(x)}")
|
|
|
|
|
|
-def to_named_value(name: str) -> Callable[[str], Tuple[str,str]]:
|
|
|
- return lambda e: (f'{name}#{e[0]}', e[1])
|
|
|
|
|
|
def blank_tags_row(idx: int) -> Tuple[AutoCompleteEdit, Edit]:
|
|
|
return (
|
|
@@ -110,10 +94,11 @@ class TransactionEditor(FocusWidget):
|
|
|
|
|
|
def apply_choice(self, name, value):
|
|
|
self.apply_changes(name, value)
|
|
|
- data = dict(#filter(
|
|
|
- # in_same_row(name),
|
|
|
- map(to_numbered_field, self.data.items())
|
|
|
- )#)
|
|
|
+ data = {
|
|
|
+ (field, idx): v for field, idx, v in map(
|
|
|
+ to_numbered_field, self.data.items()
|
|
|
+ )
|
|
|
+ }
|
|
|
for k,v in data.items():
|
|
|
if f'{k[0]}#{k[1]}' == name or v:
|
|
|
continue
|
|
@@ -172,16 +157,12 @@ class TransactionEditor(FocusWidget):
|
|
|
|
|
|
|
|
|
def init_tags(self):
|
|
|
- #_tags = LineBox(Pile([AttrMap(
|
|
|
_tags = Pile([AttrMap(
|
|
|
AutoCompletePopUp(
|
|
|
tag[0],
|
|
|
self.apply_choice,
|
|
|
lambda: self.activity_manager.show(self.update())
|
|
|
), 'streak') for tag in self._tags])
|
|
|
- # title=f'Tags',
|
|
|
- # title_align='left'
|
|
|
- #)
|
|
|
gutter = Pile([
|
|
|
*[ Divider() for _ in self._tags[:-1] ],
|
|
|
Divider(),
|
|
@@ -196,7 +177,6 @@ class TransactionEditor(FocusWidget):
|
|
|
blank_tags_row(len(self._tags))
|
|
|
)
|
|
|
_tags, gutter = self.init_tags()
|
|
|
- #self.components['tags'][1].original_widget.contents = list(_tags.original_widget.contents)
|
|
|
self.components['tags'].contents = list(_tags.contents)
|
|
|
self.components['gutter'][1].contents = list(gutter.contents)
|
|
|
for widget in self._tags:
|
|
@@ -204,16 +184,13 @@ class TransactionEditor(FocusWidget):
|
|
|
connect_signal(widget[0], 'apply', lambda w, name: self.autocomplete_callback(
|
|
|
w, name, self.autocomplete_options(name, dict(map(
|
|
|
to_unnumbered_field,
|
|
|
- #filter(
|
|
|
- # in_same_row(name),
|
|
|
- map(to_numbered_field, self.data.items()
|
|
|
- #)
|
|
|
+ map(to_numbered_field, self.data.items()
|
|
|
))))
|
|
|
))
|
|
|
|
|
|
|
|
|
def clear(self):
|
|
|
- self._tags = []
|
|
|
+ self._tags: List[Tuple[AutoCompleteEdit, Edit]] = []
|
|
|
self.add_tag()
|
|
|
for (k, ef) in self.edit_fields.items():
|
|
|
if k in ('ts', 'store',):
|
|
@@ -421,10 +398,7 @@ class TransactionEditor(FocusWidget):
|
|
|
connect_signal(ef, 'apply', lambda w, name: self.autocomplete_callback(
|
|
|
w, name, self.autocomplete_options(name, dict(map(
|
|
|
to_unnumbered_field,
|
|
|
- #filter(
|
|
|
- # in_same_row(name),
|
|
|
map(to_numbered_field, self.data.items()
|
|
|
- #)
|
|
|
))))
|
|
|
))
|
|
|
|
|
@@ -438,8 +412,6 @@ class TransactionEditor(FocusWidget):
|
|
|
title=k.title(), title_align='left'
|
|
|
) for k in self.edit_fields if k != 'product'
|
|
|
})
|
|
|
- header = Text(u'Fill Transaction', 'center')
|
|
|
- _copyright = Text(COPYRIGHT, 'center')
|
|
|
|
|
|
self.components.update({
|
|
|
'bottom_button_bar': Columns(
|
|
@@ -472,11 +444,6 @@ class TransactionEditor(FocusWidget):
|
|
|
connect_signal(self.buttons['clear'], 'click', lambda _: self.clear())
|
|
|
connect_signal(self.buttons['add'], 'click', lambda _: self.add_tag())
|
|
|
|
|
|
- banner = Pile([
|
|
|
- Padding(header, 'center', width=('relative', 100)),
|
|
|
- Padding(_copyright, 'center', width=('relative', 100)),
|
|
|
- ])
|
|
|
- banner = AttrMap(banner, 'banner')
|
|
|
_widgets.update({
|
|
|
'product': LineBox(Columns([
|
|
|
AttrMap(AutoCompletePopUp(
|
|
@@ -507,7 +474,7 @@ class TransactionEditor(FocusWidget):
|
|
|
self.add_tag()
|
|
|
|
|
|
widget = Pile([
|
|
|
- banner,
|
|
|
+ banner(u'Fill Transaction'),
|
|
|
Divider(),
|
|
|
Columns([
|
|
|
self.components['main_pane'],
|