Menu.py 1.17 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
"""
  Nome: Menu.py
  Autor: Alessandro dos Santos Ferreira ( santosferreira.alessandro@gmail.com )

  Descricão: TODO
"""

import sys
if sys.version_info[0] < 3:
    import Tkinter as Tk
else:
    import tkinter as Tk

from ItemMenu import *

class Menu(object):
    
    label = None
    __items_menu = None
    
    def __init__(self, label):
        self.label = label
        self.__items_menu = []
        

    def add_command(self, label, action, shortcut):
        self.__items_menu.append( Command(label, action, shortcut) )
        
    def add_separator(self):
        self.__items_menu.append( Separator() )

    def render(self, menubar):
        menu = Tk.Menu(menubar, tearoff=0)
        
        for item in self.__items_menu:
            menu = item.render(menu)
            
        menubar.add_cascade(label=self.label, menu=menu)
            
        return menubar

    def get_shorcuts(self):
        sh = []
        
        for item in self.__items_menu:
            shortcut, action = item.get_shortcut()
            if shortcut is not None:
                sh.append({"shortcut": shortcut, "action": action})

        return sh