Python kivy.lang.Builder.load_string() Examples

The following are 22 code examples of kivy.lang.Builder.load_string(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module kivy.lang.Builder , or try the search function .
Example #1
Source File: app.py    From kivy-launcher with MIT License 9 votes vote down vote up
def build(self):
        self.log('start of log')
        if KIVYLAUNCHER_PATHS:
            self.paths.extend(KIVYLAUNCHER_PATHS.split(","))
        else:
            from jnius import autoclass
            Environment = autoclass('android.os.Environment')
            sdcard_path = Environment.getExternalStorageDirectory().getAbsolutePath()
            self.paths = [
                sdcard_path + "/kivy",
            ]

        self.root = Builder.load_string(KV)
        self.refresh_entries()

        if platform == 'android':
            from android.permissions import request_permissions, Permission
            request_permissions([Permission.READ_EXTERNAL_STORAGE]) 
Example #2
Source File: textinput.py    From Tickeys-linux with MIT License 7 votes vote down vote up
def build(self):

            Builder.load_string('''
<TextInput>
    on_text:
        self.suggestion_text = ''
        self.suggestion_text = 'ion_text'

''')
            root = BoxLayout(orientation='vertical')
            textinput = TextInput(multiline=True, use_bubble=True,
                                  use_handles=True)
            #textinput.text = __doc__
            root.add_widget(textinput)
            textinput2 = TextInput(multiline=False, text='monoline textinput',
                                   size_hint=(1, None), height=30)
            root.add_widget(textinput2)
            return root 
Example #3
Source File: textinput.py    From Tickeys-linux with MIT License 6 votes vote down vote up
def build(self):

            Builder.load_string('''
<TextInput>
    on_text:
        self.suggestion_text = ''
        self.suggestion_text = 'ion_text'

''')
            root = BoxLayout(orientation='vertical')
            textinput = TextInput(multiline=True, use_bubble=True,
                                  use_handles=True)
            #textinput.text = __doc__
            root.add_widget(textinput)
            textinput2 = TextInput(multiline=False, text='monoline textinput',
                                   size_hint=(1, None), height=30)
            root.add_widget(textinput2)
            return root 
Example #4
Source File: main.py    From Kivy-Tutorials with GNU General Public License v2.0 6 votes vote down vote up
def btn_new_on_press(self):# callback; Add a new Tab
		panel = self.ids.tab_panel
		#create a tab by KV string
		tab_str = '''
TabbedPanelItem:
	id: tab_%d
	text: 'Tab %d'
	BoxLayout:
		Button:
			id: btn_new
            text: 'New Tab'
        Button:
            id: btn_close
            text: 'Close tab'
		'''
		self.max_id += 1 #max tab id
		tab = Builder.load_string(tab_str %(self.max_id, self.max_id)) #create a widget by string
		tab.ids.btn_new.on_press = self.btn_new_on_press #set events
		tab.ids.btn_close.on_press = self.btn_close_on_press
		panel.add_widget(tab) # add the tab 
Example #5
Source File: dropdown.py    From Tickeys-linux with MIT License 6 votes vote down vote up
def __init__(self, **kwargs):
        self._win = None
        if 'container' not in kwargs:
            c = self.container = Builder.load_string(_grid_kv)
        else:
            c = None
        kwargs.setdefault('do_scroll_x', False)
        if 'size_hint' not in kwargs:
            kwargs.setdefault('size_hint_x', None)
            kwargs.setdefault('size_hint_y', None)
        super(DropDown, self).__init__(**kwargs)
        if c is not None:
            super(DropDown, self).add_widget(c)
            self.on_container(self, c)
        Window.bind(on_key_down=self.on_key_down)
        self.bind(size=self._reposition) 
Example #6
Source File: dropdown.py    From Tickeys-linux with MIT License 6 votes vote down vote up
def __init__(self, **kwargs):
        self._win = None
        if 'container' not in kwargs:
            c = self.container = Builder.load_string(_grid_kv)
        else:
            c = None
        kwargs.setdefault('do_scroll_x', False)
        if 'size_hint' not in kwargs:
            kwargs.setdefault('size_hint_x', None)
            kwargs.setdefault('size_hint_y', None)
        super(DropDown, self).__init__(**kwargs)
        if c is not None:
            super(DropDown, self).add_widget(c)
            self.on_container(self, c)
        Window.bind(on_key_down=self.on_key_down)
        self.bind(size=self._reposition) 
Example #7
Source File: main.py    From KivyMD with MIT License 5 votes vote down vote up
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)
		return main_widget 
