11"""
22Copyright: MAXON Computer GmbH
33Author: Maxime Adam
4-
54Description:
65 - Creates a Modal Dialog displaying a different SubDialog according to the selected entry of the QuickTab.
76 - Demonstrates how to add, flushes, remove tab interactively.
8-
97Class/method highlighted:
108 - c4d.gui.QuickTabCustomGui
119 - QuickTabCustomGui.ClearStrings()
1715 - GeDialog.HideElement()
1816 - GeDialog.RemoveElement()
1917 - c4d.gui.SubDialog
20-
2118Compatible:
2219 - Win / Mac
2320 - R19, R20, R21
@@ -61,7 +58,6 @@ def __init__(self):
6158 def _DrawQuickTabGroup (self ):
6259 """
6360 Creates and draws all the SubDialog for each tab, take care it does not hide these according to a selection state.
64-
6561 :return: True if success otherwise False.
6662 """
6763
@@ -82,38 +78,38 @@ def _DrawQuickTabGroup(self):
8278
8379 return True
8480
85- def GetActiveTab (self ):
81+ def GetActiveTabs (self ):
8682 """
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)
9186 """
9287 # Checks if the quicktab is defined
9388 if self ._quickTab is None :
9489 return False , False
9590
91+ returnIds = []
92+ returnNames = []
93+
9694 for tabId , (tabName , tabGui ) in enumerate (self ._tabList .iteritems ()):
9795 if self ._quickTab .IsSelected (tabId ):
98- return tabId , tabName
96+ returnIds .append (tabId )
97+ returnNames .append (tabName )
9998
100- return False , False
99+ return returnIds , returnNames
101100
102101 def DisplayCorrectGroup (self ):
103102 """
104103 Hides all unused groups and display the correct one.
105-
106104 :return: True if success otherwise False.
107105 """
108106 # Retrieves the selected tab
109- activeId , activeName = self .GetActiveTab ()
110- if activeId is False :
111- return False
107+ activeIds , activeNames = self .GetActiveTabs ()
112108
113109 # Iterates each CustomGui and defines if they are hidden or not
114110 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 )
117113
118114 # Notifies the content of the MainGroup has changed
119115 self .LayoutChanged (ID_MAINGROUP )
@@ -122,7 +118,6 @@ def DisplayCorrectGroup(self):
122118 def AppendTab (self , tabName , content , active = True ):
123119 """
124120 Appends a tab to the current quicktab with the associated content to be displayed.
125-
126121 :param tabName: The name the tab should have.
127122 :type tabName: str
128123 :param content: The SubDialog to be drawn/linked when the tab is selected.
@@ -142,16 +137,17 @@ def AppendTab(self, tabName, content, active=True):
142137 self ._tabList .update ({tabName : content })
143138
144139 # Retrieves the current selected tab
145- previousActiveId , previousActiveName = self .GetActiveTab ()
140+ previousActiveId , previousActiveName = self .GetActiveTabs ()
146141
147142 # Draws the quicktab SubDialog (in order to have the new one drawn)
148143 self ._DrawQuickTabGroup ()
149144
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 )
155151
156152 # Display only the selected tab and hides all others
157153 self .DisplayCorrectGroup ()
@@ -161,7 +157,6 @@ def AppendTab(self, tabName, content, active=True):
161157 def FlushAllTabs (self ):
162158 """
163159 Removes all tabs and their content from the GUI.
164-
165160 :return: True if success otherwise False.
166161 """
167162 # Checks if the quicktab is defined
@@ -186,7 +181,6 @@ def FlushAllTabs(self):
186181 def RemoveTab (self , tabNameToRemove ):
187182 """
188183 Removes a tab by its name
189-
190184 :param tabNameToRemove: The tab to remove.
191185 :type tabNameToRemove: str
192186 :return: True if success otherwise False.
@@ -223,7 +217,7 @@ def CreateLayout(self):
223217 bc = c4d .BaseContainer ()
224218 bc .SetBool (c4d .QUICKTAB_BAR , False )
225219 bc .SetBool (c4d .QUICKTAB_SHOWSINGLE , True )
226- bc .SetBool (c4d .QUICKTAB_NOMULTISELECT , True )
220+ bc .SetBool (c4d .QUICKTAB_NOMULTISELECT , False )
227221 self ._quickTab = self .AddCustomGui (ID_QUICKTAB_BAR , c4d .CUSTOMGUI_QUICKTAB , '' ,
228222 c4d .BFH_SCALEFIT | c4d .BFV_SCALEFIT , 0 , 0 , bc )
229223
@@ -247,7 +241,7 @@ def InitValues(self):
247241 """
248242 # Creates the first Tab
249243 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 )
251245
252246 # Creates the second Tab
253247 cg2 = CustomGroup (["This is the second Tab" , "Just another dummy text here" ])
@@ -258,7 +252,6 @@ def Command(self, id, msg):
258252 """
259253 This Method is called automatically when the user clicks on a gadget and/or changes its value this function will be called.
260254 It is also called when a string menu item is selected.
261-
262255 :param id: The ID of the gadget that triggered the event.
263256 :param msg: The original message container
264257 :return: False if there was an error, otherwise True.
@@ -276,7 +269,7 @@ def Command(self, id, msg):
276269
277270 # Displays the ID and name of the selected tab
278271 if id == BUTTON_PRINT_SELECTED :
279- print self .GetActiveTab ()
272+ print self .GetActiveTabs ()
280273
281274 # Removes all tabs
282275 if id == BUTTON_FLUSH_ALL :
@@ -285,7 +278,7 @@ def Command(self, id, msg):
285278 # Adds a new Tab to the quicktab
286279 if id == BUTTON_ADD :
287280 cg3 = CustomGroup (["This is the third Tab" ])
288- self .AppendTab ("Third Tab" , cg3 , False )
281+ self .AppendTab ("Third Tab" , cg3 , True )
289282
290283 # Removes the first tab of the quicktab
291284 if id == BUTTON_REMOVE :
@@ -305,4 +298,4 @@ def main():
305298
306299# Execute main()
307300if __name__ == '__main__' :
308- main ()
301+ main ()
0 commit comments