~dpm/qreator/snap

« back to all changes in this revision

Viewing changes to qreator/qrcodes/QRCodeSMSGtk.py

  • Committer: Stefan Schwarzburg
  • Date: 2012-10-30 08:57:13 UTC
  • mfrom: (89.7.4 qreator)
  • mto: (89.10.24 qreator_sms)
  • mto: This revision was merged to the branch mainline in revision 101.
  • Revision ID: stefan.schwarzburg@googlemail.com-20121030085713-2zk6dhgn13fqzx7g
added sms icons; added missing tools file; added a line to shrink the main window to a reasonable size...

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
### END LICENSE
16
16
 
17
17
from gi.repository import Gtk
 
18
from qreator_lib.i18n import _
18
19
from qreator_lib.helpers import get_data_file
19
20
 
20
21
 
 
22
MESSAGE_TYPES = [(_("SMS"), "SMS"),
 
23
                 (_("MMS"), "MMS"),
 
24
               ]
 
25
 
 
26
 
21
27
class QRCodeSMSGtk(object):
22
28
    def __init__(self, qr_code_update_func):
23
29
        self.qr_code_update_func = qr_code_update_func
24
 
        builder = Gtk.Builder()
 
30
        self.builder = Gtk.Builder()
25
31
 
26
 
        builder.add_from_file(
 
32
        self.builder.add_from_file(
27
33
            get_data_file('ui', '%s.ui' % ('QrCodeSMS',)))
28
 
        self.grid = builder.get_object('qr_code_sms')
29
 
 
30
 
        textbuffer = builder.get_object('entryText').get_buffer()
31
 
        textbuffer.connect("changed", self.on_entryText_changed, None)
 
34
        self.grid = self.builder.get_object('qr_code_sms')
 
35
 
 
36
        self.messagecombo = self.builder.get_object('comboboxType')
 
37
        for t in MESSAGE_TYPES:
 
38
            self.messagecombo.append_text(t[0])
 
39
        self.messagecombo.set_active(0)
 
40
        self.messagecombo.connect("changed", self.on_comboboxType_changed, None)
 
41
 
 
42
        self.text = self.builder.get_object('entryText')
 
43
        self.text.connect("changed", self.on_entryText_changed, None)
 
44
 
 
45
        self.builder.get_object('eventboxmessage').connect("button-press-event", self.on_eventboxmessage_press_event, None)
32
46
 
33
47
    def on_activated(self):
34
 
        print 'activated!'
 
48
        pass
 
49
 
 
50
    def on_comboboxType_changed(self, widget, data=None):
 
51
        self.on_entryText_changed(self.text)
35
52
 
36
53
    def on_entryText_changed(self, widget, data=None):
37
 
        self.qr_code_update_func(widget.get_text(widget.get_start_iter(),
38
 
                                            widget.get_end_iter(),
39
 
                                            False))
 
54
        ty = MESSAGE_TYPES[self.builder.get_object('comboboxType').get_active()][1]
 
55
        n = self.builder.get_object('entryNumber').get_text()
 
56
        te = widget.get_text()
 
57
        if te == "":
 
58
            self.qr_code_update_func("{0}:{1}".format(ty, n))
 
59
        else:
 
60
            self.qr_code_update_func("{0}:{1}?body={2}".format(ty, n, te))
 
61
 
 
62
    def on_eventboxmessage_press_event(self, widget, event, data=None):
 
63
        print widget, event, data
 
64
        dialog = Gtk.MessageDialog(message_type=Gtk.MessageType.INFO,
 
65
                                   buttons=Gtk.ButtonsType.OK, message_format="Not all QR Code readers can handle SMS codes with message!")
 
66
        dialog.format_secondary_text("""Different QR Code scanning applications expect different formats.
 
67
 
 
68
Some accept SMS with predefined message, while others might either ignore the text or get the whole data wrong.
 
69
 
 
70
The format Qreator uses is:
 
71
 
 
72
SMSTO:<phone number>:<message>
 
73
 
 
74
or
 
75
 
 
76
SMSTO:<phone number>.""")
 
77
        dialog.run()
 
78
        dialog.destroy()