enamlnative.core package

Submodules

enamlnative.core.api module

Copyright (c) 2017, CodeLV.

Distributed under the terms of the MIT License.

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

Created on Apr 15, 2017

@author: jrm

enamlnative.core.app module

Copyright (c) 2017, CodeLV.

Distributed under the terms of the MIT License.

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

@author jrm

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”

name

A value of type unicode.

By default, plain strings will be promoted to unicode strings. Pass strict=True to the constructor to enable strict unicode checking.

source

A value of type unicode.

By default, plain strings will be promoted to unicode strings. Pass strict=True to the constructor to enable strict unicode checking.

load()[source]

Load the object defined by the plugin entry point

__atom_members__ = {'name': <atom.scalars.Unicode object at 0x7fb6a3ffb9b0>, 'source': <atom.scalars.Unicode object at 0x7fb6a3fb62d0>}
__module__ = 'enamlnative.core.app'
__slots__ = ()
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.

__id__

A value of type int.

By default, ints are strictly typed. Pass strict=False to the constructor to enable int casting for longs and floats.

keep_screen_on

Keep screen on by setting the WindowManager flag

state

Application lifecycle state must be set by the implementation

view

View to display within the activity

load_view

Factory to create and show the view. It takes the app as the first arg

debug

If true, debug bridge statements

dev

Use dev server

loop

Event loop

plugins

Entry points to load plugins

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

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

start()[source]

Start the application’s main event loop using either twisted or tornado.

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.
  • **kwargs (*args,) –

    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.
  • **kwargs (*args,) –

    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
has_permission(permission)[source]

Return a future that resolves with the result of the permission

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()[source]

Create a future object using the EventLoop implementation

run_iteration()[source]

Run an iteration of the event loop

add_done_callback(future, callback)[source]

Add a callback on a future object put here so it can be implemented with different event loops.

Parameters:
  • future (Future or Deferred) – Future implementation for the current EventLoop
  • callback (callable) – Callback to invoke when the future is done
set_future_result(future, result)[source]

Set the result of the future

Parameters:
  • future (Future or Deferred) – Future implementation for the current EventLoop
  • result (object) – Result to set
show_view()[source]

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

get_view()[source]

Get the root view to display. Make sure it is properly initialized.

show_error(msg)[source]

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

