Last active
July 23, 2017 15:51
-
-
Save Bakterija/a4f301e911230130129b336d262e3234 to your computer and use it in GitHub Desktop.
HoverBehavior2 example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.properties import NumericProperty, ObjectProperty, BooleanProperty | |
try: | |
from kivy.uix.behaviors import HoverBehavior | |
except: | |
from kivys import HoverBehavior | |
from kivy.uix.floatlayout import FloatLayout | |
from kivy.uix.slider import Slider | |
from kivy.uix.widget import Widget | |
from kivy.uix.button import Button | |
from kivy.app import runTouchApp | |
from kivy.lang import Builder | |
from kivy.clock import Clock | |
class RootWidget(FloatLayout): | |
def on_ids(self, _, value): | |
if value and 'morebtn' in value: | |
for i in range(3, 103): | |
new = HovButton(text=str(i)) | |
value['morebtn'].add_widget(new) | |
class TransparentWidget(HoverBehavior, Widget): | |
pass | |
class HovButton(HoverBehavior, Button): | |
pass | |
class HovSlider(HoverBehavior, Slider): | |
pass | |
Builder.load_string(''' | |
<TransparentWidget>: | |
canvas: | |
Color: | |
rgba: [0.5, 0.9, 0.9, 0.4] if self.hovering else [0.4, 0.4, 0.4, 0.4] | |
Rectangle: | |
size: self.size | |
pos: self.pos | |
<Label>: | |
color: 0.9, 0.9, 0.9, 1 | |
<HovButton>: | |
background_color: [0.2, 0.2, 0.8, 1] if self.hovering else [0.2, 0.2, 0.2, 1] | |
<RootWidget>: | |
HovSlider: | |
id: hovslider | |
size_hint: 0.9, 0.1 | |
pos_hint: {'center': (0.5, 0.95)} | |
value_track: True | |
value_track_color: (0.95, 0.1, 0.0, 1) if self.hovering else (0.3, 0.3, 0.5, 1) | |
min: 0 | |
max: 1000 | |
value: int(self.max * 0.5) | |
GridLayout: | |
size_hint: 1, 0.9 | |
pos_hint: {'center': (0.5, 0.45)} | |
cols: 2 | |
rows: 2 | |
HovButton: | |
text: 'Hoverable button 0' | |
HovButton: | |
text: 'Hoverable button 1' | |
HovButton: | |
text: 'Hoverable button 2' | |
GridLayout: | |
id: morebtn | |
cols: 10 | |
rows: 10 | |
TransparentWidget: | |
size_hint: 0.9, 0.12 | |
pos_hint: {'center': (0.5, 0.45)} | |
Label: | |
text: 'Hover widget above widgets' | |
size: self.parent.size | |
pos: self.parent.pos | |
font_size: self.parent.height * 0.4 | |
color: 1.0, 0.3, 0.3, 1 | |
''') | |
runTouchApp(RootWidget()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment