home *** CD-ROM | disk | FTP | other *** search
/ Komputer for Alle 2002 #9 / K-CD-9-2002.ISO / Freedom Force / data1.cab / System_Files / cvarEdit.py < prev    next >
Encoding:
Python Source  |  2002-03-21  |  3.8 KB  |  130 lines

  1. title = 'CVAR Tweaker'
  2.  
  3. # Import Pmw from this directory tree.
  4. import sys
  5. import string
  6. import Tkinter
  7. import Pmw
  8. if __name__ == "ff":
  9.     import js
  10.  
  11. class cvarEdit: 
  12.     def __init__(self, parent, name, val, min, max, inc):
  13.         self.w = Pmw.Counter(parent,
  14.             labelpos = 'w',
  15.             label_text = name,
  16.             orient = 'horizontal',
  17.             datatype = 'real',
  18.             entry_width = 6,
  19.             increment = inc,
  20.             entryfield_value = val,
  21.                 entryfield_validate = {'validator' : 'real',
  22.                 'min' : min, 'max' : max}
  23.             )            
  24.         self.w.pack(fill='x', padx=10, pady=2)
  25.         self.name = name
  26.         
  27.     def get(self): 
  28.         return string.atof(self.w.get())
  29.                 
  30.  
  31. class cvarApp:
  32.     def __init__(self, parent):                            
  33.         # initialise values from engine if embedded    
  34.         self.widgets = ["DUMMY"]
  35.         self.cvars = ["DUMMY"]
  36.  
  37.         c = cvarEdit(parent, "ff.APP_FADE_DIST", APP_FADE_DIST, 0.0, 500.0, 1.0)
  38.         self.cvars.append(c)
  39.         self.widgets.append(c.w)
  40.         c = cvarEdit(parent, "ff.APP_MOUSE_ORBIT", APP_MOUSE_ORBIT, 0.0, 20.0, 0.1)
  41.         self.cvars.append(c)
  42.         self.widgets.append(c.w)                        
  43.         c = cvarEdit(parent, "ff.APP_MOUSE_SCROLL", APP_MOUSE_SCROLL, 0.0, 1.0, 0.001)
  44.         self.cvars.append(c)
  45.         self.widgets.append(c.w)            
  46.         c = cvarEdit(parent, "ff.APP_MOVE_INC", APP_MOVE_INC, -500.0, 500.0, 1.0)
  47.         self.cvars.append(c)
  48.         self.widgets.append(c.w)            
  49.         c = cvarEdit(parent, "ff.APP_TURN_INC", APP_TURN_INC, 0.0, 20.0, 0.1)
  50.         self.cvars.append(c)
  51.         self.widgets.append(c.w)            
  52.         c = cvarEdit(parent, "ff.APP_ZOOM_INC", APP_ZOOM_INC, 0.0, 1000.0, 1.0)
  53.         self.cvars.append(c)
  54.         self.widgets.append(c.w)            
  55.         c = cvarEdit(parent, "ff.APP_ASPECT", APP_ASPECT, 0.0, 5.0, 0.01)
  56.         self.cvars.append(c)
  57.         self.widgets.append(c.w)            
  58.         c = cvarEdit(parent, "ff.APP_NEAR", APP_NEAR, 0.0, 50.0, 0.1)
  59.         self.cvars.append(c)
  60.         self.widgets.append(c.w)            
  61.         c = cvarEdit(parent, "ff.APP_FAR", APP_FAR, 0.0, 5000.0, 1.0)
  62.         self.cvars.append(c)
  63.         self.widgets.append(c.w)            
  64.         c = cvarEdit(parent, "ff.CAM_MIN_ZOOM", CAM_MIN_ZOOM, 0.0, 500.0, 1.0)
  65.         self.cvars.append(c)
  66.         self.widgets.append(c.w)            
  67.         c = cvarEdit(parent, "ff.CAM_MAX_ZOOM", CAM_MAX_ZOOM, 0.0, 5000.0, 1.0)
  68.         self.cvars.append(c)
  69.         self.widgets.append(c.w)            
  70.         c = cvarEdit(parent, "ff.CAM_MIN_TILT", CAM_MIN_TILT, 0.0, 10.0, 0.01)
  71.         self.cvars.append(c)
  72.         self.widgets.append(c.w)            
  73.         c = cvarEdit(parent, "ff.CAM_MAX_TILT", CAM_MAX_TILT, 0.0, 10.0, 0.01)
  74.         self.cvars.append(c)
  75.         self.widgets.append(c.w)            
  76.  
  77.         Pmw.alignlabels(self.widgets[1:])
  78.         
  79.         # add a buttonBox and some buttons
  80.         self.buttonBox = Pmw.ButtonBox(parent)
  81.         self.buttonBox.pack(fill = 'x', padx = 10, pady = 10, side='bottom')
  82.         self.buttonBox.add('Apply', command = self.applyToEngine)
  83.         self.buttonBox.add('Export', command = self.writeToFile)
  84.         self.buttonBox.add('Exit', command = root.destroy)
  85.         self.buttonBox.setdefault('Apply')
  86.         parent.bind('<Return>', self._processReturnKey)
  87.         parent.focus_set()
  88.         self.buttonBox.alignbuttons()
  89.  
  90.  
  91.     def _processReturnKey(self, event):
  92.         self.buttonBox.invoke()
  93.         
  94.     def applyToEngine(self):
  95.         if __name__ == "ff":            
  96.             for c in self.cvars[1:]:
  97.                 cmd = "%s = %g" % (c.name, c.get())
  98.                 exec cmd
  99.             js.setDirty()
  100.                                     
  101.     def writeToFile(self):
  102.          # write new init.py file to current directory                            
  103.         print 'writing init.py file'
  104.  
  105.  
  106. ######################################################################
  107. # Create demo in root window for testing.
  108. #
  109. root = Tkinter.Tk()
  110. Pmw.initialise(root)
  111. root.title(title)        
  112.  
  113. if __name__ != "ff":
  114.     APP_FADE_DIST        = 50.0
  115.     APP_MOUSE_ORBIT        = 0.2
  116.     APP_MOUSE_SCROLL    = 0.002
  117.     APP_MOVE_INC        = -200.0
  118.     APP_TURN_INC        = 3.0
  119.     APP_ZOOM_INC        = 400.0
  120.     APP_ASPECT        = 0.75
  121.     APP_NEAR        = 5.0
  122.     APP_FAR            = 700.0
  123.     CAM_MIN_ZOOM        = 80.0
  124.     CAM_MAX_ZOOM        = 600.0
  125.     CAM_MIN_TILT        = 2.58
  126.     CAM_MAX_TILT        = 1.58
  127.  
  128. app = cvarApp(root)    
  129. root.mainloop()
  130.