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”
- 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.
- deferred_call(callback, *args, **kwargs)[source]¶
Invoke a callable on the next cycle of the main event loop thread.
- Parameters
- timed_call(ms, callback, *args, **kwargs)[source]¶
Invoke a callable on the main event loop thread at a specified time in the future.
- Parameters
- 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
- create_future(return_type: Optional[type] = None) enamlnative.core.bridge.BridgeFuture [source]¶
Create a future object using the EventLoop implementation
- send_event(name: str, *args, **kwargs)[source]¶
Send an event to the native handler. This call is queued and batched.
- Parameters
- 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.
- 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
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.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.