DirectScrolledFrame.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. """Undocumented Module"""
  2. __all__ = ['DirectScrolledFrame']
  3. from pandac.PandaModules import *
  4. import DirectGuiGlobals as DGG
  5. from DirectFrame import *
  6. from DirectScrollBar import *
  7. """
  8. import DirectScrolledFrame
  9. d = DirectScrolledFrame(borderWidth=(0, 0))
  10. """
  11. class DirectScrolledFrame(DirectFrame):
  12. """
  13. DirectScrolledFrame -- a special frame that uses DirectScrollBar to
  14. implement a small window (the frameSize) into a potentially much
  15. larger virtual canvas (the canvasSize, scrolledFrame.getCanvas()).
  16. Unless specified otherwise, scroll bars are automatically created
  17. and managed as needed, based on the relative sizes od the
  18. frameSize and the canvasSize. You can also set manageScrollBars =
  19. 0 and explicitly position and hide or show the scroll bars
  20. yourself.
  21. """
  22. def __init__(self, parent = None, **kw):
  23. optiondefs = (
  24. # Define type of DirectGuiWidget
  25. ('pgFunc', PGScrollFrame, None),
  26. ('frameSize', (-0.5, 0.5, -0.5, 0.5), None),
  27. ('canvasSize', (-1, 1, -1, 1), self.setCanvasSize),
  28. ('manageScrollBars', 1, self.setManageScrollBars),
  29. ('autoHideScrollBars', 1, self.setAutoHideScrollBars),
  30. ('scrollBarWidth', 0.08, None),
  31. )
  32. # Merge keyword options with default options
  33. self.defineoptions(kw, optiondefs)
  34. # Initialize superclasses
  35. DirectFrame.__init__(self, parent)
  36. # The scrollBarWidth parameter is just used at scroll bar
  37. # construction time, and supplies a default frame. It does
  38. # not override an explicit frame specified on the scroll bar.
  39. # If you want to change the frame width after construction,
  40. # you must specify their frameSize tuples explicitly.
  41. w = self['scrollBarWidth']
  42. self.verticalScroll = self.createcomponent(
  43. "verticalScroll", (), None,
  44. DirectScrollBar, (self,),
  45. borderWidth = self['borderWidth'],
  46. frameSize = (-w / 2.0, w / 2.0, -1, 1),
  47. orientation = DGG.VERTICAL)
  48. self.horizontalScroll = self.createcomponent(
  49. "horizontalScroll", (), None,
  50. DirectScrollBar, (self,),
  51. borderWidth = self['borderWidth'],
  52. frameSize = (-1, 1, -w / 2.0, w / 2.0),
  53. orientation = DGG.HORIZONTAL)
  54. self.guiItem.setVerticalSlider(self.verticalScroll.guiItem)
  55. self.guiItem.setHorizontalSlider(self.horizontalScroll.guiItem)
  56. self.canvas = NodePath(self.guiItem.getCanvasNode())
  57. # Call option initialization functions
  58. self.initialiseoptions(DirectScrolledFrame)
  59. def setCanvasSize(self):
  60. f = self['canvasSize']
  61. self.guiItem.setVirtualFrame(f[0], f[1], f[2], f[3])
  62. def getCanvas(self):
  63. return self.canvas
  64. def setManageScrollBars(self):
  65. self.guiItem.setManagePieces(self['manageScrollBars'])
  66. def setAutoHideScrollBars(self):
  67. self.guiItem.setAutoHide(self['autoHideScrollBars'])
  68. def commandFunc(self):
  69. if self['command']:
  70. apply(self['command'], self['extraArgs'])
  71. def destroy(self):
  72. # Destroy children of the canvas
  73. for child in self.canvas.getChildrenAsList():
  74. childGui = self.guiDict.get(child.getName())
  75. if childGui:
  76. childGui.destroy()
  77. else:
  78. parts = child.getName().split('-')
  79. simpleChildGui = self.guiDict.get(parts[-1])
  80. if simpleChildGui:
  81. simpleChildGui.destroy()
  82. self.verticalScroll.destroy()
  83. self.horizontalScroll.destroy()
  84. del self.verticalScroll
  85. del self.horizontalScroll
  86. DirectFrame.destroy(self)