Project

General

Profile

Bricks

Overview of a Brick

A Brick is a part of a GUI, generally used to display information about a piece of equipment, and/or allow the user to interact with it.

Architecture

A Brick is a class inheriting from Framework4.GUI.Core.BaseBrick.

A Brick is connected to Control Objects when building a new application. Each Brick may define several connections. Each connection specifies which signals and slots the brick expects from the Control Object.

The definition is stored in the 'connections' variable in the brick class. It has the form:

connections = { 'connection_name': Connection([Signal('signal_name'), ...], [Slot('slot_name'), ...], 'status_function_name') }

The Connection, Signal and Slot classes are located in the Framework4.GUI.Core package.

The 'status_function_name' is a string. It is the name of one of the Brick's methods. This method will be called every time the connection is made or lost. It should have one argument (besides self), which will be set to the connection status (true: connected, false: disconnected).

The Brick must also have an init method, with no arguments. This method is called by the framework after the brick has been instantiated.

A Brick code example

from Framework4.Control.Core.CObject import CObjectBase, Signal, Slot

class Shutter(CObjectBase):
    signals = [ Signal("statusChanged"), Signal("stateChanged") ]
    slots = [ Slot("open"), Slot("close") ]

    shutterState = {
        0: 'unknown',
        3: 'closed',
        4: 'opened',
        9: 'moving',
        17: 'automatic',
        23: 'fault',
        46: 'disabled',
        -1: 'error'
    }

    def __init__(self, *args, **kwargs):
        CObjectBase.__init__(self, *args, **kwargs)

    def init(self):
        self.shutter_state = "unknown" 

        status_chan = self.channels.get("status")
        if status_chan is not None:
            status_chan.connect("update", self.statusChanged)

        state_chan = self.channels.get("state")
        if state_chan is not None:
            state_chan.connect("update", self.stateChanged)

    def connectNotify(self, signal_name):
        if signal_name == 'statusChanged':
          status_chan = self.channels.get("status")
          if status_chan is not None: self.statusChanged(status_chan.value())
        elif signal_name == 'stateChanged':
          state_chan = self.channels.get("state")
          if state_chan is not None: self.stateChanged(state_chan.value())

    def open(self):
        print '********** OPEN****************'
        self.commands['open']()

    def close(self):
        print '***********CLOSE *******************'
        self.commands['close']()

    def statusChanged(self, status):
        self.emit("statusChanged", status)

    def stateChanged(self, state):
        self.shutter_state = Shutter.shutterState.get(state, "unknown")
        self.emit("stateChanged", self.shutter_state)