From 379da28f75bebb519e5c9d3c32d8b1337023100e Mon Sep 17 00:00:00 2001 From: Mark Mine Date: Fri, 11 May 2001 23:10:51 +0000 Subject: [PATCH] *** empty log message *** --- direct/src/directtools/DirectUtil.py | 21 --------------- direct/src/showbase/PythonUtil.py | 37 +++++++++++++++++++++++++- direct/src/tkwidgets/EntryScale.py | 39 +++++++++++++++++++++++----- 3 files changed, 68 insertions(+), 29 deletions(-) diff --git a/direct/src/directtools/DirectUtil.py b/direct/src/directtools/DirectUtil.py index fa5b89b0ae..85451d67b0 100644 --- a/direct/src/directtools/DirectUtil.py +++ b/direct/src/directtools/DirectUtil.py @@ -1,25 +1,4 @@ from PandaObject import * -from EntryScale import EntryScale - -def adjust(**kw): - """ - Popup and entry scale to adjust a parameter - Accepts any EntryScale keyword argument. Typical arguments include: - command: The one argument command to execute - min: The min value of the slider - max: The max value of the slider - resolution: The resolution of the slider - text: The label on the slider - """ - from Tkinter import * - import Pmw - from EntryScale import * - tl = Toplevel() - tl.title('Parameter Adjust') - es = apply(EntryScale, (tl,), kw) - es.pack(expand = 1, fill = X) - es.tl = tl - return es ## Background Color ## def setBackgroundColor(r,g,b): diff --git a/direct/src/showbase/PythonUtil.py b/direct/src/showbase/PythonUtil.py index f2988e72b4..9eb339c90f 100644 --- a/direct/src/showbase/PythonUtil.py +++ b/direct/src/showbase/PythonUtil.py @@ -145,7 +145,6 @@ def _pdir(obj, str = None, fOverloaded = 0, width = None, strvalue = strvalue[:max(1,lineWidth - maxWidth)] print (format % key)[:maxWidth] + '\t' + strvalue - # Magic numbers: These are the bit masks in func_code.co_flags that # reveal whether or not the function has a *arg or **kw argument. _POS_LIST = 4 @@ -267,6 +266,42 @@ def doc(obj): (isinstance(obj, types.FunctionType)): print obj.__doc__ +def adjust(parent = None, **kw): + """ + adjust(parent = None, **kw) + Popup and entry scale to adjust a parameter + + Accepts any EntryScale keyword argument. Typical arguments include: + command: The one argument command to execute + min: The min value of the slider + max: The max value of the slider + resolution: The resolution of the slider + text: The label on the slider + + These values can be accessed and/or changed after the fact + >>> es = adjust() + >>> es['min'] + 0.0 + >>> es['min'] = 10.0 + >>> es['min'] + 10.0 + """ + # Make sure we enable Tk + base.wantDIRECT = 1 + base.wantTk = 1 + import TkGlobal + from Tkinter import * + import EntryScale + import Pmw + # Create toplevel if needed + if not parent: + parent = Toplevel() + parent.title('Parameter Adjust') + es = apply(EntryScale.EntryScale, (parent,), kw) + es.pack(expand = 1, fill = X) + es.parent = parent + return es + def intersection(a, b): """ intersection(list, list): diff --git a/direct/src/tkwidgets/EntryScale.py b/direct/src/tkwidgets/EntryScale.py index ca6383828a..57ae25cbc7 100644 --- a/direct/src/tkwidgets/EntryScale.py +++ b/direct/src/tkwidgets/EntryScale.py @@ -6,7 +6,7 @@ from Tkinter import * import Pmw import string import tkColorChooser -from tkSimpleDialog import askfloat +from tkSimpleDialog import * """ Change Min/Max buttons to labels, add highlight binding @@ -74,6 +74,7 @@ class EntryScale(Pmw.MegaWidget): anchor = 'center', font = "Arial 12 bold") self.label.pack(side='left', expand = 1, fill = 'x') + self.label.bind('', self.askForLabel) # Now pack the frame self.labelFrame.pack(expand = 1, fill = 'both') @@ -83,14 +84,14 @@ class EntryScale(Pmw.MegaWidget): Frame, interior) # Create the EntryScale's min max labels self.minLabel = self.createcomponent('minLabel', (), None, - Button, self.minMaxFrame, - command = self.askForMin, + Label, self.minMaxFrame, text = `self['min']`, relief = FLAT, width = 5, anchor = W, font = "Arial 8") self.minLabel.pack(side='left', fill = 'x') + self.minLabel.bind('', self.askForMin) # Create the scale component. self.scale = self.createcomponent('scale', (), None, @@ -107,15 +108,16 @@ class EntryScale(Pmw.MegaWidget): self.scale.set(self['initialValue']) self.scale.bind('', self.__onPress) self.scale.bind('', self.__onRelease) + self.scale.bind('', self.askForResolution) self.maxLabel = self.createcomponent('maxLabel', (), None, - Button, self.minMaxFrame, - command = self.askForMax, + Label, self.minMaxFrame, text = `self['max']`, relief = FLAT, width = 5, anchor = E, font = "Arial 8") + self.maxLabel.bind('', self.askForMax) self.maxLabel.pack(side='left', fill = 'x') self.minMaxFrame.pack(expand = 1, fill = 'both') @@ -129,9 +131,18 @@ class EntryScale(Pmw.MegaWidget): def entry(self): return self.entry - def askForMin(self): + def askForLabel(self, event = None): + newLabel = askstring(title = self['text'], + prompt = 'New label:', + initialvalue = `self['text']`, + parent = self.interior()) + if newLabel: + self['text'] = newLabel + + def askForMin(self, event = None): newMin = askfloat(title = self['text'], prompt = 'New min val:', + initialvalue = `self['min']`, parent = self.interior()) if newMin: self.setMin(newMin) @@ -142,9 +153,10 @@ class EntryScale(Pmw.MegaWidget): self.minLabel['text'] = newMin self.entry.checkentry() - def askForMax(self): + def askForMax(self, event = None): newMax = askfloat(title = self['text'], parent = self.interior(), + initialvalue = self['max'], prompt = 'New max val:') if newMax: self.setMax(newMax) @@ -155,6 +167,19 @@ class EntryScale(Pmw.MegaWidget): self.maxLabel['text'] = newMax self.entry.checkentry() + def askForResolution(self, event = None): + newResolution = askfloat(title = self['text'], + parent = self.interior(), + initialvalue = self['resolution'], + prompt = 'New resolution:') + if newResolution: + self.setResolution(newResolution) + + def setResolution(self, newResolution): + self['resolution'] = newResolution + self.scale['resolution'] = newResolution + self.entry.checkentry() + def _updateLabelText(self): self.label['text'] = self['text']