Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import print_function
- import sys
- from collections import OrderedDict
- from vcScript import *
- class Button(object):
- """
- switch := button is pressed
- light := light is on
- """
- def __init__(self, name, true_color='light_green', false_color='dark_green'):
- comp = getComponent()
- app = getApplication()
- self.app = app
- self.comp = comp
- comp.Material = None
- comp.update()
- app.render()
- self.name = name
- self.true_color = app.findMaterial(true_color)
- self.false_color = app.findMaterial(false_color)
- self.node = comp.findNode('Link_' + name)
- self.node.MaterialInheritance = VC_MATERIAL_FORCE_INHERIT_NODE
- # print(self.node.Name)
- self._option = comp.getProperty('Options::' + name)
- self._input = comp.findBehaviour('Signals::{}_pressed'.format(name))
- self._output = comp.findBehaviour('Signals::{}_light'.format(name))
- if self._output:
- self._output.OnValueChange = self.light_changed
- self._joginfo = comp.findBehaviour('{}_joginfo'.format(name))
- self._joginfo.OnInteract = self.pressed
- def light_changed(self, property):
- if self.light:
- self.node.NodeMaterial = self.true_color
- else:
- self.node.NodeMaterial = self.false_color
- self.comp.update()
- self.app.render()
- def pressed(self, behaviour, action, data):
- if action == 1:
- self.state = not self.state
- self.switch = self.state
- self.comp.update()
- self.app.render()
- @property
- def switch(self):
- return self._input.Value
- @switch.setter
- def switch(self, value):
- print('Setting value for switch', self._input.Name, 'to', value)
- # direct write to Value of the property does
- # not work
- # the methdod signal must be used to set the new value
- self._input.signal(value)
- @property
- def light(self):
- return self._output.Value
- @property
- def state(self):
- return self._option.Value
- @state.setter
- def state(self, value):
- self._option.Value = value
- def __repr__(self):
- return 'Button("{}")'.format(self.name)
- __str__ = __repr__
- class Buttons(object):
- def __init__(self, switches, true_color, false_color):
- self._buttons = OrderedDict()
- for sw in switches:
- self._buttons[sw] = Button(sw, true_color, false_color)
- def __repr__(self):
- return 'Buttons([{}])'.format(self.switches)
- __str__ = __repr__
- def __getitem__(self, key):
- return self._buttons[key]
- __getattr__ = __getitem__
- if __name__ == '__main__':
- print(sys.version)
- app = getApplication()
- switches = ('Start', 'Stop', 'ACK', 'REF', 'Reset')
- buttons = Buttons(switches, 'light_red', 'dark_red')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement