How to use the vpython.vpython.controls function in vpython

To help you get started, we’ve selected a few vpython examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vpython / vpython-jupyter / vpython / vpython.py View on Github external
def setup(self, args):
        super(controls, self).__init__()  ## get idx, attrsupdt from baseObj
        ## default values of common attributes
        self._constructing = True
        argsToSend = []
        objName = args['_objName']
        del args['_objName']
        if 'pos' in args:
            self.location = args['pos']
            argsToSend.append('location')
            del args['pos']
        if 'canvas' in args:  ## specified in constructor
            self.canvas = args['canvas']
            del args['canvas']
        else:
            self.canvas = canvas.get_selected()
        if 'bind' in args:
            self._bind = args['bind']
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
    @text.setter
    def text(self, value):
        self._text = value
        if not self._constructing:
            self.addattr('text')
            
    @property
    def checked(self):
        return self._checked
    @checked.setter
    def checked(self, value):
        self._checked = value
        if not self._constructing:
            self.addattr('checked')
            
class menu(controls):
    def __init__(self, **args):
        args['_objName'] = 'menu'
        self._selected = "None"
        self._choices = args['choices']
        if 'index' in args:
            args['selected'] = self._choices[ args['index'] ]
            del args['index']
        super(menu, self).setup(args)
        
    @property
    def choices(self):
        return self._choices
    @choices.setter
    def choices(self, value):
        raise AttributeError('choices cannot be modified after a menu is created')
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
    @property
    def selected(self):
        if self._selected == "None":
            return None
        else:
            return self._selected
    @selected.setter
    def selected(self, value):
        if value is None:
            value = "None"
        self._selected = value
        if not self._constructing:
            self.addattr('selected')
            
class slider(controls):
    def __init__(self, **args): 
        args['_objName'] = 'slider'
        self._vertical = False
        if 'min' in args:  ## set here in order to set step
            self._min = args['min']
        else:
            self._min = 0
        if 'max' in args:
            self._max = args['max']
        else:
            self._max = 1
        self._step = 0.001*(self._max - self._min)
        self._value = self._min
        self._length = 400
        self._width = 10
        self._left = 0
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
    @property
    def selected(self):
        if self._selected == "None":
            return None
        else:
            return self._selected
    @selected.setter
    def selected(self, value):
        if value is None:
            value = "None"
        self._selected = value
        if not self._constructing:
            self.addattr('selected')
            
class slider(controls):
    def __init__(self, **args): 
        args['_objName'] = 'slider'
        self._vertical = False
        if 'min' in args:  ## set here in order to set step
            self._min = args['min']
        else:
            self._min = 0
        if 'max' in args:
            self._max = args['max']
        else:
            self._max = 1
        self._step = 0.001*(self._max - self._min)
        self._value = self._min
        self._length = 400
        self._width = 10
        self._left = 0
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
    @background.setter
    def background(self, value):
        self._background = value
        if not self._constructing:
            self.addattr('background')
            
    @property
    def disabled(self):
        return self._disabled
    @disabled.setter
    def disabled(self, value):
        self._disabled = value
        if not self._constructing:
            self.addattr('disabled')

class checkbox(controls): 
    def __init__(self, **args):
        args['_objName'] = 'checkbox'
        self._checked = False
        self._text = ''
        super(checkbox, 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
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
    @text.setter
    def text(self, value):
        self._text = value
        if not self._constructing:
            self.addattr('text')
            
    @property
    def checked(self):
        return self._checked
    @checked.setter
    def checked(self, value):
        self._checked = value
        if not self._constructing:
            self.addattr('checked')
            
class radio(controls):
    def __init__(self, **args):
        args['_objName'] = 'radio'
        self._checked = False
        self._text = ''
        super(radio, 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
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
    @text.setter
    def text(self, value):
        self._text = value
        if not self._constructing:
            self.addattr('text')
            
    @property
    def checked(self):
        return self._checked
    @checked.setter
    def checked(self, value):
        self._checked = value
        if not self._constructing:
            self.addattr('checked')
            
class radio(controls):
    def __init__(self, **args):
        args['_objName'] = 'radio'
        self._checked = False
        self._text = ''
        super(radio, 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
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
    @text.setter
    def text(self, value):
        self._text = value
        if not self._constructing:
            self.addattr('text')
            
    @property
    def checked(self):
        return self._checked
    @checked.setter
    def checked(self, value):
        self._checked = value
        if not self._constructing:
            self.addattr('checked')
            
class menu(controls):
    def __init__(self, **args):
        args['_objName'] = 'menu'
        self._selected = "None"
        self._choices = args['choices']
        if 'index' in args:
            args['selected'] = self._choices[ args['index'] ]
            del args['index']
        super(menu, self).setup(args)
        
    @property
    def choices(self):
        return self._choices
    @choices.setter
    def choices(self, value):
        raise AttributeError('choices cannot be modified after a menu is created')
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
    @background.setter
    def background(self, value):
        self._background = vector(value)
        if not self._constructing:
            self.addattr('background')
            
    @property
    def disabled(self):
        return self._disabled
    @disabled.setter
    def disabled(self, value):
        self._disabled = value
        if not self._constructing:
            self.addattr('disabled')

class checkbox(controls): 
    def __init__(self, **args):
        args['_objName'] = 'checkbox'
        self._checked = False
        self._text = ''
        super(checkbox, 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
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
else:
            raise AttributeError('bind missing')
            
        ## override default vector attributes        
        vectorAttributes = ['textcolor', 'background']        
        for a in vectorAttributes:
            if a in args:
                argsToSend.append(a)
                val = args[a]
                if isinstance(val, vector): setattr(self, '_'+a, val)
                else: raise AttributeError(a+' must be a vector')
                del args[a]        
        ## override default scalar attributes

        for a,val in args.items():
            if a in controls.attrlists[objName]:
                argsToSend.append(a)
                setattr(self, '_'+a, val)
            else:
                setattr(self, a, val)
        cmd = {"cmd": objName, "idx": self.idx, "attrs":[]}
        cmd["attrs"].append({"attr": 'canvas', "value": self.canvas.idx})        
                
        ## send only args specified in constructor
        for a in argsToSend:  ## all shared attributes are scalars
            aval = getattr(self,a)
            if isinstance(aval, vector):
                aval = aval.value
            cmd["attrs"].append({"attr":a, "value": aval})
            
        self.appendcmd(cmd)                     
        self._constructing = False