File size: 1,539 Bytes
7a71a69 | 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 | # Menu classes
from browser import html, document
class Menu(html.DIV):
def __init__(self):
html.DIV.__init__(self,style=dict(paddingBottom='5px'))
class BarItem:
def __init__(self, parent, label):
self.item = html.DIV(label,style=dict(float='left',
padding='5px 7px 5px 7px',
borderWidth='1px', borderStyle='solid', borderColor='#FFF')
)
self.item.bind('click', self.open)
parent <= self.item
self.children = []
def open(self, ev):
self.menu = html.DIV(style=dict(position='absolute',
left=self.item.left,
top=self.item.top+self.item.height,
zIndex=99,padding='5px',backgroundColor='#FFF',
borderStyle='solid', borderWidth='1px', borderColor="#777"))
for child in self.children:
self.menu <= child
self.item.style.borderColor = '#777'
document <= self.menu
ev.stopPropagation()
def close(self):
self.item.style.borderColor = '#FFF'
document.remove(self.menu)
class MenuListItem:
def __init__(self, parent, label, action=None):
item = html.DIV(label, style=dict(padding='10px'))
item.bind('mouseover', over_menu)
item.bind('mouseout', out_menu)
if action is not None:
item.bind('click', action)
parent.children.append(item)
def over_menu(ev):
ev.target.style.backgroundColor='#DDD'
def out_menu(ev):
ev.target.style.backgroundColor='#FFF'
|