def build(self):
Window.bind(keyboard_height=self.updateHeight)
if platform == 'android':
return MainWidget()
# the dreaded splash screen code
from kivy.uix.screenmanager import NoTransition, ScreenManager, Screen
from kivy.uix.image import Image
sm = ScreenManager(transition=NoTransition())
splashScr = Screen(name='SplashScreen')
splashScr.add_widget(Image(source='misc/splash-desktop.png'))
sm.add_widget(splashScr)
mainScr = Screen(name='MainScreen')
mainScr.add_widget(MainWidget())
sm.add_widget(mainScr)
def switchToMainScr(instance):
sm.current = 'MainScreen'
Clock.schedule_once(switchToMainScr, 3)
return sm
python类bind()的实例源码
def create_item(self, account):
"""
Creates an account list item from given account.
"""
address = "0x" + account.address.encode("hex")
# gets the alias if exists
try:
text = Controller.get_address_alias(address)
except KeyError:
text = address
list_item = OneLineListItem(text=text)
# makes sure the address doesn't overlap on small screen
list_item.ids._lbl_primary.shorten = True
list_item.account = account
list_item.bind(on_release=lambda x: self.on_release(x))
return list_item
def set_font_and_shorten(self):
"""
Makes the font slightly smaller on mobile
by using "Body1" rather than "Button" style.
Also shorten content size using ellipsis.
"""
content = self.ids.content
content.font_style = 'Body1'
content.shorten = True
def on_parent_size(instance, size):
# see BaseRectangularButton.width definition
button_margin = dp(32)
parent_width = instance.width
# TODO: the new size should be a min() of
# parent_width and actual content size
content.width = parent_width - button_margin
self.parent.bind(size=on_parent_size)
# call it once manually, refs:
# https://github.com/AndreMiras/PyWallet/issues/74
on_parent_size(self.parent, None)
def __init__(self, client, **kwargs):
self.client = client
self.disp_size = [0, 0]
self.child_size = Window.size
self.canvas = RenderContext(use_parent_projection = True)
with self.canvas:
self.fbo = Fbo(size = Window.size, use_parent_projection = True)
with self.fbo:
ClearColor(0, 0, 0, 0)
ClearBuffers()
super(DisplaySource, self).__init__(**kwargs)
self.texture = self.fbo.texture
if self.client.config.get('outputs', 'shmsink') == 'yes':
from .GStreamerOutput import GStreamerOutput
self.shmsinkoutput = GStreamerOutput(self.texture)
else:
self.shmsinkoutput = False
Window.bind(on_resize = self.resize)
def __init__(self, **kwargs):
super(ResizeCursor, self).__init__(**kwargs)
self.size_hint = (None, None)
self.pos_hint = (None, None)
self.source = ''
self.rect = Rectangle(pos=(-9998,-9998), size=(1, 1))
self.size = (dp(22), dp(22))
self.pos = [-9998, -9998]
# Makes an instruction group with a rectangle and
# loads an image inside it
# Binds its properties to mouse positional changes and events triggered
instr = InstructionGroup()
instr.add(self.rect)
self.canvas.after.add(instr)
self.bind(pos=lambda obj, val: setattr(self.rect, 'pos', val))
self.bind(source=lambda obj, val: setattr(self.rect, 'source', val))
self.bind(hidden=lambda obj, val: self.on_mouse_move(Window.mouse_pos))
Window.bind(mouse_pos=lambda obj, val: self.on_mouse_move(val))
def __init__(self, **kwargs):
super(ResizableCursor, self).__init__(**kwargs)
self.size_hint = (None, None)
self.pos_hint = (None, None)
self.source = ''
self.rect = Rectangle(pos=(-9998,-9998), size=(1, 1))
self.size = (dp(22), dp(22))
self.pos = [-9998, -9998]
# Makes an instruction group with a rectangle and
# loads an image inside it
# Binds its properties to mouse positional changes and events triggered
instr = InstructionGroup()
instr.add(self.rect)
self.canvas.after.add(instr)
self.bind(pos=lambda obj, val: setattr(self.rect, 'pos', val))
self.bind(source=lambda obj, val: setattr(self.rect, 'source', val))
self.bind(hidden=lambda obj, val: self.on_mouse_move(Window.mouse_pos))
Window.bind(mouse_pos=lambda obj, val: self.on_mouse_move(val))
def setup(self):
"""
Binds Controller.current_account property.
"""
self.controller = App.get_running_app().controller
self.controller.bind(
current_account=lambda _, value: self.on_current_account(value))
def setup(self):
"""
Binds Controller current_account and on_alias_updated.
"""
self.controller = App.get_running_app().controller
self.controller.bind(current_account=self.setter('current_account'))
self.controller.bind(on_alias_updated=self.on_alias_updated)
# triggers the update
self.current_account = self.controller.current_account
def setup(self):
"""
Binds Controller.current_account property.
"""
self.controller = App.get_running_app().controller
self.controller.bind(current_account=self.setter('current_account'))
# triggers the update
self.current_account = self.controller.current_account
self.controller.bind(accounts_history=self.update_history_list)
def setup(self):
"""
Binds Controller current_account and on_alias_updated.
"""
self.controller = App.get_running_app().controller
self.controller.bind(current_account=self.setter('current_account'))
self.controller.bind(on_alias_updated=self.on_alias_updated)
# triggers the update
self.current_account = self.controller.current_account
def setup(self):
"""
Binds Controller.current_account property.
"""
self.controller = App.get_running_app().controller
self.pywalib = self.controller.pywalib
self.controller.bind(current_account=self.setter('current_account'))
# triggers the update
self.current_account = self.controller.current_account
def bind_on_symbols(self):
"""
Since the camera doesn't seem to stop properly, we always bind/unbind
on_pre_enter/on_pre_leave.
"""
self.zbarcam.bind(symbols=self.on_symbols)
def __init__(self, **kwargs):
super(Controller, self).__init__(**kwargs)
keystore_path = Controller.get_keystore_path()
self.pywalib = PyWalib(keystore_path)
self.screen_history = []
self.register_event_type('on_alias_updated')
Clock.schedule_once(lambda dt: self.load_landing_page())
Window.bind(on_keyboard=self.on_keyboard)
def bind_current_account_balance(self):
"""
Binds the accounts_balance to the Toolbar title.
"""
self.bind(accounts_balance=self.update_toolbar_title_balance)
def __init__(self, **kvargs):
super(Program, self).__init__(**kvargs)
Window.bind(on_keyboard=self.events_program)
# ??? ??????? ????????? ? programclass.
self.FadeTransition = FadeTransition
self.Screen = Screen
self.Clock = Clock
# ----------------------------------
self.parsing_xml = parsing_xml
self.get_page = get_page
self.set_cookie = set_cookie
self.Manifest = Manifest
self.core = core
# ----------------------------------
self.sendmail = sendmail
self.setattachtoforum = setattachtoforum
# ----------------------------------
self.KDialog = KDialog
self.FileChooser = FileChooser
self.SelectColor = SelectColor
self.CustomSpinner = CustomSpinner
self.PageSendMail = PageSendMail
self.ScrollButton = ScrollButton
self.ThemesForum = ThemesForum
self.AboutDialog = AboutDialog
self.UploadFiles = UploadFiles
self.MessageViewer = MessageViewer
self.MailList = MailList
self.BugReporter = BugReporter
self.ImageViewer = ImageViewer
self.customspinner = customspinner
self._urllib = _urllib
self.traceback = traceback
# ----------------------------------
self.clipboard = clipboard
# ----------------------------------
self.theme_decorator_window = core.theme_decorator_window
def __init__(self, **kwargs):
super(HoverBehavior, self).__init__(**kwargs)
self.bind(parent=self._on_parent_update_hover)
def __init__(self, **kwargs):
self.register_event_type('on_focus_textinput')
super(FocusBehavior, self).__init__(**kwargs)
self.fbind('focus', self.remove_other_focused)
self.fbind('is_focusable', self.update_is_focusable)
if not self.is_subfocus:
self.bind(parent=on_parent)
if self.grab_focus and self.is_focusable:
self.focus_widget(self)
def on_is_subfocus(self, _, value):
if value:
self.funbind('parent', on_parent)
self.remove_from_focus()
else:
self.bind(parent=on_parent)
def __init__(self,**kwargs):
super(Main,self).__init__(**kwargs)
Window.bind(on_keyboard=self.my_key_handler)
def kve_start(self):
r'''????????????????????????Method'''
Window.bind(on_keyboard=self.on_keyboard)
def create_grid(self, x_hint_list, rows_to_create):
#x_hint_list is a list of ints, relating to the intended
#width of each column in the grid.
for row in range(rows_to_create):
for x_hint in x_hint_list:
grid_button = Button(text = '', valign = 'middle', shorten = True, size_hint_y = None,
height = 30, size_hint_x = x_hint, background_color = cfg_primary_neutral,
background_normal = '', color = cfg_primary_dark)
grid_button.bind(size=grid_button.setter('text_size'))
grid_button.bind(on_touch_down=self.button_press)
self.add_widget(grid_button)
self._avail += rows_to_create
def __init__(self, **kwargs):
super(EditingGrid, self).__init__(**kwargs)
self.create_grid(EditingGrid.x_hint_list, 30)
Window.bind(on_dropfile=self.file_drop)
def create_stats(self):
num_labels = 74 * 2
for i in range(num_labels):
label = Label(shorten=True)
label.bind(size=label.setter('text_size'))
self.add_widget(label)
self.get_stats()
def __init__(self, **kwargs):
super(MotorJuego, self).__init__(**kwargs)
Window.bind(on_key_down=self.Key_Down)
Window.bind(on_key_up=self.Key_Up)
self.gameworld.init_gameworld(
['renderer','position','color'],
callback=self.init_game)
def __init__(self, parent):
super(DaySelector, self).__init__()
self.parent_class = parent
self.parent_class.add_widget(self, index=7)
self.selected_widget = None
Window.bind(on_resize=self.move_resize)
def __init__(self, **kwargs):
super(ThemeManager, self).__init__(**kwargs)
self.rec_shadow = Atlas('{}rec_shadow.atlas'.format(images_path))
self.rec_st_shadow = Atlas('{}rec_st_shadow.atlas'.format(images_path))
self.quad_shadow = Atlas('{}quad_shadow.atlas'.format(images_path))
self.round_shadow = Atlas('{}round_shadow.atlas'.format(images_path))
Clock.schedule_once(lambda x: self.on_theme_style(0, self.theme_style))
self._determine_device_orientation(None, Window.size)
Window.bind(size=self._determine_device_orientation)
def __init__(self, parent):
super(DaySelector, self).__init__()
self.parent_class = parent
self.parent_class.add_widget(self, index=7)
self.selected_widget = None
Window.bind(on_resize=self.move_resize)
def __init__(self, **kwargs):
super(ThemeManager, self).__init__(**kwargs)
self.rec_shadow = Atlas('{}rec_shadow.atlas'.format(images_path))
self.rec_st_shadow = Atlas('{}rec_st_shadow.atlas'.format(images_path))
self.quad_shadow = Atlas('{}quad_shadow.atlas'.format(images_path))
self.round_shadow = Atlas('{}round_shadow.atlas'.format(images_path))
Clock.schedule_once(lambda x: self.on_theme_style(0, self.theme_style))
self._determine_device_orientation(None, Window.size)
Window.bind(size=self._determine_device_orientation)
def __init__(self, panel, height, tab):
self.panel = panel
self.height = height
self.tab = tab
super(MDBottomNavigationHeader, self).__init__()
self._current_color = self.theme_cls.disabled_hint_text_color
self._label = self.ids._label
self._label_font_size = sp(12)
self.theme_cls.bind(primary_color=self._update_theme_color,
disabled_hint_text_color=self._update_theme_style)
self.active = False
def __init__(self, **kwargs):
super(MDBottomNavigation, self).__init__(**kwargs)
self.previous_tab = None
self.widget_index = 0
self._refresh_tabs()
Window.bind(on_resize=self.on_resize)
Clock.schedule_once(lambda x: self.on_resize(), 2)