19
from gi.repository import Gtk, Gdk, GdkPixbuf # pylint: disable=E0611
19
from gi.repository import Gtk, Gdk, GdkPixbuf, GLib # pylint: disable=E0611
20
20
from gi.repository import GtkChamplain, Clutter, Champlain
21
21
from gi.repository import NetworkManager, NMClient
75
75
# Initialize placeholder text (we need to do that because due to
76
76
# a Glade bug they are otherwise not marked as translatable)
77
77
self.ui.entryURL.set_placeholder_text(_('[URL]'))
78
# TRANSLATORS: 'expand' refers to expanding the drop-down menu
79
# that shows autodetected wireless network identifiers
78
80
self.ui.entrySSID.set_placeholder_text(
79
81
_('[Network identifier - expand for autodetection]'))
80
82
self.ui.entryPassword.set_placeholder_text(_('[Network password]'))
114
116
self.usc_apps_complete.set_hexpand(True)
115
117
self.usc_apps_complete.connect("changed",
116
118
self.on_usc_apps_complete_changed, None)
119
self.usc_apps_complete.connect("icon-press",
120
self.on_usc_apps_complete_icon_pressed)
121
self.usc_apps_complete.set_icon_from_icon_name(
122
Gtk.EntryIconPosition.PRIMARY, 'edit-find-symbolic')
123
self.usc_apps_complete.set_icon_from_stock(
124
Gtk.EntryIconPosition.SECONDARY, None)
118
126
#self.get_softwarecenterapps()
119
127
#self.on_get_softwarecenterapps()
120
deferred = defer.defer(self.get_softwarecenterapps)
121
deferred.add_callback(self.on_get_softwarecenterapps)
128
#deferred = defer.defer(self.get_softwarecenterapps)
129
#deferred.add_callback(self.on_get_softwarecenterapps)
123
131
self.ui.qr_app.attach(self.usc_apps_complete, 1, 0, 1, 1)
132
self.softwarecenter_apps_init = False
125
134
# Load the background texture
126
135
self.texture = cairo.ImageSurface.create_from_png(
166
175
# Add an initial text, so that there is an initial QR code
167
176
self.qr_code_placeholder = 'http://launchpad.net/qreator'
178
def on_usc_apps_complete_icon_pressed(self, widget, icon, mouse_button):
179
self._clear_text_entry(widget, icon)
181
def _clear_text_entry(self, widget, icon):
182
if icon == Gtk.EntryIconPosition.SECONDARY:
184
self._check_style(widget)
186
elif icon == Gtk.EntryIconPosition.PRIMARY:
187
widget.select_region(0, -1)
190
def _check_style(self, widget):
192
Show the clear icon whenever the field is not empty
194
if widget.get_text() != "":
195
widget.set_icon_from_stock(Gtk.EntryIconPosition.SECONDARY,
197
# reverse the icon if we are in an rtl environment
198
if widget.get_direction() == Gtk.TextDirection.RTL:
199
pb = widget.get_icon_pixbuf(
200
Gtk.EntryIconPosition.SECONDARY).flip(True)
201
widget.set_icon_from_pixbuf(Gtk.EntryIconPosition.SECONDARY,
204
widget.set_icon_from_stock(Gtk.EntryIconPosition.SECONDARY, None)
206
def init_softwarecenter_apps(self):
207
deferred = defer.defer(self.get_softwarecenterapps)
208
deferred.add_callback(self.on_get_softwarecenterapps)
209
self.softwarecenter_apps_init = True
169
211
def fill_qr_types_store(self):
170
212
self.qr_types_store.clear()
242
284
# We're now loading the UI for the Software Center app QR type
243
285
self._hide_children(self.ui.qr_input)
244
286
self.ui.qr_app.show_all()
287
if not self.softwarecenter_apps_init:
288
GLib.idle_add(self.init_softwarecenter_apps)
246
290
def on_qr_text_clicked(self):
247
291
# Initialize multi-line text entry
352
396
self.ui.qr_drawingarea.queue_draw()
354
398
def on_usc_apps_complete_changed(self, widget, data=None):
399
self._check_style(widget)
355
400
USC_APPS_BASE_URL = 'https://apps.ubuntu.com/cat/applications/'
356
401
self.update_qr_code(USC_APPS_BASE_URL + widget.get_text())
403
def on_entryURL_icon_press(self, widget, icon, mouse_button):
404
self._clear_text_entry(widget, icon)
358
406
def on_entryURL_changed(self, widget, data=None):
407
self._check_style(widget)
359
408
self.update_url_qr_code(www=widget.get_text())
361
410
def on_comboboxtextProtocol_changed(self, widget, data=None):
390
439
def on_comboboxtextSecurity_changed(self, widget, data=None):
391
440
self.update_wifi_qr_code(security=widget.get_active_text())
393
def on_entrySSID_changed(self, widget, data=None):
394
self.update_wifi_qr_code(ssid=widget.get_text())
442
def on_entrySSID_icon_press(self, widget, icon, mouse_button):
443
self._clear_text_entry(widget, icon)
396
445
def on_comboboxtextSSID_changed(self, widget, data=None):
446
self._check_style(self.ui.entrySSID)
397
447
self.update_wifi_qr_code(ssid=widget.get_active_text())
449
def on_entryPassword_icon_press(self, widget, icon, mouse_button):
450
self._clear_text_entry(widget, icon)
399
452
def on_entryPassword_changed(self, widget, data=None):
453
self._check_style(widget)
400
454
self.update_wifi_qr_code(password=widget.get_text())
402
456
def on_checkbutton1_clicked(self, widget):
457
509
ctx.set_source(pattern)
460
## Create the QR code
462
self.surface = qr_code.encode(text, QRCodeOutput.CAIRO_SURFACE)
464
# Center the image in the drawing area
465
centered_width, centered_height = \
466
self.get_centered_coordinates(widget, self.surface)
467
ctx.translate(centered_width, centered_height)
469
# Set the surface as the context's source
470
ctx.set_source_surface(self.surface)
513
## Create the QR code
515
self.surface = qr_code.encode(text, QRCodeOutput.CAIRO_SURFACE)
517
# Center the image in the drawing area
518
centered_width, centered_height = \
519
self.get_centered_coordinates(widget, self.surface)
520
ctx.translate(centered_width, centered_height)
522
# Set the surface as the context's source
523
ctx.set_source_surface(self.surface)
475
528
def get_softwarecenterapps(self):
476
529
print 'Task STARTED!'
615
# TRANSLATORS: this message appears for a few seconds on the
616
# Software Center apps text entry until the app names to
617
# suggest for autocompletion have been read from the Software
562
619
self.set_placeholder_text(
563
620
_('[Wait a few seconds to enable autocompletion...]'))
569
626
_('[Type the name of an app]'))
571
628
def _remember(self, app):
572
'''add a value to the list of strings to suggest'''
629
'''Add a value to the list of strings to suggest'''
574
631
icon = self.icons.load_icon(
575
632
"{0}".format(app.icon),