Example #8
Source File: kitchen_sink.py    From KivyMD with MIT License 5 votes vote down vote up
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)
		return main_widget 
Example #9
Source File: screenregister.py    From PyCon-Mobile-App with GNU General Public License v3.0 5 votes vote down vote up
def show_file_chooser(self):
        # update data_file_dir here
        pop = Builder.load_string('''
Popup
    title: 'Select data flie dir'
    BoxLayout
        padding: dp(9)
        spacing: dp(20)
        orientation: 'vertical'
        FileChooserIconView
            id: fl
            filters: ['*.']
            path: '/mnt/sdcard/'
            # dirselect: True
            #filter_dirs: True
        BoxLayout
            spacing: dp(9)
            size_hint_y: None
            height: dp(36)
            ActiveButton
                text: 'Select'
                on_release:
                    app.screenregister.data_file_dir = fl.path
                    root.dismiss()
            ActiveButton
                text: 'Cancel'
                on_release: root.dismiss()
''')
        pop.ids.fl.path = self.data_file_dir
        pop.open() 
Example #10
Source File: space_editor.py    From kivy3dgui with MIT License 5 votes vote down vote up
def __init__(self, layout, parent, editor_manager):
        self.layout = layout
        self.parent = parent
        self.node_helper = NodeHelper()
        self.node_helper.editor_manager = editor_manager
        axis = '''
            Node:
                translate: (0, 0, 0)
                scale: (0.05, 0.05, 0.05)
                min_light_intensity: 0.8
                alpha: 0.5
                always_on_top: True
                receive_shadows: False
                meshes: ("{0}",)
                Button:
                    id: c_button
                    text: "Hello"
                    background_normal: "{1}"
            '''
        
        meshes = ["./editor/meshes/x-rot-axis.obj", "./editor/meshes/y-rot-axis.obj", "./editor/meshes/z-rot-axis.obj",
                  "./editor/meshes/x-scale-axis.obj", "./editor/meshes/z-scale-axis.obj", "./editor/meshes/y-scale-axis.obj",
                  "./editor/meshes/x-axis.obj", "./editor/meshes/z-axis.obj", "./editor/meshes/y-axis.obj"]
                  
        colors = ["./editor/images/red.png", "./editor/images/green.png", "./editor/images/blue.png",
                  "./editor/images/green.png", "./editor/images/blue.png", "./editor/images/red.png",
                  "./editor/images/red.png", "./editor/images/green.png", "./editor/images/blue.png"]
                  
        for i, e in enumerate(meshes):
            node = Builder.load_string(dedent(axis.format(e, colors[i])))
            node.ids.c_button.bind(on_touch_down=parent.on_button_touch_down)
            node.ids.c_button.bind(on_touch_up=parent.on_button_touch_up)
            node.ids.c_button.bind(on_touch_move=parent.on_button_touch_move)
            node.ids.c_button.c_id = i
            layout.add_widget(node)
            self.node_helper.add_mesh(node) 
Example #11
Source File: editor_manager.py    From kivy3dgui with MIT License 5 votes vote down vote up
def restore(self, *args):
        
        node = Node(**self.c_dict)
        float = dedent("""
                FloatLayout:
                    Button:
                        size_hint: (1., 1.)
                        id: a_button""")
        selector = Builder.load_string(float)
        node.add_widget( selector )   
        for e in args[0][:-1]:
            if e.obj == self.obj:
                e.obj = node
        self.callback(node, node.translate, node.scale, selector.ids.a_button, [node.pitch, node.yaw, node.roll])        
        #self.layout.add_widget(node) 
Example #12
Source File: backend_kivy.py    From garden.matplotlib with MIT License 5 votes vote down vote up
def __init__(self, canvas, **kwargs):
        self.actionbar = ActionBar(pos_hint={'top': 1.0})
        super(NavigationToolbar2Kivy, self).__init__(canvas)
        self.rubberband_color = (1.0, 0.0, 0.0, 1.0)
        self.lastrect = None
        self.save_dialog = Builder.load_string(textwrap.dedent('''\
            <SaveDialog>:
                text_input: text_input
                BoxLayout:
                    size: root.size
                    pos: root.pos
                    orientation: "vertical"
                    FileChooserListView:
                        id: filechooser
                        on_selection: text_input.text = self.selection and\
                        self.selection[0] or ''

                    TextInput:
                        id: text_input
                        size_hint_y: None
                        height: 30
                        multiline: False

                    BoxLayout:
                        size_hint_y: None
                        height: 30
                        Button:
                            text: "Cancel"
                            on_release: root.cancel()

                        Button:
                            text: "Save"
                            on_release: root.save(filechooser.path,\
                            text_input.text)
            ''')) 
