我们从Python开源项目中,提取了以下35个代码示例,用于说明如何使用kivy.lang.Builder.load_string()。
def __init__(self, **kvargs): super(CustomSettings, self).__init__(**kvargs) Builder.load_string( title_item.format( background_color_title=BACKGROUND_COLOR_TITLE, background_image_title=BACKGROUND_IMAGE_TITLE, background_color_item=BACKGROUND_COLOR_ITEM, background_image_item=BACKGROUND_IMAGE_ITEM, background_sections=', '.join( [str(value) for value in BACKGROUND_SECTIONS[:-1]]), separator_color=SEPARATOR_COLOR, color_text_title=COLOR_TEXT_INPUT ) ) SettingOptions._create_popup = self.options_popup SettingNumeric._create_popup = self.input_popup SettingString._create_popup = self.input_popup SettingPath._create_popup = self.path_popup
def __init__(self, **kwargs): ''' if kv is not loaded the load it either from string or a file specified need to specify "kv_string" or "kv_file", as well as unique "name" ''' if not self.kv_loaded: from kivy.lang import Builder if self.kv_string: Builder.load_string(self.kv_string) if self.kv_file: Builder.load_file(self.kv_file) self.kv_loaded = True super(DynamicScreen, self).__init__(**kwargs)
def build(self): self.recv_stream, self.send_stream = get_socket_stream('linvor') return Builder.load_string(kv)
def build(self): if platform == 'android': from android import AndroidService service = AndroidService('pupy', 'running') service.start('service started') self.service = service App.get_running_app().stop() return Builder.load_string(kv)
def kve_preview(self): r'''Editor?text??Widget???????Preview Builder.load_string? 1. ?????Kv???????????????? 2. ?????Kv????root rule?????None??? ????????????????????????????????????? Label??????????? ''' editor = self.ids.editor # Editor???Widget(CodeInput) preview = self.ids.preview # Preview??????Widget editor.text = tab2spaces(editor.text) preview.clear_widgets() # ???Preview??? Builder.unload_file(self.KV_FILENAME) # ???Kv??????? widget = None try: widget = Builder.load_string( editor.text, filename=self.KV_FILENAME ) except Exception as e: temp = [str(e.__class__)] temp.extend([str(arg) for arg in e.args]) error_msg = '\n'.join(temp) else: if widget is None: error_msg = r'No root rules.' if widget is None: # Widget????????????????????????????Label # ?????? preview.add_widget(Factory.Label(text=error_msg)) else: preview.add_widget(widget)
def build(self): main_widget = Builder.load_string(main_widget_kv) # self.theme_cls.theme_style = 'Dark' main_widget.ids.text_field_error.bind( on_text_validate=self.set_error_message, on_focus=self.set_error_message) self.bottom_navigation_remove_mobile(main_widget) return main_widget
def build(self): return Builder.load_string(KV)
def build(self): main_widget = Builder.load_string(main_widget_kv) self.nav_drawer = Navigator() return main_widget
def build(self): return Builder.load_string("""#:import MDSlider kivymd.slider.MDSlider BoxLayout: orientation:'vertical' padding: '8dp' MDSlider: id:slider min:0 max:100 value: 40 MDProgressBar: value: slider.value MDProgressBar: reversed: True value: slider.value BoxLayout: MDProgressBar: orientation:"vertical" reversed: True value: slider.value MDProgressBar: orientation:"vertical" value: slider.value """)
def build(self): main_widget = Builder.load_string(""" #:import MDRaisedButton kivymd.button.MDRaisedButton #:import MDThemePicker kivymd.theme_picker.MDThemePicker FloatLayout: MDRaisedButton: size_hint: None, None pos_hint: {'center_x': .5, 'center_y': .5} size: 3 * dp(48), dp(48) center_x: self.parent.center_x text: 'Open theme picker' on_release: MDThemePicker().open() opposite_colors: True """) return main_widget
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 _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 build(self): root = Builder.load_string(kv) Clock.schedule_interval(self.print_something, 2) # Clock.schedule_interval(self.test_pyjnius, 5) print('testing metrics') from kivy.metrics import Metrics print('dpi is', Metrics.dpi) print('density is', Metrics.density) print('fontscale is', Metrics.fontscale) return root
def build(self): main_widget = Builder.load_string(main_widget_kv) # self.theme_cls.theme_style = 'Dark' main_widget.ids.text_field.bind( on_text_validate=self.set_error_message, on_focus=self.set_error_message) self.nav_drawer = KitchenSinkNavDrawer() return main_widget
def __init__(self, **kwargs): super(MapChoice, self).__init__(**kwargs) self.root = Builder.load_string(kv) self.map_items = kwargs.get('map_items', []) list_item_args_converter = \ lambda row_index, selectable: {'name': selectable.name, 'max_zoom': selectable.max_zoom, 'description': selectable.description, 'size_hint_y': None, 'is_selected': selectable.is_selected, 'select_change_callback': selectable.on_selection_change, 'calibration_callback': selectable.on_calibration, 'index': row_index} map_list_adapter = \ ListAdapter(data=self.map_items, args_converter=list_item_args_converter, selection_mode='single', allow_empty_selection=False, template='CustomListItem') list_view = ListView(adapter=map_list_adapter) # map_list_adapter.bind(on_selection_change=self.callback_function) self.add_widget(list_view)
def __init__(self, **kwargs): super(MapChoice2, self).__init__(**kwargs) self.root = Builder.load_string(KV) rv = self.root.ids.rv rv.key_viewclass = "viewclass" rv.key_size = "height" self.map_items = kwargs.get('map_items', []) self.load_data(self.map_items) self.add_widget(self.root)
def build(self): self.root = Builder.load_string(kv) self.icon = 'systray.png' return self.root
def build(self): return Builder.load_string(kv)
def build(self): self.title = 'Simple context menu example' return Builder.load_string(kv)
def build(self): self.title = 'Simple app menu example' return Builder.load_string(kv)
def build(self): if not self.notif_icon: self.notif_icon = self.get_application_icon() Clock.schedule_once(self._hide_window, 0) if KWARGS['timeout_close']: Clock.schedule_once(self.stop, KWARGS['timeout']) if KWARGS['kv']: path = dirname(abspath(__file__)) kv = Builder.load_file(join(path, 'notification.kv')) kv.ids.container.clear_widgets() kv.ids.container.add_widget( Builder.load_string(KWARGS['kv']) ) return kv
def build(self): return Builder.load_string(""" BoxLayout: orientation:'vertical' BoxLayout: size_hint_y:None height: '48dp' Label: text:"Toggle disabled" color: [0,0,0,1] CheckBox: on_press: slider.disabled = not slider.disabled BoxLayout: size_hint_y:None height: '48dp' Label: text:"Toggle active" color: [0,0,0,1] CheckBox: on_press: slider.active = not slider.active BoxLayout: size_hint_y:None height: '48dp' Label: text:"Toggle show off" color: [0,0,0,1] CheckBox: on_press: slider.show_off = not slider.show_off MDSlider: id:slider min:0 max:100 value: 40 MDSlider: id:slider2 orientation:"vertical" min:0 max:100 value: 40 """)
def build(self): Clock.schedule_interval(self.callback, 1) return Builder.load_string("""#:import MDSlider kivymd.slider.MDSlider #:import MDLabel kivymd.label.MDLabel BoxLayout: orientation:'vertical' padding: '8dp' MDSlider: id:slider min:0 max:100 value: 10 MDProgressBar: value: app.rvalue rgbr:"00FF00" MDProgressBar: reversed: True value: app.rvalue rgbr:"00FFFF" BoxLayout: MDProgressBar: orientation:"vertical" reversed: False value: slider.value rgbr:"FFFF00" test: True alpha:.7 MDProgressBar: orientation:"vertical" value: slider.value reversed:True rgbr:"00ff77" MDLabel: text: str(app.rvalue) theme_text_color: 'Primary' font_style:"Caption" size_hint_y: None halign: 'center' height: self.texture_size[1] + dp(64) """)
def build(self): # self.theme_cls.primary_palette = 'Indigo' return Builder.load_string(""" #:import MDLabel kivymd.label.MDLabel BoxLayout: spacing: '64dp' MDAccordion: orientation: 'vertical' MDAccordionItem: title: 'Item 1' icon: 'home' MDAccordionSubItem: text: "Subitem 1" MDAccordionSubItem: text: "Subitem 2" MDAccordionSubItem: text: "Subitem 3" MDAccordionItem: title: 'Item 2' icon: 'earth' MDAccordionSubItem: text: "Subitem 4" MDAccordionSubItem: text: "Subitem 5" MDAccordionSubItem: text: "Subitem 6" MDAccordionItem: title: 'Item 3' MDAccordionSubItem: text: "Subitem 7" MDAccordionSubItem: text: "Subitem 8" MDAccordionSubItem: text: "Subitem 9" MDAccordion: orientation: 'horizontal' MDAccordionItem: title:'Item 1' icon: 'home' MDLabel: text:'Content 1' theme_text_color:'Primary' MDAccordionItem: title:'Item 2' MDLabel: text:'Content 2' theme_text_color:'Primary' MDAccordionItem: title:'Item 3' MDLabel: text:'Content 3' theme_text_color:'Primary' """)