1
1
"""
2
2
Copyright: MAXON Computer GmbH
3
3
Author: Maxime Adam
4
-
5
4
Description:
6
5
- Creates a Modal Dialog displaying a different SubDialog according to the selected entry of the QuickTab.
7
6
- Demonstrates how to add, flushes, remove tab interactively.
8
-
9
7
Class/method highlighted:
10
8
- c4d.gui.QuickTabCustomGui
11
9
- QuickTabCustomGui.ClearStrings()
17
15
- GeDialog.HideElement()
18
16
- GeDialog.RemoveElement()
19
17
- c4d.gui.SubDialog
20
-
21
18
Compatible:
22
19
- Win / Mac
23
20
- R19, R20, R21
@@ -61,7 +58,6 @@ def __init__(self):
61
58
def _DrawQuickTabGroup (self ):
62
59
"""
63
60
Creates and draws all the SubDialog for each tab, take care it does not hide these according to a selection state.
64
-
65
61
:return: True if success otherwise False.
66
62
"""
67
63
@@ -82,38 +78,38 @@ def _DrawQuickTabGroup(self):
82
78
83
79
return True
84
80
85
- def GetActiveTab (self ):
81
+ def GetActiveTabs (self ):
86
82
"""
87
- Retrieves the current selected tab from the self._quickTab.
88
-
89
- :return: The tab Id (from the dict) and the name of the selected tab
90
- :rtype: (int, str) or (False, False) if fail.
83
+ Retrieves two list of currently selected tabs from the self._quickTab.
84
+ :return: The first list, contains tabs Id (from self._quickTab the dict) and the second list contains all names of the selected tabs.
85
+ :rtype: list(int), list(name)
91
86
"""
92
87
# Checks if the quicktab is defined
93
88
if self ._quickTab is None :
94
89
return False , False
95
90
91
+ returnIds = []
92
+ returnNames = []
93
+
96
94
for tabId , (tabName , tabGui ) in enumerate (self ._tabList .iteritems ()):
97
95
if self ._quickTab .IsSelected (tabId ):
98
- return tabId , tabName
96
+ returnIds .append (tabId )
97
+ returnNames .append (tabName )
99
98
100
- return False , False
99
+ return returnIds , returnNames
101
100
102
101
def DisplayCorrectGroup (self ):
103
102
"""
104
103
Hides all unused groups and display the correct one.
105
-
106
104
:return: True if success otherwise False.
107
105
"""
108
106
# Retrieves the selected tab
109
- activeId , activeName = self .GetActiveTab ()
110
- if activeId is False :
111
- return False
107
+ activeIds , activeNames = self .GetActiveTabs ()
112
108
113
109
# Iterates each CustomGui and defines if they are hidden or not
114
110
for tabId in xrange (len (self ._tabList )):
115
- toHide = activeId == tabId
116
- self .HideElement (ID_QUICKTAB_BASE_GROUP + tabId , not toHide )
111
+ toDisplay = tabId in activeIds
112
+ self .HideElement (ID_QUICKTAB_BASE_GROUP + tabId , not toDisplay )
117
113
118
114
# Notifies the content of the MainGroup has changed
119
115
self .LayoutChanged (ID_MAINGROUP )
@@ -122,7 +118,6 @@ def DisplayCorrectGroup(self):
122
118
def AppendTab (self , tabName , content , active = True ):
123
119
"""
124
120
Appends a tab to the current quicktab with the associated content to be displayed.
125
-
126
121
:param tabName: The name the tab should have.
127
122
:type tabName: str
128
123
:param content: The SubDialog to be drawn/linked when the tab is selected.
@@ -142,16 +137,17 @@ def AppendTab(self, tabName, content, active=True):
142
137
self ._tabList .update ({tabName : content })
143
138
144
139
# Retrieves the current selected tab
145
- previousActiveId , previousActiveName = self .GetActiveTab ()
140
+ previousActiveId , previousActiveName = self .GetActiveTabs ()
146
141
147
142
# Draws the quicktab SubDialog (in order to have the new one drawn)
148
143
self ._DrawQuickTabGroup ()
149
144
150
- # Defines which tab should be active
151
- if active :
152
- self ._quickTab .Select (len (self ._tabList ) - 1 , True )
153
- else :
154
- self ._quickTab .Select (previousActiveId , True )
145
+ # Defines the just added tab according state
146
+ self ._quickTab .Select (len (self ._tabList ) - 1 , active )
147
+
148
+ # Defines previous active tab
149
+ for tabId in previousActiveId :
150
+ self ._quickTab .Select (tabId , True )
155
151
156
152
# Display only the selected tab and hides all others
157
153
self .DisplayCorrectGroup ()
@@ -161,7 +157,6 @@ def AppendTab(self, tabName, content, active=True):
161
157
def FlushAllTabs (self ):
162
158
"""
163
159
Removes all tabs and their content from the GUI.
164
-
165
160
:return: True if success otherwise False.
166
161
"""
167
162
# Checks if the quicktab is defined
@@ -186,7 +181,6 @@ def FlushAllTabs(self):
186
181
def RemoveTab (self , tabNameToRemove ):
187
182
"""
188
183
Removes a tab by its name
189
-
190
184
:param tabNameToRemove: The tab to remove.
191
185
:type tabNameToRemove: str
192
186
:return: True if success otherwise False.
@@ -223,7 +217,7 @@ def CreateLayout(self):
223
217
bc = c4d .BaseContainer ()
224
218
bc .SetBool (c4d .QUICKTAB_BAR , False )
225
219
bc .SetBool (c4d .QUICKTAB_SHOWSINGLE , True )
226
- bc .SetBool (c4d .QUICKTAB_NOMULTISELECT , True )
220
+ bc .SetBool (c4d .QUICKTAB_NOMULTISELECT , False )
227
221
self ._quickTab = self .AddCustomGui (ID_QUICKTAB_BAR , c4d .CUSTOMGUI_QUICKTAB , '' ,
228
222
c4d .BFH_SCALEFIT | c4d .BFV_SCALEFIT , 0 , 0 , bc )
229
223
@@ -247,7 +241,7 @@ def InitValues(self):
247
241
"""
248
242
# Creates the first Tab
249
243
cg1 = CustomGroup (["This is the first Tab" , "Just dummy text here" ])
250
- self .AppendTab ("First Tab" , cg1 , False )
244
+ self .AppendTab ("First Tab" , cg1 , True )
251
245
252
246
# Creates the second Tab
253
247
cg2 = CustomGroup (["This is the second Tab" , "Just another dummy text here" ])
@@ -258,7 +252,6 @@ def Command(self, id, msg):
258
252
"""
259
253
This Method is called automatically when the user clicks on a gadget and/or changes its value this function will be called.
260
254
It is also called when a string menu item is selected.
261
-
262
255
:param id: The ID of the gadget that triggered the event.
263
256
:param msg: The original message container
264
257
:return: False if there was an error, otherwise True.
@@ -276,7 +269,7 @@ def Command(self, id, msg):
276
269
277
270
# Displays the ID and name of the selected tab
278
271
if id == BUTTON_PRINT_SELECTED :
279
- print self .GetActiveTab ()
272
+ print self .GetActiveTabs ()
280
273
281
274
# Removes all tabs
282
275
if id == BUTTON_FLUSH_ALL :
@@ -285,7 +278,7 @@ def Command(self, id, msg):
285
278
# Adds a new Tab to the quicktab
286
279
if id == BUTTON_ADD :
287
280
cg3 = CustomGroup (["This is the third Tab" ])
288
- self .AppendTab ("Third Tab" , cg3 , False )
281
+ self .AppendTab ("Third Tab" , cg3 , True )
289
282
290
283
# Removes the first tab of the quicktab
291
284
if id == BUTTON_REMOVE :
@@ -305,4 +298,4 @@ def main():
305
298
306
299
# Execute main()
307
300
if __name__ == '__main__' :
308
- main ()
301
+ main ()
0 commit comments