~thomas-deruyter-3/qreator/qreator

« back to all changes in this revision

Viewing changes to qreator/QreatorWindow.py

  • Committer: David Planella
  • Date: 2012-01-21 07:41:57 UTC
  • Revision ID: david.planella@ubuntu.com-20120121074157-o8kr3f30xs4qxs5r
Scaling is now done at the source

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
import qrencode
23
23
import array
24
 
 
 
24
import Image
25
25
 
26
26
COL_TEXT = 0
27
27
COL_PIXBUF = 1
56
56
        self.ui.entry1.connect('changed', self.on_entry1_changed)
57
57
        
58
58
        ## alpha is starting transparency
59
 
        self.alpha = 0
 
59
        self.alpha = 0.25
60
60
        ## delta is amount to increase alpha
61
61
        self.delta = 0.01
62
62
 
126
126
        self.clipboard.set_image(pixbuf)
127
127
 
128
128
    def on_entry1_changed(self, widget, data=None):
129
 
        self.alpha = 0
 
129
        self.alpha = 0.25
130
130
        self.ui.drawingarea1.queue_draw()
131
131
 
132
132
    def get_centered_coordinates(self, drawing_area, surface):
133
133
 
134
134
        drawing_area_height = drawing_area.get_allocated_height()
135
135
        drawing_area_width = drawing_area.get_allocated_width()
136
 
        image_height = surface.get_height() * self.scale_factor
137
 
        image_width = surface.get_width() * self.scale_factor
 
136
        image_height = surface.get_height()
 
137
        image_width = surface.get_width()
138
138
 
139
139
        return (drawing_area_width / 2 - image_width / 2,
140
140
                drawing_area_height / 2 - image_height / 2)
153
153
        # See http://cairographics.org/pythoncairopil/ and
154
154
        # http://mail.python.org/pipermail/image-sig/2005-October/003604.html
155
155
        # http://mail.gnome.org/archives/gtkmm-list/2007-May/msg00111.html
 
156
        # http://pygame.org/wiki/CairoPygame
 
157
        # Other:
 
158
        # http://stackoverflow.com/questions/8761887/scrolling-gtkdrawingarea
 
159
        # http://docs.clutter-project.org/docs/clutter-cookbook/1.0/textures-crossfade.html
156
160
 
 
161
        im = im.resize((168, 168),
 
162
                       Image.NEAREST)
 
163
        #im = im.resize((self.scale_factor * size, self.scale_factor * size),
 
164
        #               Image.NEAREST)
157
165
        im = im.convert('RGBA')
158
166
        bytearr = array.array('B', im.tostring())
159
167
        height, width = im.size
163
171
                                                     width, height,
164
172
                                                     width * 4)
165
173
 
166
 
        # Scale the image
167
 
        imgpat = cairo.SurfacePattern(self.surface)
168
 
 
169
 
        scaler = cairo.Matrix()
170
 
        scaler.scale(1.0 / self.scale_factor, 1.0 / self.scale_factor)
171
 
        imgpat.set_matrix(scaler)
172
 
 
173
 
        # Set resampling filter
174
 
        imgpat.set_filter(cairo.FILTER_NEAREST)
175
 
 
176
174
        # Center the image
177
175
        centered_width, centered_height = \
178
176
            self.get_centered_coordinates(widget, self.surface)
179
177
        ctx.translate(centered_width, centered_height)
180
 
        ctx.set_source(imgpat)
 
178
        
 
179
        # Set the surface as the context's source
 
180
        ctx.set_source_surface(self.surface)
181
181
 
182
182
        # Render the image
183
 
        #ctx.paint()
 
183
        ##ctx.paint()
184
184
        ctx.paint_with_alpha(self.alpha)
185
185
        self.alpha += self.delta
186
186