1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
# Copyright (C) 2012 David Planella <david.planella@ubuntu.com>
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU General Public License version 3, as published
6
# by the Free Software Foundation.
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranties of
10
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
# PURPOSE. See the GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License along
14
# with this program. If not, see <http://www.gnu.org/licenses/>.
17
from gi.repository import Gtk
18
from qreator_lib.helpers import get_data_file
19
from qreator_lib.i18n import _
22
class QRCodeURLGtk(object):
23
def __init__(self, qr_code_update_func):
24
self.qr_code_update_func = qr_code_update_func
25
builder = Gtk.Builder()
27
builder.add_from_file(
28
get_data_file('ui', '%s.ui' % ('QrCodeURL',)))
29
self.grid = builder.get_object('qr_code_url')
31
self.entry = builder.get_object('entryURL')
32
self.combobox = builder.get_object('comboboxtextProtocol')
34
# Initialize placeholder text (we need to do that because due to
35
# a Glade bug they are otherwise not marked as translatable)
36
self.entry.set_placeholder_text(_('[URL]'))
37
self.combobox.set_active(0)
39
self.entry.connect("changed", self.on_entryURL_changed)
40
self.combobox.connect("changed", self.on_comboboxtextProtocol_changed)
42
def on_activated(self):
45
def update_url_qr_code(self, protocol=None, www=None):
47
protocol = self.combobox.get_active_text()
49
www = self.entry.get_text()
51
if not protocol or www == '':
54
self.qr_code_update_func(protocol + www)
56
#def on_entryURL_icon_press(self, widget, icon, mouse_button):
57
# self._clear_text_entry(widget, icon)
59
def on_entryURL_changed(self, widget, data=None):
60
#self._check_style(widget)
61
self.update_url_qr_code(www=widget.get_text())
63
def on_comboboxtextProtocol_changed(self, widget, data=None):
64
self.update_url_qr_code(protocol=widget.get_active_text())