Skip to content

Commit

Permalink
Implement winput
Browse files Browse the repository at this point in the history
  • Loading branch information
BruceSherwood committed Nov 7, 2018
1 parent e8d1002 commit 6c74af9
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 7 deletions.
53 changes: 49 additions & 4 deletions vpython/vpython.py
Expand Up @@ -15,8 +15,8 @@
from ._vector_import_helper import (vector, mag, norm, dot, adjust_up,
adjust_axis, object_rotate)

# List of names that will be imported form this file with import *
__all__ = ['Camera', 'GlowWidget', 'GSversion', 'Mouse', 'arrow', 'attach_arrow',
# List of names that will be imported from this file with import *
__all__ = ['Camera', 'GlowWidget', 'version', 'GSversion', 'Mouse', 'arrow', 'attach_arrow',
'attach_trail', 'baseObj', 'box', 'bumpmaps', 'button',
'canvas', 'checkbox', 'clock', 'color', 'combin', 'compound', 'cone', 'controls',
'curve', 'curveMethods', 'cylinder', 'distant_light', 'ellipsoid',
Expand All @@ -25,7 +25,7 @@
'local_light', 'menu', 'meta_canvas', 'points', 'pyramid',
'quad', 'radio', 'ring', 'simple_sphere', 'sleep', 'slider', 'sphere',
'standardAttributes', 'text', 'textures', 'triangle', 'vertex',
'wtext']
'wtext', 'winput']

__p = platform.python_version()
_ispython3 = (__p[0] == '3')
Expand Down Expand Up @@ -360,6 +360,9 @@ def handle_msg(self, msg):
obj._checked = evt['value']
elif evt['widget'] == 'radio':
obj._checked = evt['value']
elif evt['widget'] == 'winput':
obj._text = evt['text']
obj._number = evt['value']
# inspect the bound function and see what it's expecting
if _ispython3: # Python 3
a = signature(obj._bind)
Expand Down Expand Up @@ -3296,7 +3299,8 @@ class controls(baseObj):
'radio':['checked', 'text', 'disabled'],
'menu':['selected', 'choices', 'index', 'disabled'],
'slider':['vertical', 'min', 'max', 'step', 'value', 'length',
'width', 'left', 'right', 'top', 'bottom', 'align', 'disabled']
'width', 'left', 'right', 'top', 'bottom', 'align', 'disabled'],
'winput':['width', 'height', 'text', 'type', 'disabled']
}
def setup(self, args):
super(controls, self).__init__() ## get idx, attrsupdt from baseObj
Expand Down Expand Up @@ -3479,6 +3483,47 @@ def checked(self, value):
if not self._constructing:
self.addattr('checked')

class winput(controls):
def __init__(self, **args):
args['_objName'] = 'winput'
self._checked = False
self._text = ''
self._type = 'numeric'
self._number = None
self._width = 100
self._height = 20
super(winput, self).setup(args)

@property
def text(self):
return self._text
@text.setter
def text(self, value):
self._text = value
if not self._constructing:
self.addattr('text')

@property
def number(self):
return self._number
@number.setter
def number(self, value):
raise AttributeError('Cannot change the winput number attribute.')

@property
def width(self):
return self._width
@width.setter
def width(self, value):
raise AttributeError('Cannot change the winput width attribute.')

@property
def type(self):
return self._type
@type.setter
def type(self, value):
raise AttributeError('Cannot change the winput type attribute.')

class menu(controls):
def __init__(self, **args):
args['_objName'] = 'menu'
Expand Down
2 changes: 1 addition & 1 deletion vpython/vpython_libraries/glow.min.js

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion vpython/vpython_libraries/glowcomm.html
Expand Up @@ -308,7 +308,7 @@

var sliders = {}

function control_handler(obj) { // button, menu, slider, radio, checkbox
function control_handler(obj) { // button, menu, slider, radio, checkbox, winput
"use strict";
var evt = {idx: obj.idx}
if (obj.objName === 'button') {
Expand All @@ -330,6 +330,10 @@
} else if (obj.objName === 'menu') {
evt.value = obj.index
evt.widget = 'menu'
} else if (obj.objName === 'winput') {
evt.text = obj.text
evt.value = obj.number
evt.widget = 'winput'
} else {
console.log('unrecognized control', 'obj=', obj, obj.text)
}
Expand Down Expand Up @@ -707,6 +711,13 @@
cfg = fix_location(cfg)
glowObjs[idx] = wtext(cfg)
break
}
case 'winput': {
cfg.objName = obj
cfg.bind = control_handler
cfg = fix_location(cfg)
glowObjs[idx] = winput(cfg)
break
}
case 'checkbox': {
cfg.objName = obj
Expand Down
13 changes: 12 additions & 1 deletion vpython/vpython_libraries/glowcomm.js
Expand Up @@ -338,7 +338,7 @@ function process_binding(event) { // event associated with a previous bind comma

var sliders = {}

function control_handler(obj) { // button, menu, slider, radio, checkbox
function control_handler(obj) { // button, menu, slider, radio, checkbox, winput
"use strict";
var evt = {idx: obj.idx}
if (obj.objName === 'button') {
Expand All @@ -360,6 +360,10 @@ function control_handler(obj) { // button, menu, slider, radio, checkbox
} else if (obj.objName === 'menu') {
evt.value = obj.index
evt.widget = 'menu'
} else if (obj.objName === 'winput') {
evt.text = obj.text
evt.value = obj.number
evt.widget = 'winput'
} else {
console.log('unrecognized control', 'obj=', obj, obj.text)
}
Expand Down Expand Up @@ -750,6 +754,13 @@ function handle_cmds(dcmds) {
cfg = fix_location(cfg)
glowObjs[idx] = wtext(cfg)
break
}
case 'winput': {
cfg.objName = obj
cfg.bind = control_handler
cfg = fix_location(cfg)
glowObjs[idx] = winput(cfg)
break
}
case 'checkbox': {
cfg.objName = obj
Expand Down

0 comments on commit 6c74af9

Please sign in to comment.