Specify GTK version explicitly to shut GI up.
[automanga.git] / manga / reader.py
index 442f1f8..c4d322d 100644 (file)
@@ -1,6 +1,8 @@
 import threading
+import gi
+gi.require_version("Gtk", "3.0")
 from gi.repository import Gtk as gtk, GdkPixbuf as gdkpix, Gdk as gdk, GObject as gobject
-import lib, profile
+from . import lib, profile
 
 class notdone(Exception): pass
 
@@ -12,13 +14,13 @@ class future(threading.Thread):
         self._val = None
         self._exc = None
         self._notlist = []
-        self._started = False
+        self._tstarted = False
         self.setDaemon(True)
 
     def start(self):
-        if not self._started:
+        if not self._tstarted:
             super(future, self).start()
-            self._started = True
+            self._tstarted = True
 
     def run(self):
         try:
@@ -77,20 +79,26 @@ class imgload(future):
 
     def value(self):
         buf = gdkpix.PixbufLoader()
+        done = False
         try:
             with self.page.open() as st:
                 self.p = 0
                 self.st = st
                 while True:
                     read = st.read(1024)
-                    if read == "":
+                    if read == b"":
                         break
                     self.p += len(read)
                     buf.write(read)
                     self.progcb()
             self.st = None
+            done = True
         finally:
-            buf.close()
+            try:
+                buf.close()
+            except:
+                if done:
+                    raise
         return buf.get_pixbuf()
 
     @property
@@ -151,7 +159,10 @@ class idpageget(future):
         self.idlist = idlist
 
     def value(self):
-        return lib.cursor(self.bnode.byidlist(self.idlist)).cur
+        try:
+            return lib.cursor(self.bnode.byidlist(self.idlist)).cur
+        except KeyError:
+            raise KeyError("could not find last read page: " + repr(self.idlist))
 
 class pageget(future):
     def __init__(self, fnode):
@@ -295,7 +306,7 @@ class pageview(gtk.Widget):
 class msgproc(object):
     def attach(self, reader):
         self.rd = reader
-        self.msg = gtk.Alignment(yalign=0.5)
+        self.msg = gtk.Alignment(xalign=0.0, yalign=0.5, xscale=0.0, yscale=0.0)
         self.hlay = gtk.HBox()
         self.lbl = gtk.Label("")
         self.hlay.pack_start(self.lbl, True, True, 0)
@@ -513,8 +524,8 @@ class reader(gtk.Window):
         vlay.pack_start(self.pfr, True, True, 0)
         self.pfr.show()
         self.sboxbar = gtk.HBox()
-        algn = gtk.Alignment(yalign=0.5)
-        sboxlbl = gtk.Label(self.manga.name + u": ")
+        algn = gtk.Alignment(xalign=0.0, yalign=0.5, xscale=0.0, yscale=0.0)
+        sboxlbl = gtk.Label(self.manga.name + ": ")
         algn.add(sboxlbl)
         sboxlbl.show()
         self.sboxbar.pack_start(algn, False, True, 0)
@@ -523,7 +534,7 @@ class reader(gtk.Window):
         self.sboxbar.show()
         self.sbar = gtk.HBox()
         self.pagelbl = gtk.Label("")
-        algn = gtk.Alignment(yalign=0.5)
+        algn = gtk.Alignment(xalign=0.0, yalign=0.5, xscale=0.0, yscale=0.0)
         algn.add(self.pagelbl)
         self.pagelbl.show()
         self.sbar.pack_start(algn, True, True, 0)
@@ -547,7 +558,7 @@ class reader(gtk.Window):
             self.pagelbl.set_text("")
         else:
             w, h = self.page.get_osize()
-            self.pagelbl.set_text(u"%s\u00d7%s (%d%%)" % (w, h, int(self.page.zoom * 100)))
+            self.pagelbl.set_text("%s\u00d7%s (%d%%)" % (w, h, int(self.page.zoom * 100)))
 
     def updsboxes(self, page):
         nodes = [node for node, idx in page.stack[1:]] + [page]
@@ -556,10 +567,10 @@ class reader(gtk.Window):
             if pbox.node != node:
                 l = i
                 break
-        for i in xrange(l, len(self.sboxes)):
+        for i in range(l, len(self.sboxes)):
             self.sboxbar.remove(self.sboxes[i])
         self.sboxes = self.sboxes[:l]
-        for i in xrange(l, len(nodes)):
+        for i in range(l, len(nodes)):
             new = sbox(self, nodes[i])
             self.sboxbar.pack_start(new, False, True, 5)
             self.sboxes.append(new)
@@ -596,7 +607,7 @@ class reader(gtk.Window):
         return proc
 
     def updtitle(self):
-        self.set_title(u"Automanga \u2013 " + self.manga.name)
+        self.set_title("Automanga \u2013 " + self.manga.name)
 
     @property
     def zoom(self):