On 25/03/2013 at 07:35, xxxxxxxx wrote:
I'm tring to open a 2nd (modal) dialog in another dialog.
It works ok, until I close and re-open the plugin with the dialog.
Then an incorrect dialog is displayed and later Cinema 4d crashes.
It seems that i do not restore correctly?
import c4d
import os
from c4d import gui, plugins, bitmaps, utils, documents
PLUGIN_ID = 1011310 # Test ID
MY_CITY = 11001
MY_BUTTON = 11004
class MyDialog2(gui.GeDialog) : #2nd (modal) dialog
def CreateLayout(self) :
self.GroupBegin(id=1011, flags=c4d.BFH_FIT, cols=2)
self.element = self.AddStaticText(id=1003, flags=c4d.BFH_LEFT, initw=100, name="City")
self.AddEditText(MY_CITY, c4d.BFH_SCALEFIT, 100, 0)
self.GroupEnd()
self.GroupBegin(id=1013, flags=c4d.BFH_SCALEFIT, cols=1)
self.AddButton(MY_BUTTON, c4d.BFV_MASK, initw=100, name="Done")
self.GroupEnd()
return True
def Command(self, id, msg) :
if (id == MY_BUTTON) :
print "city: ", self.GetString (MY_CITY)
self.Close()
return True
return True
class MyDialog(gui.GeDialog) : #main dialog
def CreateLayout(self) :
self.GroupBegin(id=1013, flags=c4d.BFH_SCALEFIT, cols=1)
self.AddButton(MY_BUTTON, c4d.BFV_MASK, initw=100, name="Goto 2nd dialog")
self.GroupEnd()
return True
def Command(self, id, msg) :
if (id == MY_BUTTON) :
self.dialog2 = MyDialog2() #init and open 2nd dialog
self.dialog2.Open(dlgtype=c4d.DLG_TYPE_MODAL, pluginid=PLUGIN_ID, defaultw=200, defaulth=150, xpos=-1, ypos=-1)
return True
return True
#################################################################################################
class MyMenuPlugin(plugins.CommandData) :
dialog = None
def Execute(self, doc) :
# create the dialog
if self.dialog is None:
self.dialog = MyDialog()
return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=PLUGIN_ID, defaultw=200, defaulth=150, xpos=-1, ypos=-1)
def RestoreLayout(self, sec_ref) :
# manage the dialog
if self.dialog is None:
self.dialog = MyDialog()
print "Restore."
return self.dialog.Restore(pluginid=PLUGIN_ID, secret=sec_ref)
if __name__ == "__main__":
path, fn = os.path.split(__file__)
bmp = bitmaps.BaseBitmap()
bmp.InitWith(os.path.join(path, "res/icons/", "icon.tif"))
okyn = plugins.RegisterCommandPlugin(PLUGIN_ID, "OSM",0, bmp, "OSM", MyMenuPlugin())
if (okyn) :
print "Initialized."