Skip to content

Instantly share code, notes, and snippets.

@GreyGnome
Last active January 21, 2017 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GreyGnome/166eb80812afdb95e248a71a47ddccd3 to your computer and use it in GitHub Desktop.
Save GreyGnome/166eb80812afdb95e248a71a47ddccd3 to your computer and use it in GitHub Desktop.
<HeaderButton>:
background_normal: "red10x10.png"
<SubWindow>:
WindowHeader:
orientation: "horizontal"
size_hint: 1, None
height: 40
padding: 5
spacing: 5
canvas.before:
Color:
rgba: 0.0, 0.0, 0,9, 1.0
Rectangle:
pos: self.pos
size: self.size
HeaderButton:
text: "Play"
size_hint: 1, 1
on_press: root.play()
HeaderButton:
text: "Close"
size_hint: 1, 1
on_press: root.close(args[0])
on_touch_down: root.touch_down(args[0], args[1])
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.anchorlayout import AnchorLayout
import Overlay
class ButtonOverlay(AnchorLayout, Overlay.Overlay):
def __init__(self, *args, **kwargs):
print "++++++++++++++++"
print "ButtonOverlay"
super(ButtonOverlay, self).__init__(*args, **kwargs)
self.button_new=(Button(text="New"))
self.button_new.bind(on_press=self.new_pressed)
self.add_widget(self.button_new)
def new_pressed(self, something):
print "press: ButtonOverlay: Button 'New'!", something, "RETURN TRUE"
self.parent_container.add_newthing(something)
return True
class HeaderButton(Button):
def __init__(self, *args, **kwargs):
print "++++++++++++++++"
print "HeaderButton"
super(HeaderButton, self).__init__(*args, **kwargs)
class WindowHeader(BoxLayout):
def __init__(self, *args, **kwargs):
print "========================================================"
print "WindowHeader"
super(WindowHeader, self).__init__(*args, **kwargs)
def on_touch_down(self, touch):
print "WindowHeader DOWN"
super(WindowHeader, self).on_touch_down(touch)
def close(self):
print "WindowHeader close"
class SubWindow(BoxLayout):
def __init__(self, *args, **kwargs):
print "**********************************************************"
self.orientation = "vertical"
self.title = "BIG TITLE"
super(SubWindow, self).__init__(*args, **kwargs)
self.button_internal=Button(text="[color=3333ff]Label: " + self.title + "[/color]", markup=True,
background_normal="white10x10.png")
self.add_widget(self.button_internal)
self.button_internal.bind(on_press=self.press)
self.button_internal.bind(on_touch_down=self.touch_down)
def on_parent(self, widget, parent):
print "SubWindow: Added to parent"
def play(self):
print "SubWindow: Play"
# PalmMediator.play(self.collection)
def close(self, thingy):
print "SubWindow: close:", "***" + self.title + "***, my x,y pos:", thingy.x, thingy.y
print "thingy:", thingy
print "parent:", thingy.parent
grandparent = thingy.parent.parent
print "grandparent:", thingy.parent.parent
print "root, remove:",
self.get_root_window().children[0].remove_this(grandparent)
# remove_this(grandparent)
def touch_down(self, thingy, touch):
print "SubWindow: touch_down", "***" + self.title + "***:", thingy.x, thingy.y, thingy.width, thingy.height,\
"touch coords:", touch.x, touch.y
print " touch_down: Parent:", self.parent
def press(self, thingy):
print "SubWindow: button_internal: press:", thingy
print " parent:", self.parent
print " is_triggered?:", self._trigger_layout.is_triggered
class newthing(FloatLayout, Overlay.Overlay):
def __init__(self, *args, **kwargs):
super(newthing, self).__init__(*args, **kwargs)
self.button_new=Button(text='Top', size_hint=(None,None),
pos=(50,50), size=(800,200))
self.add_widget(self.button_new)
self.button_new.bind(on_press=self.press)
self.button_new.bind(on_touch_down=self.touch_down)
def press(self, thingy):
print "newthing: press", thingy
def touch_down(self, thingy, touch):
print "newthing: touch", thingy, touch
class ui(FloatLayout):
def __init__(self, *args, **kwargs):
super(ui, self).__init__(*args, **kwargs)
print "__init__ ui"
self.internal_layout = BoxLayout(
orientation='vertical'
)
self.add_widget(self.internal_layout)
self.button_top=Button(text='Top')
self.button_does_no_thing = Button(text='Does No Thing')
self.internal_layout.add_widget(self.button_top)
self.internal_layout.add_widget(self.button_does_no_thing)
self.button_does_no_thing.bind(on_touch_down=self.touch_down)
self.button_does_no_thing.bind(on_press=self.press)
self.overlay = ButtonOverlay(
size_hint=(None, None),
# pos_hint={'left': None, 'top': None},
anchor_x = 'left',
anchor_y = 'top',
size=(60, 60)
# orientation='vertical'
)
self.overlay.register(self)
def press(self, thingy):
print "ui: press: does_no_thing button:", thingy
def add_newthing(self, thingy):
print "ui: add_new_thing", thingy
self.new_thing=SubWindow()
self.internal_layout.add_widget(self.new_thing)
def touch_down(self, thingy, touch):
print "ui: touch:", thingy, touch
print "ui: touch: does_no_thing button:", self.button_does_no_thing
def remove_newthing(self):
self.internal_layout.remove_widget(self.new_thing)
def remove_this(self, widget):
print "SELF:", self, "WANT TO REMOVE:", widget
print "CHILDREN:"
print self.children
self.internal_layout.remove_widget(widget)
def get_newthing(self):
return self.new_thing
class App3(App):
def build(self):
return ui()
if __name__ == '__main__':
App3().run()
from kivy.core.window import Window
from kivy.clock import Clock
from kivy.uix.widget import Widget
class Overlay(Widget):
def __init__(self, *args, **kwargs):
self.parent_container = kwargs.pop("registered_parent", None)
super(Overlay, self).__init__(*args, **kwargs)
if self.parent_container is not None:
self.start_fade_timer()
self.show()
self.mouse_pos = Window.mouse_pos
def fade_in_out(self, dt):
if Window.mouse_pos != self.mouse_pos:
self.mouse_pos = Window.mouse_pos
self.idle_ticks = 0
if self.parent == None:
self.show()
return
if self.idle_ticks > 3:
self.parent_container.remove_widget(self)
else:
self.idle_ticks += 1
def show(self):
if self.parent is not None:
return
if self.parent_container is not None:
self.parent_container.add_widget(self)
def on_touch_move(self, touch):
super(Overlay, self).on_touch_move(touch)
self.idle_ticks = 0
def start_fade_timer(self):
self.idle_ticks = 0
self.fader_event = Clock.schedule_interval(self.fade_in_out, 0.25)
def on_touch_down(self, touch):
super(Overlay, self).on_touch_down(touch)
def register(self, container):
self.parent_container = container
self.show()
self.start_fade_timer()
def unregister(self):
self.fader_event.cancel()
if self.parent_container is not None:
self.parent_container.remove_widget(self)
self.parent_container = None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment