Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / lib / python2.4 / site-packages / Pmw / Pmw_1_2 / lib / PmwGroup.py
CommitLineData
920dae64
AT
1import string
2import Tkinter
3import Pmw
4
5def aligngrouptags(groups):
6 # Adjust the y position of the tags in /groups/ so that they all
7 # have the height of the highest tag.
8
9 maxTagHeight = 0
10 for group in groups:
11 if group._tag is None:
12 height = (string.atoi(str(group._ring.cget('borderwidth'))) +
13 string.atoi(str(group._ring.cget('highlightthickness'))))
14 else:
15 height = group._tag.winfo_reqheight()
16 if maxTagHeight < height:
17 maxTagHeight = height
18
19 for group in groups:
20 ringBorder = (string.atoi(str(group._ring.cget('borderwidth'))) +
21 string.atoi(str(group._ring.cget('highlightthickness'))))
22 topBorder = maxTagHeight / 2 - ringBorder / 2
23 group._hull.grid_rowconfigure(0, minsize = topBorder)
24 group._ring.grid_rowconfigure(0,
25 minsize = maxTagHeight - topBorder - ringBorder)
26 if group._tag is not None:
27 group._tag.place(y = maxTagHeight / 2)
28
29class Group( Pmw.MegaWidget ):
30 def __init__(self, parent = None, **kw):
31
32 # Define the megawidget options.
33 INITOPT = Pmw.INITOPT
34 optiondefs = (
35 ('collapsedsize', 6, INITOPT),
36 ('ring_borderwidth', 2, None),
37 ('ring_relief', 'groove', None),
38 ('tagindent', 10, INITOPT),
39 )
40 self.defineoptions(kw, optiondefs)
41
42 # Initialise the base class (after defining the options).
43 Pmw.MegaWidget.__init__(self, parent)
44
45 # Create the components.
46 interior = Pmw.MegaWidget.interior(self)
47
48 self._ring = self.createcomponent(
49 'ring',
50 (), None,
51 Tkinter.Frame, (interior,),
52 )
53
54 self._groupChildSite = self.createcomponent(
55 'groupchildsite',
56 (), None,
57 Tkinter.Frame, (self._ring,)
58 )
59
60 self._tag = self.createcomponent(
61 'tag',
62 (), None,
63 Tkinter.Label, (interior,),
64 )
65
66 ringBorder = (string.atoi(str(self._ring.cget('borderwidth'))) +
67 string.atoi(str(self._ring.cget('highlightthickness'))))
68 if self._tag is None:
69 tagHeight = ringBorder
70 else:
71 tagHeight = self._tag.winfo_reqheight()
72 self._tag.place(
73 x = ringBorder + self['tagindent'],
74 y = tagHeight / 2,
75 anchor = 'w')
76
77 topBorder = tagHeight / 2 - ringBorder / 2
78 self._ring.grid(column = 0, row = 1, sticky = 'nsew')
79 interior.grid_columnconfigure(0, weight = 1)
80 interior.grid_rowconfigure(1, weight = 1)
81 interior.grid_rowconfigure(0, minsize = topBorder)
82
83 self._groupChildSite.grid(column = 0, row = 1, sticky = 'nsew')
84 self._ring.grid_columnconfigure(0, weight = 1)
85 self._ring.grid_rowconfigure(1, weight = 1)
86 self._ring.grid_rowconfigure(0,
87 minsize = tagHeight - topBorder - ringBorder)
88
89 self.showing = 1
90
91 # Check keywords and initialise options.
92 self.initialiseoptions()
93
94 def toggle(self):
95 if self.showing:
96 self.collapse()
97 else:
98 self.expand()
99 self.showing = not self.showing
100
101 def expand(self):
102 self._groupChildSite.grid(column = 0, row = 1, sticky = 'nsew')
103
104 def collapse(self):
105 self._groupChildSite.grid_forget()
106 if self._tag is None:
107 tagHeight = 0
108 else:
109 tagHeight = self._tag.winfo_reqheight()
110 self._ring.configure(height=(tagHeight / 2) + self['collapsedsize'])
111
112 def interior(self):
113 return self._groupChildSite