ItemMenu.py 1.31 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 54 55 56 57 58 59 60 61
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
"""
  Nome: ItemMenu.py
  Autor: Alessandro dos Santos Ferreira ( santosferreira.alessandro@gmail.com )

  Descricão: TODO
"""

from abc import ABCMeta, abstractmethod

class ItemMenu(object):
    
    __metaclass__ = ABCMeta

    @abstractmethod
    def render(self, menu):
        pass
    
    @abstractmethod
    def get_shortcut(self):
        pass


class Command(ItemMenu):
    
    label = None
    action = None
    shortcut = None
    
    def __init__(self, label, action, shortcut = None):
        self.label = label
        self.action = action
        if shortcut is not None:
            self.shortcut = str(shortcut).upper()
        
    def render(self, menu):
        accelerator = None if self.shortcut is None else "Ctrl+" + str(self.shortcut)
        underline = None if self.shortcut is None else self.label.upper().find( self.shortcut )
        
        menu.add_command(label=self.label, command=self.action, accelerator=accelerator, underline=underline)
        
        return menu
        
    def get_shortcut(self):
        return self.shortcut, self.action


class Separator(ItemMenu):
    
    def __init__(self):
        pass

    def render(self, menu):
        menu.add_separator()
        
        return menu

    def get_shortcut(self):
        return None, None