1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
### BEGIN LICENSE
# Copyright (C) 2012 David Planella <david.planella@ubuntu.com>
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranties of
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
### END LICENSE
from gi.repository import Gtk
from GtkHelpers import clear_text_entry, show_clear_icon
from qreator_lib.helpers import get_data_file
from qreator_lib.i18n import _
class QRCodeURLGtk(object):
def __init__(self, qr_code_update_func):
self.qr_code_update_func = qr_code_update_func
self.builder = Gtk.Builder()
self.builder.add_from_file(
get_data_file('ui', '%s.ui' % ('QrCodeURL',)))
self.builder.connect_signals(self)
self.grid = self.builder.get_object('qr_code_url')
self.entry = self.builder.get_object('entryURL')
self.combobox = self.builder.get_object('comboboxtextProtocol')
# Initialize placeholder text (we need to do that because due to
# a Glade bug they are otherwise not marked as translatable)
self.entry.set_placeholder_text(_('[URL]'))
self.combobox.set_active(0)
self.entry.connect("changed", self.on_entryURL_changed)
self.combobox.connect("changed", self.on_comboboxtextProtocol_changed)
def on_activated(self):
pass
def on_prepared(self):
pass
def update_url_qr_code(self, protocol=None, www=None):
if not protocol:
protocol = self.combobox.get_active_text()
if not www:
www = self.entry.get_text()
if not protocol or www == '':
return
self.qr_code_update_func(protocol + www)
def on_entryURL_icon_press(self, widget, icon, mouse_button):
clear_text_entry(widget, icon)
def check_and_remove_protocol(self, widget):
"""
Creates a list of protocols (as given by the combobox).
Checks if beginning of the text entry is in that list. If so, remove the protocol
and select the appropriate protocol in the combobox.
"""
for n, protocol in enumerate([mr[0] for mr in self.combobox.get_model()]):
if widget.get_text().strip().startswith(protocol):
widget.set_text(widget.get_text().strip().strip(protocol))
self.combobox.set_active(n)
return
def on_entryURL_changed(self, widget, data=None):
show_clear_icon(widget)
self.check_and_remove_protocol(widget)
self.update_url_qr_code(www=widget.get_text())
def on_comboboxtextProtocol_changed(self, widget, data=None):
self.update_url_qr_code(protocol=widget.get_active_text())
|