From 2869169d44baa53eca78ec1e55342fe882b692c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Sun, 2 Nov 2008 23:50:23 +0100 Subject: Improvement to session handling of selections. Increased gui SESSION_VERSION. --- portato/gui/session.py | 2 +- portato/gui/windows/main.py | 123 +++++++++++++++++++++++++++++++------------- portato/session.py | 8 ++- 3 files changed, 91 insertions(+), 42 deletions(-) (limited to 'portato') diff --git a/portato/gui/session.py b/portato/gui/session.py index 1eca248..a7e1ffa 100644 --- a/portato/gui/session.py +++ b/portato/gui/session.py @@ -14,7 +14,7 @@ from ..helper import debug # the current version for saved sessions # change this, whenever the change is incompatible with previous versions -SESSION_VERSION = 1 +SESSION_VERSION = 2 class SessionException (Exception): diff --git a/portato/gui/windows/main.py b/portato/gui/windows/main.py index 5a69e5b..b76bb73 100644 --- a/portato/gui/windows/main.py +++ b/portato/gui/windows/main.py @@ -977,7 +977,7 @@ class MainWindow (Window): return oldVersion = SESSION_VERSION - allowedVersions = (0,1) + allowedVersions = (1,2) if sessionEx and isinstance(sessionEx, SessionException): if sessionEx.got in allowedVersions: @@ -1017,44 +1017,80 @@ class MainWindow (Window): return [x.get_position() for x in (self.vpaned, self.hpaned)] # SELECTION - def load_selection (list, col): - def _load (name): - pos = "0" # default - - if name: - for cname, path in ((x[col], x.path) for x in list.get_model()): + def load_pkg_selection (name): + pos = "0" + col = 1 + model = self.pkgList.get_model() + + if name: + if oldVersion > 1: # newer one + name, pos = map(str.strip, name.split(",")) + + if model[pos][col] != name: # need to search :( + debug("Pkg path does not match. Searching...") + for cname, path in ((x[col], x.path) for x in model): if cname == name: pos = path break - if self.cfg.get_boolean("collapseCats", "GUI") and \ - pos == "0" and isinstance(list.get_model(), gtk.TreeStore): # try the new split up - - try: - pre, post = name.split("-", 1) - except ValueError: # nothing to split - pass - else: - for row in list.get_model(): - if row[col] == pre: # found first part - pos = row.path - list.expand_row(pos, False) - for cname, path in ((x[col], x.path) for x in row.iterchildren()): - if cname == post: # found second - pos = ":".join(map(str,path)) - break - break + + debug("Selecting pkg path '%s'. Value: '%s'", pos, model[pos][col]) + self.pkgList.get_selection().select_path(pos) + self.pkgList.scroll_to_cell(pos) + + def load_cat_selection (name): + pos = "0" + col = 0 + model = self.catList.get_model() + + if name: + if oldVersion > 1: # newer one + name, pos = map(str.strip, name.split(",")) + + if self.cfg.get_boolean("collapseCats", "GUI"): + try: + sname = name.split("-", 1) + except ValueError: # nothing to split + sname = None + else: + sname = None + + if sname is None and model[pos][col] != name: # need to search in normal list + debug("Cat path does not match. Searching...") + for cname, path in ((x[col], x.path) for x in model): + if cname == name: + pos = path + break - debug("Selecting path '%s'.", pos) - list.get_selection().select_path(pos) - list.scroll_to_cell(pos) - - return _load + elif sname: # the collapse case + row = model[pos.split(":")[0]] + no_match = False + if row[col] != sname[0]: # first part does not match :( + debug("First part of cat path does not match. Searching...") + no_match = True + for r in model: + if r[col] == sname[0]: + row = r + break + + if no_match or model[pos][col] != sname[1]: + debug("Second part of cat path does not match. Searching...") + for cname, path in ((x[col], x.path) for x in row.iterchildren()): + if cname == sname[1]: # found second + pos = ":".join(map(str,path)) + break + + self.catList.expand_to_path(pos) + + + debug("Selecting cat path '%s'. Value: '%s'", pos, model[pos][col]) + self.catList.get_selection().select_path(pos) + self.catList.scroll_to_cell(pos) def save_pkg_selection (): store, iter = self.pkgList.get_selection().get_selected() if iter: - return store.get_value(iter, 1) + return "%s, %s" % (store.get_value(iter, 1), store.get_string_from_iter(iter)) else: return "" @@ -1062,11 +1098,26 @@ class MainWindow (Window): # try to find the correct category using the pkgList selection # so we do not select ALL =) # if no package has been selected - return selCatName - store, iter = self.pkgList.get_selection().get_selected() - if iter: - return store.get_value(iter, 2) + + catStore, catIter = self.catList.get_selection().get_selected() + pkgStore, pkgIter = self.pkgList.get_selection().get_selected() + if pkgIter: + pkgVal = pkgStore.get_value(pkgIter, 2) + pos = "0" + + if catIter: # check for the more exact category position if possible + catVal = catStore.get_value(catIter, 0) + catParent = self.catList.get_model().iter_parent(catIter) + + if catParent: + catVal = "%s-%s" % (catStore.get_value(catParent, 0), catVal) + + if catVal == pkgVal: # the info in the pkgList has higher precedence + pos = catStore.get_string_from_iter(catIter) + + return "%s, %s" % (pkgVal, pos) else: - return self.selCatName + return "%s, 0" % self.selCatName # PLUGIN def load_plugin (p): @@ -1108,8 +1159,8 @@ class MainWindow (Window): ([("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, ["app-portage"]), - ([("pkgsel", "window")], load_selection(self.pkgList, 1), save_pkg_selection, ["portato"]) + ([("catsel", "window")], load_cat_selection, save_cat_selection, ["app-portage, 0"]), + ([("pkgsel", "window")], load_pkg_selection, save_pkg_selection, ["portato, 0"]) #([("merge", "queue"), ("unmerge", "queue"), ("oneshot", "queue")], load_queue, save_queue), ]) diff --git a/portato/session.py b/portato/session.py index 9f08ff7..4b0edb0 100644 --- a/portato/session.py +++ b/portato/session.py @@ -72,14 +72,12 @@ class Session (object): loaded = [self._cfg.get(*x) for x in options] except KeyError: # does not exist -> ignore debug("No values for %s.", options) + if default: + debug("Loading %s with defaults %s.", options, default) + lfn(*default) else: debug("Loading %s with values %s.", options, loaded) lfn(*loaded) - continue - - if default: - debug("Loading %s with defaults %s.", options, default) - lfn(*default) def save (self): """ -- cgit v1.2.3