On 06/04/2014 at 09:29, xxxxxxxx wrote:
here is an example similar to yours that demonstrates how you can easily restore even sub-dialogs.
It also demonstrates a few techniques that are good practice and useful.
One big problem of your code, for instance, was that, if restoring the sub dialog would have
worked, pressing the button on the main dialog would've opened another dialog than the one
that was restored into the layout.
a) the subid does not need to be a plugin ID
b) for GeDialog.Restore(), the first argument must be the command plugins PLUGIN_ID,
same when opening the main and sub dialog.
The reason it didn't restore is that the first time RestoreLayout() was called, you create the
sub-dialog, but the second time, the block that forwards the restoring to the sub-dialog isn't
even executed because of
if self.subDialog is None: # False in the second call # ...
import c4d PLUGIN_ID = 1000004 # Test ID class MainDialog(c4d.gui.GeDialog) : # Do not create the object on class-level, although it might # be unimportant since you do not open multiple objects of your # MainDialog, it is contradicting to have one instance of sub # dialog for all instances of the main dialog. # A property that creates the dialog on-demand is perfect for # this purpose. @property def sub_dialog(self) : if not hasattr(self, '_sub_dialog') : self._sub_dialog = SubDialog() return self._sub_dialog # c4d.gui.GeDialog def CreateLayout(self) : self.SetTitle('Main Dialog') self.AddButton(1000, 0, name="Open Sub-Dialog") return True def Command(self, param, bc) : if param == 1000: self.sub_dialog.Open(c4d.DLG_TYPE_ASYNC, PLUGIN_ID, subid=1) return True def Restore(self, pluginid, secref) : # We override this method so we don't have to handle the sub- # dialog from the CommandData plugin. THIS dialog is responsible # for the sub-dialog, do not split such management throughout # your program or it gets confusing. if secref['subid'] == 1: return self.sub_dialog.Restore(pluginid, secref) else: return super(MainDialog, self).Restore(pluginid, secref) class SubDialog(c4d.gui.GeDialog) : # c4d.gui.GeDialog def CreateLayout(self) : self.SetTitle('Sub-Dialog') self.AddStaticText(1000, 0, name="This is the sub-dialog.") return True class Command(c4d.plugins.CommandData) : def Register(self) : return c4d.plugins.RegisterCommandPlugin( PLUGIN_ID, "Sub-Dialog Docking Test", 0, None, "", self) @property def dialog(self) : if not hasattr(self, '_dialog') : self._dialog = MainDialog() return self._dialog # c4d.plugins.CommandData def Execute(self, doc) : return self.dialog.Open(c4d.DLG_TYPE_ASYNC, PLUGIN_ID) def RestoreLayout(self, secref) : return self.dialog.Restore(PLUGIN_ID, secref) if __name__ == '__main__': Command().Register()