home *** CD-ROM | disk | FTP | other *** search
- title = 'CVAR Tweaker'
-
- # Import Pmw from this directory tree.
- import sys
- import string
- import Tkinter
- import Pmw
- if __name__ == "ff":
- import js
-
- class cvarEdit:
- def __init__(self, parent, name, val, min, max, inc):
- self.w = Pmw.Counter(parent,
- labelpos = 'w',
- label_text = name,
- orient = 'horizontal',
- datatype = 'real',
- entry_width = 6,
- increment = inc,
- entryfield_value = val,
- entryfield_validate = {'validator' : 'real',
- 'min' : min, 'max' : max}
- )
- self.w.pack(fill='x', padx=10, pady=2)
- self.name = name
-
- def get(self):
- return string.atof(self.w.get())
-
-
- class cvarApp:
- def __init__(self, parent):
- # initialise values from engine if embedded
- self.widgets = ["DUMMY"]
- self.cvars = ["DUMMY"]
-
- c = cvarEdit(parent, "ff.APP_FADE_DIST", APP_FADE_DIST, 0.0, 500.0, 1.0)
- self.cvars.append(c)
- self.widgets.append(c.w)
- c = cvarEdit(parent, "ff.APP_MOUSE_ORBIT", APP_MOUSE_ORBIT, 0.0, 20.0, 0.1)
- self.cvars.append(c)
- self.widgets.append(c.w)
- c = cvarEdit(parent, "ff.APP_MOUSE_SCROLL", APP_MOUSE_SCROLL, 0.0, 1.0, 0.001)
- self.cvars.append(c)
- self.widgets.append(c.w)
- c = cvarEdit(parent, "ff.APP_MOVE_INC", APP_MOVE_INC, -500.0, 500.0, 1.0)
- self.cvars.append(c)
- self.widgets.append(c.w)
- c = cvarEdit(parent, "ff.APP_TURN_INC", APP_TURN_INC, 0.0, 20.0, 0.1)
- self.cvars.append(c)
- self.widgets.append(c.w)
- c = cvarEdit(parent, "ff.APP_ZOOM_INC", APP_ZOOM_INC, 0.0, 1000.0, 1.0)
- self.cvars.append(c)
- self.widgets.append(c.w)
- c = cvarEdit(parent, "ff.APP_ASPECT", APP_ASPECT, 0.0, 5.0, 0.01)
- self.cvars.append(c)
- self.widgets.append(c.w)
- c = cvarEdit(parent, "ff.APP_NEAR", APP_NEAR, 0.0, 50.0, 0.1)
- self.cvars.append(c)
- self.widgets.append(c.w)
- c = cvarEdit(parent, "ff.APP_FAR", APP_FAR, 0.0, 5000.0, 1.0)
- self.cvars.append(c)
- self.widgets.append(c.w)
- c = cvarEdit(parent, "ff.CAM_MIN_ZOOM", CAM_MIN_ZOOM, 0.0, 500.0, 1.0)
- self.cvars.append(c)
- self.widgets.append(c.w)
- c = cvarEdit(parent, "ff.CAM_MAX_ZOOM", CAM_MAX_ZOOM, 0.0, 5000.0, 1.0)
- self.cvars.append(c)
- self.widgets.append(c.w)
- c = cvarEdit(parent, "ff.CAM_MIN_TILT", CAM_MIN_TILT, 0.0, 10.0, 0.01)
- self.cvars.append(c)
- self.widgets.append(c.w)
- c = cvarEdit(parent, "ff.CAM_MAX_TILT", CAM_MAX_TILT, 0.0, 10.0, 0.01)
- self.cvars.append(c)
- self.widgets.append(c.w)
-
- Pmw.alignlabels(self.widgets[1:])
-
- # add a buttonBox and some buttons
- self.buttonBox = Pmw.ButtonBox(parent)
- self.buttonBox.pack(fill = 'x', padx = 10, pady = 10, side='bottom')
- self.buttonBox.add('Apply', command = self.applyToEngine)
- self.buttonBox.add('Export', command = self.writeToFile)
- self.buttonBox.add('Exit', command = root.destroy)
- self.buttonBox.setdefault('Apply')
- parent.bind('<Return>', self._processReturnKey)
- parent.focus_set()
- self.buttonBox.alignbuttons()
-
-
- def _processReturnKey(self, event):
- self.buttonBox.invoke()
-
- def applyToEngine(self):
- if __name__ == "ff":
- for c in self.cvars[1:]:
- cmd = "%s = %g" % (c.name, c.get())
- exec cmd
- js.setDirty()
-
- def writeToFile(self):
- # write new init.py file to current directory
- print 'writing init.py file'
-
-
- ######################################################################
- # Create demo in root window for testing.
- #
- root = Tkinter.Tk()
- Pmw.initialise(root)
- root.title(title)
-
- if __name__ != "ff":
- APP_FADE_DIST = 50.0
- APP_MOUSE_ORBIT = 0.2
- APP_MOUSE_SCROLL = 0.002
- APP_MOVE_INC = -200.0
- APP_TURN_INC = 3.0
- APP_ZOOM_INC = 400.0
- APP_ASPECT = 0.75
- APP_NEAR = 5.0
- APP_FAR = 700.0
- CAM_MIN_ZOOM = 80.0
- CAM_MAX_ZOOM = 600.0
- CAM_MIN_TILT = 2.58
- CAM_MAX_TILT = 1.58
-
- app = cvarApp(root)
- root.mainloop()
-