AbstractLabel.__init__()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
import abc
2
import gettext
3
import logging
4
5
gettext.bindtextdomain("msquaredc", ".")
6
gettext.textdomain("msquaredc")
7
_ = gettext.gettext
8
9
10
# logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p',level=logging.DEBUG)
11
12
class AbstractMenu:
13
    __metaclass__ = abc.ABCMeta
14
15
    def __init__(self, main, name, logger=None):
16
        if logger:
17
            self.logger = logging.getLogger(logger)
18
        else:
19
            self.logger = logging.getLogger(__name__)
20
        self.name = name
21
        self.main = main
22
        self.entries = []
23
24
    def addEntry(self, entry, handle, *args, **kwargs):
25
        self.entries.append((entry, handle))
26
        self.logger.debug("Adding Entry {} to menu {} ".format(entry, self.name))
27
28
    def addSubmenu(self, menu, *args, **kwargs):
29
        self.entries.append((menu.name, menu.entries))
30
        self.logger.debug("Adding Submenu {} to menu {} ".format(menu.name, self.name))
31
32
    def getLabel(self):
33
        pass
34
35
36
class AbstractLabel:
37
    __metaclass__ = abc.ABCMeta
38
39
    def __init__(self, text):
40
        self.text = text
41
42
43
class AbstractPresenter:
44
    __metaclass__ = abc.ABCMeta
45
46
    def __init__(self, name=None, menuclass=AbstractMenu, projectbuilder=None, *args, **kwargs):
47
        if name:
48
            self.logger = logging.getLogger(name)
49
        else:
50
            self.logger = logging.getLogger(__name__)
51
52
        self._menuclass = menuclass
53
        self.labels = {}
54
55
        # Init Menu
56
        self.menu = menuclass(_("Main Menu"), self)
57
        submenu = menuclass(_("File"), self.menu)
58
        submenu.addEntry("New", None)
59
        submenu.addEntry("Open", None)
60
        submenu.addEntry("Exit", None)
61
        self.menu.addSubmenu(submenu)
62
        submenu2 = menuclass("Edit", self.menu)
63
        submenu2.addEntry("Settings", None)
64
        self.menu.addSubmenu(submenu2)
65
66
        self.pb = projectbuilder
67
68
    def build_project(self):
69
        if self.pb.config is None:
70
            self.get_config_file()
71
        if self.pb.data is None:
72
            self.get_data_file()
73
        if self.pb.coder is None:
74
            self.get_coder()
75
76
    def get_coder(self):
77
        self.logger.log(logging.ERROR,
78
                        "Tried to ask for the coder, probably the child class hasn't implemented it yet!")
79
80
    def get_config_file(self):
81
        self.logger.log(logging.ERROR,
82
                        "Tried to ask for the config file, probably the child class hasn't implemented it yet!")
83
84
    def get_data_file(self):
85
        self.logger.log(logging.ERROR,
86
                        "Tried to ask for the data file, probably the child class hasn't implemented it yet!")
87
88
    def add_label(self, key, callable_f):
89
        self.labels[key] = self.labels.get(key, []).append(callable_f)
90
91
    def update_labels(self):
92
        for key in self.labels:
93
            for callable_f in self.labels[key]:
94
                callable_f()
95
96
    def info(self, msg, *args, **kwargs):
97
        self.logger.log(logging.INFO, "Informing user with: " + str(msg), *args, **kwargs)
98
99
    def handle(self, event, *args, **kwargs):
100
        self.logger.log(logging.INFO, "Handling event : " + str(event), *args, **kwargs)
101
102
    def set_ui_element(self, ui_element, msg, *args, **kwargs):
103
        self.logger.log(logging.INFO,
104
                        "Tried to set an UI-Element of the Interface, probably the child class hasn't implemented it yet!")
105
106
    def new_project_wizard(self, path=None):
107
        self.logger.log(logging.ERROR,
108
                        "Tried to start the Project Wizard from the Interface, probably the child class hasn't implemented it yet!")
109
110
    def load_mainframe(self, *args, **kwargs):
111
        self.logger.log(logging.ERROR,
112
                        "Tried to load the Mainframe from the Interface, probably the child class hasn't implemented it yet!")
113
114
    def show_settings(self, *args, **kwargs):
115
        self.logger.log(logging.ERROR,
116
                        "Tried to show the settings pane from the Interface, probably the child class hasn't implemented it yet!")
117
118
    def run(self):
119
        if not self.pb.finished():
120
            self.build_project()
121
        self.load_mainframe(self.pb.build())
122