summaryrefslogtreecommitdiff
path: root/portato
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2008-11-02 23:50:23 +0100
committerRené 'Necoro' Neumann <necoro@necoro.net>2008-11-02 23:50:23 +0100
commit2869169d44baa53eca78ec1e55342fe882b692c2 (patch)
tree6161e6607a39d2abe15be4ffcec42a80f048653c /portato
parentc3bc1482872c4199114decd3a9f68b046433b5a0 (diff)
downloadportato-2869169d44baa53eca78ec1e55342fe882b692c2.tar.gz
portato-2869169d44baa53eca78ec1e55342fe882b692c2.tar.bz2
portato-2869169d44baa53eca78ec1e55342fe882b692c2.zip
Improvement to session handling of selections. Increased gui SESSION_VERSION.
Diffstat (limited to 'portato')
-rw-r--r--portato/gui/session.py2
-rw-r--r--portato/gui/windows/main.py123
-rw-r--r--portato/session.py8
3 files changed, 91 insertions, 42 deletions
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):
"""