electrum-bitcoinprivate/gui/kivy/uix/context_menu.py

53 lines
1.2 KiB
Python
Raw Normal View History

2015-12-12 07:54:32 -08:00
#!python
#!/usr/bin/env python
from kivy.app import App
from kivy.uix.bubble import Bubble
from kivy.animation import Animation
from kivy.uix.floatlayout import FloatLayout
from kivy.lang import Builder
from kivy.factory import Factory
from kivy.clock import Clock
2015-12-12 07:54:32 -08:00
Builder.load_string('''
<MenuItem@Button>
background_color: .2, .9, 1, 1
height: '48dp'
2015-12-12 07:54:32 -08:00
size_hint: 1, None
<ContextMenu>
size_hint: 1, None
height: '48dp'
2015-12-12 07:54:32 -08:00
pos: (0, 0)
show_arrow: False
arrow_pos: 'top_mid'
2015-12-12 07:54:32 -08:00
padding: 0
orientation: 'horizontal'
BoxLayout:
size_hint: 1, 1
height: '48dp'
2015-12-12 07:54:32 -08:00
orientation: 'horizontal'
id: buttons
''')
class MenuItem(Factory.Button):
pass
class ContextMenu(Bubble):
2015-12-12 07:54:32 -08:00
def __init__(self, obj, action_list):
Bubble.__init__(self)
self.obj = obj
for k, v in action_list:
l = MenuItem()
l.text = k
2015-12-14 03:08:11 -08:00
def func(f=v):
Clock.schedule_once(lambda dt: self.hide(), 0.1)
Clock.schedule_once(lambda dt: f(obj), 0.15)
2015-12-14 03:08:11 -08:00
l.on_release = func
2015-12-12 07:54:32 -08:00
self.ids.buttons.add_widget(l)
def hide(self):
if self.parent:
self.parent.hide_menu()