[SCM] GUI front-end for Debian Live. branch, master, updated. 50db20df21dddbdb1b40ba59ea9e7bef02a2bcd5
Chris Lamb
chris at chris-lamb.co.uk
Wed Mar 5 00:41:19 UTC 2008
The following commit has been merged in the master branch:
commit 08fbe0d36d09345e6953d1fb127eb5010ec83d36
Author: Chris Lamb <chris at chris-lamb.co.uk>
Date: Wed Mar 5 00:39:35 2008 +0000
Move view and controller startup code to their respective modules.
Signed-off-by: Chris Lamb <chris at chris-lamb.co.uk>
diff --git a/LiveMagic/__init__.py b/LiveMagic/__init__.py
index e69de29..2428b97 100644
--- a/LiveMagic/__init__.py
+++ b/LiveMagic/__init__.py
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+
+import gtk
+import pygtk
+pygtk.require('2.0')
+
+import sys
+
+from LiveMagic import views, controllers
+
+class LiveMagic(object):
+
+ def __init__(self, args):
+ c = controllers.Controller(sys.argv[1:])
+ v = views.View(c)
+
+ c.ready()
+
+ gtk.gdk.threads_init()
+ gtk.main()
diff --git a/LiveMagic/controllers/__init__.py b/LiveMagic/controllers/__init__.py
index 0dc2c48..b999b85 100644
--- a/LiveMagic/controllers/__init__.py
+++ b/LiveMagic/controllers/__init__.py
@@ -1,4 +1,13 @@
-from build import *
-from main import *
-from hooks import *
-from wizard import *
+from build import BuildController as Build
+from main import MainController as Main
+from hooks import HooksController as Hooks
+from wizard import WizardController as Wizard
+
+class Controller(Main, Build, Hooks, Wizard):
+ def __init__(self, args):
+ self.model = None
+
+ Main.__init__(self, args)
+ Build.__init__(self)
+ Hooks.__init__(self)
+ Wizard.__init__(self)
diff --git a/LiveMagic/controllers/hooks.py b/LiveMagic/controllers/hooks.py
index 9ffa9b9..edc6d4a 100644
--- a/LiveMagic/controllers/hooks.py
+++ b/LiveMagic/controllers/hooks.py
@@ -1,7 +1,7 @@
class HooksController(object):
def __init__(self):
- self.model.attach_load_observer(self.notify_load_hooks)
+ #self.model.attach_load_observer(self.notify_load_hooks)
self.hook_select_triggers_change = True
def on_hook_select(self, *_):
@@ -24,7 +24,7 @@ class HooksController(object):
"pl" : "#!/usr/bin/perl",
"py" : "#!/usr/bin/env python",
}[hook_name.rsplit(".")[1]]
- except (KeyError, IndexError):
+ except:
# Can't guess: assume it's a shell script.
interpreter = "#!/bin/sh"
@@ -54,7 +54,8 @@ class HooksController(object):
hook_name = self.view.get_selected_hook()
new_hook_name = self.view.do_show_rename_hook_window(hook_name)
- if new_hook_name is None: return
+ if new_hook_name is None:
+ return
try:
self.model.hooks.rename(hook_name, new_hook_name)
@@ -65,14 +66,16 @@ class HooksController(object):
self.view.do_show_error("The name already exists")
def on_button_hook_delete_clicked(self, *_):
- res = self.view.do_show_hook_delete_confirm_window()
- if res:
- hook_name = self.view.get_selected_hook()
- self.model.hooks.delete(hook_name)
- self.notify_load_hooks()
- self.view.do_clear_hook_contents()
- self.view.do_enable_edit_hook(False)
- self.view.set_save_enabled(True)
+ ret = self.view.do_show_hook_delete_confirm_window()
+ if not ret:
+ return
+
+ hook_name = self.view.get_selected_hook()
+ self.model.hooks.delete(hook_name)
+ self.notify_load_hooks()
+ self.view.do_clear_hook_contents()
+ self.view.do_enable_edit_hook(False)
+ self.view.set_save_enabled(True)
def on_hook_editor_changed(self, *_):
if self.hook_select_triggers_change:
diff --git a/LiveMagic/controllers/main.py b/LiveMagic/controllers/main.py
index 1f6e73d..55363cd 100644
--- a/LiveMagic/controllers/main.py
+++ b/LiveMagic/controllers/main.py
@@ -1,24 +1,12 @@
import gtk
-from LiveMagic.models import KeyVarConfigFile
class MainController(object):
def __init__(self, args):
- self.model.attach_load_observer(self.notify_load)
+ #self.model.attach_load_observer(self.notify_load)
self.args = args
- def notify_load(self):
- for child in self.model.children:
- # Check we are dealing with normal configuration values
- if type(child) is KeyVarConfigFile:
- for key in child:
- # Set the value in the view
- self.view.do_set_key_var(child.shortname, key, getattr(child, key))
-
def ready(self):
- """
- Called when the view is ready for setup.
- """
- sections = ['common', 'chroot', 'binary', 'bootstrap', 'source', 'hooks']
+ sections = ('common', 'chroot', 'binary', 'bootstrap', 'source', 'hooks')
self.view.setup_sections(sections)
# Notify all the observers that depend on the model
diff --git a/LiveMagic/views/__init__.py b/LiveMagic/views/__init__.py
index 0dc2c48..19346b3 100644
--- a/LiveMagic/views/__init__.py
+++ b/LiveMagic/views/__init__.py
@@ -1,4 +1,20 @@
-from build import *
-from main import *
-from hooks import *
-from wizard import *
+from build import BuildView as Build
+from main import MainView as Main
+from hooks import HooksView as Hooks
+from wizard import WizardView as Wizard
+
+from LiveMagic.utils import find_resource
+
+import gtk.glade
+
+class View(Main, Build, Hooks, Wizard):
+ def __init__(self, controller):
+ self.controller = controller
+
+ self.xml = gtk.glade.XML(find_resource('main.glade'))
+ self.xml.signal_autoconnect(self.controller)
+
+ Main.__init__(self)
+ Build.__init__(self)
+ Hooks.__init__(self)
+ Wizard.__init__(self)
diff --git a/LiveMagic/views/wizard.py b/LiveMagic/views/wizard.py
index af140de..ddb586e 100644
--- a/LiveMagic/views/wizard.py
+++ b/LiveMagic/views/wizard.py
@@ -2,46 +2,34 @@ import gtk
class WizardView(object):
def __init__(self):
- self.asst = self.construct_assistant()
+ self.asst = gtk.Assistant()
+ self.asst.set_title('Debian Live Magic')
+ self.asst.set_default_size(640, 480)
- def do_show_wizard(self):
- self.asst.show()
-
- def do_dim_wizard(self):
- self.asst.set_sensitive(False)
-
- def do_hide_wizard(self):
- self.asst.hide()
-
- def construct_assistant(self):
- asst = gtk.Assistant()
- asst.set_title('Debian Live Magic')
- asst.set_default_size(640, 480)
+ self.asst.connect('apply', self.controller.on_wizard_apply)
+ self.asst.connect('cancel', self.controller.on_wizard_cancel)
- asst.connect('apply', self.controller.on_wizard_apply)
- asst.connect('cancel', lambda _: gtk.main_quit())
+ def add_expert_mode():
+ label = gtk.Label('Expert mode')
+ label.show()
- label = gtk.Label('Expert mode')
- label.show()
+ image = gtk.Image()
+ image.set_from_stock(gtk.STOCK_EDIT, gtk.ICON_SIZE_BUTTON)
+ image.show()
- image = gtk.Image()
- image.set_from_stock(gtk.STOCK_EDIT, gtk.ICON_SIZE_BUTTON)
- image.show()
+ vbox = gtk.HBox(spacing=4)
+ vbox.add(label)
+ vbox.add(image)
+ vbox.show()
- vbox = gtk.HBox(spacing=4)
- vbox.add(label)
- vbox.add(image)
- vbox.show()
+ btn = gtk.Button()
+ btn.add(vbox)
+ btn.connect('clicked', self.controller.on_wizard_expert_mode_selected)
+ btn.show()
- btn = gtk.Button()
- btn.add(vbox)
- btn.connect('clicked', self.controller.on_wizard_expert_mode_selected)
- btn.show()
+ self.asst.add_action_widget(btn)
- asst.add_action_widget(btn)
-
- # Don't construct to pages of the gtk.Assistant manually, load
- # them from the Glade resource file.
+ # Load paages from Glade resource file.
notebook = self['notebook_wizard']
page_types = [gtk.ASSISTANT_PAGE_INTRO] + \
[gtk.ASSISTANT_PAGE_CONTENT] * (notebook.get_n_pages() - 2) + \
@@ -50,17 +38,24 @@ class WizardView(object):
for i in range(notebook.get_n_pages()):
page = notebook.get_nth_page(i)
page.unparent()
- asst.append_page(page)
- asst.set_page_complete(page, True)
- asst.set_page_type(page, page_types[i])
+ self.asst.append_page(page)
+ self.asst.set_page_complete(page, True)
+ self.asst.set_page_type(page, page_types[i])
- asst.set_page_title(page, notebook.get_tab_label_text(page))
+ self.asst.set_page_title(page, notebook.get_tab_label_text(page))
c = self['combobox_mirror']
c.prepend_text(self.controller.get_suggested_mirror())
c.set_active(0)
- return asst
+ def do_show_wizard(self):
+ self.asst.show()
+
+ def do_dim_wizard(self):
+ self.asst.set_sensitive(False)
+
+ def do_hide_wizard(self):
+ self.asst.hide()
def get_wizard_completed_details(self):
data = {}
diff --git a/live-magic b/live-magic
index 8ca04f9..0fc7a12 100755
--- a/live-magic
+++ b/live-magic
@@ -1,62 +1,8 @@
#!/usr/bin/env python
-import pygtk
-pygtk.require('2.0')
-import gtk
-import gtk.glade
-import os.path
import sys
-from LiveMagic import models, views, controllers
+from LiveMagic import LiveMagic
-class Model(object):
- def __init__(self, dir=None):
- self.config = models.LiveHelperConfiguration(dir)
- def __getattr__(self, k):
- return getattr(self.config, k)
- def __setattr__(self, k, v):
- self.__dict__[k] = v
-
-class View(views.MainView, views.BuildView, views.HooksView, views.WizardView):
- def __init__(self, controller):
- self.controller = controller
- self.xml = gtk.glade.XML(glade_filename())
-
- views.MainView.__init__(self)
- views.BuildView.__init__(self)
- views.HooksView.__init__(self)
- views.WizardView.__init__(self)
-
- self.xml.signal_autoconnect(self.controller)
-
-class Controller(controllers.MainController,
- controllers.BuildController,
- controllers.HooksController,
- controllers.WizardController):
- def __init__(self, model, args):
- self.model = model
- controllers.MainController.__init__(self, args)
- controllers.BuildController.__init__(self)
- controllers.HooksController.__init__(self)
- controllers.WizardController.__init__(self)
-
-def glade_filename():
- suffix = 'main.glade'
-
- local = os.path.join('glade', suffix)
- if os.path.isfile(local):
- return local
-
- for path in ['/usr/share/live-magic']:
- path = os.path.join(path, suffix)
- if os.path.isfile(path):
- return path
-
-if __name__ == "__main__":
- m = Model()
- c = Controller(m, sys.argv[1:])
- v = View(c)
- c.ready()
-
- gtk.gdk.threads_init()
- gtk.main()
+if __name__ == '__main__':
+ LiveMagic(sys.argv[1:])
--
GUI front-end for Debian Live.
More information about the debian-live-changes
mailing list