1
by David Planella
Initial project creation with Quickly! |
1 |
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
|
2 |
### BEGIN LICENSE
|
|
20
by David Planella
Added license |
3 |
# Copyright (C) 2012 David Planella <david.planella@ubuntu.com>
|
89.8.1
by Stefan Schwarzburg
Added a plugin-style class of type "type" which is used by the QRCode class as a metaclass, registering all classes implementing a QRCode. |
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
|
|
20
by David Planella
Added license |
6 |
# by the Free Software Foundation.
|
89.8.1
by Stefan Schwarzburg
Added a plugin-style class of type "type" which is used by the QRCode class as a metaclass, registering all classes implementing a QRCode. |
7 |
#
|
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
|
|
20
by David Planella
Added license |
11 |
# PURPOSE. See the GNU General Public License for more details.
|
89.8.1
by Stefan Schwarzburg
Added a plugin-style class of type "type" which is used by the QRCode class as a metaclass, registering all classes implementing a QRCode. |
12 |
#
|
13 |
# You should have received a copy of the GNU General Public License along
|
|
20
by David Planella
Added license |
14 |
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
1
by David Planella
Initial project creation with Quickly! |
15 |
### END LICENSE
|
16 |
||
17 |
import optparse |
|
18 |
||
61.1.16
by David Planella
Simplified internationalization code and made it work with /opt without having to depend on quickly packaging changes |
19 |
from qreator_lib.i18n import _ |
90
by Stefan Schwarzburg
A first attempt to introduce threads in order to give IO-heavy autocompleters a chance to do the lifting in the background. |
20 |
from gi.repository import Gtk, Gdk, GLib, GObject # pylint: disable=E0611 |
1
by David Planella
Initial project creation with Quickly! |
21 |
from qreator import QreatorWindow |
22 |
from qreator_lib import set_up_logging, get_version |
|
89.8.4
by Stefan Schwarzburg
The refactoring seems to work now. Commandline options are now also created dynamically. |
23 |
from qreator.qrcodes.QRCodeType import QRCodeType |
24 |
||
25 |
# use dynamic importing to get all qrcode dataformats without
|
|
26 |
# knowing their names.
|
|
27 |
# That way, all the information of a qrcode dataformat can
|
|
28 |
# be kept in a single file, like a plugin.
|
|
29 |
import pkgutil |
|
30 |
import qreator.qrcodes |
|
31 |
||
32 |
for qr in list(pkgutil.iter_modules(qreator.qrcodes.__path__)): |
|
33 |
name = "qreator.qrcodes." + qr[1] |
|
34 |
__import__(name, fromlist=[]) |
|
1
by David Planella
Initial project creation with Quickly! |
35 |
|
61.1.6
by David Planella
Started using the gettext C API (locale module) instead of the Python one (gettext module), so that translations are loaded when installing the app in /opt. See http://askubuntu.com/questions/140552/how-to-make-glade-load-translations-from-opt. Minor whitespace fixes. Removed shebang from QRCode.py to stop Lintian complaining |
36 |
|
73
by David Planella
Make optparse not crash when using gettext, thanks Nicolas Delvaux for the help |
37 |
def UTF8_(message): |
38 |
return _(message).decode('UTF-8') |
|
39 |
||
40 |
||
89.8.4
by Stefan Schwarzburg
The refactoring seems to work now. Commandline options are now also created dynamically. |
41 |
def parse_options(qr_types): |
1
by David Planella
Initial project creation with Quickly! |
42 |
"""Support for command line options"""
|
43 |
parser = optparse.OptionParser(version="%%prog %s" % get_version()) |
|
44 |
parser.add_option( |
|
45 |
"-v", "--verbose", action="count", dest="verbose", |
|
73
by David Planella
Make optparse not crash when using gettext, thanks Nicolas Delvaux for the help |
46 |
help=UTF8_("Show debug messages (-vv debugs qreator_lib also)")) |
89.8.4
by Stefan Schwarzburg
The refactoring seems to work now. Commandline options are now also created dynamically. |
47 |
|
48 |
for n, qr in enumerate(qr_types): |
|
49 |
parser.add_option( |
|
50 |
qr.cmdline_option_short, qr.cmdline_option_long, |
|
51 |
dest="view", action="store_const", const=n, |
|
52 |
help=qr.message.decode('UTF-8')) |
|
53 |
||
1
by David Planella
Initial project creation with Quickly! |
54 |
(options, args) = parser.parse_args() |
55 |
||
56 |
set_up_logging(options) |
|
32.1.2
by Michael Hall
Add the ability to go directly to a section from the commandline |
57 |
return options |
1
by David Planella
Initial project creation with Quickly! |
58 |
|
61.1.6
by David Planella
Started using the gettext C API (locale module) instead of the Python one (gettext module), so that translations are loaded when installing the app in /opt. See http://askubuntu.com/questions/140552/how-to-make-glade-load-translations-from-opt. Minor whitespace fixes. Removed shebang from QRCode.py to stop Lintian complaining |
59 |
|
1
by David Planella
Initial project creation with Quickly! |
60 |
def main(): |
61 |
'constructor for your class instances'
|
|
61.1.6
by David Planella
Started using the gettext C API (locale module) instead of the Python one (gettext module), so that translations are loaded when installing the app in /opt. See http://askubuntu.com/questions/140552/how-to-make-glade-load-translations-from-opt. Minor whitespace fixes. Removed shebang from QRCode.py to stop Lintian complaining |
62 |
# Run the application
|
1
by David Planella
Initial project creation with Quickly! |
63 |
window = QreatorWindow.QreatorWindow() |
89.8.4
by Stefan Schwarzburg
The refactoring seems to work now. Commandline options are now also created dynamically. |
64 |
|
65 |
qr_types = [d(window.update_qr_code) for d in QRCodeType.dataformats] |
|
66 |
options = parse_options(qr_types) |
|
67 |
||
68 |
window.qr_types = qr_types |
|
1
by David Planella
Initial project creation with Quickly! |
69 |
window.show() |
32.1.2
by Michael Hall
Add the ability to go directly to a section from the commandline |
70 |
if getattr(options, 'view', None) is not None: |
89.8.4
by Stefan Schwarzburg
The refactoring seems to work now. Commandline options are now also created dynamically. |
71 |
qr_id = options.view |
89.3.1
by Stefan Schwarzburg
fixed bug 1016826 |
72 |
window.switch_qrcode_view(qr_id) |
32.1.2
by Michael Hall
Add the ability to go directly to a section from the commandline |
73 |
window.ui.notebook1.set_current_page(QreatorWindow.PAGE_QR) |
90
by Stefan Schwarzburg
A first attempt to introduce threads in order to give IO-heavy autocompleters a chance to do the lifting in the background. |
74 |
GObject.threads_init() |
75 |
GLib.threads_init() |
|
76 |
Gdk.threads_init() |
|
1
by David Planella
Initial project creation with Quickly! |
77 |
Gtk.main() |