App

Common

Copyright (c) 2017-2022, CodeLV.

Distributed under the terms of the MIT License.

The full license is in the file LICENSE, distributed with this software.

class enamlnative.core.app.Plugin[source]

Bases: atom.atom.Atom

Simplified way to load a plugin from an entry_point line. The enaml-native and p4a build process removes pkg_resources and all package related metadata this simply imports from an entry point string in the format “package.path.module:attr”

load()[source]

Load the object defined by the plugin entry point

class enamlnative.core.app.BridgedApplication(*args, **kwargs)[source]

Bases: enaml.application.Application

An abstract implementation of an Enaml application.

This serves as a base class for both Android and iOS applications and provides support for the python event loop, the development server and the bridge.

activity

View to display within the activity

debug

If true, debug bridge statements

dev

Use dev server

loop

Event loop

plugins

Entry points to load plugins

error_occurred

Event triggered when an error occurs

__init__(*args, **kwargs)[source]

Initialize the event loop error handler. Subclasses must properly initialize the proxy resolver.

start()[source]

Start the application event loop

stop()[source]

Stop the application’s main event loop.

deferred_call(callback, *args, **kwargs)[source]

Invoke a callable on the next cycle of the main event loop thread.

Parameters
  • callback (callable) – The callable object to execute at some point in the future.

  • *args – Any additional positional and keyword arguments to pass to the callback.

  • **kwargs – Any additional positional and keyword arguments to pass to the callback.

timed_call(ms, callback, *args, **kwargs)[source]

Invoke a callable on the main event loop thread at a specified time in the future.

Parameters
  • ms (int) – The time to delay, in milliseconds, before executing the callable.

  • callback (callable) – The callable object to execute at some point in the future.

  • *args – Any additional positional and keyword arguments to pass to the callback.

  • **kwargs – Any additional positional and keyword arguments to pass to the callback.

is_main_thread()[source]

Indicates whether the caller is on the main gui thread.

Returns

result – True if called from the main gui thread. False otherwise.

Return type

bool

async has_permission(permission)[source]

Return a future that resolves with the result of the permission

async request_permissions(permissions)[source]

Return a future that resolves with the result of the permission request

init_error_handler()[source]

When an error occurs, set the error view in the App

create_future(return_type: Optional[type] = None) enamlnative.core.bridge.BridgeFuture[source]

Create a future object using the EventLoop implementation

show_error(msg: Union[bytes, str])[source]

Show the error view with the given message on the UI.

send_event(name: str, *args, **kwargs)[source]

Send an event to the native handler. This call is queued and batched.

Parameters
  • name (str) – The event name to be processed by MainActivity.processMessages.

  • *args (args) – The arguments required by the event.

  • **kwargs (kwargs) –

    Options for sending. These are:

    now: boolean

    Send the event now

force_update()[source]

Force an update now.

dispatch_events(data)[source]

Send events to the bridge using the system specific implementation.

async process_events(data: str)[source]

The native implementation must use this call to

async handle_event(result_id: int, ptr: int, method: str, args: list)[source]

When we get an ‘event’ type from the bridge handle it by invoking the handler and if needed sending back the result.

handle_error(callback, exc: Exception)[source]

Called when an error occurs in an event loop callback. By default, sets the error view.

on_events(data)[source]

Called when the bridge sends an event. For instance the return result of a method call or a callback from a widget event.

on_pause()[source]

Called when the app is paused.

on_resume()[source]

Called when the app is resumed.

on_stop()[source]

Called when the app is stopped.

on_destroy()[source]

Called when the app is destroyed.

start_dev_session()[source]

Start a client that attempts to connect to the dev server running on the host app.dev

get_plugins(group: str) list[enamlnative.core.app.Plugin][source]

Was going to use entry points but that requires a ton of stuff which will be extremely slow.

load_plugin_widgets()[source]

Pull widgets added via plugins using the enaml_native_widgets entry point. The entry point function must return a dictionary of Widget declarations to add to the core api.

def install():

from charts.widgets.chart_view import BarChart, LineChart return {

‘BarChart’: BarChart, ‘LineCart’: LineChart,

}

load_plugin_factories()[source]

Pull widgets added via plugins using the enaml_native_ios_factories or enaml_native_android_factories entry points. The entry point function must return a dictionary of Widget declarations to add to the factories for this platform.

def install():
return {

‘MyWidget’:my_widget_factory, # etc…

}

Android App

Copyright (c) 2017-2022, CodeLV.

Distributed under the terms of the MIT License.

The full license is in the file LICENSE, distributed with this software.

class enamlnative.android.app.AndroidApplication(*args, **kwargs)[source]

Bases: enamlnative.core.app.BridgedApplication

An Android implementation of an Enaml Native BridgedApplication.

A AndroidApplication uses the native Android widget toolkit to implement an Enaml UI that runs in the local process.

async has_permission(permission: str) bool[source]

Return a future that resolves with the result of the permission

async request_permissions(*permissions) dict[str, bool][source]

Return a future that resolves with the results of the permission requests

show_toast(msg: str, long: bool = True)[source]

Show a toast message for the given duration. This is an android specific api.

Parameters
  • msg (str) – Text to display in the toast message

  • long (bool) – Display for a long or short (system defined) duration

dispatch_events(data)[source]

Send the data to the Native application for processing

async get_system_service(cls)[source]

Wrapper for getSystemService. You MUST wrap the class with the appropriate object.

load_plugin_factories()[source]

Add any plugin toolkit widgets to the ANDROID_FACTORIES

iOS App

Copyright (c) 2017-2022, CodeLV.

Distributed under the terms of the MIT License.

The full license is in the file LICENSE, distributed with this software.

class enamlnative.ios.app.ENBridge(*args, **kwargs)[source]

Bases: enamlnative.ios.bridge.ObjcBridgeObject

Access ENBridge.m using ctypes.

Based on: https://stackoverflow.com/questions/1490039/ calling-objective-c-functions-from-python#1490644

objc

Objc library

bridge

Bridge.m access via ctypes

processEvents(data)[source]

Sends msgpack data to the ENBridge instance by calling the processEvents method via ctypes.

addTarget

Add a target to a UIControl that invokes a python callback

class enamlnative.ios.app.AppDelegate(*args, **kwargs)[source]

Bases: enamlnative.ios.bridge.ObjcBridgeObject

class enamlnative.ios.app.ViewController(*args, **kwargs)[source]

Bases: enamlnative.ios.bridge.ObjcBridgeObject

class enamlnative.ios.app.IPhoneApplication(*args, **kwargs)[source]

Bases: enamlnative.core.app.BridgedApplication

An iPhone implementation of an Enaml Native BridgedApplication.

An IPhoneApplication uses the native iOS widget toolkit to implement an Enaml UI that runs in the local process.

Since Objective-C can easily use the Python C-API, much if this classes implementation is done directly. For instance, the AppEventListener API is implemented directly in Objective-C (in Bridge.m) and invokes methods on this directly.

app_delegate

AppDelegate widget

view_controller

ViewControler

bridge

ENBridge

dp

Pixel density of the device Loaded immediately as this is used often.

__init__(*args, **kwargs)[source]

Initialize a IPhoneApplication.

show_view()[source]

Show the current app.view. This will fade out the previous with the new view.

dispatch_events(data)[source]

Send the data to the Native application for processing

load_plugin_factories()[source]

Add any plugin toolkit widgets to the ANDROID_FACTORIES