Post

MyApp

MyApp

SimpleKivy.SimpleKivy.MyApp(layout=[[]], title='MyApp', event_manager=None, custom_titlebar=False, alpha=1, keep_on_top=False, icon='skdata/logo/simplekivy-icon-32.png', layout_class=None, layout_args={}, do_auto_config=True, **kwargs)

A complete overhaul of how the App object is created. For simplicity, in this page app represents an instance of MyApp inside code blocks.

Init Arguments

title (str): App title. Defaults to "MyApp".

layout (list): List (or matrix-like list) of widgets that represent your program. When layout_class = None, a matrix-like list must be used (see Grid). Otherwise, the list argument must conform to the layout_class constructor. Defaults to [[]].

event_manager: function or EventManager instance. Must accept at least two positional arguments: app and event.

1
2
3
4
5
6
7
def evman(app, event):
    pass
app=sk.MyApp(
    ...
    event_manager = evman
    ...
)

custom_titlebar (bool): Whether the app will use the first widget in the layout as titlebar. Defaults to False

alpha (float): Transparency of the window. Only works on Windows at the moment. Defaults to 1 (opaque).

keep_on_top (bool): Wheter your application’s window is shown on top of all other windows. Defaults to False.

icon (str): Image of your application’s icon. Defaults to “skdata/logo/simplekivy-icon-32.png”.

ico (str): Path to an *.ico file. Needed for file dialogs (askdirectory, askopenfile, etc.) in Windows platforms only.

layout_class: (None, Widget)

Layuout widget that will be used to represent the layout.

  • None: The layout base will be SimpleKivy.kvWidgets.GridLayoutB, in which case the layout argument must be list (matrix-like). See Grid.
  • Widget: The layout constructor will be this value. The layout argument must conform to the requirements of layout_class.

Default is None.

layout_args (dict): Dictionary of arguments used to initilize the layout_class (e.g, bcolor, padding, spacing, lcolor, etc.). Defaults to {}.

do_auto_config: (bool)

Whether to automatically configure kivy by calling SimpleKivy.utils.auto_config when MyApp is initialized. Visit utils.auto_config for more information.

  • True: Calls auto_config with default arguments: (size=(800,600),exit_on_escape=False,multisamples=2,desktop=True,resizable=True,multitouch_emulation=False,window_state='visible').
  • False: Doesn’t call auto_config. You need to configure kivy yourself, or make a call to auto_config before initializing MyApp.

Default is True.

Attributes

window_is_maximized (BooleanProperty): Whether the window is maximized. Can be set to maximize (= True) or restore (= False) the window.

top_widget (AliasProperty): Current widget being shown on top of all other widgets. Intended for menus, tooltips, etc.

subtop_widget (AliasProperty): Current widget being shown on top of all other widgets, besides top_widget. Intended for submenus.

hwnd (int): OS window id (hwnd) of the application.

keep_on_top (bool): Wheter your application’s window is shown on top of all other windows. Defaults to False.

alpha (float): Transparency of the window. Only works on Windows at the moment. Defaults to 1 (opaque).

Clock: Alias of kivy.clock.Clock.

mdi: Alias of SimpleKivy.utils.mdi.

kvWindow: Alias of kivy.core.window.Window.

ids (IDS): Dictionary of ids of all app widgets. You can access widgets with variable name conformant ids with dot notation (app.ids.widget_id) if the widget was created like this: sk.Label("text",k='widget_id').

event_manager: function or EventManager instance. Must accept at least two positional arguments: app and event.

1
2
3
4
5
6
7
def evman(app, event):
    pass
app=sk.MyApp(
    ...
    event_manager = evman
    ...
)

ico (str): Path to an *.ico file. Needed for file dialogs (askdirectory, askopenfile, etc.) in Windows platforms only.

poolt: Initialized as ThreadPoolExecutor(thread_name_prefix='SimpleKivy'). You can use it to submit threaded tasks.

queue (dict): Don’t overwrite it. This dict is populated by the thread_pool_new method.

Methods

process_added_widgets(): Call this after creating new SimpleKivy widgets when your program is already running (e.g., adding Popup widgets, menus, buttons, etc.). Finishes processing widgets and incorporating them into the app.

Aliases: paw

thread_pool_new(name, max_workers=None): Creates a thread pool with ThreadPoolExecutor(max_workers=max_workers,thread_name_prefix=name) and adds it to the queue dictionary with the name as key.

queue_new(name): Creates a thread pool with a single worker (a queue) with ThreadPoolExecutor(max_workers=1,thread_name_prefix=name) and adds it to the queue dictionary with the name as key.

hide(*key_list, shrink = True): Hides widgets by their key/id.

  • *key_list: Positional arguments representing all the widgets by their key which will be hidden.
  • shrink (bool): Whether the widget’s size will be set to (0,0) while hidden.

unhide(*key_list, enforce = {}): Unhides widgets.

  • *key_list: Positional arguments representing all the widgets by their key which will be unhidden.
  • enforce (dict): Properties to enforce after unhiding. In case the widget’s size is not fully restored after hiding it.

destroy_widget(k, default = None): Removes a widget from the extra references kept by SimpleKivy, like app.ids.

