7
#from gettext import gettext as _
7
from gettext import gettext as _
8
8
gettext.textdomain('qreator')
10
from gi.repository import Gtk, Gdk # pylint: disable=E0611
11
gi.require_version('Gdk', '3.0')
12
gi.require_version('Gtk', '3.0')
13
from gi.repository import Gtk, Gdk, GLib # pylint: disable=E0611
13
16
logger = logging.getLogger('qreator')
52
55
self.ui.notebook1.set_show_tabs(False)
53
56
self.ui.entry1.connect('changed', self.on_entry1_changed)
58
## alpha is starting transparency
60
## delta is amount to increase alpha
55
63
def on_toolbuttonHome_clicked(self, widget, data=None):
56
64
self.ui.notebook1.set_current_page(PAGE_HOME)
84
92
if not self.surface:
87
# We cannot write directly from the surface, as the
88
# Surface.write_to_png() method writes the image in the original
89
# size returned by qrencode (i.e. non-scaled), and the SurfacePattern
90
# does not have any methods to write to disk.
91
# So we read the contents from the Gtk.DrawingArea, put them into a
92
# Gdk.Pixbuf and use its 'savev' method to write to disk.
94
pixbuf = self.get_pixbuf_from_drawing_area()
96
pixbuf.savev(r'/tmp/somefile.png', 'png', [], [])
95
dialog = Gtk.FileChooserDialog(_("Please choose a file"), self,
96
Gtk.FileChooserAction.SAVE,
97
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
98
Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
100
filter_png = Gtk.FileFilter()
101
filter_png.set_name(_("PNG images"))
102
filter_png.add_mime_type("image/png")
103
dialog.add_filter(filter_png)
105
response = dialog.run()
107
if response == Gtk.ResponseType.OK:
108
# We cannot write directly from the surface, as the
109
# Surface.write_to_png() method writes the image in the original
110
# size returned by qrencode (i.e. non-scaled), and the
111
# SurfacePattern does not have any methods to write to disk.
112
# So we read the contents from the Gtk.DrawingArea, put them into
113
# a Gdk.Pixbuf and use its 'savev' method to write to disk.
115
pixbuf = self.get_pixbuf_from_drawing_area()
117
pixbuf.savev(dialog.get_filename(), 'png', [], [])
98
121
def on_toolbuttonCopy_clicked(self, widget, data=None):
99
122
if not self.surface:
115
138
return (drawing_area_width / 2 - image_width / 2,
116
139
drawing_area_height / 2 - image_height / 2)
142
self.ui.drawingarea1.queue_draw()
118
144
def on_drawingarea1_draw(self, widget, ctx, data=None):
119
145
text = self.ui.entry1.get_text()
123
149
version, size, im = qrencode.encode(text)
151
# --------------- Cairo surface conversion ---------------------------
152
# See http://cairographics.org/pythoncairopil/ and
153
# http://mail.python.org/pipermail/image-sig/2005-October/003604.html
154
# http://mail.gnome.org/archives/gtkmm-list/2007-May/msg00111.html
124
156
im = im.convert('RGBA')
126
# --------------- Cairo surface conversion ---------------------------
127
# See http://cairographics.org/pythoncairopil/
128
# and http://mail.python.org/pipermail/image-sig/2005-October/003604.html
130
157
bytearr = array.array('B', im.tostring())
131
158
height, width = im.size
145
172
# Set resampling filter
146
173
imgpat.set_filter(cairo.FILTER_NEAREST)
148
176
centered_width, centered_height = \
149
177
self.get_centered_coordinates(widget, self.surface)
150
178
ctx.translate(centered_width, centered_height)
151
179
ctx.set_source(imgpat)
153
181
# Render the image
183
ctx.paint_with_alpha(self.alpha)
184
self.alpha += self.delta
190
GLib.timeout_add(50, self.fadeImage)