Project

General

Profile

Link to Exercise 8 solution

from Framework4.GUI import Core
from Framework4.GUI.Core import Property, PropertyGroup, Connection, Signal, Slot
import FoilsWidget

class FoilsBrick(Core.BaseBrick):
  description = "FWK4 training Foils brick" 
  properties = {}
  connections =  { "foils control": Connection("Foils Control",
                                               [Signal("foilChanged", "foilChanged"),
                                                Signal("stateChanged", "foilStateChanged")],
                                               [Slot("set_foil"), Slot("get_positions")],
                                               "isConnected")}

  def init(self):
    self.foils_widget = FoilsWidget.FoilsWidget(self.brick_widget, onFoilSelected=self.changeFoil)
    FoilsWidget.QtGui.QVBoxLayout(self.brick_widget)
    self.brick_widget.layout().addWidget(self.foils_widget)

  def isConnected(self, foils_control_object):
    self.foils_control_object = foils_control_object

    if foils_control_object:
      self.foils_widget.setEnabled(True)

      self.foils_widget.setLabel(foils_control_object.username())
      self.foils_widget.setFoils([name for name, _ in foils_control_object.get_positions()])
    else:
      self.foils_widget.setEnabled(False)
      self.foils_widget.setFoils([])

  def foilChanged(self, new_foil_name):
    self.foils_widget.setFoil(new_foil_name)

  def foilStateChanged(self, new_state):
    self.foils_widget.setState(new_state)

  def changeFoil(self, new_foil_name):
    self.foils_control_object.set_foil(new_foil_name)