From 2f604638e8911e52289b0f10acac616ae9b605ae Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Tue, 18 Aug 2009 00:03:55 +0200 Subject: [PATCH] Extract some common view stuff into a View class. This class forms a superclass to ListView, and does all the non-list-specific stuff. This also moves some code from classes below ListView into View, since that code really shouldn't be where it was. --- src/gui/gui.py | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/src/gui/gui.py b/src/gui/gui.py index e4b3db0..a8f2171 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,22 +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) - super(ListView, self).__init__() + 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 @@ -128,10 +133,27 @@ 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.change_entry)) + def change_entry(self): + pass + def update(self,subject=None): #logger.log(u'Updated %s'%repr(self)) if self.lock: @@ -167,7 +189,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() -- 2.30.2