OSDN Git Service

fixed setting of default background
authorMartin Renold <martinxyz@gmx.ch>
Fri, 31 Jul 2009 16:21:28 +0000 (18:21 +0200)
committerMartin Renold <martinxyz@gmx.ch>
Fri, 31 Jul 2009 16:21:28 +0000 (18:21 +0200)
backgrounds/default.png [new file with mode: 0644]
gui/backgroundwindow.py
gui/drawwindow.py
lib/backgroundsurface.py
lib/document.py

diff --git a/backgrounds/default.png b/backgrounds/default.png
new file mode 100644 (file)
index 0000000..9c09d6a
Binary files /dev/null and b/backgrounds/default.png differ
index 29de0e9..4ccab1a 100644 (file)
@@ -59,19 +59,22 @@ class Window(gtk.Window):
         rgb = self.cs.get_current_color()
         rgb = rgb.red, rgb.green, rgb.blue
         rgb = [int(x / 65535.0 * 255.0) for x in rgb] 
-        self.set_background(rgb)
+        pixbuf = gdk.Pixbuf(gdk.COLORSPACE_RGB, False, 8, N, N)
+        arr = helpers.gdkpixbuf2numpy(pixbuf)
+        arr[:,:] = rgb
+        self.set_background(pixbuf)
 
     def save_as_default_cb(self, widget):
-        pixbuf = self.app.drawWindow.doc.get_background_pixbuf()
+        pixbuf = self.current_background_pixbuf
         pixbuf.save(os.path.join(self.app.confpath, 'backgrounds', 'default.png'), 'png')
-        self.set_background(pixbuf)
 
-    def set_background(self, obj):
+    def set_background(self, pixbuf):
         doc = self.app.drawWindow.doc
-        doc.set_background(obj)
+        doc.set_background(pixbuf)
+        self.current_background_pixbuf = pixbuf
 
     def add_color_to_patterns_cb(self, widget):
-        pixbuf = self.app.drawWindow.doc.get_background_pixbuf()
+        pixbuf = self.current_background_pixbuf
         i = 1
         while 1:
             filename = os.path.join(self.app.confpath, 'backgrounds', 'color%02d.png' % i)
index 184eca7..a6fbfa2 100644 (file)
@@ -55,7 +55,7 @@ class Window(gtk.Window):
         # FIXME: hack, to be removed
         filename = os.path.join(self.app.datapath, 'backgrounds', '03_check1.png')
         pixbuf = gdk.pixbuf_new_from_file(filename)
-        self.tdw.neutral_background_pixbuf = backgroundsurface.Background(helpers.gdkpixbuf2numpy(pixbuf))
+        self.tdw.neutral_background_pixbuf = backgroundsurface.Background(pixbuf)
 
         self.zoomlevel_values = [1.0/8, 2.0/11, 0.25, 1.0/3, 0.50, 2.0/3, 1.0, 1.5, 2.0, 3.0, 4.0, 5.5, 8.0]
         self.zoomlevel = self.zoomlevel_values.index(1.0)
index 6563ecb..c1c5af6 100644 (file)
@@ -16,7 +16,7 @@ class Background:
         try:
             obj = helpers.gdkpixbuf2numpy(obj)
         except:
-            # it was already an array (FIXME: is this codepath ever used?)
+            # it was already an array (eg. when creating the mipmap)
             pass
         try:
             r, g, b = obj
index 83d6ebc..26da732 100644 (file)
@@ -210,12 +210,6 @@ class Document():
 
         self.invalidate_all()
 
-    def get_background_pixbuf(self):
-        pixbuf = gdk.Pixbuf(gdk.COLORSPACE_RGB, False, 8, N, N)
-        arr = helpers.gdkpixbuf2numpy(pixbuf)
-        arr[:,:,:] = self.background
-        return pixbuf
-
     def load_from_pixbuf(self, pixbuf):
         self.clear()
         self.load_layer_from_pixbuf(pixbuf)