Simplify callback type checking.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
This commit is contained in:
parent
95873edc0e
commit
d4d61cf452
2 changed files with 23 additions and 9 deletions
|
|
@ -4,6 +4,9 @@ class NewfolError(Exception):
|
|||
class LockError(NewfolError):
|
||||
pass
|
||||
|
||||
class ImplementationError(NewfolError):
|
||||
pass
|
||||
|
||||
class FilemanipError(Exception):
|
||||
pass
|
||||
|
||||
|
|
|
|||
29
newfol
29
newfol
|
|
@ -226,6 +226,17 @@ class View:
|
|||
@staticmethod
|
||||
def text(text, *classes):
|
||||
return urwid.AttrMap(urwid.Text(text), *classes)
|
||||
@staticmethod
|
||||
def is_callback_type(type_, category):
|
||||
if category == "select":
|
||||
return type_.startswith("select") or type_.startswith("next")
|
||||
elif category == "simple-select":
|
||||
return type_ in ("select", "next")
|
||||
elif category in ("change", "cancel"):
|
||||
return type_ == category
|
||||
else:
|
||||
raise newfol.exception.ImplementationError("Unknown type %s" %
|
||||
type_)
|
||||
|
||||
class IntroView(View):
|
||||
def render(self, loop):
|
||||
|
|
@ -436,7 +447,7 @@ class DisplayRecordView(RecordView):
|
|||
continue
|
||||
self.cells[i+1].widget_list[1].set_edit_text(str(val))
|
||||
def callback(self, type_, obj):
|
||||
if type_ in ("select", "next"):
|
||||
if self.is_callback_type(type_, "simple-select"):
|
||||
dbd = DatabaseData()
|
||||
newrec = self._build_record()
|
||||
recs = []
|
||||
|
|
@ -474,7 +485,7 @@ class SearchRecordView(RecordView):
|
|||
return [i.widget_list[1].get_edit_text() for i in self.cells]
|
||||
def callback(self, type_, obj):
|
||||
dbd = DatabaseData()
|
||||
if type_ in ("select", "next"):
|
||||
if self.is_callback_type(type_, "select"):
|
||||
fields = self._get_fields()
|
||||
fieldres = []
|
||||
for f in fields:
|
||||
|
|
@ -521,7 +532,7 @@ class DisplayTemplateRecordView(RecordView):
|
|||
def _get_fields(self):
|
||||
return [i.widget_list[1].get_state() for i in self.cells]
|
||||
def callback(self, type_, obj):
|
||||
if type_.startswith("select") or type_.startswith("next"):
|
||||
if self.is_callback_type(type_, "select"):
|
||||
dbd = DatabaseData()
|
||||
selected = self._get_fields()
|
||||
view = SortingTemplateRecordView(self.table, self.records,
|
||||
|
|
@ -584,7 +595,7 @@ class SortingTemplateRecordView(RecordView):
|
|||
l[0] = True
|
||||
return l
|
||||
def callback(self, type_, obj):
|
||||
if type_.startswith("select") or type_.startswith("next"):
|
||||
if self.is_callback_type(type_, "select"):
|
||||
dbd = DatabaseData()
|
||||
fieldno = self._get_fields().index(True)
|
||||
def lookup(x):
|
||||
|
|
@ -743,7 +754,7 @@ class RecordListView(ListView):
|
|||
if type_ == "remove":
|
||||
self._toggle_selected_record()
|
||||
self._full_rerender = True
|
||||
if type_ != "select" and not type_.startswith("next"):
|
||||
if not self.is_callback_type(type_, "select"):
|
||||
return
|
||||
cur = self._current_item()
|
||||
if cur is None:
|
||||
|
|
@ -764,7 +775,7 @@ class TableContentsListView(RecordListView):
|
|||
|
||||
class TableListView(ListView):
|
||||
def callback(self, type_, obj):
|
||||
if type_ != "select" and not type_.startswith("next"):
|
||||
if not self.is_callback_type(type_, "select"):
|
||||
return
|
||||
if obj is None:
|
||||
text = self._current_item()
|
||||
|
|
@ -825,7 +836,7 @@ class MessageBox(View):
|
|||
else:
|
||||
self.message = message
|
||||
def callback(self, type_, obj):
|
||||
if type_ == "select":
|
||||
if self.is_callback_type(type_, "select"):
|
||||
render_previous_view(self.loop)
|
||||
def _render_buttons(self):
|
||||
def callback_glue(button):
|
||||
|
|
@ -858,12 +869,12 @@ class MenuView(ListView):
|
|||
("About newfol", "about")
|
||||
])
|
||||
def callback(self, type_, obj):
|
||||
if type_ != "select" and not type_.startswith("next"):
|
||||
if not self.is_callback_type(type_, "select"):
|
||||
return
|
||||
text = self.listbox.get_focus()[0].original_widget.get_text()[0]
|
||||
command = self.OPTIONS[text]
|
||||
if command == "browse-all":
|
||||
if type_ == "select" or type_.startswith("next"):
|
||||
if self.is_callback_type(type_, "select"):
|
||||
ccview = CompleteContentsListView()
|
||||
ccview.set_render_type(type_)
|
||||
ccview.render(self.loop)
|
||||
|
|
|
|||
Loading…
Reference in a new issue