SideWindow.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. #################################################################
  2. # sideWindow.py
  3. # Written by Yi-Hong Lin, [email protected], 2004
  4. #################################################################
  5. from direct.tkwidgets.AppShell import AppShell
  6. from direct.tkwidgets.VectorWidgets import ColorEntry
  7. from direct.showbase.TkGlobal import spawnTkLoop, Toplevel
  8. import seSceneGraphExplorer
  9. from Tkinter import Frame, IntVar, Checkbutton
  10. import Pmw, Tkinter
  11. class sideWindow(AppShell):
  12. #################################################################
  13. # sideWindow(AppShell)
  14. # This class will open a side window wich contains a scene graph and
  15. # a world setting page.
  16. #################################################################
  17. appversion = '1.0'
  18. appname = 'Navigation Window'
  19. frameWidth = 325
  20. frameHeight = 580
  21. frameIniPosX = 0
  22. frameIniPosY = 110
  23. padx = 0
  24. pady = 0
  25. lightEnable = 0
  26. ParticleEnable = 0
  27. basedriveEnable = 0
  28. collision = 0
  29. backface = 0
  30. texture = 1
  31. wireframe = 0
  32. enableBaseUseDrive = 0
  33. def __init__(self, worldColor,lightEnable,ParticleEnable, basedriveEnable,collision,
  34. backface, texture, wireframe, grid, widgetVis, enableAutoCamera, parent = None, nodePath = render, **kw):
  35. self.worldColor = worldColor
  36. self.lightEnable = lightEnable
  37. self.ParticleEnable = ParticleEnable
  38. self.basedriveEnable = basedriveEnable
  39. self.collision = collision
  40. self.backface = backface
  41. self.texture = texture
  42. self.wireframe = wireframe
  43. self.grid = grid
  44. self.enableAutoCamera = enableAutoCamera
  45. self.widgetVis = widgetVis
  46. # Define the megawidget options.
  47. optiondefs = (
  48. ('title', self.appname, None),
  49. )
  50. self.defineoptions(kw, optiondefs)
  51. if parent == None:
  52. self.parent = Toplevel()
  53. else:
  54. self.parent = parent
  55. AppShell.__init__(self, self.parent)
  56. self.parent.geometry('%dx%d+%d+%d' % (self.frameWidth, self.frameHeight,self.frameIniPosX,self.frameIniPosY))
  57. self.parent.resizable(False,False) ## Disable the ability to resize for this Window.
  58. def appInit(self):
  59. print '----SideWindow is Initialized!!'
  60. def createInterface(self):
  61. # The interior of the toplevel panel
  62. interior = self.interior()
  63. mainFrame = Frame(interior)
  64. ## Creat NoteBook
  65. self.notebookFrame = Pmw.NoteBook(mainFrame)
  66. self.notebookFrame.pack(fill=Tkinter.BOTH,expand=1)
  67. sgePage = self.notebookFrame.add('Tree Graph')
  68. envPage = self.notebookFrame.add('World Setting')
  69. self.notebookFrame['raisecommand'] = self.updateInfo
  70. ## Tree Grapgh Page
  71. self.SGE = seSceneGraphExplorer.seSceneGraphExplorer(
  72. sgePage, nodePath = render,
  73. scrolledCanvas_hull_width = 270,
  74. scrolledCanvas_hull_height = 570)
  75. self.SGE.pack(fill = Tkinter.BOTH, expand = 0)
  76. ## World Setting Page
  77. envPage = Frame(envPage)
  78. pageFrame = Frame(envPage)
  79. self.LightingVar = IntVar()
  80. self.LightingVar.set(self.lightEnable)
  81. self.LightingButton = Checkbutton(
  82. pageFrame,
  83. text = 'Enable Lighting',
  84. variable = self.LightingVar,
  85. command = self.toggleLights)
  86. self.LightingButton.pack(side=Tkinter.LEFT, expand=False)
  87. pageFrame.pack(side=Tkinter.TOP, fill=Tkinter.X, expand=True)
  88. pageFrame = Frame(envPage)
  89. self.CollisionVar = IntVar()
  90. self.CollisionVar.set(self.collision)
  91. self.CollisionButton = Checkbutton(
  92. pageFrame,
  93. text = 'Show Collision Object',
  94. variable = self.CollisionVar,
  95. command = self.showCollision)
  96. self.CollisionButton.pack(side=Tkinter.LEFT, expand=False)
  97. pageFrame.pack(side=Tkinter.TOP, fill=Tkinter.X, expand=True)
  98. pageFrame = Frame(envPage)
  99. self.ParticleVar = IntVar()
  100. self.ParticleVar.set(self.ParticleEnable)
  101. self.ParticleButton = Checkbutton(
  102. pageFrame,
  103. text = 'Show Particle Dummy',
  104. variable = self.ParticleVar,
  105. command = self.enableParticle)
  106. self.ParticleButton.pack(side=Tkinter.LEFT, expand=False)
  107. pageFrame.pack(side=Tkinter.TOP, fill=Tkinter.X, expand=True)
  108. pageFrame = Frame(envPage)
  109. self.baseUseDriveVar = IntVar()
  110. self.baseUseDriveVar.set(self.basedriveEnable)
  111. self.baseUseDriveButton = Checkbutton(
  112. pageFrame,
  113. text = 'Enable base.usedrive',
  114. variable = self.baseUseDriveVar,
  115. command = self.enablebaseUseDrive)
  116. self.baseUseDriveButton.pack(side=Tkinter.LEFT, expand=False)
  117. pageFrame.pack(side=Tkinter.TOP, fill=Tkinter.X, expand=True)
  118. pageFrame = Frame(envPage)
  119. self.backfaceVar = IntVar()
  120. self.backfaceVar.set(self.backface)
  121. self.backfaceButton = Checkbutton(
  122. pageFrame,
  123. text = 'Enable BackFace',
  124. variable = self.backfaceVar,
  125. command = self.toggleBackface)
  126. self.backfaceButton.pack(side=Tkinter.LEFT, expand=False)
  127. pageFrame.pack(side=Tkinter.TOP, fill=Tkinter.X, expand=True)
  128. pageFrame = Frame(envPage)
  129. self.textureVar = IntVar()
  130. self.textureVar.set(self.texture)
  131. self.textureButton = Checkbutton(
  132. pageFrame,
  133. text = 'Enable Texture',
  134. variable = self.textureVar,
  135. command = self.toggleTexture)
  136. self.textureButton.pack(side=Tkinter.LEFT, expand=False)
  137. pageFrame.pack(side=Tkinter.TOP, fill=Tkinter.X, expand=True)
  138. pageFrame = Frame(envPage)
  139. self.wireframeVar = IntVar()
  140. self.wireframeVar.set(self.wireframe)
  141. self.wireframeButton = Checkbutton(
  142. pageFrame,
  143. text = 'Enable Wireframe',
  144. variable = self.wireframeVar,
  145. command = self.toggleWireframe)
  146. self.wireframeButton.pack(side=Tkinter.LEFT, expand=False)
  147. pageFrame.pack(side=Tkinter.TOP, fill=Tkinter.X, expand=True)
  148. pageFrame = Frame(envPage)
  149. self.gridVar = IntVar()
  150. self.gridVar.set(self.grid)
  151. self.gridButton = Checkbutton(
  152. pageFrame,
  153. text = 'Enable Grid',
  154. variable = self.gridVar,
  155. command = self.toggleGrid)
  156. self.gridButton.pack(side=Tkinter.LEFT, expand=False)
  157. pageFrame.pack(side=Tkinter.TOP, fill=Tkinter.X, expand=True)
  158. pageFrame = Frame(envPage)
  159. self.widgetVisVar = IntVar()
  160. self.widgetVisVar.set(self.widgetVis)
  161. self.widgetVisButton = Checkbutton(
  162. pageFrame,
  163. text = 'Enable WidgetVisible',
  164. variable = self.widgetVisVar,
  165. command = self.togglewidgetVis)
  166. self.widgetVisButton.pack(side=Tkinter.LEFT, expand=False)
  167. pageFrame.pack(side=Tkinter.TOP, fill=Tkinter.X, expand=True)
  168. pageFrame = Frame(envPage)
  169. self.enableAutoCameraVar = IntVar()
  170. self.enableAutoCameraVar.set(self.enableAutoCamera)
  171. self.enableAutoCameraButton = Checkbutton(
  172. pageFrame,
  173. text = 'Enable Auto Camera Movement for Loading Objects',
  174. variable = self.enableAutoCameraVar,
  175. command = self.toggleAutoCamera)
  176. self.enableAutoCameraButton.pack(side=Tkinter.LEFT, expand=False)
  177. pageFrame.pack(side=Tkinter.TOP, fill=Tkinter.X, expand=True)
  178. pageFrame = Frame(envPage)
  179. self.backgroundColor = ColorEntry(
  180. pageFrame, text = 'BG Color', value=self.worldColor)
  181. self.backgroundColor['command'] = self.setBackgroundColorVec
  182. self.backgroundColor['resetValue'] = [0,0,0,0]
  183. self.backgroundColor.pack(side=Tkinter.LEFT, expand=False)
  184. self.bind(self.backgroundColor, 'Set background color')
  185. pageFrame.pack(side=Tkinter.TOP, fill=Tkinter.X, expand=True)
  186. envPage.pack(expand=False)
  187. ## Set all stuff done
  188. self.notebookFrame.setnaturalsize()
  189. mainFrame.pack(fill = 'both', expand = 1)
  190. def createMenuBar(self):
  191. # We don't need menu bar here.
  192. self.menuBar.destroy()
  193. def onDestroy(self, event):
  194. #################################################################
  195. # onDestroy(self, event)
  196. # This function will be called when user closed the side window.
  197. # Here we will send out a message with whole data set we will need
  198. # for the next time user open the side window.
  199. #################################################################
  200. messenger.send('SW_close',[self.worldColor,
  201. self.lightEnable,
  202. self.ParticleEnable,
  203. self.basedriveEnable,
  204. self.collision,
  205. self.backface,
  206. self.texture,
  207. self.wireframe,
  208. self.grid,
  209. self.widgetVis,
  210. self.enableAutoCamera])
  211. '''
  212. If you have open any thing, please rewrite here!
  213. '''
  214. pass
  215. ###############################
  216. def updateInfo(self, page = 'Tree Graph'):
  217. #################################################################
  218. # updateInfo(self, page = 'Tree Graph')
  219. # This function will be called when each time user change the main
  220. # page of the window.
  221. # What it dose is to call right function to restore the data for current selected page.
  222. #################################################################
  223. if page=='Tree Graph':
  224. self.updateTreeGraph()
  225. elif page == 'World Setting':
  226. self.updateWorldSetting()
  227. def updateTreeGraph(self):
  228. #################################################################
  229. # updateTreeGraph(self)
  230. # When scene graoh page has been opend, call sceneGraphExplorer to
  231. # updata the tree.
  232. #################################################################
  233. self.SGE.update()
  234. pass
  235. def updateWorldSetting(self):
  236. #################################################################
  237. # updateWorldSetting(self)
  238. # When world setting page has been selected, this function will
  239. # reset those check box in the page to reflect the current world setting.
  240. #################################################################
  241. self.LightingVar.set(self.lightEnable)
  242. self.CollisionVar.set(self.collision)
  243. self.ParticleVar.set(self.ParticleEnable)
  244. self.baseUseDriveVar.set(self.basedriveEnable)
  245. self.backgroundColor.set(value = self.worldColor)
  246. pass
  247. def toggleLights(self):
  248. #################################################################
  249. # toggleLights(self)
  250. # send out a message to let sceneEditor know we need to toggle the light.
  251. # Then, sceneEditor will pass the message to dataHolder to disable/enable
  252. # the lights. (lightManager is inside the dataHolder)
  253. #################################################################
  254. self.lightEnable = (self.lightEnable+1)%2
  255. messenger.send('SW_lightToggle')
  256. pass
  257. def showCollision(self):
  258. #################################################################
  259. # showCollision(self)
  260. # This function will send out a message to sceneEditor to toggle
  261. # the visibility of collision objects.
  262. #################################################################
  263. self.collision = (self.collision+1)%2
  264. messenger.send('SW_collisionToggle', [self.collision])
  265. pass
  266. def enableParticle(self):
  267. #################################################################
  268. # enableParticle(self)
  269. # This function will send out a message to sceneEditor to toggle
  270. # the visibility of particle objects.
  271. #################################################################
  272. self.ParticleEnable = (self.ParticleEnable+1)%2
  273. messenger.send('SW_particleToggle', [self.ParticleEnable])
  274. pass
  275. def enablebaseUseDrive(self):
  276. #################################################################
  277. # enablebaseUseDrive(self)
  278. # This function will toggle the usage of base.useDrive.
  279. # Well, it may not usefull at all.
  280. #
  281. # We won't send out any message in this time to notice
  282. # the sceneEditor this event happend.
  283. # In the other hand, we will restore it back when
  284. # the side window has been closed.
  285. #
  286. #################################################################
  287. if self.enableBaseUseDrive==0:
  288. print 'Enabled'
  289. base.useDrive()
  290. self.enableBaseUseDrive = 1
  291. else:
  292. print 'disabled'
  293. #base.useTrackball()
  294. base.disableMouse()
  295. self.enableBaseUseDrive = 0
  296. self.basedriveEnable = (self.basedriveEnable+1)%2
  297. pass
  298. def toggleBackface(self):
  299. #################################################################
  300. # toggleBackface(self)
  301. # This function will toggle the back face setting. so it will
  302. # render the polygon with two sides.
  303. #################################################################
  304. base.toggleBackface()
  305. self.backface = (self.backface+1)%2
  306. return
  307. def toggleBackfaceFromMainW(self):
  308. #################################################################
  309. # toggleBackfaceFromMainW(self)
  310. # This function is called by sceneEditor when user used hot key
  311. # to toggle the back face setting in the main panda window.
  312. # In here we will only reset the flag and reset the state of
  313. # check box
  314. #################################################################
  315. self.backface = (self.backface+1)%2
  316. self.backfaceButton.toggle()
  317. return
  318. def toggleTexture(self):
  319. #################################################################
  320. # toggleTexture(self)
  321. # This function will toggle the txture using option for the whole scene.
  322. #################################################################
  323. base.toggleTexture()
  324. self.texture = (self.texture+1)%2
  325. return
  326. def toggleTextureFromMainW(self):
  327. #################################################################
  328. # toggleTextureFromMainW(self)
  329. # This function is called by sceneEditor when user used hot key
  330. # to toggle the texture usage from the main panda window.
  331. # In here we will only reset the flag and reset the state of
  332. # check box
  333. #################################################################
  334. self.texture = (self.texture+1)%2
  335. self.textureButton.toggle()
  336. return
  337. def toggleWireframe(self):
  338. #################################################################
  339. # toggleWireframe(self)
  340. # This function will toggle the wire frame mode.
  341. #################################################################
  342. base.toggleWireframe()
  343. self.wireframe = (self.wireframe+1)%2
  344. return
  345. def toggleWireframeFromMainW(self):
  346. #################################################################
  347. # toggleWireframeFromMainW(self)
  348. # This function is called by sceneEditor when user used hot key
  349. # to toggle the wire frame mode in the main panda window.
  350. # In here we will only reset the flag and reset the state of
  351. # check box
  352. #################################################################
  353. self.wireframe = (self.wireframe+1)%2
  354. self.wireframeButton.toggle()
  355. return
  356. def toggleGrid(self):
  357. #################################################################
  358. # toggleGrid(self)
  359. # This function will toggle the usage of the grid.
  360. #################################################################
  361. self.grid = (self.grid+1)%2
  362. if self.grid==1:
  363. SEditor.grid.enable()
  364. else:
  365. SEditor.grid.disable()
  366. def togglewidgetVis(self):
  367. #################################################################
  368. # togglewidgetVis(self)
  369. # This function will toggle the visibility of the widget of the grid.
  370. #################################################################
  371. self.widgetVis = (self.widgetVis+1)%2
  372. SEditor.toggleWidgetVis()
  373. if SEditor.widget.fActive:
  374. messenger.send('shift-f')
  375. return
  376. def toggleWidgetVisFromMainW(self):
  377. #################################################################
  378. # toggleWidgetVisFromMainW(self)
  379. # This function is called by sceneEditor when user used hot key
  380. # to toggle the visibility of widgets ('v') from the main panda window.
  381. # In here we will only reset the flag and reset the state of
  382. # check box
  383. #################################################################
  384. self.widgetVis = (self.widgetVis+1)%2
  385. self.widgetVisButton.toggle()
  386. return
  387. def setBackgroundColorVec(self,color):
  388. #################################################################
  389. # setBackgroundColorVec(self,color)
  390. # Call back function
  391. # This will be called from the colorEntry on the world setting page.
  392. # The "color" here is a list containing three integer data, R, G and B.
  393. #################################################################
  394. base.setBackgroundColor(color[0]/255.0,
  395. color[1]/255.0,
  396. color[2]/255.0)
  397. self.worldColor = [color[0],color[1],color[2],0]
  398. def toggleAutoCamera(self):
  399. #################################################################
  400. # toggleAutoCamera(self)
  401. # This function will toggle the usage of the auto-camera movement
  402. # when user loaded model or actor into the scene.
  403. #################################################################
  404. self.enableAutoCamera = (self.enableAutoCamera+1)%2
  405. SEditor.toggleAutoCamera()
  406. return
  407. def selectPage(self,page='Tree Graph'):
  408. #################################################################
  409. #################################################################
  410. self.notebookFrame.selectpage(page)