5 from . import basic, button
7 class _Menu_Options(table.Table):
8 def __init__(self,menu,**params):
9 table.Table.__init__(self,**params)
15 arect = self.get_abs_rect()
17 if e.type == MOUSEMOTION:
18 abspos = e.pos[0]+arect.x,e.pos[1]+arect.y
19 for w in self.menu.container.widgets:
20 if not w is self.menu:
21 mrect = w.get_abs_rect()
22 if mrect.collidepoint(abspos):
23 self.menu._close(None)
27 if not handled: table.Table.event(self,e)
29 class _Menu(button.Button):
30 def __init__(self,parent,widget=None,**params): #TODO widget= could conflict with module widget
31 params.setdefault('cls','menu')
32 button.Button.__init__(self,widget,**params)
37 self.options = _Menu_Options(self, cls=self.cls+".options")
39 self.connect(CLICK,self._open,None)
43 def _open(self,value):
44 self.parent.value = self
48 self.container.open(self.options,self.rect.x,self.rect.bottom)
49 self.options.connect(BLUR,self._close,None)
53 def _pass(self,value):
56 def _close(self,value):
58 self.parent.value = None
62 def _valuefunc(self,value):
64 if value['fnc'] != None:
65 value['fnc'](value['value'])
68 button.Button.event(self,e)
70 if self.parent.value == self:
73 def add(self,w,fnc=None,value=None):
75 b = button.Button(w,cls=self.cls+".option")
76 b.connect(CLICK,self._valuefunc,{'fnc':fnc,'value':value})
83 class Menus(table.Table):
84 """A drop down menu bar.
88 ('File/Save', fnc_save, None),
89 ('File/New', fnc_new, None),
90 ('Edit/Copy', fnc_copy, None),
91 ('Edit/Cut', fnc_cut, None),
92 ('Help/About', fnc_help, help_about_content),
93 ('Help/Reference', fnc_help, help_reference_content),
99 def __init__(self,data,menu_cls='menu',**params):
100 params.setdefault('cls','menus')
101 table.Table.__init__(self,**params)
106 for path,cmd,value in data:
107 parts = path.split("/")
110 m = _Menu(self,basic.Label(mt,cls=menu_cls+".label"),cls=menu_cls)
113 print ("add", parts[1], cmd, value)
114 m.add(basic.Label(parts[1],cls=m.cls+".option.label"),cmd,value)