duplicateWindow.py 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #################################################################
  2. # duplicateWindow.py
  3. # Written by Yi-Hong Lin, [email protected], 2004
  4. #################################################################
  5. from direct.tkwidgets.AppShell import *
  6. from direct.showbase.TkGlobal import *
  7. import seSceneGraphExplorer
  8. class duplicateWindow(AppShell):
  9. #################################################################
  10. # duplicateWindow(AppShell)
  11. # This class is used to create a dialog window
  12. # for handling the "dupicate" command from the sceneEditor
  13. #
  14. # Notice!
  15. # The actual duplicating process is not happending here!
  16. # The one handle the process is dataHolder...
  17. #################################################################
  18. appversion = '1.0'
  19. appname = 'Duplication'
  20. frameWidth = 450
  21. frameHeight = 320
  22. frameIniPosX = 250
  23. frameIniPosY = 250
  24. padx = 0
  25. pady = 0
  26. def __init__(self, parent = None, nodePath = None, **kw):
  27. # Define the megawidget options.
  28. optiondefs = (
  29. ('title', self.appname, None),
  30. )
  31. self.defineoptions(kw, optiondefs)
  32. if parent == None:
  33. self.parent = Toplevel()
  34. AppShell.__init__(self, self.parent)
  35. self.parent.geometry('%dx%d+%d+%d' % (self.frameWidth, self.frameHeight,self.frameIniPosX,self.frameIniPosY))
  36. self.nodePath = nodePath
  37. self.parent.resizable(False,False) ## Disable the ability to resize for this Window.
  38. def appInit(self):
  39. print '----SideWindow is Initialized!!'
  40. def createInterface(self):
  41. # The interior of the toplevel panel
  42. interior = self.interior()
  43. mainFrame = Frame(interior)
  44. self.inputZone = Pmw.Group(mainFrame, tag_text='Offset setting')
  45. self.inputZone.pack(fill='both',expand=1)
  46. settingFrame = self.inputZone.interior()
  47. Label(settingFrame,text=' X ').place(anchor=NW,x=110,y=15)
  48. Label(settingFrame,text=' Y ').place(anchor=NW,x=205,y=15)
  49. Label(settingFrame,text=' Z ').place(anchor=NW,x=295,y=15)
  50. self.move_x = Pmw.EntryField(settingFrame,label_text='Move :',labelpos='w',value='0.0', validate=Pmw.realvalidator)
  51. self.move_x.component('entry').config(width=10)
  52. self.move_y = Pmw.EntryField(settingFrame,value='0.0', validate=Pmw.realvalidator)
  53. self.move_y.component('entry').config(width=10)
  54. self.move_z = Pmw.EntryField(settingFrame, value='0.0', validate=Pmw.realvalidator)
  55. self.move_z.component('entry').config(width=10)
  56. self.move_x.place(anchor=NW,x=50,y=40)
  57. self.move_y.place(anchor=NW,x=185,y=40)
  58. self.move_z.place(anchor=NW,x=275,y=40)
  59. self.rotate_x = Pmw.EntryField(settingFrame,label_text='Rotate:',labelpos='w',value='0.0', validate=Pmw.realvalidator)
  60. self.rotate_x.component('entry').config(width=10)
  61. self.rotate_y = Pmw.EntryField(settingFrame,value='0.0', validate=Pmw.realvalidator)
  62. self.rotate_y.component('entry').config(width=10)
  63. self.rotate_z = Pmw.EntryField(settingFrame, value='0.0', validate=Pmw.realvalidator)
  64. self.rotate_z.component('entry').config(width=10)
  65. self.rotate_x.place(anchor=NW,x=50,y=70)
  66. self.rotate_y.place(anchor=NW,x=185,y=70)
  67. self.rotate_z.place(anchor=NW,x=275,y=70)
  68. self.scale_x = Pmw.EntryField(settingFrame,label_text='Scale :',labelpos='w',value='1.0', validate=Pmw.realvalidator)
  69. self.scale_x.component('entry').config(width=10)
  70. self.scale_y = Pmw.EntryField(settingFrame,value='1.0', validate=Pmw.realvalidator)
  71. self.scale_y.component('entry').config(width=10)
  72. self.scale_z = Pmw.EntryField(settingFrame, value='1.0', validate=Pmw.realvalidator)
  73. self.scale_z.component('entry').config(width=10)
  74. self.scale_x.place(anchor=NW,x=52,y=100)
  75. self.scale_y.place(anchor=NW,x=185,y=100)
  76. self.scale_z.place(anchor=NW,x=275,y=100)
  77. self.numberOfCopy = Pmw.EntryField(settingFrame,label_text='Number of Copy :',labelpos='w',value='1', validate=Pmw.integervalidator)
  78. self.numberOfCopy.component('entry').config(width=15)
  79. self.numberOfCopy.place(anchor=NW,x=52,y=150)
  80. settingFrame.pack(fill=BOTH,expand=1,padx=7,pady=7)
  81. self.button_ok = Button(mainFrame, text="OK", command=self.ok_press,width=10)
  82. self.button_ok.pack(fill=BOTH,expand=0,side=RIGHT)
  83. mainFrame.pack(fill = 'both', expand = 1,padx=7,pady=7)
  84. def createMenuBar(self):
  85. self.menuBar.destroy()
  86. def onDestroy(self, event):
  87. messenger.send('DW_close')
  88. '''
  89. If you have open any thing, please rewrite here!
  90. '''
  91. pass
  92. ###############################
  93. def ok_press(self):
  94. #################################################################
  95. # ok_press(self)
  96. # Callback function
  97. # This function will be called when user click on the "OK" button on the window.
  98. # After collect all data we need for the duplication process,
  99. # this function will send out a message with all data.
  100. # 'DW_duplicating'
  101. # This message will be caught by sceneEditor.
  102. #################################################################
  103. if not self.allEntryValid():
  104. print '---- Duplication Window: Invalid value!!'
  105. return
  106. x = self.move_x.getvalue()
  107. y = self.move_y.getvalue()
  108. z = self.move_z.getvalue()
  109. pos=Vec3(FloatType(x),FloatType(y),FloatType(z))
  110. x = self.rotate_x.getvalue()
  111. y = self.rotate_y.getvalue()
  112. z = self.rotate_z.getvalue()
  113. hpr=Vec3(FloatType(x),FloatType(y),FloatType(z))
  114. x = self.scale_x.getvalue()
  115. y = self.scale_y.getvalue()
  116. z = self.scale_z.getvalue()
  117. scale=Vec3(FloatType(x),FloatType(y),FloatType(z))
  118. num = int(self.numberOfCopy.getvalue())
  119. messenger.send('DW_duplicating',[self.nodePath,pos,hpr,scale,num])
  120. self.quit()
  121. def allEntryValid(self):
  122. #################################################################
  123. # allEntryValid(self)
  124. # This function is used to check all data in the input entries are valid.
  125. #
  126. # For example, none of entries contains blank data.
  127. #
  128. #################################################################
  129. if not self.move_x.valid():
  130. return False
  131. elif not self.move_y.valid():
  132. return False
  133. elif not self.move_z.valid():
  134. return False
  135. elif not self.rotate_x.valid():
  136. return False
  137. elif not self.rotate_y.valid():
  138. return False
  139. elif not self.rotate_z.valid():
  140. return False
  141. elif not self.scale_x.valid():
  142. return False
  143. elif not self.scale_y.valid():
  144. return False
  145. elif not self.scale_z.valid():
  146. return False
  147. elif not self.numberOfCopy.valid():
  148. return False
  149. return True