11
11
gi.require_version('Gdk', '3.0')
12
12
gi.require_version('Gtk', '3.0')
13
from gi.repository import Gtk, Gdk, GLib # pylint: disable=E0611
13
from gi.repository import Gtk, Gdk # pylint: disable=E0611
16
16
logger = logging.getLogger('qreator')
48
55
# Code for other initialization actions should be added here.
49
56
self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
57
self.barcode_size = BarcodeSize.SMALL
51
59
self.surface = None
52
60
self.ui.iconview1.set_text_column(COL_TEXT)
53
61
self.ui.iconview1.set_pixbuf_column(COL_PIXBUF)
55
63
self.ui.notebook1.set_show_tabs(False)
56
64
self.ui.entry1.connect('changed', self.on_entry1_changed)
58
## alpha is starting transparency
60
## delta is amount to increase alpha
63
66
def on_toolbuttonHome_clicked(self, widget, data=None):
64
67
self.ui.notebook1.set_current_page(PAGE_HOME)
83
86
src_x, src_y = self.get_centered_coordinates(self.ui.drawingarea1,
85
image_height = self.surface.get_height() * self.scale_factor
86
image_width = self.surface.get_width() * self.scale_factor
88
image_height = self.surface.get_height()
89
image_width = self.surface.get_width()
88
91
return Gdk.pixbuf_get_from_window(window, src_x, src_y,
89
92
image_width, image_height)
139
141
return (drawing_area_width / 2 - image_width / 2,
140
142
drawing_area_height / 2 - image_height / 2)
143
self.ui.drawingarea1.queue_draw()
144
def set_pixel_size(self, barcode_orig_size):
148
while pixel_size * barcode_orig_size < self.barcode_size:
151
while ((pixel_size * barcode_orig_size > self.barcode_size) or \
152
((pixel_size * barcode_orig_size) % 2 != 0)):
158
self.pixel_size = pixel_size
145
160
def on_drawingarea1_draw(self, widget, ctx, data=None):
146
161
text = self.ui.entry1.get_text()
150
166
version, size, im = qrencode.encode(text)
152
# --------------- Cairo surface conversion ---------------------------
168
# Resize the original image
169
self.set_pixel_size(size)
170
print self.pixel_size, size
171
im = im.resize((self.pixel_size * size, self.pixel_size * size),
173
im = im.convert('RGBA')
176
im = ImageOps.expand(im, border=(self.barcode_size - im.size[0]) / 2,
179
# Convert the Python PIL image to a Cairo surface.
180
# Notice the conversion to BGRA that Cairo expects
153
181
# See http://cairographics.org/pythoncairopil/ and
154
# http://mail.python.org/pipermail/image-sig/2005-October/003604.html
155
182
# http://mail.gnome.org/archives/gtkmm-list/2007-May/msg00111.html
156
# http://pygame.org/wiki/CairoPygame
158
# http://stackoverflow.com/questions/8761887/scrolling-gtkdrawingarea
159
# http://docs.clutter-project.org/docs/clutter-cookbook/1.0/textures-crossfade.html
161
im = im.resize((168, 168),
163
#im = im.resize((self.scale_factor * size, self.scale_factor * size),
165
im = im.convert('RGBA')
166
bytearr = array.array('B', im.tostring())
183
bytearr = array.array('B', im.tostring("raw", "BGRA", 0, 1))
167
184
height, width = im.size
169
187
self.surface = cairo.ImageSurface.create_for_data(bytearr,
170
188
cairo.FORMAT_ARGB32,
192
# Center the image in the drawing area
175
193
centered_width, centered_height = \
176
194
self.get_centered_coordinates(widget, self.surface)
177
195
ctx.translate(centered_width, centered_height)