Browse Source

*** empty log message ***

Mark Mine 24 years ago
parent
commit
379da28f75

+ 0 - 21
direct/src/directtools/DirectUtil.py

@@ -1,25 +1,4 @@
 from PandaObject import *
 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 ##
 ## Background Color ##
 def setBackgroundColor(r,g,b):
 def setBackgroundColor(r,g,b):

+ 36 - 1
direct/src/showbase/PythonUtil.py

@@ -145,7 +145,6 @@ def _pdir(obj, str = None, fOverloaded = 0, width = None,
             strvalue = strvalue[:max(1,lineWidth - maxWidth)]
             strvalue = strvalue[:max(1,lineWidth - maxWidth)]
         print (format % key)[:maxWidth] + '\t' + strvalue
         print (format % key)[:maxWidth] + '\t' + strvalue
 
 
-
 # Magic numbers: These are the bit masks in func_code.co_flags that
 # 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.
 # reveal whether or not the function has a *arg or **kw argument.
 _POS_LIST = 4
 _POS_LIST = 4
@@ -267,6 +266,42 @@ def doc(obj):
        (isinstance(obj, types.FunctionType)):
        (isinstance(obj, types.FunctionType)):
         print obj.__doc__
         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):
 def intersection(a, b):
     """
     """
     intersection(list, list):
     intersection(list, list):

+ 32 - 7
direct/src/tkwidgets/EntryScale.py

@@ -6,7 +6,7 @@ from Tkinter import *
 import Pmw
 import Pmw
 import string
 import string
 import tkColorChooser
 import tkColorChooser
-from tkSimpleDialog import askfloat
+from tkSimpleDialog import *
 
 
 """
 """
 Change Min/Max buttons to labels, add highlight binding
 Change Min/Max buttons to labels, add highlight binding
@@ -74,6 +74,7 @@ class EntryScale(Pmw.MegaWidget):
                                           anchor = 'center',
                                           anchor = 'center',
                                           font = "Arial 12 bold")
                                           font = "Arial 12 bold")
         self.label.pack(side='left', expand = 1, fill = 'x')
         self.label.pack(side='left', expand = 1, fill = 'x')
+        self.label.bind('<Button-3>', self.askForLabel)
 
 
         # Now pack the frame
         # Now pack the frame
         self.labelFrame.pack(expand = 1, fill = 'both')
         self.labelFrame.pack(expand = 1, fill = 'both')
@@ -83,14 +84,14 @@ class EntryScale(Pmw.MegaWidget):
                                                 Frame, interior)
                                                 Frame, interior)
         # Create the EntryScale's min max labels
         # Create the EntryScale's min max labels
         self.minLabel = self.createcomponent('minLabel', (), None,
         self.minLabel = self.createcomponent('minLabel', (), None,
-                                             Button, self.minMaxFrame,
-                                             command = self.askForMin,
+                                             Label, self.minMaxFrame,
                                              text = `self['min']`,
                                              text = `self['min']`,
                                              relief = FLAT,
                                              relief = FLAT,
                                              width = 5,
                                              width = 5,
                                              anchor = W,
                                              anchor = W,
                                              font = "Arial 8")
                                              font = "Arial 8")
         self.minLabel.pack(side='left', fill = 'x')
         self.minLabel.pack(side='left', fill = 'x')
+        self.minLabel.bind('<Button-3>', self.askForMin)
 
 
         # Create the scale component.
         # Create the scale component.
         self.scale = self.createcomponent('scale', (), None,
         self.scale = self.createcomponent('scale', (), None,
@@ -107,15 +108,16 @@ class EntryScale(Pmw.MegaWidget):
         self.scale.set(self['initialValue'])
         self.scale.set(self['initialValue'])
         self.scale.bind('<Button-1>', self.__onPress)
         self.scale.bind('<Button-1>', self.__onPress)
         self.scale.bind('<ButtonRelease-1>', self.__onRelease)
         self.scale.bind('<ButtonRelease-1>', self.__onRelease)
+        self.scale.bind('<Button-3>', self.askForResolution)
 
 
         self.maxLabel = self.createcomponent('maxLabel', (), None,
         self.maxLabel = self.createcomponent('maxLabel', (), None,
-                                             Button, self.minMaxFrame,
-                                             command = self.askForMax,
+                                             Label, self.minMaxFrame,
                                              text = `self['max']`,
                                              text = `self['max']`,
                                              relief = FLAT,
                                              relief = FLAT,
                                              width = 5,
                                              width = 5,
                                              anchor = E,
                                              anchor = E,
                                              font = "Arial 8")
                                              font = "Arial 8")
+        self.maxLabel.bind('<Button-3>', self.askForMax)
         self.maxLabel.pack(side='left', fill = 'x')
         self.maxLabel.pack(side='left', fill = 'x')
         self.minMaxFrame.pack(expand = 1, fill = 'both')
         self.minMaxFrame.pack(expand = 1, fill = 'both')
          
          
@@ -129,9 +131,18 @@ class EntryScale(Pmw.MegaWidget):
     def entry(self):
     def entry(self):
         return self.entry
         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'],
         newMin = askfloat(title = self['text'],
                           prompt = 'New min val:',
                           prompt = 'New min val:',
+                          initialvalue = `self['min']`,
                           parent = self.interior())
                           parent = self.interior())
         if newMin:
         if newMin:
             self.setMin(newMin)
             self.setMin(newMin)
@@ -142,9 +153,10 @@ class EntryScale(Pmw.MegaWidget):
         self.minLabel['text'] = newMin
         self.minLabel['text'] = newMin
         self.entry.checkentry()
         self.entry.checkentry()
     
     
-    def askForMax(self):
+    def askForMax(self, event = None):
         newMax = askfloat(title = self['text'],
         newMax = askfloat(title = self['text'],
                           parent = self.interior(),
                           parent = self.interior(),
+                          initialvalue = self['max'],
                           prompt = 'New max val:')
                           prompt = 'New max val:')
         if newMax:
         if newMax:
             self.setMax(newMax)
             self.setMax(newMax)
@@ -155,6 +167,19 @@ class EntryScale(Pmw.MegaWidget):
         self.maxLabel['text'] = newMax
         self.maxLabel['text'] = newMax
         self.entry.checkentry()
         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):
     def _updateLabelText(self):
         self.label['text'] = self['text']
         self.label['text'] = self['text']