Module fullscreenwrapper2 :: Class Layout
[hide private]
[frames] | no frames]

Class Layout

source code

object --+
         |
        Layout

Defines a "screen" with an xml layout that contains views. Layout is a abstract class - you MUST derive your own Layout class.

To use a Layout, you need to first derive a class with Layout as a base class: MyLayout(Layout) and define the functions on_show(self) and on_close(self). in your MyLayout.__init__(), you MUST include a call to super(MyLayout,self).__init__(xml, title)

the xml property stores the xml text. This is used by FullScreenWrapper2App.show_layout() to actually display the layout.

The layout contains importantly a BaseDict called views. A BaseDict is a dict that allows access to members by either [key] or .key

IMPORTANT: The views BaseDict is populated by FullScreenWrapper2App.show_layout() once the xml is displayed on the screen. Your layout's Views that have an id only become accessible once the xml is displayed & the Layout.on_show() function is caled by the framework. DO NOT try to access views in the __init__() and put all your view initialization code & event handler attachment in the on_show() function.

The views BaseDict allows you to access & modify properties of your views & allows event based interaction. You would typically access view properties as Layout.views.view_id.property with the FullScreenWrapper2 framework making the appropriate SL4A api calls to access the property. To set events for the views, use Layout.views.view_id.add_event(EventHandler)

The FullScreenWrapper2App actually stores layout objects in a stack allowing you to seamlessly the right parent layout on closing a child layout. This lets you build a natural interaction using the "back" key. Note however that every time a layout is shown, its views are created afresh & the Layout.views BaseDict is cleared & re-populated and the Layout.on_show() function is called. This is why you should put all your view initialization & event handler setup code in Layout.on_show()

Layout.on_close method MUST also be defined - though it can simply be a 1 line function containing pass. This is called when a layout is either closed or a child layout is opened. This method to save state.

Layouts also allow you to set "Layout" events through Layout.add_event() - you would typically use this for things like "back key press" or even for other events which are accessible through the SL4A EventFacade's event system like sensor data. For catching these events, you would typically set EventHandler.compare_attribute to None.

Layout events are internally handled by adding a special "layout" view to the views collection identified by a hashtag. You should not yourself access this special view.

Nested Classes [hide private]
  __metaclass__
Metaclass for defining Abstract Base Classes (ABCs).
Instance Methods [hide private]
 
__init__(self, xml, title)
creates a layout and stes its xml and title, initializes the views collection
source code
 
_reset(self)
This function will clear the views collection & add the special "Layout" view which is used to handle layout events internally
source code
 
add_event(self, eventhandler)
This function adds a Layout event.
source code
 
remove_event(self, event_name)
This function removes a Layout event by event name.
source code
 
on_show(self)
The on_show method is called after your layout is displayed to allow you to initialize your layout's views' attributes & setup event handlers.
source code
 
on_close(self)
The on_close method MUST be defined & is called both when your layout is closed or before displaying a child layout to let you save state.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  __abstractmethods__ = frozenset(['on_close', 'on_show'])
  _abc_cache = <_weakrefset.WeakSet object at 0x018433B0>
  _abc_negative_cache = <_weakrefset.WeakSet object at 0x018433F0>
  _abc_negative_cache_version = 10
  _abc_registry = <_weakrefset.WeakSet object at 0x01843350>
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, xml, title)
(Constructor)

source code 

creates a layout and stes its xml and title, initializes the views collection

NOTE that this DOES NOT display the layout and the layout Views are also not populated. The special "layout" view for handling Layout evnets however is created here

Overrides: object.__init__

add_event(self, eventhandler)

source code 

This function adds a Layout event. This event is added to the special "layout" view in the views collection

remove_event(self, event_name)

source code 

This function removes a Layout event by event name. This event is actually stored in the special "layout" view in the views collection

on_show(self)

source code 

The on_show method is called after your layout is displayed to allow you to initialize your layout's views' attributes & setup event handlers.

on_show is an abstract method which MUST be defined in the your layout class. FullScreenWrapper2App.show_layout() displays the layout & populates the views BaseDict collection and then calls Layout.on_show() letting you do your view initializations & setup event handlers. This function is called every time a view is displayed - for eg. after a child layout is closed & the parent layout shown again on screen

If you have saved state in Layout.on_close() be sure to read back state & populate data in your layout's views in on_show()

Decorators:
  • @abc.abstractmethod

on_close(self)

source code 

The on_close method MUST be defined & is called both when your layout is closed or before displaying a child layout to let you save state.

If you're saving state here, you can read back state on on_show() method

Decorators:
  • @abc.abstractmethod