forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectScrolledFrame.py
More file actions
123 lines (100 loc) · 4.59 KB
/
DirectScrolledFrame.py
File metadata and controls
123 lines (100 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
"""Contains the DirectScrolledFrame class.
See the :ref:`directscrolledframe` page in the programming manual for a more
in-depth explanation and an example of how to use this class.
"""
__all__ = ['DirectScrolledFrame']
from panda3d.core import *
from . import DirectGuiGlobals as DGG
from .DirectFrame import *
from .DirectScrollBar import *
"""
import DirectScrolledFrame
d = DirectScrolledFrame(borderWidth=(0, 0))
"""
class DirectScrolledFrame(DirectFrame):
"""
DirectScrolledFrame -- a special frame that uses DirectScrollBar to
implement a small window (the frameSize) into a potentially much
larger virtual canvas (the canvasSize, scrolledFrame.getCanvas()).
Unless specified otherwise, scroll bars are automatically created
and managed as needed, based on the relative sizes od the
frameSize and the canvasSize. You can also set manageScrollBars =
0 and explicitly position and hide or show the scroll bars
yourself.
"""
def __init__(self, parent = None, **kw):
optiondefs = (
# Define type of DirectGuiWidget
('pgFunc', PGScrollFrame, None),
('frameSize', (-0.5, 0.5, -0.5, 0.5), None),
('canvasSize', (-1, 1, -1, 1), self.setCanvasSize),
('manageScrollBars', 1, self.setManageScrollBars),
('autoHideScrollBars', 1, self.setAutoHideScrollBars),
('scrollBarWidth', 0.08, self.setScrollBarWidth),
('borderWidth', (0.01, 0.01), self.setBorderWidth),
)
# Merge keyword options with default options
self.defineoptions(kw, optiondefs)
# Initialize superclasses
DirectFrame.__init__(self, parent)
# The scrollBarWidth parameter is just used at scroll bar
# construction time, and supplies a default frame. It does
# not override an explicit frame specified on the scroll bar.
# If you want to change the frame width after construction,
# you must specify their frameSize tuples explicitly.
w = self['scrollBarWidth']
self.verticalScroll = self.createcomponent(
"verticalScroll", (), None,
DirectScrollBar, (self,),
borderWidth = self['borderWidth'],
frameSize = (-w / 2.0, w / 2.0, -1, 1),
orientation = DGG.VERTICAL)
self.horizontalScroll = self.createcomponent(
"horizontalScroll", (), None,
DirectScrollBar, (self,),
borderWidth = self['borderWidth'],
frameSize = (-1, 1, -w / 2.0, w / 2.0),
orientation = DGG.HORIZONTAL)
self.guiItem.setVerticalSlider(self.verticalScroll.guiItem)
self.guiItem.setHorizontalSlider(self.horizontalScroll.guiItem)
self.canvas = NodePath(self.guiItem.getCanvasNode())
# Call option initialization functions
self.initialiseoptions(DirectScrolledFrame)
def setScrollBarWidth(self):
if self.fInit: return
w = self['scrollBarWidth']
self.verticalScroll["frameSize"] = (-w / 2.0, w / 2.0, self.verticalScroll["frameSize"][2], self.verticalScroll["frameSize"][3])
self.horizontalScroll["frameSize"] = (self.horizontalScroll["frameSize"][0], self.horizontalScroll["frameSize"][1], -w / 2.0, w / 2.0)
def setCanvasSize(self):
f = self['canvasSize']
self.guiItem.setVirtualFrame(f[0], f[1], f[2], f[3])
def getCanvas(self):
"""Returns the NodePath of the virtual canvas. Nodes parented to this
canvas will show inside the scrolled area.
"""
return self.canvas
def setManageScrollBars(self):
self.guiItem.setManagePieces(self['manageScrollBars'])
def setAutoHideScrollBars(self):
self.guiItem.setAutoHide(self['autoHideScrollBars'])
def commandFunc(self):
if self['command']:
self['command'](*self['extraArgs'])
def destroy(self):
# Destroy children of the canvas
for child in self.canvas.getChildren():
childGui = self.guiDict.get(child.getName())
if childGui:
childGui.destroy()
else:
parts = child.getName().split('-')
simpleChildGui = self.guiDict.get(parts[-1])
if simpleChildGui:
simpleChildGui.destroy()
if self.verticalScroll:
self.verticalScroll.destroy()
if self.horizontalScroll:
self.horizontalScroll.destroy()
self.verticalScroll = None
self.horizontalScroll = None
DirectFrame.destroy(self)