Project

General

Profile

Info Bricks » History » Version 3

Ohlsson, Staffan, 20/01/2012 08:23 AM

1 1 Ohlsson, Staffan
{{toc}} 
2 1 Ohlsson, Staffan
3 1 Ohlsson, Staffan
h1. Bricks
4 1 Ohlsson, Staffan
5 1 Ohlsson, Staffan
h2. Overview of a Brick
6 1 Ohlsson, Staffan
7 1 Ohlsson, Staffan
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. 
8 1 Ohlsson, Staffan
9 1 Ohlsson, Staffan
h2. Architecture
10 1 Ohlsson, Staffan
11 1 Ohlsson, Staffan
A Brick is a class inheriting from Framework4.GUI.Core.BaseBrick.
12 1 Ohlsson, Staffan
13 1 Ohlsson, Staffan
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.
14 1 Ohlsson, Staffan
15 1 Ohlsson, Staffan
The definition is stored in the 'connections' variable in the brick class. It has the form:
16 1 Ohlsson, Staffan
17 1 Ohlsson, Staffan
<pre>
18 1 Ohlsson, Staffan
connections = { 'connection_name': Connection([Signal('signal_name'), ...], [Slot('slot_name'), ...], 'status_function_name') }
19 1 Ohlsson, Staffan
</pre>
20 1 Ohlsson, Staffan
21 1 Ohlsson, Staffan
The Connection, Signal and Slot classes are located in the Framework4.GUI.Core package.
22 1 Ohlsson, Staffan
23 1 Ohlsson, Staffan
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).
24 1 Ohlsson, Staffan
25 1 Ohlsson, Staffan
The Brick must also have an init method, with no arguments. This method is called by the framework after the brick has been instantiated.
26 1 Ohlsson, Staffan
27 1 Ohlsson, Staffan
The Brick class may also have a 'properties' variable. *TODO* _: describe this_ 
28 1 Ohlsson, Staffan
29 2 Ohlsson, Staffan
h2. Particularities when using object groups
30 1 Ohlsson, Staffan
31 2 Ohlsson, Staffan
When using object groups, the group contains Pyro proxies to the control objects. Since the connections cannot be made using the normal mechanism (the connections definition), they must be established manually. This is done using the Core.BaseBrick connectObject method. It is used as follow:
32 2 Ohlsson, Staffan
33 2 Ohlsson, Staffan
<pre>
34 2 Ohlsson, Staffan
self.connectObject(pyro_proxy, 'signal_name', callback_for_signal) 
35 2 Ohlsson, Staffan
</pre>
36 2 Ohlsson, Staffan
37 1 Ohlsson, Staffan
h2. Commented Brick code example
38 2 Ohlsson, Staffan
39 2 Ohlsson, Staffan
<pre>
40 3 Ohlsson, Staffan
<code class=Python>
41 2 Ohlsson, Staffan
from Framework4.Control.Core.CObject import CObjectBase, Signal, Slot
42 2 Ohlsson, Staffan
43 2 Ohlsson, Staffan
class Shutter(CObjectBase):
44 2 Ohlsson, Staffan
    signals = [ Signal("statusChanged"), Signal("stateChanged") ]
45 2 Ohlsson, Staffan
    slots = [ Slot("open"), Slot("close") ]
46 2 Ohlsson, Staffan
   
47 2 Ohlsson, Staffan
    shutterState = {
48 2 Ohlsson, Staffan
        0: 'unknown',
49 2 Ohlsson, Staffan
        3: 'closed',
50 2 Ohlsson, Staffan
        4: 'opened',
51 2 Ohlsson, Staffan
        9: 'moving',
52 2 Ohlsson, Staffan
        17: 'automatic',
53 2 Ohlsson, Staffan
        23: 'fault',
54 2 Ohlsson, Staffan
        46: 'disabled',
55 2 Ohlsson, Staffan
        -1: 'error'
56 2 Ohlsson, Staffan
    }
57 2 Ohlsson, Staffan
 
58 2 Ohlsson, Staffan
    def __init__(self, *args, **kwargs):
59 2 Ohlsson, Staffan
        CObjectBase.__init__(self, *args, **kwargs)
60 2 Ohlsson, Staffan
61 2 Ohlsson, Staffan
62 2 Ohlsson, Staffan
    def init(self):
63 2 Ohlsson, Staffan
        self.shutter_state = "unknown"
64 2 Ohlsson, Staffan
65 2 Ohlsson, Staffan
        status_chan = self.channels.get("status")
66 2 Ohlsson, Staffan
        if status_chan is not None:
67 2 Ohlsson, Staffan
            status_chan.connect("update", self.statusChanged)
68 2 Ohlsson, Staffan
69 2 Ohlsson, Staffan
        state_chan = self.channels.get("state")
70 2 Ohlsson, Staffan
        if state_chan is not None:
71 2 Ohlsson, Staffan
            state_chan.connect("update", self.stateChanged)
72 2 Ohlsson, Staffan
        
73 2 Ohlsson, Staffan
74 2 Ohlsson, Staffan
    def connectNotify(self, signal_name):
75 2 Ohlsson, Staffan
        if signal_name == 'statusChanged':
76 2 Ohlsson, Staffan
          status_chan = self.channels.get("status")
77 2 Ohlsson, Staffan
          if status_chan is not None: self.statusChanged(status_chan.value())
78 2 Ohlsson, Staffan
        elif signal_name == 'stateChanged':
79 2 Ohlsson, Staffan
          state_chan = self.channels.get("state")
80 2 Ohlsson, Staffan
          if state_chan is not None: self.stateChanged(state_chan.value())
81 2 Ohlsson, Staffan
82 2 Ohlsson, Staffan
83 2 Ohlsson, Staffan
    def open(self):
84 2 Ohlsson, Staffan
        print '********** OPEN****************'
85 2 Ohlsson, Staffan
        self.commands['open']()
86 2 Ohlsson, Staffan
87 2 Ohlsson, Staffan
88 2 Ohlsson, Staffan
    def close(self):
89 2 Ohlsson, Staffan
        print '***********CLOSE *******************'
90 2 Ohlsson, Staffan
        self.commands['close']()
91 2 Ohlsson, Staffan
        
92 2 Ohlsson, Staffan
93 2 Ohlsson, Staffan
    def statusChanged(self, status):
94 2 Ohlsson, Staffan
        self.emit("statusChanged", status)
95 2 Ohlsson, Staffan
96 2 Ohlsson, Staffan
97 2 Ohlsson, Staffan
    def stateChanged(self, state):
98 2 Ohlsson, Staffan
        self.shutter_state = Shutter.shutterState.get(state, "unknown")
99 1 Ohlsson, Staffan
        self.emit("stateChanged", self.shutter_state)
100 3 Ohlsson, Staffan
101 2 Ohlsson, Staffan
</code></pre>