Skip to content

Instantly share code, notes, and snippets.

@onslauth
Last active March 27, 2019 07:51
Show Gist options
  • Save onslauth/2e99bd886808548488f56740a9e61cb2 to your computer and use it in GitHub Desktop.
Save onslauth/2e99bd886808548488f56740a9e61cb2 to your computer and use it in GitHub Desktop.
from kivy.config import Config
Config.set('kivy', 'log_level', 'debug')
from kivy.app import App
from kivy.lang import Builder
from kivy.factory import Factory
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.modalview import ModalView
from kivy.properties import ObjectProperty
from kivy.metrics import *
kv = """
<CustomContent>:
button_1: button_1
size_hint: None, None
width: dp( 275 )
height: dp( 25 )
orientation: 'horizontal'
Button:
id: button_1
size_hint: 0.9, 1.0
text_size: self.size
halign: 'left'
valign: 'middle'
markup: True
text: root.text
canvas:
Color:
rgba: root.colour
Rectangle:
pos: self.pos[ 0 ] + 1, self.pos[ 1 ]
size: 10, self.height
Button:
size_hint: None, 1.0
width: dp( 30 )
border: 0, 0, 0, 0
text: 'B'
"""
class CustomContent(BoxLayout):
text = ObjectProperty( )
colour = ObjectProperty( )
pass
class TestApp(App):
def build(self):
button = CustomContent( text = "[b] Hello[/b]", colour = ( 1.0, 0, 0, 1 ) )
grid = GridLayout( size_hint_y = None,
cols = 1,
spacing = ( 20, 0 ),
padding = ( 0, 0, 0, 0 ) )
grid.add_widget( button )
popup = ModalView( size_hint = ( None, None ),
width = dp( 275 ),
height = dp( 0 ),
background_color = ( 0, 0, 0, 0 ) )
popup.add_widget( grid )
popup.height = grid.minimum_height
popup.open( )
print( "popup.size: {}".format( popup.size ) )
print( "grid.size: {}".format( grid.size ) )
print( "grid.miminum_height: {}".format( grid.minimum_height ) )
print( "button.size: {}".format( button.size ) )
print( "button.button_1.size: {}".format( button.button_1.size ) )
if __name__ == '__main__':
Builder.load_string(kv)
TestApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment