Пример #1
0
 def destroy(self):
     self.entry.unbind_all(self.entry)
     self.entry.destroy()
     self.button_frame.destroy()
     self.up_button.destroy()
     self.down_button.destroy()
     self.command = self.args = None
     TFrame.destroy(self)
Пример #2
0
	def destroy(self):
		self.entry.unbind_all(self.entry)
		self.entry.destroy()
		self.button_frame.destroy()
		self.up_button.destroy()
		self.down_button.destroy()
		self.command = self.args = None
		TFrame.destroy(self)
Пример #3
0
class TSpinbox(TFrame):
    def __init__(self,
                 master=None,
                 min=0,
                 max=100,
                 step=1,
                 textvariable=None,
                 var=0,
                 vartype=0,
                 command=None,
                 state=NORMAL,
                 width=5,
                 args=(),
                 **kw):
        '''vartype=0 - integer   vartype=1 - float '''
        self.min_value = min
        self.max_value = max
        self.step = step
        self.variable = var
        self.vartype = vartype
        if textvariable:
            self.text_var = textvariable
        else:
            self.text_var = StringVar()
        self.command = command
        self.state = state
        self.width = width
        apply(TFrame.__init__, (self, master), kw)
        self["style"] = "FlatFrame"
        self.entry = TEntryExt(self,
                               textvariable=self.text_var,
                               width=self.width,
                               style='SpinEntry')
        self.entry.pack(side=LEFT, expand=1, fill=BOTH)
        self.button_frame = TFrame(self, style="FlatFrame")
        self.button_frame.pack(side=LEFT, fill=Y)
        self.up_button = TButton(self.button_frame,
                                 class_='Repeater',
                                 command=self.increase,
                                 image='pal_arrow_up',
                                 style='SpinUpButton',
                                 takefocus=0)
        self.up_button.pack(side=TOP)
        self.down_button = TButton(self.button_frame,
                                   class_='Repeater',
                                   command=self.decrease,
                                   image='pal_arrow_down',
                                   style='SpinDownButton',
                                   takefocus=0)
        self.down_button.pack(side=TOP)
        if self.vartype == 1:
            self.variable = float(self.variable)
        else:
            self.variable = int(self.variable)
        self.text_var.set(str(self.variable))
        self.entry.bind('<Button-4>', self.wheel_increase)
        self.entry.bind('<Button-5>', self.wheel_decrease)
        self.entry.bind('<Key-Up>', self.wheel_increase)
        self.entry.bind('<Key-Down>', self.wheel_decrease)
        self.entry.bind('<Key-Return>', self.apply_command)
        self.entry.bind('<Key-KP_Enter>', self.apply_command)
        #self.entry.bind ( '<KeyPress>', self.check_input)

    def check_input(self, event):
        event = None

    def apply_command(self, *args):
        if self.state == NORMAL:
            text = self.entry.get()
            text = text.replace(',', '.')
            text = text.replace('/', '*1./')
            if text and not expression.search(text):
                try:
                    variable = eval(text)
                except:
                    pass
                else:
                    self.set_value(variable)
                    self.command(*args)

    def set_state(self, state):
        self.state = state
        self.entry.configure(state=state)
        self.up_button.configure(state=state)
        self.down_button.configure(state=state)

    def get_state(self):
        return self.state

    def wheel_increase(self, event):
        self.increase()

    def wheel_decrease(self, event):
        self.decrease()

    def increase(self):
        if self.state == NORMAL:
            try:
                self.variable = float(self.text_var.get())
            except:
                self.text_var.set('0')
                self.variable = float(self.text_var.get())
            self.variable = self.variable + self.step

            self.set_value(self.variable)

    def decrease(self):
        if self.state == NORMAL:
            try:
                self.variable = float(self.text_var.get())
            except:
                self.text_var.set('0')
                self.variable = float(self.text_var.get())
            self.variable = self.variable - self.step

            self.set_value(self.variable)

    def set_value(self, value=0):
        try:
            value = float(value)
        except:
            value = 0
        value = min(self.max_value, value)
        value = max(self.min_value, value)
        if self.vartype == 1:
            self.variable = float(value)
        else:
            self.variable = int(round(value))
        self.text_var.set(str(self.variable))

    def get_value(self):
        try:
            self.variable = float(self.text_var.get())
        except:
            self.text_var.set('0')
            self.variable = float(self.text_var.get())
        if self.vartype == 1:
            self.variable = float(self.variable)
        else:
            self.variable = int(round(self.variable))
        return self.variable

    def destroy(self):
        self.entry.unbind_all(self.entry)
        self.entry.destroy()
        self.button_frame.destroy()
        self.up_button.destroy()
        self.down_button.destroy()
        self.command = self.args = None
        TFrame.destroy(self)