add_top_widget(widget, remove_on_click=True): Adds a top widget to be shown on top of other widgets.

  • widget (Widget): Widget (sets as app.top_widget value).
  • remove_on_click (bool): Whether the top_widget will be removed automatically when a mouse click event is detected.

remove_top_widget(): Remove the current top_widget if any.

add_top_widget(widget, remove_on_click=True): Adds a subtop widget to be shown on top of other widgets, besides the top_widget.

  • widget (Widget): Widget (sets as app.subtop_widget value).
  • remove_on_click (bool): Whether the subtop_widget will be removed automatically when a mouse click event is detected.

remove_subtop_widget(): Remove the current subtop_widget if any.

infotip(text='info', height=30, remove_on_click=True, size_hint_y=None, pos_hint={'left': 0, 'bottom': 0}, timeout=3, lcolor='white', bcolor='gray', halign='center', padding=4, markup=False, font_size=15, color=[1, 1, 1, 1], max_lines=1, auto_remove=True, size_behavior='normal', **kw)

See MyApp.infotip. Shows an infotip.

infotip_schedule: Schedules an infotip to be shown in the next frame.

infotip_remove_schedule: Schedules the top_widget to be removed in the next frame.

disable_widgets(*widgets): Sets disabled = True of the positional arguments *widgets given:

  • *widgets: One or many str or Widget values. If str, must be a widget id.

enable_widgets(*widgets): Sets disabled = False of the positional arguments *widgets given:

  • *widgets: One or many str or Widget values. If str, must be a widget id.

Resize(width, height): Setes the Window size.

bring_to_front(): Brings the Window to the front of all other opened programs.

__call__(k,prop=None,val=None,timeout=0,_kw_prepro=False,ignore_errors=False,**kwargs): You can call the app as if it were a function to schedule property changes (app(...)).

  • k (str, Widget): The Value of the k argument represents a widget, either by its widget id, or by the Widget instance itself.

Example:

1
app(k='label_widget_id',text='New text', haling='right')

dt_call(k,prop=None,val=None,_kw_prepro=False,ignore_errors=False,**kwargs): Returns a lambda function that calls app.__call__ (same as app(...)) with the given arguments.

schedule_call_once(k,prop=None,val=None,timeout=0,_kw_prepro=False,ignore_errors=False,**kwargs): Schedules app(...) with the given arguments to be called in the next frame.

schedule_call_interval(k,prop=None,val=None,timeout=0,_kw_prepro=False,ignore_errors=False,**kwargs): Schedules app(...) with the given arguments to be called every timeout seconds.

trigger_event(event,*args,**kwargs): Gets or creates a trigger for the event. The trigger created will call the event_manager with the given arguments.

schedule_event_once(event,*args,timeout=0,**kwargs): Schedule a call of the event_manager for the next frame with the given arguments.

schedule_func_once(func,*args,timeout=0,**kwargs): Schedule a function to be called in the next frame with the given arguments.

schedule_get_call(key,method,*args,**kwargs): Schedule once a call to the method named method of a widget with ID key, and with the given arguments *args and **kwargs.

submit_thread_event(event,*args,**kwargs): Submits a call of the event_manager in the poolt thread pool with the given arguments.

Aliases: thread_event

submit_thread_event_at(thread_name,event,*args,**kwargs): Submits a call of the event_manager in the queue[thread_name] thread pool with the given arguments.

Aliases: thread_event_at

call_event(event,*args,**kwargs): Calls the event_manager with the given arguments.

keys(): Shortcut to app.ids.keys().

values(): Shortcut to app.ids.values().

items(): Shortcut to app.ids.items().

AskOpenFile(initialdir='./', filetypes=(('All files', '*.*'),), callback=None, **kw)

See MyApp.AskOpenFile. Creates a SimpleKivy file dialog to open a file.

AskDirectory(initialdir='./', callback=None, **kw)

See MyApp.AskDirectory. Creates a SimpleKivy file dialog to open a directory.

askdirectory(callback=None, **kw)

See MyApp.askdirectory. Creates a native platform file dialog to open a directory.

askopenfile(filetypes=(('All files', '*.*'),), callback=None, **kw)

See MyApp.askopenfile. Creates a native platform file dialog to open a file.

askopenfiles(filetypes=(('All files', '*.*'),), callback=None, **kw)

See MyApp.askopenfiles. Creates a native platform file dialog to open multiple files.

asksaveasfile(initialfile='', filetypes=(('All files', '*.*'),), callback=None, **kw)

See MyApp.asksaveasfile. Creates a native platform file dialog to save a file as the input name and location.

popup_message: Creates a popup widget with a message.

lock(): Show a lock screen that only gets dismissed when you call the unlock method.

unlock(): Dismisses the lock screen.

build(): Internal. Processes and returns the layout as a widget.

minimize(): Shortcut to kivy.core.Window.minimize()

restore(): Shortcut to kivy.core.Window.restore()

maximize(): Shortcut to kivy.core.Window.maximize()

close(): Closes the app.

is_leaving(): Whether the app is in the closing sequence. Useful when there are threaded tasks that have not finished.

sleep_in_thread(timeout = 0): Similar to the time.sleep function, but returns immediately if the app is in the closing sequence.

Kivy Bases

App

This page only details the new or modified features. All other parameters inherit from the base Kivy widgets and can be found in the official Kivy documentation.

This post is licensed under CC BY 4.0 by the author.