def build(self):
#with open("tips.txt", "r") as stream:
# labeltext = stream.read()
label = Label(text="[size=50]hi[/size]", markup=True)
box = BoxLayout()
marvell = Marvel()
box.add_widget(marvell)
box.add_widget(label)
return box
python类BoxLayout()的实例源码
def __init__(self, **kwargs): # inicializace
super(StatsScreen, self).__init__(**kwargs)
self.root.insertStrings.append((self, "STR_STATS"))
self.stats = BoxLayout(orientation='vertical', size_hint=(.77, .83), pos_hint={'center_x': .5, 'center_y': .49})
self.title = BoxLayout(orientation='horizontal')
self.title.add_widget(Label(font_name='font/Roboto-Bold.ttf', text=''))
self.title.add_widget(Label(font_name='font/Roboto-Bold.ttf', text=''))
self.title.add_widget(Label(font_name='font/Roboto-Bold.ttf', text=''))
self.stats.add_widget(self.title)
self.add_widget(self.stats)
self.root.insertStrings.append((self.title.children[2], "STR_TYPE"))
self.root.insertStrings.append((self.title.children[1], "STR_NAME"))
self.root.insertStrings.append((self.title.children[0], "STR_SCORE"))
def on_pre_enter(self, *args):
# P?ed vstupem na obrazovku na?te seznam oblíbených server?
if len(self.layout.children) == 0:
bookmarks = self.root.Cfg[-1]
if len(bookmarks) == 0:
self.layout.add_widget(Label(text=self.STR_NO_BOOKMARKS, font_name='font/Roboto-Regular.ttf', font_size='18dp', size_hint_y = None, text_size=(self.width*3, None)))
else:
head = BoxLayout(size_hint=(1,None), height=50)
head.add_widget(Label(text=self.STR_SERVER, font_name='font/Roboto-Bold.ttf', size_hint=(None,1), font_size="20dp", width = self.width*1.9, text_size=(self.width*1.9, None)))
head.add_widget(Label(text=self.STR_MOD, font_name='font/Roboto-Bold.ttf', size_hint=(1,1), font_size="15dp", width = self.width, text_size=(self.width, None)))
head.add_widget(DelButton(opacity=0, size_hint=(None, 1)))
self.layout.add_widget(head)
for y, server in enumerate(bookmarks):
srvr = Bookmark(size_hint=(1,None), height = 50)
for i, cell in enumerate(server):
if i == 0:
lbl = Label(text="[ref={0}]{1}[/ref]".format(y,cell), markup=True, font_name='font/Roboto-Regular.ttf', size_hint=(None,1), font_size="20dp", text_size=(None, None))
lbl.bind(on_ref_press=self.connectBookmark)
srvr.add_widget(lbl)
elif i == 1:
pass
elif i == 2:
lbl = Label(text="[ref={0}]{1}[/ref]".format(y,cell), markup=True, font_name='font/Roboto-Regular.ttf', size_hint=(1,1), font_size="20dp")
lbl.bind(on_ref_press=self.connectBookmark)
srvr.add_widget(lbl)
btn = DelButton(OBJ=srvr, ID=y, background_normal="crop/delete.png", background_down="crop/delete.png",size_hint=(None, 1))
btn.bind(on_press=self.removeBookmark)
srvr.add_widget(btn)
self.layout.add_widget(srvr)
def _key_handler(self, instance, KEY, *args): # Reakce na stisk systémové klávesy OS Android
print "Key: {0}".format(KEY)
if KEY == 1001:
if self.sm.current not in ('MainMenuScreen', 'GameScreen'):
if self.sm.current == "SettingsScreen":
self.sm.get_screen("SettingsScreen").dropdown.dismiss()
self.sm.current_screen.prev()
else:
if self.sm.current == 'MainMenuScreen':
text = self.L.STR_POPUP_EXIT
title = self.L.STR_POPUP_EXIT_TITLE
yes_callback = self.popupStop
else:
text = self.L.STR_POPUP_DISCONNECT
title = self.L.STR_POPUP_DISCONNECT_TITLE
yes_callback = self.popupDisconnect
content = BoxLayout(orientation='vertical')
content.add_widget(Label(text=text, font_name='font/Roboto-Regular.ttf', font_size='14dp'))
buttons = GridLayout(cols=2, rows=1, spacing=10, size_hint=(1, .3))
yes = Button(text=self.L.STR_YES)
yes.bind(on_press=yes_callback)
no = Button(text=self.L.STR_NO)
buttons.add_widget(yes)
buttons.add_widget(no)
content.add_widget(buttons)
self.popupExit = Popup(title=title, size_hint=(.7,.3), content=content, auto_dismiss=False)
no.bind(on_press=self.popupExit.dismiss)
self.popupExit.open()
elif KEY == 1002:
self.dispatch('on_pause')
elif KEY == 1004:
self.dispatch('on_pause')
def build(self):
layout = BoxLayout(orientation='vertical')
b1 = Button(text='button 1')
b2 = Button(text='button 2')
layout.add_widget(b1)
layout.add_widget(b2)
return layout
def __init__(self, **kwargs):
super(MyScreen, self).__init__(**kwargs)
scrollView = ScrollView()
self.add_widget(scrollView)
boxLayout = BoxLayout(orientation='vertical', height=dp(1000), padding=dp(48))
scrollView.add_widget(boxLayout)
textField = SingleLineTextField(id='text_filed', size_hint=(0.8, None), height=dp(48))
textField.hint_text='This is a pretty text filed'
boxLayout.add_widget(textField)
buttonContainer = BoxLayout(orientation='horizontal', height=dp(48))
flatButton = MDFlatButton(text='FlatButton')
# size is not working somehow
# flatButton.size = (3*dp(48), dp(48))
buttonContainer.add_widget(flatButton)
raiseButton = MDRaisedButton(text='RaiseButton')
# raiseButton.size = (3*dp(48), dp(48))
buttonContainer.add_widget(raiseButton)
boxLayout.add_widget(buttonContainer)
switchContainer = BoxLayout(orientation='horizontal')
checkbox1 = MDCheckbox(group='test')
# checkbox1.size=(dp(48), dp(48))
switchContainer.add_widget(checkbox1)
checkbox2 = MDCheckbox(group='test')
# checkbox2.size=(dp(48), dp(48))
switchContainer.add_widget(checkbox2)
boxLayout.add_widget(switchContainer)
def build(self):
from kivy.core.window import Window
Window.size = (540, 720)
# self.theme_cls.theme_style = 'Dark'
return Builder.load_string("""
#:import Toolbar kivymd.toolbar.Toolbar
BoxLayout:
orientation:'vertical'
Toolbar:
id: toolbar
title: 'Page title'
background_color: app.theme_cls.primary_color
left_action_items: [['menu', lambda x: '']]
right_action_items: [['search', lambda x: ''],['more-vert',lambda x:'']]
MDTabbedPanel:
id: tab_mgr
tab_display_mode:'icons'
MDTab:
name: 'music'
text: "Music" # Why are these not set!!!
icon: "playlist-audio"
MDLabel:
font_style: 'Body1'
theme_text_color: 'Primary'
text: "Here is my music list :)"
halign: 'center'
MDTab:
name: 'movies'
text: 'Movies'
icon: "movie"
MDLabel:
font_style: 'Body1'
theme_text_color: 'Primary'
text: "Show movies here :)"
halign: 'center'
""")
def open_message_popup(self):
if self.response is not None:
content = BoxLayout(orientation='vertical', spacing=5)
content.add_widget(PopupButton(text='Add bookmark',on_release=self.add_bookmark))
if self.response.opt.content_format is coap.media_types_rev['application/link-format']:
content.add_widget(PopupButton(text='Process link format',on_release=self.process_link_format))
self.controller.popup.content = content
self.controller.popup.open()
def open_node_label_popup(self, link_node, value):
if value=='node' and self.level == 1:
content = BoxLayout(orientation='vertical', spacing=5)
content.add_widget(PopupButton(text='Repeat discovery',on_release=self.open_link))
content.add_widget(PopupButton(text='Remove discovery result',on_release=self.remove_node))
self.controller.popup.content = content
self.controller.popup.open()
elif value=='uri':
content = BoxLayout(orientation='vertical', spacing=5)
content.add_widget(PopupButton(text='Open bookmark',on_release=self.open_link))
content.add_widget(PopupButton(text='Remove bookmark',on_release=self.remove_bookmark))
self.controller.popup.content = content
self.controller.popup.open()
def onSearch(self):
popup = BoxLayout(orientation='vertical', size=self.size, pos=self.pos)
self.search_popup = Popup(
title='Search', content=popup, size_hint=(
0.9, 0.25), auto_dismiss=False)
self.search_textinput = TextInput()
cancel = Button(text='Cancel', on_release=self.dismiss_search_popup)
ok = Button(text='Ok', on_release=self.search_ok)
buttons = BoxLayout(size_hint_y=None, height=self.height / 20)
buttons.add_widget(cancel)
buttons.add_widget(ok)
popup.add_widget(self.search_textinput)
popup.add_widget(buttons)
self.search_popup.open()
def build(self):
box = BoxLayout()
graph = DemoGraph(points=[0, .2, 1, 0.25, 2, .4, 5, .5, 10, .6, 30, .5],
font_size=30,
line_width=5,
x_labels=['A', 'B', 'C', 'D'],
x_ticks=[0, 10, 20, 30],
y_ticks=[.1, .2, .5, .9],
max_y=1)
box.add_widget(graph)
return box
def show_banners(self, interval):
if self.screen.ids.screen_manager.current == '':
name_banner = self.choice(self.banner_list)
box_banner = BoxLayout()
new_banner = ImageButton(
id=name_banner.split('.')[0],
source='Data/Images/banners/{}'.format(name_banner),
on_release=self.press_banner
)
box_banner.add_widget(new_banner)
name_screen = name_banner
banner = self.Screen(name=name_screen)
banner.add_widget(box_banner)
self.screen.ids.banner_manager.add_widget(banner)
effect = self.choice(self.effects_transition)
direction = self.choice(self.directions)
if effect != self.SwapTransition:
self.screen.ids.banner_manager.transition = effect(
direction=direction
)
else:
self.screen.ids.banner_manager.transition = effect()
self.screen.ids.banner_manager.current = name_screen
self.screen.ids.banner_manager.screens.pop()
def __init__(self, **kvargs):
super(PDialog, self).__init__(**kvargs)
self.box = BoxLayout(orientation='vertical')
self.label_one = Label(text='', size_hint=(1, .1), markup=True)
self.label_two = Label(text='', size_hint=(1, .1), markup=True)
self.progress_load = Progress()
self.button_cancel = Button(
text='Cancel', on_press=self.events_callback, size_hint=(1, .1),
background_normal=self.background_image_buttons[0],
background_down=self.background_image_shadows[0]
)
self.label_one.bind(size=lambda *args: self._update_text_size(args))
self.label_two.bind(size=lambda *args: self._update_text_size(args))
self.box.add_widget(self.label_one)
self.box.add_widget(self.label_two)
self.box.add_widget(Widget(size_hint=(None, .02)))
self.box.add_widget(SettingSpacer())
self.box.add_widget(Widget(size_hint=(None, .02)))
self.box.add_widget(self.progress_load)
self.box.add_widget(Widget(size_hint=(None, .3)))
self.box.add_widget(SettingSpacer())
self.box.add_widget(Widget(size_hint=(None, .02)))
self.box.add_widget(self.button_cancel)
self.progress_load.min = 0
self.progress_load.max = 100
self.progress_load.bar_value = 0
self.progress_load.height_widget = self.dp(self.progress_line_height)
self.progress_load.color = self.progress_line_color
self.progress_load.border_color = self.progress_border_color
def _get_body(self):
layout = BoxLayout(orientation='vertical')
layout.add_widget(super(XProgress, self)._get_body())
layout.add_widget(self._progress)
return layout
def _get_body(self):
from kivy.lang import Builder
import textwrap
self.browser = Builder.load_string(textwrap.dedent('''\
FileChooser:
FileChooserIconLayout
FileChooserListLayout
'''))
self.browser.path = self.path
self.browser.multiselect = self.multiselect
self.browser.dirselect = self.dirselect
self.browser.filters = self.filters
self.browser.bind(path=self.setter('path'),
selection=self.setter('selection'))
self.bind(view_mode=self.browser.setter('view_mode'),
multiselect=self.browser.setter('multiselect'),
dirselect=self.browser.setter('dirselect'),
filters=self.browser.setter('filters'))
lbl_path = Factory.XLabel(
text=self.browser.path, valign='top', halign='left',
size_hint_y=None, height=metrics.dp(25))
self.browser.bind(path=lbl_path.setter('text'))
layout = BoxLayout(orientation='vertical')
layout.add_widget(self._ctrls_init())
layout.add_widget(lbl_path)
layout.add_widget(self.browser)
return layout
def _ctrls_init(self):
pnl_controls = BoxLayout(size_hint_y=None, height=metrics.dp(25))
pnl_controls.add_widget(Factory.XButton(
text=_('Icons'), id=self.CTRL_VIEW_ICON,
on_release=self._ctrls_click))
pnl_controls.add_widget(Factory.XButton(
text=_('List'), id=self.CTRL_VIEW_LIST,
on_release=self._ctrls_click))
pnl_controls.add_widget(Factory.XButton(
text=_('New folder'), id=self.CTRL_NEW_FOLDER,
on_release=self._ctrls_click))
return pnl_controls
def _get_form(self):
layout = BoxLayout(orientation='vertical', spacing=5)
text_input = TextInput(id='text', multiline=False, text=self.text,
on_text_validate=self._on_text_validate,
# DON`T UNCOMMENT OR FOUND AND FIX THE ISSUE
# if `focus` set to `True` - TextInput will be
# inactive to edit
# focus=True,
size_hint_y=None, height=metrics.dp(33))
layout.add_widget(Widget())
layout.add_widget(text_input)
layout.add_widget(Widget())
return layout
def _get_form(self):
layout = BoxLayout(orientation='vertical', spacing=5)
layout.add_widget(Widget())
pnl = BoxLayout(size_hint_y=None, height=metrics.dp(28), spacing=5)
pnl.add_widget(
Factory.XLabel(text=_('Login:'), halign='right',
size_hint_x=None, width=metrics.dp(80)))
pnl.add_widget(TextInput(id='login', multiline=False,
font_size=metrics.sp(14), text=self.login))
layout.add_widget(pnl)
pnl = BoxLayout(size_hint_y=None, height=metrics.dp(28), spacing=5)
pnl.add_widget(
Factory.XLabel(text=_('Password:'), halign='right',
size_hint_x=None, width=metrics.dp(80)))
pnl.add_widget(TextInput(id='password', multiline=False, font_size=14,
password=True, text=self.password))
layout.add_widget(pnl)
if self.autologin is not None:
pnl = BoxLayout(size_hint_y=None, height=metrics.dp(28), spacing=5)
pnl.add_widget(CheckBox(
id='autologin', size_hint_x=None, width=metrics.dp(80),
active=self.autologin))
pnl.add_widget(
Factory.XLabel(text=_('Login automatically'), halign='left'))
layout.add_widget(pnl)
layout.add_widget(Widget())
return layout
def build(self):
f = FloatLayout()
s = Scatter()
l = Label(text='Hello!', font_size=150)
b = BoxLayout(orientation='vertical')
t = TextInput(font_size=150)
f.add_widget(s)
s.add_widget(l)
b.add_widget(f)
b.add_widget(t)
return b
def _generate_layout(self, l_text, btn_text, f):
"""
Layouts are similar in fashion: Text and Call to Action button
creates layout with text and button and binds f to button
"""
layout = BoxLayout(orientation='vertical')
btn = Button(text=btn_text, font_size=30)
l = Label(text=l_text, font_size=30)
btn.bind(on_press=f)
layout.add_widget(l)
layout.add_widget(btn)
return layout