send_event(name, *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.

process_events(data)[source]

The native implementation must use this call to

handle_event(event)[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)[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)[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…

}

__atom_members__ = {'__id__': <atom.scalars.Int object at 0x7fb6a3fb6370>, '_bridge_last_scheduled': <atom.scalars.Float object at 0x7fb6a3fb69b0>, '_bridge_max_delay': <atom.scalars.Float object at 0x7fb6a3fb6910>, '_bridge_queue': <atom.list.List object at 0x7fb6a411eec0>, '_counter': <atom.scalars.Value object at 0x7fb6a4061730>, '_dev_session': <atom.scalars.Value object at 0x7fb6a3fb67d0>, '_heap_lock': <atom.scalars.Value object at 0x7fb6a40617d0>, '_task_heap': <atom.list.List object at 0x7fb6a4431ad0>, 'debug': <atom.scalars.Bool object at 0x7fb6a3fb6690>, 'dev': <atom.scalars.Unicode object at 0x7fb6a3fb6730>, 'keep_screen_on': <atom.scalars.Bool object at 0x7fb6a3fb6410>, 'load_view': <atom.scalars.Callable object at 0x7fb6a3fb65f0>, 'loop': <atom.instance.Instance object at 0x7fb6a3fb6870>, 'plugins': <atom.dict.Dict object at 0x7fb6a3fb6a50>, 'resolver': <atom.typed.Typed object at 0x7fb6a4061690>, 'state': <atom.enum.Enum object at 0x7fb6a3fb64b0>, 'style_sheet': <atom.typed.ForwardTyped object at 0x7fb6a444d8f0>, 'view': <atom.scalars.Value object at 0x7fb6a3fb6550>}
__module__ = 'enamlnative.core.app'
__slots__ = ()

enamlnative.core.block module

Copyright (c) 2017, CodeLV.

Distributed under the terms of the MIT License.

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

Created on Apr 15, 2017

@author: jrm

class enamlnative.core.block.Block(parent=None, **kwargs)[source]

Bases: enaml.core.declarative.Declarative

An object which dynamically insert’s its children into another block’s parent object.

The ‘Block’ object is used to cleanly and easily insert it’s children into the children of another object. The ‘Object’ instance assigned to the ‘block’ property of the ‘Block’ will be parented with the parent of the ‘Block’. Creating a ‘Block’ with no parent is a programming error.

block

The Block to which this blocks children should be inserted into

mode

If replace, replace all parent’s children (except the block of course)

initialize()[source]

A reimplemented initializer.

This method will add the include objects to the parent of the include and ensure that they are initialized.

__atom_members__ = {'_children': <atom.list.List object at 0x7fb6a3785ec0>, '_d_engine': <atom.typed.Typed object at 0x7fb6a44900f0>, '_d_storage': <atom.typed.Typed object at 0x7fb6a4490230>, '_flags': <atom.scalars.Value object at 0x7fb6a4490c30>, '_parent': <atom.scalars.Value object at 0x7fb6a444a190>, 'block': <atom.instance.ForwardInstance object at 0x7fb6a3724558>, 'destroyed': <atom.event.Event object at 0x7fb6a444a410>, 'initialized': <atom.event.Event object at 0x7fb6a44904b0>, 'mode': <atom.enum.Enum object at 0x7fb6a372cd70>, 'name': <atom.scalars.Unicode object at 0x7fb6a44905f0>}
__module__ = 'enamlnative.core.block'
__slots__ = ()

enamlnative.core.bridge module

Copyright (c) 2017, CodeLV.

Distributed under the terms of the MIT License.

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

Created on June 21, 2017

@author: jrm

class enamlnative.core.bridge.Command[source]
CREATE = 'c'
PROXY = 'p'
METHOD = 'm'
STATIC_METHOD = 'sm'
FIELD = 'f'
DELETE = 'd'
RESULT = 'r'
ERROR = 'e'
DEF = 'def'
__module__ = 'enamlnative.core.bridge'
class enamlnative.core.bridge.ExtType[source]
REF = 1
PROXY = 2
__module__ = 'enamlnative.core.bridge'
enamlnative.core.bridge.generate_id()[source]

Generate an id for an object

enamlnative.core.bridge.generate_property_id()[source]

Generate an id for an object

enamlnative.core.bridge.tag_object_with_id(obj)[source]

Generate and assign a id for the object

enamlnative.core.bridge.get_object_with_id(id)[source]

Get the object with the given id in the cache

enamlnative.core.bridge.get_app_class()[source]

Avoid circular import. Probably indicates a poor design…

enamlnative.core.bridge.encode(obj)[source]

Encode an object for proper decoding by Java or ObjC

enamlnative.core.bridge.msgpack_encoder(sig, obj)[source]

When passing a BridgeObject encode it in a special way so it can properly be interpreted as a reference.

TODO: This should use the object hooks for doing this automatically

enamlnative.core.bridge.dumps(data)[source]

Encodes events for sending over the bridge

enamlnative.core.bridge.loads(data)[source]

Decodes and processes events received from the bridge

exception enamlnative.core.bridge.BridgeReferenceError[source]

Bases: exceptions.ReferenceError

__module__ = 'enamlnative.core.bridge'
__weakref__

list of weak references to the object (if defined)

enamlnative.core.bridge.get_handler(ptr, method)[source]

Dereference the pointer and return the handler method.

class enamlnative.core.bridge.BridgeMethod(*args, **kwargs)[source]

Bases: atom.property.Property

A method that is callable via the bridge. When called, this serializes the call, packs the arguments, and delegates handling to a bridge in native code.

#: Define it class View(BridgeObject):

addView = BridgeMethod(‘android.view.View’)

#: Create instance view = View() view2 = View()

#: Use it view.addView(view2)

__slots__ = ('__signature__', '__returns__', '__cache__', '__bridge_id__')
__init__(*args, **kwargs)[source]

Initialize a Property member.

Parameters:
  • fget (callable or None, optional) – The callable invoked to get the property value. It must accept a single argument which is the owner object. If not provided, the property cannot be read. The default is None.
  • fset (callable or None, optional) – The callable invoked to set the property value. It must accept two arguments: the owner object and property value. If not provided, the property cannot be set. The default is None.
  • fdel (callable or None, optional) – The callable invoked to delete the property value. It must accept a single argument which is the owner object. If not provided, the property cannot be deleted. The default is None.
  • cached (bool, optional) – Whether or not the property caches the computed value. A cached property will only evaluate ‘fget’ once until the ‘reset’ method of the property is invoked. The default is False.
__returns__
__signature__
__cache__
__bridge_id__
suppressed(**kwds)[source]

Suppress calls within this context to avoid feedback loops

__fget__(obj)[source]
__call__(obj, *args, **kwargs)[source]

The Swift like syntax is used

pack_args(obj, *args, **kwargs)[source]

Subclasses should implement this to pack args as needed for the native bridge implementation. Must return a tuple containing (“methodName”, [list, of, encoded, args])

__module__ = 'enamlnative.core.bridge'
class enamlnative.core.bridge.BridgeStaticMethod(*args, **kwargs)[source]

Bases: atom.property.Property

A method that is callable via the bridge. When called, this serializes the call, packs the arguments, and delegates handling to a bridge in native code.

#: Define it class Toast(BridgeObject):

makeToast = BridgeStaticMethod(*args)

#: Use result = Toast.makeToast(*args)

__slots__ = ('__signature__', '__returns__', '__cache__', '__owner__', '__bridge_id__')
__init__(*args, **kwargs)[source]

Initialize a Property member.

Parameters:
  • fget (callable or None, optional) – The callable invoked to get the property value. It must accept a single argument which is the owner object. If not provided, the property cannot be read. The default is None.
  • fset (callable or None, optional) – The callable invoked to set the property value. It must accept two arguments: the owner object and property value. If not provided, the property cannot be set. The default is None.
  • fdel (callable or None, optional) – The callable invoked to delete the property value. It must accept a single argument which is the owner object. If not provided, the property cannot be deleted. The default is None.
  • cached (bool, optional) – Whether or not the property caches the computed value. A cached property will only evaluate ‘fget’ once until the ‘reset’ method of the property is invoked. The default is False.
__returns__
__signature__
__owner__
__cache__
__bridge_id__
__get__(obj[, type]) → value[source]
__call__(...) <==> x(...)[source]
pack_args(obj, *args, **kwargs)[source]

Subclasses should implement this to pack args as needed for the native bridge implementation. Must return a tuple containing (“methodName”, [list, of, encoded, args])

__module__ = 'enamlnative.core.bridge'
class enamlnative.core.bridge.BridgeField(arg)[source]

Bases: atom.property.Property

Allows you to set fields or properties over the bridge using normal python syntax.

#: Define it class View(BridgeObject):

width = BridgeField(‘int’)

#: Create instance view = View()

#: Set field view.width = 200

__slots__ = ('__signature__', '__bridge_id__', '__bridge_cached_')
__init__(arg)[source]

Initialize a Property member.

Parameters:
  • fget (callable or None, optional) – The callable invoked to get the property value. It must accept a single argument which is the owner object. If not provided, the property cannot be read. The default is None.
  • fset (callable or None, optional) – The callable invoked to set the property value. It must accept two arguments: the owner object and property value. If not provided, the property cannot be set. The default is None.
  • fdel (callable or None, optional) – The callable invoked to delete the property value. It must accept a single argument which is the owner object. If not provided, the property cannot be deleted. The default is None.
  • cached (bool, optional) – Whether or not the property caches the computed value. A cached property will only evaluate ‘fget’ once until the ‘reset’ method of the property is invoked. The default is False.
__signature__
__bridge_id__
suppressed(**kwds)[source]

Suppress calls within this context to avoid feedback loops

__fset__(obj, arg)[source]
__fget__(obj)[source]

Return an object that can be used to retrieve the value.

__module__ = 'enamlnative.core.bridge'
class enamlnative.core.bridge.BridgeCallback(*args, **kwargs)[source]

Bases: enamlnative.core.bridge.BridgeMethod

Description of a callback method of a View (or subclass) in Objc or Java. When called,it fires the connected callback. If no callback is connected it will try to lookup a default callback implementation matching the name _impl_<name>. If that does not exist, it will simply do nothing.

This is triggered when it receives an event from the bridge indicating the call has occurred.

#: Define it class View(BridgeObject):

onClick = BridgeCallback()

#: Create instance view = View()

def on_click():
print(“Clicked!”)

#: Connect to callback view.onClick.connect(on_click)

You can define a “default” callback implementation by implementing the method with name of _impl_<name>. Connecting a callback will override this behavior.

#: Define it class LocationManager(BridgeObject):

hashCode = BridgeCallback()

def _impl_hashCode(self):
return self.__id__
__fget__(obj)[source]
__call__(obj, *args)[source]

Fire the callback if one is connected

connect(obj, callback)[source]

Set the callback to be fired when the event occurs.

disconnect(obj, callback)[source]

Remove the callback to be fired when the event occurs.

__dict__ = dict_proxy({'__dict__': <attribute '__dict__' of 'BridgeCallback' objects>, '__module__': 'enamlnative.core.bridge', 'disconnect': <function disconnect>, 'connect': <function connect>, '__call__': <function __call__>, '__weakref__': <attribute '__weakref__' of 'BridgeCallback' objects>, '__doc__': ' Description of a callback method of a View (or subclass) in \n Objc or Java. When called,it fires the connected callback. If no callback \n is connected it will try to lookup a default callback implementation \n matching the name `_impl_<name>`. If that does not exist, it will simply \n do nothing.\n\n This is triggered when it receives an event from the bridge indicating the \n call has occurred.\n\n\n #: Define it\n class View(BridgeObject):\n onClick = BridgeCallback()\n\n #: Create instance\n view = View()\n\n def on_click():\n print("Clicked!")\n\n #: Connect to callback\n view.onClick.connect(on_click)\n\n\n You can define a "default" callback implementation by implementing the \n method with name of `_impl_<name>`. Connecting a callback will override \n this behavior.\n\n #: Define it\n class LocationManager(BridgeObject):\n hashCode = BridgeCallback()\n\n def _impl_hashCode(self):\n return self.__id__\n\n ', '__fget__': <function __fget__>})
__module__ = 'enamlnative.core.bridge'
__weakref__

list of weak references to the object (if defined)

enamlnative.core.bridge.tag_property(cls)[source]
class enamlnative.core.bridge.BridgeObject(*args, **kwargs)[source]

Bases: atom.atom.Atom

A proxy to a class in java. This sends the commands over the bridge for execution. The object is stored in a map with the given id and is valid until this object is deleted.

Parameters:__id__ (Int, Future, or None) –

If an __id__ keyword argument is passed during creation, then

If the __id__ is an int, this will assume the object was already created and only a reference to the object with the given id is needed.

If the __id__ is a Future (as specified by the app event loop), then the __id__ of he future will be used. When the future completes this object will then be put into the cache. This allows passing results directly instead of using the .then() method.

__slots__ = ('__weakref__',)
__nativeclass__

Native Class name

__signature__

Constructor signature

__suppressed__

Suppressed methods / fields

__callbacks__

Callbacks

__id__

Bridge object ID

__bridge_id__

ID of this class

__prefix__

Prefix to add to all names used during method and property calls used for nested objects

__app__

Bridge

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

Sends the event to create this object in Java.

__del__()[source]

Destroy this object and send a command to destroy the actual object reference the bridge implementation holds (allowing it to be released).

__atom_members__ = {'__app__': <atom.instance.ForwardInstance object at 0x7fb6a4103f68>, '__bridge_id__': <atom.scalars.Int object at 0x7fb6a3ffb2d0>, '__callbacks__': <atom.dict.Dict object at 0x7fb6a3ffb4b0>, '__id__': <atom.scalars.Int object at 0x7fb6a3ffb730>, '__nativeclass__': <atom.scalars.Unicode object at 0x7fb6a3ffb370>, '__prefix__': <atom.scalars.Unicode object at 0x7fb6a3ffb5f0>, '__signature__': <atom.tuple.Tuple object at 0x7fb6a3ffb550>, '__suppressed__': <atom.dict.Dict object at 0x7fb6a3ffb410>}
__module__ = 'enamlnative.core.bridge'
__weakref__

list of weak references to the object (if defined)

class enamlnative.core.bridge.NestedBridgeObject(root, attr, **kwargs)[source]

Bases: enamlnative.core.bridge.BridgeObject

A nested object allows you to invoke methods and set properties of an object that is a property of another object using the dot notation.

Useful for setting nested properties without needing to first create a reference bridge object (thus saving the time waiting for the bridge to reply) for example:

UIView view = [UIView new];
view.yoga.width = YES;

Would require to create a reference to the “yoga” object first but instead we just add our nested object’s prefix and let the bridge resolve the actual property. It works like a regular BridgeObject but appends the “name’.

This object is NOT in the cache on either side of the bridge.

__root__

Reference to the object this is referenced under

__init__(root, attr, **kwargs)[source]

Sends the event to create this object in Java.

__del__()[source]

Destroy this object and send a command to destroy the actual object reference the bridge implementation holds (allowing it to be released).

__atom_members__ = {'__app__': <atom.instance.ForwardInstance object at 0x7fb6a4103f68>, '__bridge_id__': <atom.scalars.Int object at 0x7fb6a3ffb2d0>, '__callbacks__': <atom.dict.Dict object at 0x7fb6a3ffb4b0>, '__id__': <atom.scalars.Int object at 0x7fb6a3ffb730>, '__nativeclass__': <atom.scalars.Unicode object at 0x7fb6a3ffb370>, '__prefix__': <atom.scalars.Unicode object at 0x7fb6a3ffb5f0>, '__root__': <atom.instance.Instance object at 0x7fb6a3ffb690>, '__signature__': <atom.tuple.Tuple object at 0x7fb6a3ffb550>, '__suppressed__': <atom.dict.Dict object at 0x7fb6a3ffb410>}
__module__ = 'enamlnative.core.bridge'
__slots__ = ()

enamlnative.core.dev module

Copyright (c) 2017, CodeLV.

Distributed under the terms of the MIT License.

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

@author jrm

enamlnative.core.dev.cd(*args, **kwds)[source]
enamlnative.core.dev.COMPONENT_FIELD_TMPL = '\n\n'

This is why enaml-web is awesome, doing this sucks!

enamlnative.core.dev.get_app()[source]
class enamlnative.core.dev.DevClient[source]

Bases: atom.atom.Atom

Abstract dev client. Override start to implement

connection

Current websocket connection

mode

Mode of operation

classmethod available()[source]

Return True if this dev client impl can be used.

start(session)[source]
write_message(data, binary=False)[source]

Write a message to the client

__atom_members__ = {'connection': <atom.instance.Instance object at 0x7fb69006e5f0>, 'mode': <atom.enum.Enum object at 0x7fb69006e690>}
__module__ = 'enamlnative.core.dev'
__slots__ = ()
class enamlnative.core.dev.TornadoDevClient[source]

Bases: enamlnative.core.dev.DevClient

classmethod available()[source]

Return True if this dev client impl can be used.

start(session)[source]
write_message(data, binary=False)[source]

Write a message to the client

__atom_members__ = {'connection': <atom.instance.Instance object at 0x7fb69006e5f0>, 'mode': <atom.enum.Enum object at 0x7fb69006e690>}
__module__ = 'enamlnative.core.dev'
__slots__ = ()
class enamlnative.core.dev.TwistedDevClient[source]

Bases: enamlnative.core.dev.DevClient

classmethod available()[source]

Return True if this dev client impl can be used.

start(session)[source]
write_message(data, binary=False)[source]

Write a message to the client

__atom_members__ = {'connection': <atom.instance.Instance object at 0x7fb69006e5f0>, 'mode': <atom.enum.Enum object at 0x7fb69006e690>}
__module__ = 'enamlnative.core.dev'
__slots__ = ()
class enamlnative.core.dev.DevServer[source]

Bases: atom.atom.Atom

Abstract dev server. Override start to implement

classmethod available()[source]

Return True if this dev server impl can be used.

get_component_members(declaration)[source]
render_component_types(declaration, member)[source]
render_files(root=None)[source]

Render the file path as accordions

render_code()[source]

Try to load the previous code (if we had a crash or something) I should allow saving.

render_component(declaration)[source]

Render a row of all the attributes

render_editor()[source]
start(session)[source]
__atom_members__ = {}
__module__ = 'enamlnative.core.dev'
__slots__ = ()
class enamlnative.core.dev.TornadoDevServer[source]

Bases: enamlnative.core.dev.DevServer

classmethod available()[source]

Return True if this dev server impl can be used.

start(session)[source]
__atom_members__ = {}
__module__ = 'enamlnative.core.dev'
__slots__ = ()
class enamlnative.core.dev.TwistedDevServer[source]

Bases: enamlnative.core.dev.DevServer

classmethod available()[source]

Return True if this dev server impl can be used.

start(session)[source]
__atom_members__ = {}
__module__ = 'enamlnative.core.dev'
__slots__ = ()
class enamlnative.core.dev.DevServerSession(*args, **kwargs)[source]

Bases: atom.atom.Atom

Connect to a dev server running on the LAN or if host is 0.0.0.0 server a page to let code be pasted in. Note this should NEVER be used in a released app!

app

Reference to the current Application

host

Host to connect to (in client mode) or if set to “server” it will enable “server” mode

port

Port to serve on (in server mode) or port to connect to (in client mode)

url

URL to connect to (in client mode)

connected

Websocket connection state

buf

Message buffer

mode

Dev session mode

hotswap

Hotswap support class

servers

Delegate dev server

server

A value which allows objects of a given type or types.

Values will be tested using the PyObject_IsInstance C API call. This call is equivalent to isinstance(value, kind) and all the same rules apply.

The value of an Instance may be set to None.

clients

Delegate dev client

client

A value which allows objects of a given type or types.

Values will be tested using the PyObject_IsInstance C API call. This call is equivalent to isinstance(value, kind) and all the same rules apply.

The value of an Instance may be set to None.

classmethod initialize(*args, **kwargs)[source]

Create an instance of this class.

classmethod instance()[source]

Get the singleton instance

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

Overridden constructor that forces only one instance to ever exist.

start()[source]

Start the dev session. Attempt to use tornado first, then try twisted

write_message(data, binary=False)[source]

Write a message to the active client

handle_message(data)[source]

When we get a message

do_reload(msg)[source]

Called when the dev server wants to reload the view.

do_hotswap(msg)[source]

Attempt to hotswap the code

save_changed_files(msg)[source]
__atom_members__ = {'app': <atom.instance.ForwardInstance object at 0x7fb6a37246c8>, 'buf': <atom.scalars.Unicode object at 0x7fb69006e9b0>, 'client': <atom.instance.Instance object at 0x7fb69006ed70>, 'clients': <atom.list.List object at 0x7fb69007b248>, 'connected': <atom.scalars.Bool object at 0x7fb69006e910>, 'host': <atom.scalars.Unicode object at 0x7fb69006e730>, 'hotswap': <atom.instance.Instance object at 0x7fb69006eaf0>, 'mode': <atom.enum.Enum object at 0x7fb69006ea50>, 'port': <atom.scalars.Int object at 0x7fb69006e7d0>, 'server': <atom.instance.Instance object at 0x7fb69006ec30>, 'servers': <atom.list.List object at 0x7fb69007b1a0>, 'url': <atom.scalars.Unicode object at 0x7fb69006e870>}
__module__ = 'enamlnative.core.dev'
__slots__ = ()

enamlnative.core.http module

Copyright (c) 2017, CodeLV.

Distributed under the terms of the MIT License.

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

@author jrm

exception enamlnative.core.http.HttpError(code, message=None, response=None)[source]

Bases: exceptions.Exception

__init__(code, message=None, response=None)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

__str__() <==> str(x)[source]
__module__ = 'enamlnative.core.http'
__weakref__

list of weak references to the object (if defined)

class enamlnative.core.http.HttpRequest(*args, **kwargs)[source]

Bases: atom.atom.Atom

The request object created for fetch calls. It’s based on the design of Tornado’s HttpRequest.

url

Request url

method

Request method

headers

Request headers

retries

Retry count

data

Request parameter data

content_type

Content type

body

Raw request body

callback

Called when complete

streaming_callback

Streaming callback

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

Build the request as configured.

start_time

Start time

response

Response created

init_request()[source]

Initialize the request using whatever native means necessary

__atom_members__ = {'body': <atom.scalars.Unicode object at 0x7fb6a336c0f0>, 'callback': <atom.scalars.Callable object at 0x7fb6a336c190>, 'content_type': <atom.scalars.Unicode object at 0x7fb6a336c050>, 'data': <atom.dict.Dict object at 0x7fb6a361ff50>, 'headers': <atom.dict.Dict object at 0x7fb6a361fe10>, 'method': <atom.scalars.Unicode object at 0x7fb6a361fd70>, 'response': <atom.instance.ForwardInstance object at 0x7fb6a36153e8>, 'retries': <atom.scalars.Int object at 0x7fb6a361feb0>, 'start_time': <atom.scalars.Float object at 0x7fb6a336c2d0>, 'streaming_callback': <atom.scalars.Callable object at 0x7fb6a336c230>, 'url': <atom.scalars.Unicode object at 0x7fb6a361fcd0>}
__module__ = 'enamlnative.core.http'
__slots__ = ()
class enamlnative.core.http.HttpResponse[source]

Bases: atom.atom.Atom

The response object returned to an AsyncHttpClient fetch callback. It is based on the the tornado HttpResponse object.

request

Request that created this response

code

Numeric HTTP status code

reason

Reason phrase for the status code

headers

Response headers list of strings

ok

Result success

body

Response body Note: if a streaming_callback is given to the request then this is NOT used and will be empty

content_length

Size

error

Error message

progress

Progress

request_time

Done time

__atom_members__ = {'body': <atom.scalars.Unicode object at 0x7fb6a336c690>, 'code': <atom.scalars.Int object at 0x7fb6a336c410>, 'content_length': <atom.scalars.Int object at 0x7fb6a336c730>, 'error': <atom.instance.Instance object at 0x7fb6a336c7d0>, 'headers': <atom.dict.Dict object at 0x7fb6a336c550>, 'ok': <atom.scalars.Bool object at 0x7fb6a336c5f0>, 'progress': <atom.scalars.Int object at 0x7fb6a336c870>, 'reason': <atom.scalars.Unicode object at 0x7fb6a336c4b0>, 'request': <atom.instance.Instance object at 0x7fb6a336c370>, 'request_time': <atom.scalars.Float object at 0x7fb6a336c910>}
__module__ = 'enamlnative.core.http'
__slots__ = ()
class enamlnative.core.http.AbstractAsyncHttpClient[source]

Bases: atom.atom.Atom

An AsyncHttpClient that lets you fetch using a format similar to tornado’s AsyncHTTPClient but using a native library.

This is done instead of using a python library so it handles all SSL stuff for us. Otherwise we have to compile and link all the SSL libraries with python which makes the app huge (at least 5Mb in ssl libs alone) and the build process even more complicated.

request_factory

Factory used to build the request

requests

Pending requests

fetch(url, callback=None, raise_error=True, **kwargs)[source]

Fetch the given url and fire the callback when ready. Optionally pass a streaming_callback to handle data from large requests.

Parameters:
  • url (string) – The url to access.
  • callback (callable) – The callback to invoke when the request completes. You can also use the return value.
  • kwargs – The arguments to pass to the HttpRequest object. See it for which values are valid.
Returns:

result – A future that resolves with the HttpResponse object when the request is complete.

Return type:

Future

__atom_members__ = {'request_factory': <atom.subclass.Subclass object at 0x7fb6a336c9b0>, 'requests': <atom.list.List object at 0x7fb6a3785440>}
__module__ = 'enamlnative.core.http'
__slots__ = ()
class enamlnative.core.http.AbstractWebsocketClient[source]

Bases: atom.atom.Atom

An AsyncWebsocketClient that lets you handle WSS using a native library implementation.

This is done instead of using a python library so it handles all SSL stuff for us. Otherwise we have to compile and link all the SSL libraries with python which makes the app huge (at least 5Mb in ssl libs alone) and the build process even more complicated.

classmethod connect(url)[source]

Start a connection and return an instance

Parameters:url (string) – The url to connect to.
Returns:result – A future that resolves with the AsyncWebsocketClient connection instance when the connection succeeds or fails.
Return type:Future : AsyncWebsocketClient
write_message(message, binary=False)[source]

Sends a message to the WebSocket server.

close(code=None, reason=None)[source]

Close the websocket with the given code and reason

on_open()[source]

Called when a connection has opened

__atom_members__ = {}
__module__ = 'enamlnative.core.http'
__slots__ = ()
on_message(message, is_binary)[source]

Called when a message is received

on_close(code=None, reason=None)[source]

Called when the connection is closed

enamlnative.core.import_hooks module

Copyright (c) 2017, CodeLV.

Distributed under the terms of the MIT License.

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

Created on July 10, 2017

@author: jrm

class enamlnative.core.import_hooks.ExtensionImporter[source]

Bases: object

Loads renamed extensions files from the app’s lib folder

extension_modules = {}
__init__()[source]

x.__init__(…) initializes x; see help(type(x)) for signature

load_module(mod)[source]

Load the extension using the load_dynamic method.

find_module(mod, path=None)[source]

Use this as the loader if the desired module is an extension within the given library folder.

__dict__ = dict_proxy({'load_module': <function load_module>, 'extension_modules': {}, '__module__': 'enamlnative.core.import_hooks', 'find_module': <function find_module>, '__dict__': <attribute '__dict__' of 'ExtensionImporter' objects>, '__weakref__': <attribute '__weakref__' of 'ExtensionImporter' objects>, '__doc__': " Loads renamed extensions files from the app's lib folder", '__init__': <function __init__>})
__module__ = 'enamlnative.core.import_hooks'
__weakref__

list of weak references to the object (if defined)

enamlnative.core.loop module

Copyright (c) 2017, CodeLV.

Distributed under the terms of the MIT License.

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

@author jrm

class enamlnative.core.loop.EventLoop[source]

Bases: atom.atom.Atom

Event loop delegation api

name

So users can check if needed

loop

Actual event loop object

future

Future implementation for type checks

classmethod default()[source]

Get the first available event loop implementation based on which packages are installed.

classmethod available()[source]

Test if the event loop implementation is available.

Returns:bool
Return type:The event loop can be used.
start()[source]
stop()[source]
deferred_call(callback, *args, **kwargs)[source]

Schedule the given callback to be invoked at the next available time.

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

Schedule the given callback to be invoked at a time ms later.

create_future()[source]

Create a future instance for this event loop.

Adds a “javascript fetch” like api with “then” and “catch”.

The object returned MUST have a method named then that takes a callback that should be invoked when the future is complete and returns the future object.

And the object returned MUST have a method named catch that takes a callback that should be invoked if the future contains an exception and returns the future object.

Likewise the future must be tagged with an id using bridge.tag_object_with_id(obj) so it can be resolved by the bridge.

run_iteration()[source]

Run one iteration of the event loop

set_error_handler(handler)[source]

Set the error handler method to be the given handler.

add_done_callback(future, callback)[source]

Add a callback will be triggered when the callback completes.

set_future_result(future, result)[source]

Set the result of a Future to trigger any attached callbacks.

log_error(callback, error=None)[source]

Log the error that occurred when running the given callback.

__atom_members__ = {'_handler': <atom.scalars.Callable object at 0x7fb6a3ffbb90>, 'future': <atom.scalars.Value object at 0x7fb6a3ffbc30>, 'loop': <atom.scalars.Value object at 0x7fb6a3ffbaf0>, 'name': <atom.scalars.Unicode object at 0x7fb6a3ffba50>}
__module__ = 'enamlnative.core.loop'
__slots__ = ()
class enamlnative.core.loop.TornadoEventLoop[source]

Bases: enamlnative.core.loop.EventLoop

Eventloop using tornado’s ioloop

base_future

A member class which supports value initialization.

A plain Value provides support for default values and factories, but does not perform any type checking or validation. It serves as a useful base class for scalar members and can be used for cases where type checking is not needed (like private attributes).

classmethod available()[source]

Test if the event loop implementation is available.

Returns:bool
Return type:The event loop can be used.
deferred_call(callback, *args, **kwargs)[source]

Schedule the given callback to be invoked at the next available time.

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

Schedule the given callback to be invoked at a time ms later.

set_error_handler(handler)[source]

Set the error handler method to be the given handler.

run_iteration()[source]

Run one iteration of the event loop

log_error(callback)[source]

Log the error that occurred when running the given callback.

__atom_members__ = {'_handler': <atom.scalars.Callable object at 0x7fb6a3ffbb90>, 'base_future': <atom.scalars.Value object at 0x7fb6a3ffbcd0>, 'future': <atom.scalars.Value object at 0x7fb6a3ffb7d0>, 'loop': <atom.scalars.Value object at 0x7fb6a3ffbeb0>, 'name': <atom.scalars.Unicode object at 0x7fb6a3ffbd70>}
__module__ = 'enamlnative.core.loop'
__slots__ = ()
future

A member class which supports value initialization.

A plain Value provides support for default values and factories, but does not perform any type checking or validation. It serves as a useful base class for scalar members and can be used for cases where type checking is not needed (like private attributes).

loop

A member class which supports value initialization.

A plain Value provides support for default values and factories, but does not perform any type checking or validation. It serves as a useful base class for scalar members and can be used for cases where type checking is not needed (like private attributes).

name

A value of type unicode.

By default, plain strings will be promoted to unicode strings. Pass strict=True to the constructor to enable strict unicode checking.

class enamlnative.core.loop.TwistedEventLoop[source]

Bases: enamlnative.core.loop.EventLoop

Eventloop using twisted’s reactor

classmethod available()[source]

Test if the event loop implementation is available.

Returns:bool
Return type:The event loop can be used.
start()[source]
deferred_call(callback, *args, **kwargs)[source]

We have to wake up the reactor after every call because it may calculate a long delay where it can sleep which causes events that happen during this period to seem really slow as they do not get processed until after the reactor “wakes up”

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

We have to wake up the reactor after every call because it may calculate a long delay where it can sleep which causes events that happen during this period to seem really slow as they do not get processed until after the reactor “wakes up”

run_iteration()[source]

Run one iteration of the event loop

__atom_members__ = {'_handler': <atom.scalars.Callable object at 0x7fb6a3ffbb90>, 'future': <atom.scalars.Value object at 0x7fb6a3fb60f0>, 'loop': <atom.scalars.Value object at 0x7fb6a3fb6050>, 'name': <atom.scalars.Unicode object at 0x7fb6a3ffbf50>}
__module__ = 'enamlnative.core.loop'
__slots__ = ()
future

A member class which supports value initialization.

A plain Value provides support for default values and factories, but does not perform any type checking or validation. It serves as a useful base class for scalar members and can be used for cases where type checking is not needed (like private attributes).

loop

A member class which supports value initialization.

A plain Value provides support for default values and factories, but does not perform any type checking or validation. It serves as a useful base class for scalar members and can be used for cases where type checking is not needed (like private attributes).

name

A value of type unicode.

By default, plain strings will be promoted to unicode strings. Pass strict=True to the constructor to enable strict unicode checking.

class enamlnative.core.loop.BuiltinEventLoop[source]

Bases: enamlnative.core.loop.TornadoEventLoop

Use the built in event loop. It’s a stripped down version of tornado, It’s currently slightly slower than tornado at the moment so use tornado if possible.

classmethod available()[source]

Test if the event loop implementation is available.

Returns:bool
Return type:The event loop can be used.
set_error_handler(handler)[source]

Set the error handler method to be the given handler.

log_error(callback, error=None)[source]

Log the error that occurred when running the given callback.

__atom_members__ = {'_handler': <atom.scalars.Callable object at 0x7fb6a3ffbb90>, 'base_future': <atom.scalars.Value object at 0x7fb6a3fb6230>, 'future': <atom.scalars.Value object at 0x7fb6a3ffb7d0>, 'loop': <atom.scalars.Value object at 0x7fb6a3fb6190>, 'name': <atom.scalars.Unicode object at 0x7fb6a3ffbd70>}
__module__ = 'enamlnative.core.loop'
__slots__ = ()
base_future

A member class which supports value initialization.

A plain Value provides support for default values and factories, but does not perform any type checking or validation. It serves as a useful base class for scalar members and can be used for cases where type checking is not needed (like private attributes).

loop

A member class which supports value initialization.

A plain Value provides support for default values and factories, but does not perform any type checking or validation. It serves as a useful base class for scalar members and can be used for cases where type checking is not needed (like private attributes).

enamlnative.core.remotehooks module

Copyright (c) 2017, CodeLV.

Distributed under the terms of the MIT License.

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

Created on Dec 11, 2017

@author jrm

enamlnative.core.remotehooks.init()[source]
enamlnative.core.remotehooks.log(msg)[source]

Normally the app’s native hooks provides this method

enamlnative.core.remotehooks.publish(data)[source]

Module contents