X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=src%2Fgui%2Fgui.py;h=815edc5be6fc2cda7afcbc6334a8a7565d63f5e2;hb=9004554dbc0e91173d38208921b361f26ac74b96;hp=0247175fc22ee76eb165184427b36aa257f67cd0;hpb=8b301d4e5f3dd8c3cc73ae23a41cd66f629c7625;p=matthijs%2Fupstream%2Fmobilegtd.git diff --git a/src/gui/gui.py b/src/gui/gui.py index 0247175..815edc5 100644 --- a/src/gui/gui.py +++ b/src/gui/gui.py @@ -93,7 +93,6 @@ def save_gui(object): object.old_menu = appuifw.app.menu object.old_exit_key_handler = appuifw.app.exit_key_handler object.old_title=appuifw.app.title - object.lock = Ao_lock() def restore_gui(object): appuifw.app.body = object.old_gui @@ -101,21 +100,28 @@ def restore_gui(object): appuifw.app.exit_key_handler = object.old_exit_key_handler appuifw.app.title = object.old_title - -class ListView(object): +class View(object): def __init__(self): - self.view = appuifw.Listbox(self.items(),self.change_entry) + self.title = None + self.view = None + self.lock = Ao_lock() + self.exit_flag = False + super(View, self).__init__() def set_title(self, title): self.title = title - - def change_entry(self): - pass - + + def set_view(self, view): + """ + Sets the main view to be displayed (e.g., an appuifw.Listbox + instance). + """ + self.view = view + def run(self): self.adjustment = None - appuifw.app.screen=COMMON_CONFIG['screen'].encode('utf-8') save_gui(self) + appuifw.app.screen=COMMON_CONFIG['screen'].encode('utf-8') appuifw.app.title=self.title appuifw.app.body=self.view appuifw.app.exit_key_handler=self.exit @@ -127,10 +133,31 @@ class ListView(object): except: pass restore_gui(self) + def exit(self): self.exit_flag = True self.lock.signal() + super(View, self).exit() + def refresh(self): + """ + Update the gui after a change in model or some user interaction. + Should be filled by subclasses. + """ + super(View, self).refresh() + +class ListView(View): + def __init__(self): + super(ListView, self).__init__() + self.set_view(appuifw.Listbox(self.items(),self.entry_selected)) + + def entry_selected(self): + """ + This function is called when the user selects an an entry (e.g., + navigates to it and push the ok button). + """ + super(ListView).entry_selected() + def update(self,subject=None): #logger.log(u'Updated %s'%repr(self)) if self.lock: @@ -166,7 +193,6 @@ class WidgetBasedListView(ListView): def __init__(self): self.widgets = self.generate_widgets() super(WidgetBasedListView,self).__init__() - self.exit_flag = False def run(self): self.refresh() @@ -196,6 +222,7 @@ class KeyBindingView(object): def __init__(self): self.binding_map = {} + super(KeyBindingView,self).__init__() def set_keybindings(self, binding_map): """ @@ -272,7 +299,6 @@ class SearchableListView(WidgetBasedListView): class EditableListView(SearchableListView,KeyBindingView): def __init__(self): - KeyBindingView.__init__(self) super(EditableListView, self).__init__() def key_and_menu_bindings(self,selected_index): @@ -284,7 +310,7 @@ class EditableListView(SearchableListView,KeyBindingView): key_and_menu_bindings.append((get_key(key),key,description,execute_and_update_function)) return key_and_menu_bindings - def change_entry(self): + def entry_selected(self): self.current_widget().change() self.refresh() def execute_and_update(self,function):