Пример #1
0
    def __init__(self,
                 value=0,
                 vmin=-sys.maxint - 1,
                 vmax=sys.maxint,
                 vstep=.1,
                 vformat='%.2f',
                 key_increase=key.UP,
                 key_decrease=key.DOWN,
                 getter=None,
                 setter=None,
                 on_change=None):
        ''' Create a numeric entry.

        :Parameters:
        `value` : scalar
            Initial value
        `vmin` : scalar
            Minimum value
        `vmax` : scalar
            Maximum value
        `vstep` : scalar
            Value step increment
        `vformat` : str
            Representation string format
        `key_increase` : char
            Key binding for increasing value
        `key_decrease` : char
            Key binding for decreasing value
        `getter` : function()
            Function to be used to get actual value
        `setter` : function(value)
            Function to be used to set actual value
        `on_change` : function(entry)
            Function to be called when entry has changed
        '''
        self._value = value
        self._vmin = vmin
        self._vmax = vmax
        self._vstep = vstep
        self._vformat = vformat
        self._key_increase = key_increase
        self._key_decrease = key_decrease
        self._setter = setter
        self._getter = getter
        self._on_change = on_change
        self._button_up = Button(u'⬆', on_click=self.increase_value)
        self._button_up._expand[0] = False
        self._button_up.style = theme.ArrowButton
        self._button_down = Button(u'⬇', on_click=self.decrease_value)
        self._button_down._expand[0] = False
        self._button_down.style = theme.ArrowButton
        self._buttons = VBox([self._button_up, self._button_down],
                             homogeneous=True)
        self._buttons._expand[0] = False
        self._entry = Entry(on_change=self._on_commit)
        self._entry._expand[0] = True
        HBox.__init__(self, [self._entry, self._buttons], homogeneous=True)
        if self._getter:
            pyglet.clock.schedule_interval(self._update_value, 0.1)
        self.value = value
Пример #2
0
    def __init__(self, name, label = None,
                 vmin=None, vmax=None, vstep=None, vformat=None,
                 getter=None, setter=None, on_change=None,
                 namespace=locals(), read_only=False):
        ''' '''
        self._name = name
        self._namespace = namespace
        self._read_only = read_only
        self._getter = getter
        self._setter = setter
        self._on_change = on_change
        self._type = None
        if '.' in name:
            self._object = eval(string.join(name.split('.')[:-1],'.'),namespace)
            self._attribute = name.split('.')[-1]
            self._type = type(getattr(self._object, self._attribute))
        else:
            self._object = None
            self._attribute = None
            self._type = type(namespace[name])

        # Create dedicated entry
        if self._type == bool:
            self._entry = BoolEntry(value=self.get(), on_change=on_change,
                                    getter=self.get, setter=self.set)
        elif self._type == int:
            if vmin == None:
                vmin = -sys.maxint-1
            if vmax == None:
                vmax = sys.maxint
            vstep = vstep or 1
            vformat = vformat or '%d'
            self._entry = ScalarEntry(value=self.get(), on_change=on_change,
                                      getter=self.get, setter=self.set,
                                      vmin=vmin, vmax=vmax, vstep=vstep, vformat=vformat)
        elif self._type == float:
            if vmin == None:
                vmin = -sys.maxint-1
            if vmax == None:
                vmax = sys.maxint
            vstep = vstep or 0.1
            vformat = vformat or '%.2f'
            self._entry = ScalarEntry(self.get(), on_change=on_change,
                                      getter=self.get, setter=self.set,
                                      vmin=vmin, vmax=vmax, vstep=vstep,vformat=vformat) 
        elif self._type == str:
            self._entry = TextEntry(self.get(), self.get, self.set, on_change=on_change)
        else:
            self._entry = Label(str(self.get()))

        if self._read_only:
            self._entry.focusable = False
            self._entry.activable = False

        if label:
            self._label = Label(label)
        else:
            self._label = Label(name)        
        HBox.__init__(self, [self._label, self._entry], homogeneous=True)
