[alacarte] MainWindow: Construct MenuEditor separately



commit ed1998449ff1e4810d5e7e78aec0aa60db5dcaa5
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Thu Jan 10 17:40:47 2013 -0500

    MainWindow: Construct MenuEditor separately
    
    We might need to switch menus at runtime, meaning we need a way
    to unload the current menu and add the new one.

 Alacarte/MainWindow.py |   14 +++++++++++---
 alacarte.in            |    3 ++-
 2 files changed, 13 insertions(+), 4 deletions(-)
---
diff --git a/Alacarte/MainWindow.py b/Alacarte/MainWindow.py
index 638ef06..ab7ae14 100644
--- a/Alacarte/MainWindow.py
+++ b/Alacarte/MainWindow.py
@@ -37,11 +37,9 @@ class MainWindow(object):
     #hack to make editing menu properties work
     edit_pool = []
 
-    def __init__(self, menu_basename, datadir, version):
+    def __init__(self, datadir, version):
         self.file_path = datadir
         self.version = version
-        self.editor = MenuEditor(menu_basename)
-        self.editor.tree.connect("changed", self.menuChanged)
         Gtk.Window.set_default_icon_name('alacarte')
         self.tree = Gtk.Builder()
         self.tree.set_translation_domain(config.GETTEXT_PACKAGE)
@@ -59,6 +57,16 @@ class MainWindow(object):
         accelgroup.connect(keyval, modifier, Gtk.AccelFlags.VISIBLE, self.on_help_button_clicked)
         self.tree.get_object('mainwindow').add_accel_group(accelgroup)
 
+        self.editor = None
+
+    def setMenuBasename(self, menu_basename):
+        if self.editor is not None:
+            self.editor.tree.disconnect(self.menuChangedId)
+
+        self.editor = MenuEditor(menu_basename)
+        self.menuChangedId = self.editor.tree.connect("changed", self.menuChanged)
+        self.menuChanged()
+
     def run(self):
         self.loadMenus()
         self.tree.get_object('mainwindow').show_all()
diff --git a/alacarte.in b/alacarte.in
index 5aa1dd0..a00469a 100644
--- a/alacarte.in
+++ b/alacarte.in
@@ -35,7 +35,8 @@ def main():
     except ImportError:
         datadir = '.'
         version = '0.9'
-    app = MainWindow(get_menu_basename(), datadir, version)
+    app = MainWindow(datadir, version)
+    app.setMenuBasename(get_menu_basename())
     app.run()
 
 if __name__ == '__main__':



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]