From 772b3bb14fc3103d774e4e0d907a6c4670ed03f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Tue, 10 Jun 2008 01:17:56 +0200 Subject: Allowed default for session; load 'app-portage/portato' as default for selections :) --- portato/gui/windows/main.py | 15 +++++++++------ portato/session.py | 13 +++++++++---- 2 files changed, 18 insertions(+), 10 deletions(-) (limited to 'portato') diff --git a/portato/gui/windows/main.py b/portato/gui/windows/main.py index 8a2f170..0d40968 100644 --- a/portato/gui/windows/main.py +++ b/portato/gui/windows/main.py @@ -702,9 +702,6 @@ class MainWindow (Window): self.queueTree = GtkTree(self.queueList.get_model()) self.queue = EmergeQueue(console = self.console, tree = self.queueTree, db = self.db, title_update = self.title_update, threadClass = GtkThread) - self.catList.get_selection().select_path(1) - self.pkgList.get_selection().select_path(0) - # session splash(_("Restoring Session")) try: @@ -1107,13 +1104,19 @@ class MainWindow (Window): elif version > SESSION_VERSION: raise NewSessionException(version, SESSION_VERSION) + def _add (value): + if len(value) == 4: + self.session.add_handler(value[:3], default = value[3]) + else: + self.session.add_handler(value) + # set the simple ones :) - map(self.session.add_handler,[ + map(_add,[ ([("gtksessionversion", "session")], load_session_version, lambda: SESSION_VERSION), ([("width", "window"), ("height", "window")], lambda w,h: self.window.resize(int(w), int(h)), self.window.get_size), ([("vpanedpos", "window"), ("hpanedpos", "window")], load_paned, save_paned), - ([("catsel", "window")], load_selection(self.catList, 0), save_cat_selection), - ([("pkgsel", "window")], load_selection(self.pkgList, 1), save_pkg_selection) + ([("catsel", "window")], load_selection(self.catList, 0), save_cat_selection, ["app-portage"]), + ([("pkgsel", "window")], load_selection(self.pkgList, 1), save_pkg_selection, ["portato"]) #([("merge", "queue"), ("unmerge", "queue"), ("oneshot", "queue")], load_queue, save_queue), ]) diff --git a/portato/session.py b/portato/session.py index 6abd899..e03f663 100644 --- a/portato/session.py +++ b/portato/session.py @@ -54,20 +54,20 @@ class Session (object): # add version check self.add_handler(([("version", "session")], self.check_version, lambda: self.VERSION)) - def add_handler (self, (options, load_fn, save_fn)): + def add_handler (self, (options, load_fn, save_fn), default = None): """ Adds a handler to this session. A handler is a three-tuple consisting of: - a list of (key,section) values - a function getting number of option arguments and applying them to the program - a function returning the number of option return values - getting them out of the program """ - self._handlers.append((options, load_fn, save_fn)) + self._handlers.append((options, load_fn, save_fn, default)) def load (self): """ Loads and applies all values of the session. """ - for options, lfn, sfn in self._handlers: + for options, lfn, sfn, default in self._handlers: try: loaded = [self._cfg.get(*x) for x in options] except KeyError: # does not exist -> ignore @@ -75,13 +75,18 @@ class Session (object): else: debug("Loading %s with values %s.", options, loaded) lfn(*loaded) + return + + if default: + debug("Loading %s with defaults %s.", options, default) + lfn(*default) def save (self): """ Saves all options into the file. """ - for options, lfn, sfn in self._handlers: + for options, lfn, sfn, default in self._handlers: vals = sfn() # map into list if necessairy -- cgit v1.2.3