home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 56 / CDPowerplay56Disc2.iso / demos / blade / data1.cab / Program_Executable_Files / Lib / EntityList.py < prev    next >
Encoding:
Python Source  |  2000-10-27  |  7.8 KB  |  265 lines

  1.  
  2.  
  3.  
  4.  
  5. import Tkinter
  6. import Pmw
  7. import Bladex
  8. import sys
  9. #import bldb
  10.  
  11.  
  12.  
  13.  
  14. #Bldb=bldb.Bldb()
  15.  
  16. class VectorEntry:
  17.   def __init__(self,text_label,parent,dim=3,labels=["X","Y","Z"],width=12):
  18.     w = Pmw.Group(parent, tag_text=text_label)
  19.     w.pack( fill='x', expand = 1, padx = 4, pady = 4)
  20.     self.dimension=dim
  21.  
  22.     self.Comp=[]
  23.     for i in range(0,dim):
  24.       self.Comp.append(
  25.          Pmw.EntryField(w.interior(),
  26.          entry_width = width,
  27.          validate = {'validator' : 'real'},
  28.          labelpos = 'w',
  29.          label_text = labels[i])
  30.         )
  31.       self.Comp[i].grid(row=0, column=i)
  32.  
  33.  
  34.   def setentry(self,s):
  35.     if s is None:
  36.       for i in range(0,self.dimension):
  37.         self.Comp[i].setentry("")
  38.     else:
  39.       for i in range(0,self.dimension):
  40.         self.Comp[i].setentry(s[i])
  41.  
  42.  
  43.  
  44.  
  45. class VectorEntryEntity(VectorEntry):
  46.  
  47.   def SetEntry(self,entity,attribute):
  48.     if hasattr(entity,attribute)==1:
  49.       s=getattr(entity,attribute)
  50.       VectorEntry.setentry(self,s)
  51.     else:
  52.       VectorEntry.setentry(self,None)
  53.       
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61. class EntitiesDialog:
  62.   def __init__(self, parent):
  63.     self.Parent=parent
  64.     exitButton = Tkinter.Button(parent, text = 'Exit', command = parent.destroy)
  65.     exitButton.pack(side = 'bottom')
  66.  
  67.     # Create and pack the MenuBar.
  68.     menuBar = Pmw.MenuBar(parent,
  69.           hull_relief = 'raised',
  70.           hull_borderwidth = 1)
  71.     menuBar.pack(fill = 'x')
  72.     self.menuBar = menuBar
  73.  
  74.     # Add some buttons to the MenuBar.
  75.     menuBar.addmenu('File', 'Close this window or exit')
  76.     menuBar.addmenuitem('File', 'command', 'Close this window',
  77. #        command = lambda: print('Action: close'),
  78.         label = 'Close')
  79.  
  80.     menuBar.addmenuitem('File', 'command', 'Exit the application',
  81.         command = self.CreateDOLFile,
  82.         label = 'Create DOL File')
  83.  
  84.     menuBar.addmenuitem('File', 'separator')
  85.     menuBar.addmenuitem('File', 'command', 'Exit the application',
  86. #        command = lambda: print('Action: exit'),
  87.         label = 'Exit')
  88.  
  89.     menuBar.addmenu('Edit', 'Cut, copy or paste')
  90.     menuBar.addmenuitem('Edit', 'command', 'Delete the current selection',
  91. #        command = lambda: print('Action: delete'),
  92.         label = 'Delete')
  93.  
  94.     menuBar.addmenu('Options', 'Set user preferences')
  95.     menuBar.addmenuitem('Options', 'command', 'Set general preferences',
  96. #        command = lambda: print('Action: general options'),
  97.         label = 'General...')
  98.  
  99.  
  100.     pane = Pmw.PanedWidget(parent, hull_width=550, hull_height=300, orient='horizontal')
  101.     pane.add('left')
  102.     pane.add('right')
  103.     pane.pack(expand = 1, fill = 'both')
  104.  
  105.     self.box = Pmw.ScrolledListBox(pane.pane("left"),
  106.         listbox_selectmode='single',
  107.           label_text='Entities  '+str(Bladex.nEntities()),
  108.         labelpos='nw',
  109.         vscrollmode = 'static',
  110.         selectioncommand=self.ListSelectionCommand)
  111.     self.box.pack(fill = 'both', expand = 'yes', padx = 10, pady = 10)
  112.  
  113.     sf=Pmw.ScrolledFrame(pane.pane("right"))
  114.     sf.pack(padx = 10, pady = 10, fill = 'both', expand = 1)
  115.     sfframe = sf.getFrame()
  116.     sfframe.configure(bg="SystemButtonFace")
  117.     self.sfpr=sfframe
  118.  
  119.     EntList=range(Bladex.nEntities())
  120.     for i in EntList:
  121.       currEntity=Bladex.GetEntity(i)
  122.       self.box.insert('end', currEntity.Name)
  123.  
  124.  
  125.     ##### Tipo ##########
  126.     self.Kind= Pmw.EntryField(sfframe,
  127.       entry_width = 20,
  128.       labelpos = 'w',
  129.       label_text = 'Kind')
  130.     self.Kind.pack(fill = "x", padx = 4, pady = 10)
  131.     #self.Kind.grid(row=0, column=1)
  132.  
  133.  
  134.     ##### Clase de Entidad ##########
  135.     self.EntityClass = Pmw.OptionMenu ( sfframe,
  136.       labelpos = 'w',
  137.       labelmargin = 10,
  138.       label_text = 'Entity Class :',
  139.       #variable = self._var,
  140.       items = ( 'Actor', 'Physic', 'Static', 'Weapon', "Arrow", "Person", "Other" ) )
  141.     self.EntityClass.pack ( fill = "x", padx = 4, pady = 10 )
  142.  
  143.     ##### Posici≤n ###########
  144.     self.Pos=VectorEntryEntity("Position",sfframe,3)
  145.  
  146.     ##### Orientaci≤n ###########
  147.     self.Ori=VectorEntryEntity("Orientation",sfframe,4,["a","b","c","d"],10)
  148.     
  149.  
  150.     ##### Escala ##########
  151.     self.Scale= Pmw.EntryField(sfframe,
  152.       validate = {'validator' : 'real'},
  153.       entry_width = 20,
  154.       labelpos = 'w',
  155.       label_text = 'Scale')
  156.     self.Scale.pack(fill = "x", padx = 4, pady = 10)
  157.  
  158.     ##### Velocidad ##########
  159.     self.Vel=VectorEntryEntity("Velocity",sfframe,3)
  160.  
  161.     ##### Gravedad ##########
  162.     self.Grav=VectorEntryEntity("Gravity",sfframe,3)
  163.  
  164.  
  165.  
  166.  
  167.   def FillDialog(self,entName):
  168.     CurrEntity=Bladex.GetEntity(entName)
  169.     self.Kind.setentry(CurrEntity.Kind)
  170.  
  171.     self.Pos.SetEntry(CurrEntity,"Position")
  172.     self.Vel.SetEntry(CurrEntity,"Velocity")
  173.     self.Grav.SetEntry(CurrEntity,"Gravity")
  174.     self.Ori.SetEntry(CurrEntity,"Orientation")
  175.     if CurrEntity.Actor==1:
  176.       self.EntityClass.select(self.EntityClass.index("Actor"))
  177.     elif CurrEntity.Static==1:
  178.       self.EntityClass.select(self.EntityClass.index("Static"))
  179.     elif CurrEntity.Weapon==1:
  180.       self.EntityClass.select(self.EntityClass.index("Weapon"))
  181.     elif CurrEntity.Arrow==1:
  182.       self.EntityClass.select(self.EntityClass.index("Arrow"))
  183.     elif CurrEntity.Person==1:
  184.       self.EntityClass.select(self.EntityClass.index("Person"))
  185.     elif CurrEntity.Physic==1:
  186.       self.EntityClass.select(self.EntityClass.index("Physic"))
  187.     else:
  188.       self.EntityClass.select(self.EntityClass.index("Other"))
  189.  
  190.  
  191.   def ListSelectionCommand(self):
  192.     EntName=self.box.getcurselection()[0]
  193.     self.FillDialog(EntName)
  194.  
  195.  
  196.   def CreateDOLFile(self):
  197.     import sys
  198.     sys.path.append("C:/Program Files/Python/Lib/Lib-tk")
  199.     import tkMessageBox.tkFileDialog
  200.     filename = tkMessageBox.tkFileDialog.asksaveasfilename(parent=self.Parent,filetypes=[("Dol files","*.dol")])
  201.     Create_DOLFile(filename)
  202.  
  203.  
  204.  
  205.  
  206.  
  207. def Create_DOLFile(FileName):
  208. #  Bldb.set_trace()
  209.   if FileName:
  210.     temp_stdout=sys.stdout
  211.     sys.stdout=open(FileName,"w")
  212.  
  213.   #print "# Archivo DOL generado a partir de Python\n"
  214.   #print "NumItems ->",Bladex.nEntities()
  215.   print "NumItems -> Hacer"
  216.   print "\n\n"
  217.   
  218.   EntList=range(Bladex.nEntities())
  219.   for i in EntList:
  220.     currEntity=Bladex.GetEntity(i)
  221.     if currEntity.Physic==1 or currEntity.Static==1:
  222.       print "BeginObject"
  223.       print "  Kind -> ",currEntity.Kind
  224.       print "  Name -> ",currEntity.Name
  225.  
  226.       print "  Static -> ",currEntity.Static
  227.       print "  Scale -> ",currEntity.Scale
  228.  
  229.       print "  Position -> ",currEntity.Position[0]/1000,-currEntity.Position[2]/1000,currEntity.Position[1]/1000
  230.       print "  Orientation -> ",currEntity.Orientation[0],currEntity.Orientation[1],currEntity.Orientation[2],currEntity.Orientation[3]
  231.  
  232.       if currEntity.nFires:
  233.         print "  nFires -> ",currEntity.nFires
  234.         for fires in range(currEntity.nFires):
  235.           print "    FireIntensity ->",fires,currEntity.FireIntensity[fires]
  236.  
  237.       if currEntity.nLights:
  238.         print "  nLights -> ",currEntity.nLights
  239.         for lights in range(currEntity.nLights):
  240.           print "    LightIntensity ->",lights,currEntity.FireIntensity[lights]
  241.           print "    LightPrecission ->",lights,currEntity.FireIntensity[lights]
  242.           print "    LightColor ->",lights,currEntity.FireIntensity[lights]
  243.           #print "    LightGlow ->",lights,currEntity.FireIntensity[lights]
  244.           # Glow no implementado
  245.  
  246.       print "EndObject\n\n\n"
  247.  
  248.   if FileName:
  249.     sys.stdout.close()
  250.     sys.stdout=temp_stdout
  251.  
  252.  
  253. def EntitiList():
  254.   root = Tkinter.Tk()
  255.   Pmw.initialise(root, fontScheme = 'pmw1')
  256.   root.title('Entities List')
  257.  
  258.   widget = EntitiesDialog(root)
  259.   root.mainloop()
  260.  
  261.  
  262. # Create demo in root window for testing.
  263. if __name__ == '__main__':
  264.   EntitiList()
  265.   #Create_DOLFile("Hola.dol")