Example #13
Source File: editor3d.py    From kivy3dgui with MIT License 5 votes vote down vote up
def bottom_touch(self, widget, touch):
        size = widget.size
        touch_pos = touch.pos
        center = [size[0] / 2, size[1] / 2]
        #g_pos = self.space_editor.node_helper.pos[:]
        g_scale = self.space_editor.node_helper.pos[:]
        
        box = Builder.load_string(dedent(self.box_str.format(0, 0, 0, 0, "box" if self.layout3d.f_type == 0 else "sphere")))
        self.set_mesh(box, self.layout3d.look_at[3:6][:], g_scale)
        self.space_editor.node_helper.save_command(3, self.layout3d) 
Example #14
Source File: main.py    From garden.recycleview with MIT License 5 votes vote down vote up
def build(self):
        self.root = Builder.load_string(KV)
        rv = self.root.ids.rv
        rv.key_viewclass = "viewclass"
        rv.key_size = "height"
        self.generate_new_data() 
Example #15
Source File: __init__.py    From RaceCapture_App with GNU General Public License v3.0 5 votes vote down vote up
def build(self):

            Builder.load_string(kvdemo)
            android_tabs = AndroidTabs()

            for n in range(1, 6):
                tab = MyTab(text='TAB %s' % n)
                android_tabs.add_widget(tab)

            return android_tabs 
Example #16
Source File: main.py    From Blogs-Posts-Tutorials with MIT License 5 votes vote down vote up
def build(self):
        main_widget = Builder.load_string(main_widget_kv)
        self.nav_drawer = Navigator()
        return main_widget 
Example #17
Source File: tabs.py    From Blogs-Posts-Tutorials with MIT License 5 votes vote down vote up
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'
     
        
""") 
Example #18
Source File: progressbar.py    From Blogs-Posts-Tutorials with MIT License 5 votes vote down vote up
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
        
""") 
Example #19
Source File: theme_picker.py    From Blogs-Posts-Tutorials with MIT License 5 votes vote down vote up
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 
Example #20
Source File: __init__.py    From garden.modernmenu with MIT License 5 votes vote down vote up
def build(self):
        return Builder.load_string(TESTAPP_KV) 
Example #21
Source File: slider.py    From Blogs-Posts-Tutorials with MIT License 4 votes vote down vote up
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
        
""") 
Example #22
Source File: main.py    From Kivy-Tutorials with GNU General Public License v2.0 4 votes vote down vote up
def draw_screen(self):
        self.game_grid.clear_widgets() # this command remove all children(blocks) from the game_grid

        # according to the level, we can change the size of the grid
        if(self.level < 3):
            self.game_grid.cols = 2
            self.game_grid.rows = 2
            self.grid_size = 2
        elif self.level < 5:
            self.game_grid.cols = 3
            self.game_grid.rows = 3
            self.grid_size = 3
        elif self.level < 10:
            self.game_grid.cols = 4
            self.game_grid.rows = 4
            self.grid_size = 4
        elif self.level < 15:
            self.game_grid.cols = 5
            self.game_grid.rows = 5
            self.grid_size = 5
        elif self.level < 20:
            self.game_grid.cols = 6
            self.game_grid.rows = 6
            self.grid_size = 6

        # this is a block in KV lang.
        btn_str = '''
ImageButton:
    source: "res/block.png"
    allow_stretch: True
    keep_ratio: False'''


        # generate a grid_sizeXgrid_size grid
        for i in range(0, self.grid_size*self.grid_size):
            btn = Builder.load_string(btn_str) # create a ImageButton from the string
            id = 'btn_' + str(i)
            btn.id = id # set the button ID
            self.game_grid.ids[id] = btn #add this button to the list of children of the GameGrid
            btn.bind(on_press=self.on_btn_press) # bind the press event
            self.game_grid.add_widget(btn) # and show this button on the grid

    # grid button event