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

GUIMenu   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 addSeparator() 0 2 1
A addEntry() 0 3 1
A __init__() 0 10 2
A addSubmenu() 0 3 1
1
from sys import version_info
2
3
from msquaredc.ui.interfaces import AbstractMenu
4
5
if version_info[0] == 2:
6
    # We are using Python 2.x
7
    import Tkinter as tk
8
    import tkFileDialog as filedialog
9
elif version_info[0] == 3:
10
    # We are using Python 3.x
11
    import tkinter as tk
12
    from tkinter import filedialog
13
14
15
class GUIMenu(AbstractMenu):
16
    def __init__(self, root, name):
17
        self.tk = root.tk
18
        self.root = root
19
        super(GUIMenu, self).__init__(root, name)
20
21
        if not isinstance(root, GUIMenu):
22
            self.menu = tk.Menu(self.tk, tearoff=False)
23
            self.tk.config(menu=self.menu)
24
        else:
25
            self.menu = tk.Menu(self.root.menu, tearoff=False)
26
27
    def addEntry(self, entry, handle, *args, **kwargs):
28
        super(GUIMenu, self).addEntry(entry, handle)
29
        self.menu.add_command(label=entry, command=handle)
30
31
    def addSeparator(self):
32
        self.menu.add_separator()
33
34
    def addSubmenu(self, entry, *args, **kwargs):
35
        super(GUIMenu, self).addSubmenu(entry)
36
        self.menu.add_cascade(label=entry.name, menu=entry.menu)
37