Project

General

Profile

Link to Exercise 8 solution » History » Version 1

Guijarro, Matias, 02/02/2012 11:56 PM

1 1 Guijarro, Matias
h1. Link to Exercise 8 solution
2 1 Guijarro, Matias
3 1 Guijarro, Matias
<pre>
4 1 Guijarro, Matias
<code class="Python">
5 1 Guijarro, Matias
from Framework4.GUI import Core
6 1 Guijarro, Matias
from Framework4.GUI.Core import Property, PropertyGroup, Connection, Signal, Slot
7 1 Guijarro, Matias
import FoilsWidget
8 1 Guijarro, Matias
9 1 Guijarro, Matias
class FoilsBrick(Core.BaseBrick):
10 1 Guijarro, Matias
  description = "FWK4 training Foils brick"
11 1 Guijarro, Matias
  properties = {}
12 1 Guijarro, Matias
  connections =  { "foils control": Connection("Foils Control",
13 1 Guijarro, Matias
                                               [Signal("foilChanged", "foilChanged"),
14 1 Guijarro, Matias
                                                Signal("stateChanged", "foilStateChanged")],
15 1 Guijarro, Matias
                                               [Slot("set_foil"), Slot("get_positions")],
16 1 Guijarro, Matias
                                               "isConnected")}
17 1 Guijarro, Matias
18 1 Guijarro, Matias
  def init(self):
19 1 Guijarro, Matias
    self.foils_widget = FoilsWidget.FoilsWidget(self.brick_widget, onFoilSelected=self.changeFoil)
20 1 Guijarro, Matias
    FoilsWidget.QtGui.QVBoxLayout(self.brick_widget)
21 1 Guijarro, Matias
    self.brick_widget.layout().addWidget(self.foils_widget)
22 1 Guijarro, Matias
23 1 Guijarro, Matias
  def isConnected(self, foils_control_object):
24 1 Guijarro, Matias
    self.foils_control_object = foils_control_object
25 1 Guijarro, Matias
26 1 Guijarro, Matias
    if foils_control_object:
27 1 Guijarro, Matias
      self.foils_widget.setEnabled(True)
28 1 Guijarro, Matias
29 1 Guijarro, Matias
      self.foils_widget.setLabel(foils_control_object.username())
30 1 Guijarro, Matias
      self.foils_widget.setFoils([name for name, _ in foils_control_object.get_positions()])
31 1 Guijarro, Matias
    else:
32 1 Guijarro, Matias
      self.foils_widget.setEnabled(False)
33 1 Guijarro, Matias
      self.foils_widget.setFoils([])
34 1 Guijarro, Matias
35 1 Guijarro, Matias
  def foilChanged(self, new_foil_name):
36 1 Guijarro, Matias
    self.foils_widget.setFoil(new_foil_name)
37 1 Guijarro, Matias
38 1 Guijarro, Matias
  def foilStateChanged(self, new_state):
39 1 Guijarro, Matias
    self.foils_widget.setState(new_state)
40 1 Guijarro, Matias
41 1 Guijarro, Matias
  def changeFoil(self, new_foil_name):
42 1 Guijarro, Matias
    self.foils_control_object.set_foil(new_foil_name)
43 1 Guijarro, Matias
</code>
44 1 Guijarro, Matias
</pre>