DirectScrolledFrame.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. """Undocumented Module"""
  2. __all__ = ['DirectScrolledFrame']
  3. from panda3d.core import *
  4. from . 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. ('borderWidth', (0.01, 0.01), self.setBorderWidth),
  32. )
  33. # Merge keyword options with default options
  34. self.defineoptions(kw, optiondefs)
  35. # Initialize superclasses
  36. DirectFrame.__init__(self, parent)
  37. # The scrollBarWidth parameter is just used at scroll bar
  38. # construction time, and supplies a default frame. It does
  39. # not override an explicit frame specified on the scroll bar.
  40. # If you want to change the frame width after construction,
  41. # you must specify their frameSize tuples explicitly.
  42. w = self['scrollBarWidth']
  43. self.verticalScroll = self.createcomponent(
  44. "verticalScroll", (), None,
  45. DirectScrollBar, (self,),
  46. borderWidth = self['borderWidth'],
  47. frameSize = (-w / 2.0, w / 2.0, -1, 1),
  48. orientation = DGG.VERTICAL)
  49. self.horizontalScroll = self.createcomponent(
  50. "horizontalScroll", (), None,
  51. DirectScrollBar, (self,),
  52. borderWidth = self['borderWidth'],
  53. frameSize = (-1, 1, -w / 2.0, w / 2.0),
  54. orientation = DGG.HORIZONTAL)
  55. self.guiItem.setVerticalSlider(self.verticalScroll.guiItem)
  56. self.guiItem.setHorizontalSlider(self.horizontalScroll.guiItem)
  57. self.canvas = NodePath(self.guiItem.getCanvasNode())
  58. # Call option initialization functions
  59. self.initialiseoptions(DirectScrolledFrame)
  60. def setCanvasSize(self):
  61. f = self['canvasSize']
  62. self.guiItem.setVirtualFrame(f[0], f[1], f[2], f[3])
  63. def getCanvas(self):
  64. return self.canvas
  65. def setManageScrollBars(self):
  66. self.guiItem.setManagePieces(self['manageScrollBars'])
  67. def setAutoHideScrollBars(self):
  68. self.guiItem.setAutoHide(self['autoHideScrollBars'])
  69. def commandFunc(self):
  70. if self['command']:
  71. self['command'](*self['extraArgs'])
  72. def destroy(self):
  73. # Destroy children of the canvas
  74. for child in self.canvas.getChildren():
  75. childGui = self.guiDict.get(child.getName())
  76. if childGui:
  77. childGui.destroy()
  78. else:
  79. parts = child.getName().split('-')
  80. simpleChildGui = self.guiDict.get(parts[-1])
  81. if simpleChildGui:
  82. simpleChildGui.destroy()
  83. self.verticalScroll.destroy()
  84. self.horizontalScroll.destroy()
  85. del self.verticalScroll
  86. del self.horizontalScroll
  87. DirectFrame.destroy(self)