Пример #3
0
    def __init__(self, value=0, vmin=-sys.maxint-1, vmax=sys.maxint, vstep=.1,
                 vformat='%.2f', key_increase=key.UP, key_decrease=key.DOWN,
                 getter=None, setter=None, action=None):
        ''' Create a numeric entry.

        :Parameters:
        `value` : scalar
            Initial value
        `vmin` : scalar
            Minimum value
        `vmax` : scalar
            Maximum value
        `vstep` : scalar
            Value step increment
        `vformat` : str
            Representation string format
        `key_increase` : char
            Key binding for increasing value
        `key_decrease` : char
            Key binding for decreasing value
        `getter` : function()
            Function to be used to get actual value
        `setter` : function(value)
            Function to be used to set actual value
        `action` : function(widget)
            Action to be executed when entry has changed
        '''
        self._value = value
        self._vmin = vmin
        self._vmax = vmax
        self._vstep = vstep
        self._vformat = vformat
        self._key_increase = key_increase
        self._key_decrease = key_decrease
        self._setter = setter
        self._getter = getter
        self._action = action
        self._button_up = Button(u'⬆', action=self.increase_value)
        self._button_up._expand[0] = False
        self._button_up.style = theme.ArrowButton
        self._button_down = Button(u'⬇', action=self.decrease_value)
        self._button_down._expand[0] = False
        self._button_down.style = theme.ArrowButton
        self._buttons = VBox([self._button_up, self._button_down], homogeneous=True)
        self._buttons._expand[0] = False
        self._entry = Entry(action=self._on_commit)
        self._entry._expand[0] = True
        HBox.__init__(self, [self._entry, self._buttons], homogeneous=True)
        if self._getter:
            pyglet.clock.schedule_interval(self._update_value, 0.1)
        self.value = value
Пример #4
0
    def __init__(self, name, label = None,
                 vmin=None, vmax=None, vstep=None, vformat=None,
                 getter=None, setter=None, action=None,
                 namespace=None, read_only=False):
        '''
        Create a new variable.

        :Parameters:
        
        `name` : str
            Name of the variable
        `label` : str
            Label to be displayed next to variable value
        `vmin` : float
            Minimum value of variable (only for scalar variables)
        `vmax` : float
            Maximum value of variable (only for scalar variables)
        `vstep` : float
            Value step increment (only for scalar variables)
        `vformat` : str
            Variable representatin format
        `getter` : function()
            Function to be used to get actual value
        `setter` : function(value)
            Function to be used to set actual value
        `action` : function(widget)
            Action to be executed when entry has changed
        '''
        self._name = name
        self._namespace = namespace
        self._read_only = read_only
        self._getter = getter
        self._setter = setter
        self._action = action
        self._type = None
        if '.' in name:
            self._object = eval(string.join(name.split('.')[:-1],'.'),namespace)
            self._attribute = name.split('.')[-1]
            self._type = type(getattr(self._object, self._attribute))
        else:
            self._object = None
            self._attribute = None
            self._type = type(namespace[name])

        # Create dedicated entry
        if self._type == bool:
            self._entry = BoolEntry(value=self.get(), action=action,
                                    getter=self.get, setter=self.set)
        elif self._type == int:
            if vmin == None:
                vmin = -sys.maxint-1
            if vmax == None:
                vmax = sys.maxint
            vstep = vstep or 1
            vformat = vformat or '%d'
            self._entry = ScalarEntry(value=self.get(), action=action,
                                      getter=self.get, setter=self.set,
                                      vmin=vmin, vmax=vmax, vstep=vstep, vformat=vformat)
        elif self._type == float:
            if vmin == None:
                vmin = -sys.maxint-1
            if vmax == None:
                vmax = sys.maxint
            vstep = vstep or 0.1
            vformat = vformat or '%.2f'
            self._entry = ScalarEntry(self.get(), action=action,
                                      getter=self.get, setter=self.set,
                                      vmin=vmin, vmax=vmax, vstep=vstep,vformat=vformat) 
        elif self._type == str:
            self._entry = TextEntry(self.get(), self.get, self.set, action=action)
        else:
            self._entry = Label(str(self.get()))

        if self._read_only:
            self._entry.focusable = False
            self._entry.activable = False

        if label:
            self._label = Label(label)
        else:
            self._label = Label(name)        
        HBox.__init__(self, [self._label, self._entry], homogeneous=True)