1
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
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
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
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
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
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
13
# You should have received a copy of the GNU General Public License along
14
14
# with this program. If not, see <http://www.gnu.org/licenses/>.
17
from qreator_lib.i18n import _
18
17
from qreator_lib.helpers import get_media_file
20
20
class DataformatsMount(type):
21
21
""" http://martyalchin.com/2008/jan/10/simple-plugin-framework/"""
22
def __init__(cls, name, bases, attrs):
22
def __init__(cls, name, bases, attrs): # pylint: disable=W0231,W0613
23
23
if not hasattr(cls, 'dataformats'):
24
# This branch only executes when processing the mount point itself.
25
# So, since this is a new dataformat type, not an implementation, this
26
# class shouldn't be registered as a plugin. Instead, it sets up a
27
# list where dataformats can be registered later.
24
# This branch only executes when processing the mount
25
# point itself. So, since this is a new dataformat type,
26
# not an implementation, this class shouldn't be
27
# registered as a plugin. Instead, it sets up a list where
28
# dataformats can be registered later.
28
29
cls.dataformats = []
30
# This must be a dataformat implementation, which should be registered.
31
# Simply appending it to the list is all that's needed to keep
31
# This must be a dataformat implementation, which should
32
# be registered. Simply appending it to the list is all
33
# that's needed to keep track of it later.
33
34
cls.dataformats.append(cls)
39
40
Classes implementing a dataformat type should provide the following class
41
==================== ======================================================
42
==================== =====================================================
42
43
description translateble, very short, used in the GUI
43
44
cmdline_option make this unique in Qreator, since it will be used to
44
45
icon_name the name of the icon in <qreator>/data/media/, which
45
46
should be used for this datatype
46
==================== ======================================================
47
==================== =====================================================
48
49
Classes implementing a dataformat type should also provide the following
50
==================== ======================================================
51
create_widget This method is called during init to create the widget
51
==================== =====================================================
52
create_widget This method is called during init to create the
53
widget for this datatype.
53
54
create_code The paramters are data format specific, but the
54
55
method should be able to recreate a code from saved
56
57
This method should return a single string to pass
57
58
to the general code update function.
58
==================== ======================================================
59
==================== =====================================================
60
61
__metaclass__ = DataformatsMount
62
description = _("DataFormat") # replace this
63
icon_name = "dataformat.png" # replace this
64
cmdline_option = "--dataformat" # replace this
63
# replace the description, and make it translatable with _("")
64
description = "DataFormat"
65
icon_name = "dataformat.png" # replace this in subclass
66
cmdline_option = "--dataformat" # replace this in subclass
66
68
def __init__(self, qr_code_update_func):
67
69
self.qr_code_update_func = qr_code_update_func
68
70
self.icon_path = get_media_file(self.icon_name)
71
self.create_widget() # pylint: disable=E1101