From 012c4cae7ca181ac6a6fbb85c8f808cc1259470c Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Sun, 12 May 2013 04:22:30 +0200 Subject: [PATCH] Keep track of current page in the profile. --- automanga | 26 +++++++++++++++++++++----- manga/profile.py | 7 +++++++ manga/reader.py | 20 ++++++++++++++++++-- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/automanga b/automanga index 34c0805..e6435cc 100755 --- a/automanga +++ b/automanga @@ -1,20 +1,20 @@ #!/usr/bin/python import sys, getopt -import manga.lib, manga.reader, manga.local +import manga.lib, manga.reader, manga.profile, manga.local import glib, gobject, gtk gobject.threads_init() gtk.gdk.threads_init() def usage(out): - out.write("usage: automanga [-h] [DIR]\n") - out.write(" automanga [-h] -l LIBRARY ID\n") + out.write("usage: automanga [-h] [-p PROFILE] [-l LIBRARY] [DIR-OR-ID]\n") out.write(" automanga [-h] -s LIBRARY NAME\n") libname = None search = False -opts, args = getopt.getopt(sys.argv[1:], "hl:s") +profile = "" +opts, args = getopt.getopt(sys.argv[1:], "hl:sp:") for o, a in opts: if o == "-h": usage(sys.stdout) @@ -23,6 +23,18 @@ for o, a in opts: libname = a elif o == "-s": search = True + elif o == "-p": + if a == "": + profile = None + else: + profile = a +if profile == "": + try: + profile = manga.profile.profile.last() + except KeyError: + profile = manga.profile.profile.byname("default") +elif profile is not None: + profile = manga.profile.profile.byname(profile) if search: if len(args) < 2: @@ -52,11 +64,15 @@ if libname is not None: sys.stderr.write("automanga: no such manga: %s\n" % args[0]) sys.exit(1) else: + libname = "local" if len(args) > 0: mng = manga.local.manga(args[0]) else: mng = manga.local.manga(".") -reader = manga.reader.reader(mng) +if profile is not None: + profile.setlast() + +reader = manga.reader.reader(mng, profile.getmanga(libname, mng.id, True)) reader.show() gtk.main() diff --git a/manga/profile.py b/manga/profile.py index 2a82df4..87f02a9 100644 --- a/manga/profile.py +++ b/manga/profile.py @@ -49,6 +49,7 @@ def splitline(line): elif c.isspace(): ret.append(buf) buf = "" + a = False break elif c == "\\" and p < len(line): buf += bsq(line[p]) @@ -104,6 +105,12 @@ class manga(object): return default return self.props[key] + def __getitem__(self, key): + return self.props[key] + + def __contains__(self, key): + return key in self.props + def setprop(self, key, val): self.props[key] = val diff --git a/manga/reader.py b/manga/reader.py index 37972b4..1a8aa05 100644 --- a/manga/reader.py +++ b/manga/reader.py @@ -136,6 +136,15 @@ class relpageget(future): self.cache[page] return page +class idpageget(future): + def __init__(self, base, idlist): + super(idpageget, self).__init__() + self.bnode = base + self.idlist = idlist + + def value(self): + return lib.cursor(self.bnode.byidlist(self.idlist)).cur + class pageget(future): def __init__(self, fnode): super(pageget, self).__init__() @@ -446,7 +455,7 @@ class sbox(gtk.ComboBox): self.rd.fetchpage(pageget(self.pnode[self.get_active()])) class reader(gtk.Window): - def __init__(self, manga): + def __init__(self, manga, profile=None): super(reader, self).__init__(gtk.WINDOW_TOPLEVEL) self.connect("delete_event", lambda wdg, ev, data=None: False) self.connect("destroy", lambda wdg, data=None: self.quit()) @@ -455,6 +464,7 @@ class reader(gtk.Window): self.pagefetch = procslot(self) self.imgfetch = procslot(self) self.preload = procslot(self) + self.profile = profile self.manga = manga self.page = None @@ -487,7 +497,10 @@ class reader(gtk.Window): self.add(vlay) vlay.show() - self.fetchpage(pageget(self.manga)) + if self.profile and "curpage" in self.profile: + self.fetchpage(idpageget(self.manga, self.profile["curpage"])) + else: + self.fetchpage(pageget(self.manga)) self.updtitle() def updpagelbl(self): @@ -527,6 +540,9 @@ class reader(gtk.Window): if self.point is not None: self.point = None if page is not None: + if self.profile: + self.profile.setprop("curpage", page.idlist()) + self.profile.saveprops() self.point = ccursor(page, self.cache) self.imgfetch.set(imgfetch(self.cache[page])) else: -- 2.11.0