|
@@ -18,18 +18,20 @@ from urwid import (
|
|
Pile,
|
|
Pile,
|
|
SimpleListWalker,
|
|
SimpleListWalker,
|
|
Text,
|
|
Text,
|
|
|
|
+ WidgetPlaceholder,
|
|
|
|
+ Widget,
|
|
)
|
|
)
|
|
from . import ActivityManager
|
|
from . import ActivityManager
|
|
from ..data.QueryManager import NON_IDENTIFIER_COLUMNS, QueryManager, get_insert_product_statement
|
|
from ..data.QueryManager import NON_IDENTIFIER_COLUMNS, QueryManager, get_insert_product_statement
|
|
from ..widgets import AutoCompleteEdit, AutoCompletePopUp
|
|
from ..widgets import AutoCompleteEdit, AutoCompletePopUp
|
|
|
|
|
|
-class NewProduct(Overlay):
|
|
|
|
|
|
+class NewProduct(WidgetPlaceholder):
|
|
|
|
|
|
def __init__(self,
|
|
def __init__(self,
|
|
activity_manager: ActivityManager,
|
|
activity_manager: ActivityManager,
|
|
query_manager: QueryManager,
|
|
query_manager: QueryManager,
|
|
- under, name, data,
|
|
|
|
- change_cb,
|
|
|
|
|
|
+ under: Widget,
|
|
|
|
+ name,
|
|
):
|
|
):
|
|
self.under = under
|
|
self.under = under
|
|
self.activity_manager = activity_manager
|
|
self.activity_manager = activity_manager
|
|
@@ -38,14 +40,14 @@ class NewProduct(Overlay):
|
|
|
|
|
|
title = Text('Enter Product Info', align='center')
|
|
title = Text('Enter Product Info', align='center')
|
|
self.fields = OrderedDict()
|
|
self.fields = OrderedDict()
|
|
- self.autocomplete_callback = lambda widget, options: len(options) and widget._emit('open', options)
|
|
|
|
|
|
+ self.autocomplete_cb = lambda widget, options: len(options) and widget._emit('open', options)
|
|
for f in ('product', 'category', 'group'):
|
|
for f in ('product', 'category', 'group'):
|
|
w = AutoCompleteEdit(('bg', f))
|
|
w = AutoCompleteEdit(('bg', f))
|
|
self.fields[f] = w
|
|
self.fields[f] = w
|
|
- w.set_edit_text(data[f])
|
|
|
|
- connect_signal(w, 'change', lambda w, v: change_cb(w.name, v))
|
|
|
|
- connect_signal(w, 'apply', lambda w, name: self.autocomplete_callback(
|
|
|
|
- w, query_manager.unique_suggestions(name, **self.data)
|
|
|
|
|
|
+ w.set_edit_text(under.data[f])
|
|
|
|
+ connect_signal(w, 'change', lambda w, v: under.apply_changes(w.name, v))
|
|
|
|
+ connect_signal(w, 'apply', lambda _, name: self.autocomplete_cb(
|
|
|
|
+ _, query_manager.unique_suggestions(name, **self.data)
|
|
))
|
|
))
|
|
|
|
|
|
ok = Button('Done', on_press=lambda _: self.insert_new_product())
|
|
ok = Button('Done', on_press=lambda _: self.insert_new_product())
|
|
@@ -53,9 +55,7 @@ class NewProduct(Overlay):
|
|
body = AttrMap(ListBox(SimpleListWalker([
|
|
body = AttrMap(ListBox(SimpleListWalker([
|
|
Padding(
|
|
Padding(
|
|
Pile([
|
|
Pile([
|
|
- #Divider(),
|
|
|
|
AttrMap(title, 'banner'),
|
|
AttrMap(title, 'banner'),
|
|
- #Divider(),
|
|
|
|
*[AttrMap(LineBox(AttrMap(
|
|
*[AttrMap(LineBox(AttrMap(
|
|
AutoCompletePopUp(
|
|
AutoCompletePopUp(
|
|
v,
|
|
v,
|
|
@@ -69,7 +69,10 @@ class NewProduct(Overlay):
|
|
align='center', left=1, right=1,
|
|
align='center', left=1, right=1,
|
|
)
|
|
)
|
|
])), 'banner')
|
|
])), 'banner')
|
|
- super().__init__(AttrMap(body, 'bg'), under,
|
|
|
|
|
|
+ super().__init__(under)
|
|
|
|
+ self.original_widget = Overlay(
|
|
|
|
+ AttrMap(body, 'bg'),
|
|
|
|
+ self.original_widget,
|
|
align='center', width=('relative', 40),
|
|
align='center', width=('relative', 40),
|
|
valign='middle', height=13,
|
|
valign='middle', height=13,
|
|
min_width=20)
|
|
min_width=20)
|
|
@@ -103,7 +106,7 @@ class NewProduct(Overlay):
|
|
if k == name or v:
|
|
if k == name or v:
|
|
continue
|
|
continue
|
|
options = self.query_manager.unique_suggestions(
|
|
options = self.query_manager.unique_suggestions(
|
|
- k, exclude=[self.name, *NON_IDENTIFIER_COLUMNS], **self.data)
|
|
|
|
|
|
+ k, exclude=['product', *NON_IDENTIFIER_COLUMNS], **self.data)
|
|
if len(options) == 1 and k != 'ts':
|
|
if len(options) == 1 and k != 'ts':
|
|
self.data = { k: list(options)[0] }
|
|
self.data = { k: list(options)[0] }
|
|
|
|
|
|
@@ -115,13 +118,13 @@ class NewProduct(Overlay):
|
|
def keypress(self, size, key):
|
|
def keypress(self, size, key):
|
|
if key == 'esc':
|
|
if key == 'esc':
|
|
self.activity_manager.show(self.under.update())
|
|
self.activity_manager.show(self.under.update())
|
|
- return
|
|
|
|
|
|
+ return None
|
|
|
|
|
|
if key == 'tab':
|
|
if key == 'tab':
|
|
- return super().keypress(size, 'down')
|
|
|
|
- elif key == 'shift tab':
|
|
|
|
- return super().keypress(size, 'up')
|
|
|
|
|
|
+ return self.original_widget.keypress(size, 'down')
|
|
|
|
+ if key == 'shift tab':
|
|
|
|
+ return self.original_widget.keypress(size, 'up')
|
|
|
|
|
|
|
|
|
|
- return super().keypress(size, key)
|
|
|
|
|
|
+ return self.original_widget.keypress(size, key)
|
|
|
|
|