Panel Factory Interface
The Panel Factory module defines a framework based on the Abstract Factory
design pattern. The framework includes the abstract classes
PanelFactory
and PanelAssembler
. Since these classes inherit
from ABCMeta
, they are truly abstract and you cannot instantiate them.
Instead, you must subclass them to get concrete instances.
In our framework, any classes that inherit from PanelFactory
will
provide all the neccessary components for it’s particular specialization. For
example, a cell panel does not have a dismiss button the way that a window
panel would. As a result, we should define one factory that specializes in
building cell parts and another factory that specializes in producing window
parts. Some panels may have resizeable borders, others may have a fixed size.
These types of panel variations would be defined by the PanelFactory
.
The PanelAssembler
classes will do the work of actually putting the
panel parts together. Here is where the internal functionality of the panel
is defined. Where the PanelFactory
defines the panel type, the
PanelAssembler
defines a panel’s functionality.
For the sake of example, suppose you have defined your own
PanelAssembler
as MenuBarAssembler
and a PanelFactory
called MenuFactory
:
class MenuFactory(PanelFactory):
def add_panel(self):
print("Creating the panel in memory.")
def add_icon(self, icon):
print("Adding an icon to the panel.")
def add_title(self, title):
pass # menus don't have titles
def add_borders(self):
print("Adding borders.")
def add_inner(self, inner):
print("Filling in the inner content.")
def add_dismiss(self):
pass # You cannot dismiss this menu
def get_panel(self):
print("Supplying the panel object that was configured.")
class MenuBarAssembler(PanelAssembler):
def build_inner(self):
return "Fancy inner menu contents."
def create_panel(self, factory):
factory.add_panel()
factory.add_borders()
factory.add_inner(self.build_inner())
result = factory.get_panel()
result.append("Special customizations.")
return result
We can now use the assembler with the factory to build a menu object. The
result would be:
>>> ma = MenuBarAssembler()
>>> mf = MenuFactory()
>>> menu_instance = ma.create_panel(mf)
Creating the panel in memory.
Adding borders.
Filling in the inner content.
Supplying the panel object that was configured.
Notice that we first create instances of the factory and the assembler. We then
use the assembler and supply the factory to the assembler. Different factories
would result in a different object coming out of the assembler. If we inspect
the menu_instance
we find:
>>> print(menu_instance)
['Special customizations.']
Note
PanelFactory and PanelAssembler are both modeled as singletons. As a
result, when you derive from them, your subclasses will also be singletons.
-
class
panel_factory.
PanelAssembler
This abstract class defines the interface for producing panel instances.
The PanelAssembler
subclasses are able to take any
PanelFactory
and use it to assemble a fully functional panel. The
classes which inherit from PanelAssembler
also houses the logic
to produce contents inside the panel as well as all the logic that makes it
work.
-
create_panel
(panel_factory, **kwargs)
Assemble the panel components by using the supplied factory.
Parameters: | panel_factory (PanelFactory) – Provides panel parts. |
-
class
panel_factory.
PanelFactory
This abstract class defines an interface that all subclasses must
implement. A PanelFactory produces panel parts. Different subtypes may
produce parts differently or omit certain parts altogether. For example,
some types of panels may not have a titlebar.
-
add_borders
(**kwargs)
Build border elements for the panel.
-
add_dismiss
(**kwargs)
Build any dismissal mechanisms for the panel.
-
add_icon
(icon, **kwargs)
Add an icon to the panel’s title bar.
Parameters: | icon (string) – The icon used to represent the panel. Any markup will be
processed before rendering. |
-
add_inner
(inner_content, **kwargs)
Add a placeholder in the panel where inner contents will be placed.
Parameters: | inner_content (kivy.Widget) – The root element of a widget tree containing all
the interior content of the panel. |
-
add_panel
(**kwargs)
Instantiate the base panel widget.
-
add_title
(title_text, **kwargs)
Build the panel’s title bar.
Parameters: | title_text (string) – The panel title. Markup will be processed before
rendering. |
-
get_panel
(**kwargs)
Return the panel object.
Concrete Panel Factories
This module contains the actual concrete implementations of the interfaces
defined by PanelFactory
and
PanelAssembler
. These objects are modeled as
singletons. Therefore, there is only ever one instance of each object in the
runtime environment.
-
class
panel_factories.
CellAssembler
This is a concrete implementation of the
PanelAssembler
interface. It is modeled as a
singleton.
Variables: |
- factory – The factory that will be used to produce parts for the cell.
- controller – The controller to assign to the cell.
- title – The title to assign to the cell.
|
-
class
panel_factories.
CellFactory
The concrete implementation of the PanelFactory interface. Produces
cell ui’s.
Variables: | cell – A placeholder where the cell will be built. |
-
class
panel_factories.
ConsoleAssembler
Makes a console panel which provides an embedded python interpreter.
Variables: |
- icon –
- title –
- color – The color that will be assigned to the title.
- GLOW – The color that will be assigned to the icon.
|
-
class
panel_factories.
OSXWindowFactory
Defines window panel elements for OSX platforms.
Variables: |
- window – A
UI_Panel
- title – A string representing the title
- config_section – The ini section name for the new window if applicable
|
Panel UI Elements
This module provides the visual representations of panel components that are
used by panel factories.
-
class
ui_panel.
Dismiss
(**kwargs)
This is a dismiss button.
Variables: | to_be_dismissed – An object that defines a dismiss() member
function. |
-
dismiss
()
Call the dismiss function of the reference object.
-
on_touch_up
(touch)
A callback function that handles the response to a touch up (unclick)
event.
Parameters: | touch (MotionEvent) – The associated touch data. |
-
class
ui_panel.
UI_Panel
(**kwargs)
This class defines the look/feel of panels which are the utility windows
that live outside of circuits.
Variables: |
- config_section – The name of the section in the ini file where this
panel’s config values will be written to.
- hidden – Indicates whether or not the panel is off-screen.
- last_pos – Used to save the position of the panel prior to sweeping it
off screen so that we can bring it back to the same
position later.
- scale – The current scale of the panel. Default is 1.
|
-
calculate_offscreen_pos
()
Calculates the closest center panel point at which the entire panel is
offscreen.
-
dismiss
()
Deletes the panel. It is entirely removed from the widget tree. To
bring it back, you need to instance a new one.
-
on_touch_up
(touch)
Internal. Handles touch up events.
Parameters: | touch (MotionEvent) – The data associated with the call. |
-
screen_sweep
()
Animates the screen moving off screen.
-
class
ui_panel.
UI_Panel_Base
(title='DEFAULT', controller=None, **kwargs)
This is the base class for all window type widgets.
Parameters: |
- title (String) – The title to assign to the panel.
- controller (object) – The controller to assign to the panel.
|
Variables: |
- deleted – An observable indicator which signals that the panel should
be removed from screen and from memory.
- color – A 4-tuple representing the rgba color of the panel.
- controller – The panel’s controller.
- title – The panel’s title. Includes BB code formatting.
- do_rotation – Determines if panel is allowed to rotate. Default is
False.
- do_scale – Determines if panel can scale. Default is False.
|
-
on_touch_down
(touch)
Internal. Determines behavior of panel when it recieves a touch down
event.
Parameters: | touch (MotionEvent) – The data associated with the call. |
-
on_touch_up
(touch)
Internal. Determines behavior of panel when it recieves a touch up
event.
Parameters: | touch (MotionEvent) – The data associated with the call. |
-
class
ui_panel.
UI_Panel_Edge
(**kwargs)
A control with touch collisions defined to resize the parent widget. To do
this, the widget defines a grab concept. It’s basically a boolean status
that determines if subsequent interactions by touches or mouse continue
to affect the widget.
Variables: |
- right_drag – A bool that indicates if right border is being dragged.
- left_drag – A bool that indicates if the left border is being dragged.
- top_drag – A bool that indicates if the top border is being dragged.
- bottom_drag – A bool that indicates if the bottom border is being
dragged.
- trunk – The panel that is the parent of this edge.
|
-
on_touch_down
(touch)
Internal. Handles touch down events. This will cause this object to
grab the touch and consume the event if it is within the collision
boundaries.
Parameters: | touch (MotionEvent) – The touch data associated with the call. |
-
on_touch_move
(touch)
Internal. Responds to touch move events if the touch is grabbed.
Parameters: | touch (MotionEvent) – The touch data associated with the move event. |
-
on_touch_up
(touch)
Internal. Responds to touch up events. Will ungrab the touch if the
touch is currently grabbed by this object.
Parameters: | touch (MotionEvent) – The touch data associated with the touch up event. |
-
class
ui_panel.
UI_Title
(**kwargs)
Determines the look/feel of title bars. Titlebars have two text
regions. The first is intended for an icon character while the second is
for the actual title.
Variables: |
- curr_color – The titlebar’s current color.
- l1_text – The region intended for an icon or id.
- l2_text – The region intended for the actual titlebar text.
- l1_padding –
- l2_padding –
|