How to use Kivy - 10 common examples

To help you get started, we’ve selected a few Kivy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github HeaTTheatR / KivyMD / demos / kitchen_sink / demo_apps / fitnessclub.py View on Github external
def set_item_menu(self):
        def anim_item(*args):
            instance_item = args[0]
            Animation(
                x=(App.get_running_app().Window.width // 2) - dp(30),
                d=0.15,
                t="in_out_bounce",
            ).start(instance_item)

        Clock.schedule_once(lambda x: anim_item(self.ids.exercises), 0.1)
        Clock.schedule_once(lambda x: anim_item(self.ids.nutrition), 0.15)
        Clock.schedule_once(lambda x: anim_item(self.ids.motivation), 0.2)
        Clock.schedule_once(lambda x: anim_item(self.ids.about), 0.25)
github HeaTTheatR / KivyMD / kivymd / uix / progressloader.py View on Github external
toast('Done')


Test().run()
"""

from kivy.clock import Clock
from kivy.core.window import Window
from kivy.animation import Animation
from kivy.network.urlrequest import UrlRequest
from kivy.lang import Builder
from kivy.properties import StringProperty, ObjectProperty, BooleanProperty

from kivymd.uix.card import MDCard

Builder.load_string(
    """
#:import Window kivy.core.window.Window



    pos: (Window.width // 2) - (self.width // 2), (Window.height // 2) - (self.height // 2)
    size_hint_y: None
    size_hint_x: .8
    height: spinner.height + dp(20)
    spacing: dp(10)
    padding: dp(10)

    canvas:
        Color:
            rgba: app.theme_cls.primary_color
        Rectangle:
github Abraxos / hermes / hermes-native / test_find_index_of_selected_conversation.py View on Github external
def run_test(self, app, *args):
        Clock.schedule_interval(self.pause, 0.000001)

        # Setup
        app.main_window.finish_init(None)
        app.main_window.add_conversation_to_UI()

        # Execute
        app.main_window.find_index_of_selected_conversation('conversation_0')

        # Assert
        self.assertEqual(app.main_window.current_screen_index, 2)

        # Comment out if you are editing the test, it'll leave the
        # Window opened.
        app.stop()
github Abraxos / hermes / hermes-native / test_selected_view_profile.py View on Github external
def run_test(self, app, *args):
        Clock.schedule_interval(self.pause, 0.000001)

        # Setup
        app.main_window.finish_init(None)
        
        # Execute
        app.main_window.selected_view_profile()

        # Assert
        self.assertEqual("Cancel", app.profile_control.children[0].text)
        self.assertEqual("Ban", app.profile_control.children[1].text)
        self.assertEqual("Kick", app.profile_control.children[2].text)
        self.assertEqual("Block", app.profile_control.children[3].text)
        self.assertEqual("Profile", app.profile_control.children[4].text)
        # Comment out if you are editing the test, it'll leave the
        # Window opened.
        app.stop()
github KeyWeeUsr / KivyUnitTest / kivyunittest / examples / test_text.py View on Github external
def run_test(self, app, *args):
        Clock.schedule_interval(self.pause, 0.000001)

        # Do something
        app.my_button.dispatch('on_release')
        self.assertEqual('Hello Test', app.my_button.text)
        #self.assertEqual('Fail Test', app.my_button.text)

        # Comment out if you are editing the test, it'll leave the
        # Window opened.
        app.stop()
github kivy / python-for-android / tests / testapp / main.py View on Github external
halign: 'center'
        Widget:
            size_hint_y: None
            height: 1000
            on_touch_down: print 'touched at', args[-1].pos

:
    title: 'Error' 
    size_hint: 0.75, 0.75
    Label:
        text: root.error_text
'''


class ErrorPopup(Popup):
    error_text = StringProperty('')

def raise_error(error):
    print('ERROR:',  error)
    ErrorPopup(error_text=error).open()

class TestApp(App):
    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
github inclement / noGo / boardview.py View on Github external
elif mode == 'wstone':
            board.input_mode = 'wstone'
        elif mode == 'estone':
            board.input_mode = 'estone'
    def on_board_to_play(self,*args):
        toplay = self.board_to_play
        if toplay == 'w' and self.bplay_button.state == 'down':
            self.wplay_button.state = 'down'
            self.bplay_button.state = 'normal'
        elif toplay == 'b' and self.wplay_button.state == 'down':
            self.bplay_button.state = 'down'
            self.wplay_button.state = 'normal'
        

class CommentInput(BoxLayout):
    board = ObjectProperty(None)
    popup = ObjectProperty(None)
    comment = StringProperty('')

class SaveQuery(BoxLayout):
    collections_list = ObjectProperty(None,allownone=True)
    board = ObjectProperty(None,allownone=True)
    sgf_model = ObjectProperty(None,allownone=True)

def get_collectioninfo_from_dir(row_index,dirn):
    sgfs = glob(dirn + '/*.sgf')
    colname = dirn.split('/')[-1]
    return {'colname': colname, 'coldir': dirn, 'numentries': len(sgfs)}

class MySpinnerOption(SpinnerOption):
    pass
github missionpinball / mpf / mpf / commands / mc.py View on Github external
mpfmc.__path__[0], args.mcconfigfile))

        machine_path = set_machine_path(machine_path,
                                        mpf_config['mpf-mc']['paths'][
                                            'machine_files'])

        mpf_config = load_machine_config(args.configfile, machine_path,
                                         mpf_config['mpf-mc']['paths'][
                                             'config'], mpf_config)

        self.preprocess_config(mpf_config)

        try:
            MpfMc(options=vars(args), config=mpf_config,
                  machine_path=machine_path).run()
            Logger.info("MC run loop ended.")
        except Exception as e:
            # Todo need to change back to a normal exception
            logging.exception(str(e))

        if args.pause:
            input('Press ENTER to close this window...')
        sys.exit()
github snuq / Snu-Photo-Manager / screensettings.py View on Github external
def _create_popup(self, *_):
        app = App.get_running_app()
        if app.database_scanning:
            return
        content = BoxLayout(orientation='vertical')
        popup_width = min(0.95 * Window.width, dp(500))
        self.popup = popup = NormalPopup(title=self.title, content=content, size_hint=(None, 0.9), width=popup_width)
        if not self.value:
            content.add_widget(ShortLabel(height=app.button_scale * 3, text="You must set at least one database directory.\n\nThis is a folder where your photos are stored.\nNew photos will be imported to a database folder."))
            content.add_widget(BoxLayout())
        else:
            folders = filter(None, self.value.split(';'))
            folderdata = []
            for folder in folders:
                folderdata.append({'text': folder})
            self.folderlist = folderlist = FolderSettingsList(size_hint=(1, .8), id='folderlist')
            folderlist.data = folderdata
            content.add_widget(folderlist)
        buttons = BoxLayout(orientation='horizontal', size_hint=(1, None), height=app.button_scale)
        addbutton = NormalButton(text='+')
        addbutton.bind(on_release=self.add_path)
        removebutton = NormalButton(text='-')
        removebutton.bind(on_release=self.remove_path)
        okbutton = WideButton(text='OK')
        okbutton.bind(on_release=self._dismiss)
        buttons.add_widget(addbutton)
github snuq / Snu-Photo-Manager / screensettings.py View on Github external
def _create_popup(self, *_):
        app = App.get_running_app()
        if app.database_scanning:
            return
        content = BoxLayout(orientation='vertical')
        popup_width = min(0.95 * Window.width, dp(500))
        self.popup = popup = NormalPopup(title=self.title, content=content, size_hint=(None, 0.9), width=popup_width)
        if not self.value:
            content.add_widget(ShortLabel(height=app.button_scale * 3, text="You must set at least one database directory.\n\nThis is a folder where your photos are stored.\nNew photos will be imported to a database folder."))
            content.add_widget(BoxLayout())
        else:
            folders = filter(None, self.value.split(';'))
            folderdata = []
            for folder in folders:
                folderdata.append({'text': folder})
            self.folderlist = folderlist = FolderSettingsList(size_hint=(1, .8), id='folderlist')
            folderlist.data = folderdata
            content.add_widget(folderlist)
        buttons = BoxLayout(orientation='horizontal', size_hint=(1, None), height=app.button_scale)
        addbutton = NormalButton(text='+')
        addbutton.bind(on_release=self.add_path)