~thomas-deruyter-3/qreator/qreator

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
# -*- 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

import optparse

from qreator_lib.i18n import _
from gi.repository import Gtk  # pylint: disable=E0611
from qreator import QreatorWindow
from qreator_lib import set_up_logging, get_version


def UTF8_(message):
    return _(message).decode('UTF-8')


def parse_options():
    """Support for command line options"""
    parser = optparse.OptionParser(version="%%prog %s" % get_version())
    parser.add_option(
        "-v", "--verbose", action="count", dest="verbose",
        help=UTF8_("Show debug messages (-vv debugs qreator_lib also)"))
    parser.add_option(
        "-u", "--url", dest="view", action="store_const", const="url",
        help=UTF8_("Create a QR code for a URL"))
    parser.add_option(
        "-t", "--text", dest="view", action="store_const", const="text",
        help=UTF8_("Create a QR code from text"))
    parser.add_option(
        "-l", "--location", dest="view", action="store_const",
        const="location", help=UTF8_("Create a QR code for a location"))
    parser.add_option(
        "-w", "--wifi", dest="view", action="store_const", const="wifi",
        help=UTF8_("Create a QR code for WiFi settings"))
    parser.add_option(
        "-s", "--software", dest="view", action="store_const", const="software",
        help=UTF8_("Create a QR code for an app from the software-center"))
    parser.add_option(
        "-b", "--businesscard", dest="view", action="store_const", const="vcard",
        help=UTF8_("Create a QR code for a business card"))
    (options, args) = parser.parse_args()

    set_up_logging(options)
    return options


def main():
    'constructor for your class instances'
    options = parse_options()

    # Run the application
    window = QreatorWindow.QreatorWindow()
    window.show()
    if getattr(options, 'view', None) is not None:
        if options.view == 'url':
            qr_id = 0
        elif options.view == 'text':
            qr_id = 1
        elif options.view == 'location':
            qr_id = 2
        elif options.view == 'wifi':
            qr_id = 3
        elif options.view == 'vcard':
            qr_id = 4
        elif options.view == 'software':
            qr_id = 5
        window.switch_qrcode_view(qr_id)
        window.ui.notebook1.set_current_page(QreatorWindow.PAGE_QR)
    Gtk.main()