def createCanvas(self, master): size = self.size self.frame = Tkinter.Frame(self, borderwidth=3, relief='sunken') self.canvas = Tkinter.Canvas(self.frame, width=size+2, height=size+2) self.xm = self.ym = size/2+2 self.rad = size/2 self.radNoArrow = self.rad-self.arrowLength self.vector = [0, 1] x1 = self.xm + self.vector[0]*self.rad y1 = self.ym + self.vector[1]*self.rad canvas = self.canvas self.circleId = canvas.create_oval(2,2,size,size, width=1, fill=self.unusedArcColor) self.arcId = canvas.create_arc(2,2,size,size, start=90., extent=0, fill=self.usedArcColor) canvas.create_line(2, self.ym, size+2, self.ym) canvas.create_line(self.xm, 2, self.ym, size+2) self.arrowPolId = canvas.create_polygon( 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, fill='gray75' ) self.arrowPolborder1 = canvas.create_line( 0,0,0,0,0,0,0,0, fill='black', width = self.arrowBorderwidth) self.arrowPolborder2 = canvas.create_line( 0,0,0,0,0,0,0,0, fill='white', width = self.arrowBorderwidth ) r = size/20 off = self.arrowBorderwidth canvas.create_oval(self.xm-r,self.ym-r-off/2,self.xm+r,self.ym+r-off/2, fill='#DDDDDD', outline='white') canvas.create_oval(self.xm-r,self.ym-r+off,self.xm+r,self.ym+r+off, fill='black', outline='black') canvas.create_oval(self.xm-r,self.ym-r,self.xm+r,self.ym+r, fill='gray70', outline='#DDDDDD') self.labelId2 = canvas.create_text(self.xm+2, self.ym+2, fill='black', justify='center', text='', font = self.labelFont) self.labelId = canvas.create_text(self.xm, self.ym, fill=self.labelColor, justify='center', text='', font = self.labelFont) self.drawArrow() self.opPanel = OptionsPanel(master = self, title="Dial Options") # pack em up self.canvas.pack(side=Tkinter.TOP) self.frame.pack(expand=1, fill='x') self.toggleWidgetLabel(self.showLabel)
def __init__(self, master=None, type='float', labCfg={ 'fg': 'black', 'side': 'left', 'text': None }, min=None, max=None, increment=.0, precision=2, showLabel=1, value=0.0, continuous=1, oneTurn=360., size=50, callback=None, lockMin=0, lockBMin=0, lockMax=0, lockBMax=0, lockIncrement=0, lockBIncrement=0, lockPrecision=0, lockShowLabel=0, lockValue=0, lockType=0, lockContinuous=0, lockOneTurn=0, **kw): Tkinter.Frame.__init__(self, master) Tkinter.Pack.config(self) self.callbacks = CallbackManager() # object to manage callback # functions. They get called with the # current value as an argument # initialize various attributes with default values self.precision = 2 # decimal places self.min = None # minimum value self.max = None # maximum value self.increment = increment # value increment self.minOld = 0. # used to store old values self.maxOld = 0. self.incrementOld = increment self.size = 50 # defines widget size self.offsetValue = 0. # used to set increment correctly self.lab = None # label self.callback = None # user specified callback self.opPanel = None # option panel widget self.oneTurn = 360. # value increment for 1 full turn self.value = 0.0 # current value of widget self.oldValue = 0.0 # old value of widget self.showLabel = 1 # turn on to display label on self.continuous = 1 # set to 1 to call callbacks at # each value change, else gets called # on button release event self.angle = 0. # angle corresponding to value self.labCfg = labCfg # Tkinter Label options self.labelFont = (ensureFontCase('helvetica'), 14, 'bold' ) # label font self.labelColor = 'yellow' # label color self.canvas = None # the canvas to create the widget in self.usedArcColor = '#aaaaaa' # filled arc color of used portion self.unusedArcColor = '#cccccc' # filled arc color of unused portion self.pyOver180 = math.pi / 180.0 # constants used in various places self.threeSixtyOver1turn = 1 self.piOver1turn = math.pi / 360. self.lockMin = lockMin # lock<X> vars are used in self.lock() self.lockMax = lockMax # to lock/unlock entries in optionpanel self.lockIncrement = lockIncrement self.lockBMin = lockBMin self.lockBMax = lockBMax self.lockBIncrement = lockBIncrement self.lockPrecision = lockPrecision self.lockShowLabel = lockShowLabel self.lockValue = lockValue self.lockType = lockType self.lockContinuous = lockContinuous self.lockOneTurn = lockOneTurn self.setArrow() # configure with user-defined values self.setSize(size) self.setCallback(callback) self.setContinuous(continuous) self.setType(type) self.setPrecision(precision) self.setOneTurn(oneTurn) self.setMin(min) self.setMax(max) self.setIncrement(increment) self.setShowLabel(showLabel) self.setValue(value) self.setLabel(self.labCfg) self.createCanvas(master) canvas = self.canvas canvas.bind("<ButtonPress-1>", self.mouseDown) canvas.bind("<ButtonRelease-1>", self.mouseUp) canvas.bind("<B1-Motion>", self.mouseMove) canvas.bind("<Button-3>", self.toggleOptPanel) if os.name == 'nt': #sys.platform == 'win32': canvas.bind("<MouseWheel>", self.mouseWheel) else: canvas.bind("<Button-4>", self.mouseWheel) canvas.bind("<Button-5>", self.mouseWheel) KeyboardEntry.__init__(self, (canvas, ), self.setFromEntry) self.opPanel = OptionsPanel(master=self, title="Dial Options")
def __init__(self, master=None, labCfg={ 'fg': 'black', 'side': 'left', 'text': None }, wheelLabCfg={}, canvasCfg={}, callback=None, type='float', min=None, max=None, increment=0.0, precision=2, showLabel=1, value=0.0, continuous=True, width=200, height=40, oneTurn=10., wheelPad=6, lockMin=0, lockBMin=0, lockMax=0, lockBMax=0, lockIncrement=0, lockBIncrement=0, lockPrecision=0, lockShowLabel=0, lockValue=0, lockType=0, lockContinuous=0, lockOneTurn=0, orient=None, reportDelta=0, **kw): # See FIXME init # if __debug__: # checkkeywords(kw) Tkinter.Frame.__init__(self, master) Tkinter.Pack.config(self, side='left', anchor='w') #FIXME: nblines are not dynamically computed self.nblines = 30 self.callback = None self.callbacks = CallbackManager() # object to manage callback # functions. They get called with the # current value as an argument self.width = 200 self.height = 40 self.setWidth(width) self.setHeight(height) # set widget orientation: either horizontal or vertical self.setOrient(orient) # initialize various attributes with default values self.precision = 2 # decimal places self.min = None # minimum value self.max = None # maximum value self.increment = increment # value increment self.minOld = 0. # used to store old values self.maxOld = 0. self.incrementOld = increment self.size = 50 # defines widget size self.offsetValue = 0. # used to set increment correctly self.lab = None # label self.opPanel = None # option panel widget self.oneTurn = 360. # value increment for 1 full turn self.value = 0.0 # current value of widget self.oldValue = 0.0 # old value of widget self.showLabel = 1 # turn on to display label on self.continuous = True # set to 1 to call callbacks at # each value change, else gets called # on button release event self.angle = 0. # angle corresponding to value self.labCfg = labCfg # Tkinter Label options self.labelFont = (ensureFontCase('helvetica'), 14, 'bold' ) # label font self.labelColor = 'yellow' # label color self.canvas = None # the canvas to create the widget in self.usedArcColor = '#aaaaaa' # filled arc color of used portion self.unusedArcColor = '#cccccc' # filled arc color of unused portion self.pyOver180 = math.pi / 180.0 # constants used in various places self.threeSixtyOver1turn = 1 self.piOver1turn = math.pi / 360. self.wheelLabCfg = wheelLabCfg # Tkinter wheel label options self.canvasCfg = canvasCfg # Tkinter Canvas options self.wheelPad = wheelPad # pad between wheel and widget borders self.deltaVal = 0. # delta with value at last callback self.valueLabel = None # Tkinter Label self.setType(type) # can be float or int self.discreteValue = 0. # value in discrete space self.lockMin = lockMin # lock<X> variables in configure() self.lockMax = lockMax # to lock/unlock entries in options # panel self.lockMin = lockMin # lock<X> vars are used in self.lock() self.lockMax = lockMax # to lock/unlock entries in optionpanel self.lockIncrement = lockIncrement self.lockBMin = lockBMin self.lockBMax = lockBMax self.lockBIncrement = lockBIncrement self.lockPrecision = lockPrecision self.lockShowLabel = lockShowLabel self.lockValue = lockValue self.lockType = lockType self.lockContinuous = lockContinuous self.lockOneTurn = lockOneTurn self.reportDelta = reportDelta self.setLabel(self.labCfg) self.createCanvas(master, wheelPad=wheelPad) self.canvas.bind("<ButtonPress-1>", self.mouseDown) self.canvas.bind("<ButtonRelease-1>", self.mouseUp) self.canvas.bind("<B1-Motion>", self.mouseMove) self.canvas.bind("<Button-3>", self.toggleOptPanel) self.valueLabel.bind("<ButtonPress-1>", self.mouseDown) self.valueLabel.bind("<ButtonRelease-1>", self.mouseUp) self.valueLabel.bind("<B1-Motion>", self.mouseMove) self.valueLabel.bind("<Button-3>", self.toggleOptPanel) if os.name == 'nt': #sys.platform == 'win32': self.canvas.bind("<MouseWheel>", self.mouseWheel) self.valueLabel.bind("<MouseWheel>", self.mouseWheel) else: self.canvas.bind("<Button-4>", self.mouseWheel) self.valueLabel.bind("<Button-4>", self.mouseWheel) self.canvas.bind("<Button-5>", self.mouseWheel) self.valueLabel.bind("<Button-5>", self.mouseWheel) self.bind("<Button-3>", self.toggleOptPanel) KeyboardEntry.__init__(self, (self, self.canvas, self.valueLabel), self.setFromEntry) self.opPanel = OptionsPanel(master=self, title="Thumbwheel Options") # now set the constructor options correctly using the configure method self.setValue(value) apply( self.configure, (), { 'type': type, 'min': min, 'max': max, 'increment': increment, 'precision': precision, 'showLabel': showLabel, 'continuous': continuous, 'oneTurn': oneTurn, 'lockType': lockType, 'lockMin': lockMin, 'lockBMin': lockBMin, 'lockMax': lockMax, 'lockBMax': lockBMax, 'lockIncrement': lockIncrement, 'lockBIncrement': lockBIncrement, 'lockPrecision': lockPrecision, 'lockShowLabel': lockShowLabel, 'lockValue': lockValue, 'lockContinuous': lockContinuous, 'lockOneTurn': lockOneTurn, 'orient': orient, 'reportDelta': reportDelta, 'callback': callback })