Completed
Push — master ( 0d93d1...88297e )
by Jerome
47s
created

AbstractMenu   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 22
rs 10
c 1
b 0
f 1
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addSubmenu() 0 3 1
A addEntry() 0 3 1
A getLabel() 0 2 1
A __init__() 0 8 2
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("Menu")
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.info("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.info("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, *args, name=None, menuclass=AbstractMenu, **kwargs):
47
        if name:
48
            self.logger = logging.getLogger(name)
49
        else:
50
            self.logger = logging.getLogger(__class__.__name__)
51
52
        self._menuclass = menuclass
53
        self.labels = {}
54
55
        # Init Menu
56
        self.menu = menuclass(self, _("File"))
57
        submenu = menuclass(self.menu, _("Title1"))
58
        submenu.addEntry("Entry", None)
59
        self.menu.addSubmenu(submenu)
60
        submenu2 = menuclass(self.menu, "Title2")
61
        submenu2.addEntry("Entry2", None)
62
        submenu2.addEntry("Entry3", None)
63
        self.menu.addSubmenu(submenu2)
64
65
    def add_label(self, key, callable_f):
66
        self.labels[key] = self.labels.get(key, []).append(callable_f)
67
68
    def update_labels(self):
69
        for key in self.labels:
70
            for callable_f in self.labels[key]:
71
                callable_f()
72
73
    def info(self, msg, *args, **kwargs):
74
        self.logger.log(logging.INFO, "Informing user with: " + str(msg), *args, **kwargs)
75
76
    def handle(self, event, *args, **kwargs):
77
        self.logger.log(logging.INFO, "Handling event : " + str(event), *args, **kwargs)
78
79
    def set_ui_element(self, ui_element, msg, *args, **kwargs):
80
        self.logger.log(logging.INFO,
81
                        "Tried to set an UI-Element of the Interface, probably the child class hasn't implemented it yet!")
82
83
    def new_project_wizard(self, path=None):
84
        self.logger.log(logging.ERROR,
85
                        "Tried to start the Project Wizard from the Interface, probably the child class hasn't implemented it yet!")
86
87
    def load_mainframe(self, *args, **kwargs):
88
        self.logger.log(logging.ERROR,
89
                        "Tried to load the Mainframe from the Interface, probably the child class hasn't implemented it yet!")
90
91
    def show_settings(self, *args, **kwargs):
92
        self.logger.log(logging.ERROR,
93
                        "Tried to show the settings pane from the Interface, probably the child class hasn't implemented it yet!")
94