b850b6cc622a51ed07b086e4d2e4bcb964eb6db0
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 _value(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
._value
,{'fnc':fnc
,'value':value
})
83 class Menus(table
.Table
):
84 """A drop down menu bar.
86 <pre>Menus(data)</pre>
89 <dt>data<dd>Menu data, a list of (path,fnc,value), see example below
92 <strong>Example</strong>
95 ('File/Save',fnc_save,None),
96 ('File/New',fnc_new,None),
97 ('Edit/Copy',fnc_copy,None),
98 ('Edit/Cut',fnc_cut,None),
99 ('Help/About',fnc_help,help_about_content),
100 ('Help/Reference',fnc_help,help_reference_content),
105 def __init__(self
,data
,menu_cls
='menu',**params
):
106 params
.setdefault('cls','menus')
107 table
.Table
.__init
__(self
,**params
)
112 for path
,cmd
,value
in data
:
113 parts
= path
.split("/")
116 m
= _Menu(self
,basic
.Label(mt
,cls
=menu_cls
+".label"),cls
=menu_cls
)
119 m
.add(basic
.Label(parts
[1],cls
=m
.cls
+".option.label"),cmd
,value
)