Пример #4
0
 def destroy(self):
     self.entry.unbind_all(self.entry)
     self.entry.destroy()
     self.command = self.args = None
     TFrame.destroy(self)
Пример #5
0
class TSpinbox(TFrame):
	def __init__(self, master=None, min=0, max=100, step=1, textvariable=None, var=0, vartype=0, 
				command=None, state=NORMAL, width=5, args=(), **kw):
		'''vartype=0 - integer   vartype=1 - float '''
		self.min_value=min
		self.max_value=max
		self.step=step
		self.variable=var
		self.vartype=vartype
		if textvariable:
			self.text_var=textvariable
		else:
			self.text_var=StringVar()
		self.command=command
		self.state=state
		self.width=width
		apply(TFrame.__init__, (self, master), kw)
		self["style"]="FlatFrame"
		self.entry=TEntryExt(self, textvariable=self.text_var, width=self.width, style='SpinEntry')
		self.entry.pack(side = LEFT, expand = 1, fill = BOTH)
		self.button_frame=TFrame(self,style="FlatFrame")
		self.button_frame.pack(side = LEFT,fill = Y)
		self.up_button=TButton(self.button_frame, class_='Repeater', command=self.increase, 
							image='pal_arrow_up', style='SpinUpButton', takefocus=0)
		self.up_button.pack(side = TOP)
		self.down_button=TButton(self.button_frame, class_='Repeater', command=self.decrease,
							image='pal_arrow_down', style='SpinDownButton', takefocus=0)
		self.down_button.pack(side = TOP)
		if self.vartype==1: 
			self.variable=float(self.variable)
		else:
			self.variable=int(self.variable)
		self.text_var.set(str(self.variable))
		self.entry.bind('<Button-4>', self.wheel_increase)
		self.entry.bind('<Button-5>', self.wheel_decrease)
		self.entry.bind('<Key-Up>', self.wheel_increase)
		self.entry.bind('<Key-Down>', self.wheel_decrease)
		self.entry.bind('<Key-Return>', self.apply_command)
		self.entry.bind('<Key-KP_Enter>', self.apply_command)
		#self.entry.bind ( '<KeyPress>', self.check_input)
		
	def check_input(self, event):
		event=None
	
	def apply_command(self, *args):
		if self.state==NORMAL:
			text = self.entry.get()
			text = text.replace(',', '.')
			text = text.replace('/', '*1./')
			if text and not expression.search(text):
				try:
					variable = eval(text)
				except:
					pass
				else:
					self.set_value(variable)
					self.command(*args)
		
	def set_state(self, state):
		self.state=state
		self.entry.configure(state = state)
		self.up_button.configure(state = state)
		self.down_button.configure(state = state)
		
	def get_state(self):
		return self.state
		
	def wheel_increase(self, event):
		self.increase()
		
	def wheel_decrease(self, event):
		self.decrease()
		
	def increase(self):
		if self.state==NORMAL:
			try:
				self.variable=float(self.text_var.get())
			except:
				self.text_var.set('0')
				self.variable=float(self.text_var.get())
			self.variable=self.variable+self.step
			
			self.set_value(self.variable)
		
	def decrease(self):
		if self.state==NORMAL:
			try:
				self.variable=float(self.text_var.get())
			except:
				self.text_var.set('0')
				self.variable=float(self.text_var.get())
			self.variable=self.variable-self.step
			
			self.set_value(self.variable)
		
	def set_value(self, value=0):
		try:
			value = float(value)
		except:
			value = 0
		value = min(self.max_value, value)
		value = max(self.min_value, value)
		if self.vartype == 1: 
			self.variable = float(value)
		else:
			self.variable = int(round(value))
		self.text_var.set(str(self.variable))
	
	def get_value(self):
		try:
			self.variable=float(self.text_var.get())
		except:
			self.text_var.set('0')
			self.variable=float(self.text_var.get())
		if self.vartype==1: 
			self.variable=float(self.variable)
		else:
			self.variable = int(round(self.variable))
		return self.variable
			
		
	def destroy(self):
		self.entry.unbind_all(self.entry)
		self.entry.destroy()
		self.button_frame.destroy()
		self.up_button.destroy()
		self.down_button.destroy()
		self.command = self.args = None
		TFrame.destroy(self)
Пример #6
0
	def destroy(self):
		self.entry.unbind_all(self.entry)
		self.entry.destroy()
		self.command = self.args = None
		TFrame.destroy(self)