def build(self):
root_widget = BoxLayout(orientation='vertical')
output_label = Label(size_hint_y=1)
button_symbols = ('1', '2', '3', '+',
'4', '5', '6', '-',
'7', '8', '9', '.',
'0', '*', '/', '=')
button_grid = GridLayout(cols=4, size_hint_y=2)
for symbol in button_symbols:
button_grid.add_widget(Button(text=symbol))
clear_button = Button(text='clear', size_hint_y=None,
height=100)
root_widget.add_widget(output_label)
root_widget.add_widget(button_grid)
root_widget.add_widget(clear_button)
return root_widget
python类BoxLayout()的实例源码
def __init__(self, **kvargs):
super(FileChooser, self).__init__(**kvargs)
box = BoxLayout(orientation="vertical", spacing=10)
filechooser = FileChooserListView()
filechooser.bind(selection=self.select_callback)
box.add_widget(filechooser)
if self.filter == "folder":
box.add_widget(SettingSpacer())
box.add_widget(Button(text=self.text_button_select,
size_hint=(1, .1),
on_press=self.select_callback))
filechooser.filters = [self.is_dir]
elif self.filter == "files":
filechooser.filters = [self.is_file]
self.body = Popup(title=self.title, content=box, size_hint=self.size,
auto_dismiss=self.auto_dismiss,
background=self.background_image)
self.body.bind(on_dismiss=self.dismiss_callback)
self.body.open()
def __init__(self, **kvargs):
super(KDialog, self).__init__(**kvargs)
self.orientation = "vertical"
self.param = None
# ???? ??? ?????? ?????? "??-???-??????".
self.box_buttons_select = BoxLayout(orientation="horizontal",
size_hint_y=None, height=40)
self.scroll = ScrollView()
self.box_content = GridLayout(cols=2, size_hint_y=None)
self.box_content.bind(minimum_height=self.box_content.setter("height"))
self.body = Popup(title_align=self.title_align,
background=self.background_image,
on_dismiss=self.dismiss_callback)
# ??? ???? ?????????.
with self.box_content.canvas:
Color(0.16, 0.16, 0.16)
self.canvas_for_box_content = \
Rectangle(pos=(5, 5), size=(self.box_content.width,
self.box_content.height))
self.box_content.bind(size=self._update_canvas_size,
pos=self._update_canvas_size)
self.scroll.add_widget(self.box_content)
def __init__(self, **kvargs):
super(SelectColor, self).__init__(**kvargs)
box = BoxLayout(orientation="vertical")
select_color = ColorPicker(hex_color=self.default_color)
button_select = Button(text=self.text_button_ok, size_hint=(1, .1))
box.add_widget(select_color)
box.add_widget(Widget(size_hint=(None, .02)))
box.add_widget(SettingSpacer())
box.add_widget(Widget(size_hint=(None, .02)))
box.add_widget(button_select)
self.body = Popup(title=self.title, content=box, size_hint=self.size,
background=self.background_image)
self.body.bind(on_dismiss=self.dismiss_callback)
button_select.bind(on_press=lambda color: self.select_callback(
select_color.hex_color), on_release=lambda *args: self.body.dismiss())
self.body.open()
def finishBuyList(self):
#ask to confirm
content = BoxLayout(orientation = 'vertical')
content.add_widget(Label(text = 'Do you really want to finish?'))
button_confirm = Button(text='Finish')
button_confirm.bind(on_press=self.registerBuy)
button_cancel = Button(text='Cancel')
button_cancel.bind(on_press=self.popup.dismiss)
options = BoxLayout()
options.add_widget(button_confirm)
options.add_widget(button_cancel)
content.add_widget(options)
#
self.popup = Popup(
title = 'Finish Buy List',
content = content,
size_hint = (None, None),
size = (400, 100)
)
# open the popup
self.popup.open()
###
def _build_evaluation_box(self):
evaluation_box = BoxLayout(orientation='horizontal')
positive_button = Button(
text="Positive",
font_size=50,
size_hint=(.5, .5),
background_normal='',
background_color=rgb_to_kivy(0, 102, 0, 1)
)
positive_button.bind(on_release=self.handle_positive_button)
negative_button = Button(
text="Negative",
font_size=50,
size_hint=(.5, .5),
background_normal='',
background_color=rgb_to_kivy(255, 0, 0, 1)
)
negative_button.bind(on_release=self.handle_negative_button)
evaluation_box.add_widget(positive_button)
evaluation_box.add_widget(negative_button)
return evaluation_box
def _build_detail_event_box(self, event):
event_layout = BoxLayout(orientation='horizontal')
label_color = rgb_to_kivy(0, 102, 0, 1) if event.evaluation else rgb_to_kivy(255, 0, 0, 1)
# event_eval_text = 'Positive' if event.evaluation else 'Negative'
# event_text = "{} [{}]".format(event.date.strftime("%d/%m/%y %H:%M:%S"), event_eval_text)
event_text = event.date.strftime("%d/%m/%y %H:%M:%S")
event_label = Label(text=event_text, font_size=70, color=label_color, size_hint=(1, 1))
event_rm_button = Button(
text="-",
font_size=50,
size_hint=(.15, 1),
background_normal='',
background_color=rgb_to_kivy(255, 0, 0, 1)
)
handle_rm_with_event = partial(self.handle_rm_event, event)
event_rm_button.bind(on_release=handle_rm_with_event)
event_layout.add_widget(event_label)
event_layout.add_widget(event_rm_button)
return event_layout
def __init__(self, auth_token, **kwargs):
super(CloudCBScreen, self).__init__(**kwargs)
self.header = {'Authorization': "Basic %s" % auth_token}
self.url = SERVER_URI + 'copy-paste/'
self.old_text = Clipboard.paste()
self.cloud_clip = TextInput(text="Fetching...")
layout = BoxLayout(orientation='vertical')
layout.add_widget(Label(text='Cloud Clipboard'))
layout.add_widget(Label(text='Current text on clipboard:'))
layout.add_widget(self.cloud_clip)
layout.add_widget(Button(text='Refresh', on_press=self.download))
layout.add_widget(Label(text='Earlier text on your clipboard:'))
layout.add_widget(TextInput(text=self.old_text))
layout.add_widget(Button(text='Update Cloud Clipboard with this text', on_press=self.upload))
self.add_widget(layout)
self.download()
def __init__(self, app, **kwargs):
self.app = app
self.bar_color = [.071, .729, .973, .9]
self.bar_width = '3dp'
self.scroll_timeout = 100
img = Image('crop/dock_POT.png')
img.texture.wrap = "repeat"
self.texture = img.texture
self.texture_size = self.texture.size
self.sOverlay = app.sOverlay
self.players = app.overlay
super(Dock, self).__init__(**kwargs)
self.bar_margin = self.texture_size[1]*0.1645
self.do_scroll_y = False
self.do_scroll_x = True
self.layout = BoxLayout(size_hint_x=None, width=0)
self.add_widget(self.layout)
def on_pre_enter(self):
with open('eventsapp/data/jsonfiles/community.json') as data_file:
data = json.load(data_file)
data = data.get("0.0.1")[0]
self.ids.logo.source = data['photo']
self.ids.about.text = data['about']
social_icons = self.ids.social_icons
social_icons.clear_widgets()
self.community_social = data['social']
def chunks(data, SIZE=10):
it = iter(data)
for i in range(0, len(data), SIZE):
yield {k:data[k] for k in islice(it, SIZE)}
if self.community_social != []:
for items in chunks(self.community_social, 3):
bl = BoxLayout()
self.add_social_icons(bl, items)
social_icons.add_widget(bl)
def build(self):
# Resource tree creation
root = resource.CoAPResource()
well_known = resource.CoAPResource()
root.putChild('.well-known', well_known)
core = CoreResource(root)
well_known.putChild('core', core)
counter = MOTDResource(self, 0)
root.putChild('motd', counter)
endpoint = resource.Endpoint(root)
reactor.listenUDP(coap.COAP_PORT, coap.Coap(endpoint))
# Kivy screen initialization
self.label = Label(text="")
self.display_counter(0)
self.messagebox = TextInput(size_hint_y=.1, multiline=False)
self.messagebox.text = "Message of the day"
self.layout = BoxLayout(orientation='vertical', padding=10)
self.layout.add_widget(self.label)
self.layout.add_widget(self.messagebox)
return self.layout
def onGoTo(self):
if self.loaded == 'Yes':
popup = BoxLayout(
orientation='vertical',
size=self.size,
pos=self.pos)
self.goto_popup = Popup(title='Go To' +
' (1~' +
str(len(self.data_view)) +
')', content=popup, size_hint=(0.9, 0.25), auto_dismiss=False)
self.goto_textinput = TextInput()
cancel = Button(text='Cancel', on_release=self.dismiss_goto_popup)
ok = Button(text='Ok', on_release=self.goto_ok)
buttons = BoxLayout(size_hint_y=None, height=self.height / 20)
buttons.add_widget(cancel)
buttons.add_widget(ok)
popup.add_widget(self.goto_textinput)
popup.add_widget(buttons)
self.goto_popup.open()
def __init__(self, **kvargs):
super(KDialog, self).__init__(**kvargs)
self.param = None
self.rst = None
self.input_dialog_double = None
# ???? ??? ?????? 'Yes, No, Cancel'.
self.box_buttons_select = \
BoxLayout(size_hint_y=None, height=self.dp(40), spacing=5)
self.scroll = self.ids.scroll
self.box_root = self.ids.box_root
self.box_content = self.ids.box_content
self.box_content.bind(
height=lambda *args: self._update_box_content_size(args)
)
def __init__(self, **kvargs):
super(CDialog, self).__init__(**kvargs)
box = BoxLayout(orientation='vertical')
select_color = ColorPicker(hex_color=self.default_color)
button_select = Button(
text=self.text_button_ok, size_hint=(1, .1),
background_normal=self.background_image_buttons[0],
background_down=self.background_image_shadows[0]
)
box.add_widget(select_color)
box.add_widget(Widget(size_hint=(None, .02)))
box.add_widget(SettingSpacer())
box.add_widget(Widget(size_hint=(None, .02)))
box.add_widget(button_select)
button_select.bind(
on_press=lambda color: self.events_callback(select_color.hex_color),
on_release=lambda *args: self.dismiss()
)
self.content = box
self.open()
def __init__(self, **kvargs):
super(FDialog, self).__init__(**kvargs)
box = BoxLayout(orientation='vertical', spacing=10)
fdialog = FileChooserListView(path=self.path)
fdialog.bind(selection=self.events_callback)
box.add_widget(fdialog)
if self.filter == 'folder':
box.add_widget(SettingSpacer())
box.add_widget(
Button(text=self.text_button_ok, size_hint=(1, .1),
background_normal=self.background_image_buttons[0],
background_down=self.background_image_shadows[0],
on_press=self.events_callback)
)
fdialog.filters = [self.is_dir]
elif self.filter == 'files':
fdialog.filters = [self.is_file]
self.content = box
self.open()
def __init__(self, **kwargs):
# preventing change content of the popup
kwargs.pop('content', None)
self._pnl_buttons = None
super(XBase, self).__init__(**kwargs)
layout = BoxLayout(orientation="vertical")
layout.add_widget(self._get_body())
self._pnl_buttons = BoxLayout(size_hint_y=None)
layout.add_widget(self._pnl_buttons)
self.add_widget(layout)
# creating buttons panel
self.property('buttons').dispatch(self)
if self.auto_open:
self.open()
def _get_body(self):
if self.dont_show_value is None:
return self._message
else:
pnl = BoxLayout(orientation='vertical')
pnl.add_widget(self._message)
pnl_cbx = BoxLayout(
size_hint_y=None, height=metrics.dp(35), spacing=5)
cbx = CheckBox(
active=self.dont_show_value, size_hint_x=None,
width=metrics.dp(50))
cbx.bind(active=self.setter('dont_show_value'))
pnl_cbx.add_widget(cbx)
pnl_cbx.add_widget(
Factory.XLabel(text=self.dont_show_text, halign='left'))
pnl.add_widget(pnl_cbx)
return pnl
def __init__(self, **kvargs):
super(CDialog, self).__init__(**kvargs)
box = BoxLayout(orientation='vertical')
select_color = ColorPicker(hex_color=self.default_color)
button_select = Button(
text=self.text_button_ok, size_hint=(1, .1),
background_normal=self.background_image_buttons[0],
background_down=self.background_image_shadows[0],
background_color=choice(self.background_color_buttons)
)
box.add_widget(select_color)
box.add_widget(Widget(size_hint=(None, .02)))
box.add_widget(SettingSpacer())
box.add_widget(Widget(size_hint=(None, .02)))
box.add_widget(button_select)
button_select.bind(
on_press=lambda color: self.events_callback(select_color.hex_color),
on_release=lambda *args: self.dismiss()
)
self.content = box
self.open()
def desktop_warning(self):
layout = BoxLayout(orientation='vertical')
layout.add_widget(Label(text='KivMob will not display ads on ' +\
'nonmobile platforms. You must build an ' +\
'Android project to demo ads. (iOS not yet ' +\
'supported)',
size_hint_y=1,
text_size=(250, None),
halign='left',
valign='middle'))
button_layout = BoxLayout()
button1=Button(text="Open Build Steps", size_hint=(0.8, 0.2))
button1.bind(on_release = lambda x :
webbrowser.open("https://www.google.com"))
button_layout.add_widget(button1)
button2=Button(text="Close", size_hint=(0.8, 0.2))
button2.bind(on_release = lambda x : popup.dismiss())
button_layout.add_widget(button2)
layout.add_widget(button_layout)
popup = Popup(title='KivMob Demo Alert',
content=layout,
size_hint=(0.9, 0.9))
popup.open()
def interstitial_warning(self):
layout = BoxLayout(orientation='vertical')
layout.add_widget(Label(text="Ad has not loaded. " +\
"Wait a few seconds and then " +\
"try again.",
size_hint_y=1,
text_size=(250, None),
halign='left',
valign='middle'))
button_layout = BoxLayout()
close=Button(text="Close", size_hint=(0.8, 0.2))
close.bind(on_release = lambda x : popup.dismiss())
button_layout.add_widget(close)
layout.add_widget(button_layout)
popup = Popup(title='KivMob Demo Alert',
content=layout,
size_hint=(0.9, 0.9))
popup.open()
def create_menu_buttons(self):
"""??????? ?????? ? ??????? ????."""
name_path_buttons_menu = {
"JUNK FILES": "Data/Images/clean_cache.png",
"MEMORY BOOST": "Data/Images/clean_memory.png",
"APP MANAGER": "Data/Images/clean_apk.png",
"SECURITY & PRIVACY": "Data/Images/clean_privacy.png"}
for name_button in name_path_buttons_menu.keys():
item_box = BoxLayout(orientation="vertical")
item_label = Label(text=name_button, color=[.1, .1, .1, 1])
item_button = \
ImageButton(source=name_path_buttons_menu[name_button],
id=name_button, on_press=self.events_callback)
item_box.add_widget(item_button)
item_box.add_widget(item_label)
self.ids.body_buttons_menu.add_widget(item_box)
def calculate(self):
''' "="??????????????? '''
try:
self.display.text = str(eval(self.display.text)) # ??????? ??eval("5 + 10")??15???
self.clear_bool = True
print('????')
except:
# ?????????'=’??????????????
print('error?????')
#class Calculator2(BoxLayout):
# def __init__(self, **kwargs):
# super(Calculator2, self).__init__(**kwargs)
def __init__(self, data=None, **kwargs):
super(RecycleDataBox, self).__init__(**kwargs)
self._topwidget = ShellWidget(place='top')
self._botwidget = ShellWidget(place='bot')
self.view = BoxLayout(size_hint_y=None, orientation='vertical')
self.view.bind(minimum_size=self.view.setter('size'))
self.height_cache = {}
for widget in self._topwidget, self.view, self._botwidget:
self.add_widget(widget)
def __init__(self, **kwargs):
super(LoginScreen, self).__init__(**kwargs)
'''self.orientation = 'vertical'
###
self.grid = GridLayout()
self.grid.cols = 2
self.grid.add_widget(Label(text='User Name'))
self.grid.username = TextInput(multiline=False)
self.grid.add_widget(self.grid.username)
self.grid.add_widget(Label(text='password'))
self.grid.password = TextInput(multiline=False)
self.grid.add_widget(self.grid.password)
###
self.options = BoxLayout()
self.options.size_hint_y = 0.5
self.options.bt_cancel = Button(text='Cancel')
self.options.add_widget(self.options.bt_cancel)
self.options.bt_login = Button(text='Login')
self.options.bt_login.bind(on_press=self.bt_login_clicked)
self.options.add_widget(self.options.bt_login)
###
self.add_widget(self.grid)
self.add_widget(self.options)'''
###
def _build_botton_box(self):
botton_box = BoxLayout(orientation='vertical', spacing=10)
self.total_label = Label(font_size=30, color=[0, 0, 0, 1], size_hint=(1, 1))
botton_box.add_widget(self.total_label)
botton_box.add_widget(self._build_evaluation_box())
return botton_box
def _filter_layout(self):
filter_box = BoxLayout(orientation='vertical', spacing=50)
dropdown = DropDown()
for filter_type in FILTERS.keys():
filter_button = Button(
text=filter_type,
font_size=30,
background_normal='',
background_color=rgb_to_kivy(239, 93, 5, 1),
size_hint_y=None,
height=130
)
handle_filter_button_with_dropdown = partial(self.handle_filter_button, dropdown)
filter_button.bind(on_release=handle_filter_button_with_dropdown)
dropdown.add_widget(filter_button)
filter_dropdown_btn = Button(
text=ALL_FILTER,
font_size=30,
size_hint=(1, 1),
background_normal='',
background_color=rgb_to_kivy(239, 93, 5, 1)
)
filter_dropdown_btn.bind(on_release=dropdown.open)
dropdown.bind(on_select=lambda instance, x: setattr(filter_dropdown_btn, 'text', x))
filter_box.add_widget(filter_dropdown_btn)
return filter_box
def _build_top_box(self):
top_box = BoxLayout(orientation='vertical')
self.positive_label = Label(text="0%", font_size=150, color=rgb_to_kivy(239, 93, 5, 1), size_hint=(1, 1))
top_box.add_widget(self._build_menu_and_reset())
top_box.add_widget(self.positive_label)
return top_box
def _build_main_box(self):
main_box = BoxLayout(orientation='vertical')
main_box.add_widget(self._build_top_box())
main_box.add_widget(self._build_botton_box())
return main_box
def _build_event_list(self):
self.event_list_layout = BoxLayout(orientation='vertical', spacing=30)
self.update_event_list()
return self.event_list_layout
def __init__(self,req):
super(BoxLayout,self).__init__()
self.request_user = req[0]
self.request_group = req[1]
self.friend_req.text = "The User '%s' Wants to join the group '%s'" %(self.request_user, self.request_group)