|
@@ -32,7 +32,6 @@ class TransactionEditor(FocusWidget):
|
|
|
elif key == 'ctrl delete':
|
|
|
self.clear()
|
|
|
self.focus_on_product()
|
|
|
- self.update()
|
|
|
elif key == 'insert':
|
|
|
self.save_and_clear_cb()
|
|
|
elif key == 'ctrl p':
|
|
@@ -57,18 +56,26 @@ class TransactionEditor(FocusWidget):
|
|
|
|
|
|
def apply_changes(self, name, value):
|
|
|
self.data.update({
|
|
|
- name: value,
|
|
|
+ name: value if name != 'organic' else {
|
|
|
+ 'yes': True, 'no': False,
|
|
|
+ True: True, False: False,
|
|
|
+ 'mixed': False
|
|
|
+ }[value],
|
|
|
})
|
|
|
|
|
|
def apply_organic_state(self, w, state):
|
|
|
- self.data['organic'] = 'yes' if state is True else 'no'
|
|
|
+ self.data['organic'] = state if state != 'mixed' else False
|
|
|
|
|
|
def clear(self):
|
|
|
for k in self.data:
|
|
|
if k in ('ts', 'store',):
|
|
|
continue
|
|
|
+ if k == 'organic':
|
|
|
+ self.data[k] = False
|
|
|
+ continue
|
|
|
self.data[k] = ''
|
|
|
- self.organic_checkbox.set_state(False)
|
|
|
+
|
|
|
+ return self.update()
|
|
|
|
|
|
def update(self):
|
|
|
for k in self.edit_fields:
|
|
@@ -79,7 +86,7 @@ class TransactionEditor(FocusWidget):
|
|
|
date or None, store or None
|
|
|
) else ''
|
|
|
)
|
|
|
- self.organic_checkbox.set_state(True if self.data['organic'] == 'yes' else False)
|
|
|
+ self.organic_checkbox.set_state(self.data['organic'])
|
|
|
return self
|
|
|
|
|
|
def focus_on_product(self):
|
|
@@ -104,12 +111,22 @@ class TransactionEditor(FocusWidget):
|
|
|
)
|
|
|
self.query_manager = query_manager
|
|
|
self.save_and_clear_cb = save_and_clear_cb
|
|
|
- self._init_data(fields)
|
|
|
self.layout = layout
|
|
|
self.side_pane = side_pane
|
|
|
self.bottom_pane = bottom_pane
|
|
|
self.edit_fields = OrderedDict()
|
|
|
self.text_fields = OrderedDict()
|
|
|
+ widgets = dict()
|
|
|
+ txn_view = urwid.Text('')
|
|
|
+ self.text_fields.update({'dbview': txn_view})
|
|
|
+ widgets.update({
|
|
|
+ 'dbview': urwid.LineBox(
|
|
|
+ urwid.AttrMap(txn_view, 'streak'),
|
|
|
+ title="Session Data",
|
|
|
+ title_align='left',
|
|
|
+ )
|
|
|
+ })
|
|
|
+ self._init_data(fields)
|
|
|
for k in self.data:
|
|
|
if k in self.side_pane and k != 'unit':
|
|
|
ef = AutoCompleteFloatEdit(('bg', k))
|
|
@@ -123,29 +140,27 @@ class TransactionEditor(FocusWidget):
|
|
|
urwid.connect_signal(ef, 'apply', lambda w, name: autocomplete_cb(w, name, self.data))
|
|
|
self.edit_fields[k] = ef
|
|
|
|
|
|
+ widgets.update(dict([
|
|
|
+ (k, urwid.LineBox(
|
|
|
+ urwid.AttrMap(AutoCompletePopUp(
|
|
|
+ self.edit_fields[k],
|
|
|
+ self.apply_choice,
|
|
|
+ lambda: activity_manager.show(self.update())
|
|
|
+ ), 'streak'), title=k.title(), title_align='left')
|
|
|
+ ) for k in self.edit_fields if k != 'product'
|
|
|
+ ]))
|
|
|
header = urwid.Text(u'Fill Transaction', 'center')
|
|
|
_copyright = urwid.Text(COPYRIGHT, 'center')
|
|
|
done_button = urwid.Button(('streak', u'Done'))
|
|
|
clear_button = urwid.Button(('streak', u'Clear'))
|
|
|
urwid.connect_signal(done_button, 'click', lambda _: save_and_clear_cb())
|
|
|
- urwid.connect_signal(clear_button, 'click', lambda _: [
|
|
|
- self.clear(), self.update()
|
|
|
- ])
|
|
|
+ urwid.connect_signal(clear_button, 'click', lambda _: self.clear())
|
|
|
banner = urwid.Pile([
|
|
|
urwid.Padding(header, 'center', width=('relative', 100)),
|
|
|
urwid.Padding(_copyright, 'center', width=('relative', 100)),
|
|
|
])
|
|
|
banner = urwid.AttrMap(banner, 'banner')
|
|
|
- fields = dict([
|
|
|
- (k, urwid.LineBox(
|
|
|
- urwid.AttrMap(AutoCompletePopUp(
|
|
|
- self.edit_fields[k],
|
|
|
- self.apply_choice,
|
|
|
- lambda: activity_manager.show(self.update())
|
|
|
- ), 'streak'), title=k.title(), title_align='left')
|
|
|
- ) for k in self.edit_fields if k != 'product'
|
|
|
- ])
|
|
|
- fields.update({
|
|
|
+ widgets.update({
|
|
|
'product': urwid.LineBox(urwid.Columns([
|
|
|
urwid.AttrMap(AutoCompletePopUp(
|
|
|
self.edit_fields['product'],
|
|
@@ -155,30 +170,21 @@ class TransactionEditor(FocusWidget):
|
|
|
self.organic_checkbox
|
|
|
], dividechars=2), title='Product', title_align='left')
|
|
|
})
|
|
|
- txn_view = urwid.Text('')
|
|
|
- self.text_fields.update({'dbview': txn_view})
|
|
|
- fields.update({
|
|
|
- 'dbview': urwid.LineBox(
|
|
|
- urwid.AttrMap(txn_view, 'streak'),
|
|
|
- title="Session Data",
|
|
|
- title_align='left',
|
|
|
- )
|
|
|
- })
|
|
|
|
|
|
side_pane_widget = (12, urwid.Pile([
|
|
|
- fields[r] if r is not None else urwid.Divider() for r in self.side_pane
|
|
|
+ widgets[r] if r is not None else urwid.Divider() for r in self.side_pane
|
|
|
]))
|
|
|
main_pane_widgets = []
|
|
|
for i, r in enumerate(self.layout):
|
|
|
- widgets = []
|
|
|
+ _widgets = []
|
|
|
for c in r:
|
|
|
if c is not None:
|
|
|
if c == 'organic':
|
|
|
continue
|
|
|
- widgets.append(fields[c])
|
|
|
+ _widgets.append(widgets[c])
|
|
|
else:
|
|
|
- widgets.append(urwid.Divider())
|
|
|
- main_pane_widgets.append(urwid.Columns(widgets))
|
|
|
+ _widgets.append(urwid.Divider())
|
|
|
+ main_pane_widgets.append(urwid.Columns(_widgets))
|
|
|
|
|
|
|
|
|
main_pane_widget = urwid.Pile(main_pane_widgets)
|
|
@@ -191,7 +197,7 @@ class TransactionEditor(FocusWidget):
|
|
|
],
|
|
|
dividechars=2,
|
|
|
),
|
|
|
- *[ fields[c] if c is not None else urwid.Divider() for c in self.bottom_pane ],
|
|
|
+ *[ widgets[c] if c is not None else urwid.Divider() for c in self.bottom_pane ],
|
|
|
urwid.Divider(),
|
|
|
urwid.Columns([
|
|
|
(8, done_button), urwid.Divider(), (9, clear_button)
|