Created
July 30, 2013 06:31
-
-
Save anonymous/6110768 to your computer and use it in GitHub Desktop.
HCameraApp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Hydrogen import * | |
from HydrogenLayouts import HColumnLayout, HBarLayout | |
class Camera(object): | |
def __init__(self, name): | |
self.name = name | |
self.sensitivity = 0.0 | |
self.is_on = False | |
def __str__(self): | |
on_off = 'ON' if self.is_on else 'OFF' | |
return self.name + ' is ' + on_off + ', Sensitivity = ' + str(self.sensitivity) | |
class HCameraApp(HScene): | |
def setup(self): | |
self.cameras = self.create_cameras(10) | |
self.add_local_laf() | |
self.build_gui() | |
def create_cameras(self, cams): | |
cameras = [] | |
for c in xrange(cams): | |
cameras.append(Camera('Camera ' + str(c))) | |
return cameras | |
def add_local_laf(self): | |
LAF['Font Size'] = 16 | |
LAF['Top Selection Bar Background'] = (1.00, 1.00, 1.00, 1.00) | |
LAF['Top Selection Bar Shape'] = round_top_rect | |
LAF['Bottom Selection Bar Background'] = (1.00, 1.00, 1.00, 1.00) | |
LAF['Bottom Selection Bar Shape'] = round_bottom_rect | |
LAF['Selection Bar Background'] = (1.00, 1.00, 1.00, 1.00) | |
LAF['Selection Bar Shape'] = rectangle | |
LAF['Spacer Show Background'] = False | |
LAF['Spacer Show Border'] = False | |
def build_gui(self): | |
panel = HContainer() | |
panel.layout = HColumnLayout(panel) | |
panel.layout.pad = HInset(0, 0, -0.5, -0.5) | |
panel.insets = HInset(10, 10, 10, 10) | |
panel.add_component(HText("HCameraApp")) | |
spacer = HComponent() | |
spacer.laf_prefix = "Spacer " | |
spacer.preferred_size = Size(10, 10) | |
panel.add_component(spacer) | |
barInfos = [] | |
for i, cam in enumerate(self.cameras): | |
barInfos.append(('', cam.name + ' ', cam)) | |
barInfos[0] = ('Top ', barInfos[0][1], barInfos[0][2]) | |
barInfos[len(barInfos) - 1] = ('Bottom ', barInfos[len(barInfos) - 1][1], barInfos[len(barInfos) - 1][2]) | |
for barInfo in barInfos: | |
bar = HContainer() | |
bar.laf_prefix = '{}Selection Bar '.format(barInfo[0]) | |
bar.layout = HBarLayout(bar) | |
bar.layout.pad = HInset(5, 5, 5, 5) | |
bar.add_component(HText(barInfo[1]), 'left') | |
switch = HSwitch() | |
switch.id = barInfo[2] | |
switch.change_listeners.append(self.switch_changed) | |
bar.add_component(switch, 'center') | |
slider = HSlider() | |
slider.id = barInfo[2] | |
slider.change_listeners.append(self.slider_changed) | |
bar.add_component(slider, 'right') | |
panel.add_component(bar) | |
panel.add_component(spacer) | |
self.change_text = HText('Camera Status') | |
panel.add_component(self.change_text) | |
self.add_component(panel) | |
panel.bounds.x = (self.bounds.w - panel.bounds.w) / 2 | |
panel.bounds.y = (self.bounds.h - panel.bounds.h) / 2 | |
def switch_changed(self, switch): | |
camera = switch.id | |
camera.is_on = switch.is_selected | |
self.change_text.set_text(camera.__str__()) | |
def slider_changed(self, slider): | |
camera = slider.id | |
camera.sensitivity = int(slider.value * 100) | |
self.change_text.set_text(camera.__str__()) | |
run(HCameraApp()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment