Skip to content

Commit

Permalink
pylint controlstest.py
Browse files Browse the repository at this point in the history
  • Loading branch information
GadgetSteve committed Dec 1, 2015
1 parent 098d80d commit b8b7117
Showing 1 changed file with 58 additions and 46 deletions.
104 changes: 58 additions & 46 deletions site-packages/visual/examples/controlstest.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,62 @@
from visual import *
from visual.controls import *

#############################################################################
# See the example program widgets.py for an alternative to visual.controls #
#############################################################################

#!/usr/bin/env python
#coding:utf-8
""" Visual Controls Example.
See the example program widgets.py for an alternative to visual.controls
"""

from __future__ import print_function, division
#from visual import *
import visual as vp
#from visual.controls import *
import visual.controls as ctrls
import math
# Create "call-back" routines, routines that are called by the interact
# machinery when certain mouse events happen:

def setdir(direction): # called on button up events
cube.dir = direction
def setdir(direction): #
""" called on button up events."""
CUBE.dir = direction

def togglecubecolor(): # called on toggle switch flips
if t1.value:
cube.color = color.cyan
def togglecubecolor():
"""called on toggle switch flips"""
if T1.value:
CUBE.color = vp.color.cyan
else:
cube.color = color.red
CUBE.color = vp.color.red

def cubecolor(value): # called on a menu choice
cube.color = value
if cube.color == color.red:
t1.value = 0 # make toggle switch setting consistent with menu choice
def cubecolor(value):
""" called on a menu choice"""
CUBE.color = value
if CUBE.color == vp.color.red:
T1.value = 0 # make toggle switch setting consistent with menu choice
else:
t1.value = 1

def setrate(obj): # called on slider drag events
T1.value = 1

def setrate(obj):
""" called on slider drag events"""
cuberate(obj.value) # value is min-max slider position
if obj is s1:
s2.value = s1.value # demonstrate coupling of the two sliders
if obj is S1:
S2.value = S1.value # demonstrate coupling of the two sliders
else:
s1.value = s2.value
S1.value = S2.value

def cuberate(value):
cube.dtheta = 2*value*pi/1e4
""" Get a rate for the cube."""
CUBE.dtheta = 2*value* math.pi/1e4

w = 350
display(x=w, y=0, width=w, height=w, range=1.5, forward=-vector(0,1,1))
cube = box(color=color.red)
WDT = 350
vp.display(x=WDT, y=0, width=WDT, height=WDT, range=1.5, forward=-vp.vector(0, 1, 1))
CUBE = vp.box(color=vp.color.red)

# In establishing the controls window, range=60 means what it usually means:
# (0,0) is in the center of the window, and (60,60) is the lower right corner.
# If range is not specified, the default is 100.
c = controls(x=0, y=0, width=w, height=w, range=60)
C = ctrls.controls(x=0, y=0, width=WDT, height=WDT, range=60)

# Buttons have a "text" attribute (the button label) which can be read and set.
# Toggles have "text0" and "text1" attributes which can be read and set.
# Toggles and sliders have a "value" attribute (0/1, or location of indicator) which can be read and set.
# Toggles and sliders have a "value" attribute (0/1, or location of indicator)
# which can be read and set.

# The pos attribute for buttons, toggles, and menus is the center of the control (like "box").
# The pos attribute for sliders is at one end, and axis points to the other end (like "cylinder").
Expand All @@ -58,25 +69,26 @@ def cuberate(value):
# is to be taken. This scheme ensures that the execution of the function takes place
# in the appropriate namespace context in the case of importing the controls module.

bl = button(pos=(-30,30), height=30, width=40, text='Left', action=lambda: setdir(-1))
br = button(pos=(30,30), height=30, width=40, text='Right', action=lambda: setdir(1))
s1 = slider(pos=(-15,-40), width=7, length=70, axis=(1,0.7,0), action=lambda: setrate(s1))
s2 = slider(pos=(-30,-50), width=7, length=50, axis=(0,1,0), action=lambda: setrate(s2))
t1 = toggle(pos=(40,-30), width=10, height=10, text0='Red', text1='Cyan', action=lambda: togglecubecolor())
m1 = menu(pos=(0,0,0), height=7, width=25, text='Options')
BL = ctrls.button(pos=(-30, 30), height=30, width=40, text='Left', action=lambda: setdir(-1))
BR = ctrls.button(pos=(30, 30), height=30, width=40, text='Right', action=lambda: setdir(1))
S1 = ctrls.slider(pos=(-15, -40), width=7, length=70, axis=(1, 0.7, 0), action=lambda: setrate(S1))
S2 = ctrls.slider(pos=(-30, -50), width=7, length=50, axis=(0, 1, 0), action=lambda: setrate(S2))
T1 = ctrls.toggle(pos=(40, -30), width=10, height=10, text0='Red', text1='Cyan',
action=lambda: togglecubecolor())
M1 = ctrls.menu(pos=(0, 0, 0), height=7, width=25, text='Options')

# After creating the menu heading, add menu items:
m1.items.append(('Left', lambda: setdir(-1))) # specify menu item title and action to perform
m1.items.append(('Right', lambda: setdir(1)))
m1.items.append(('---------',None)) # a dummy separator
m1.items.append(('Red', lambda: cubecolor(color.red)))
m1.items.append(('Cyan', lambda: cubecolor(color.cyan)))

s1.value = 70 # update the slider
setrate(s1) # set the rotation rate of the cube
M1.items.append(('Left', lambda: setdir(-1))) # specify menu item title and action to perform
M1.items.append(('Right', lambda: setdir(1)))
M1.items.append(('---------', None)) # a dummy separator
M1.items.append(('Red', lambda: cubecolor(vp.color.red)))
M1.items.append(('Cyan', lambda: cubecolor(vp.color.cyan)))

S1.value = 70 # update the slider
setrate(S1) # set the rotation rate of the cube
setdir(-1) # set the rotation direction of the cube

while True:
rate(100)
cube.rotate(axis=(0,1,0), angle=cube.dir*cube.dtheta)
vp.rate(100)
CUBE.rotate(axis=(0, 1, 0), angle=CUBE.dir*CUBE.dtheta)

0 comments on commit b8b7117

Please sign in to comment.