On 26/06/2013 at 05:29, xxxxxxxx wrote:
The dummy host is just meant to be a placeholder for the wrapping class for your dialog. Something like your plugin class or another dialog. For the values - you have simply to store them in a container. That is not much work. You could however write a fully automated value initialization GeDialog class, that might become handy in the future, as this is a common problem (with fully automated i mean a class that you can derive from a do not have to overwrite Init for initing the basic dialog elements like strings, bools, reals and so on. you would need than a BaseContainer format that does store the DescLevel.dtype, min/max values and so on.
i have not tested the code, but i guess it shows the general idea and it just does cover the four very basic dialog element types.
def someClassMethod(self) :
self.bc = c4d.BaseContainer()
self.bc.SetLong(1000, someValue)
self.bc.SetBool(1001, someValue)
self.bc.SetString(1002, someValue)
self.dlg = myDialog(self.bc)
# return self.dlg.Open( ...
def anotherClassMethod(self) :
self.bc = self.dlg.GetValues()
return self.dlg.Close()
# ...
class myDialog(c4d.gui.GeDialog) :
def __init__(self, container) :
self.bc = container
def InitValues(self) :
if isinstance(self.bc , c4d.BaseContainer) :
self.SetLong(1000, self.bc.GetLong(1000), 0, step=1)
self.SetBool(1001, self.bc.GetBool(1001), 0, step=1)
self.SetString(1002, self.bc.GetString(1002), 0, step=1)
return True
# implement some sort of fallback here
else:
return False
def Command(self, cid, msg) :
# ...
if cid in [_cid for _cid, value in self.bc]:
self.WriteValue(cid, self.bc)
return True
def GetValues(self) :
'''
Returns the dialog container.
'''
return self.bc
def WriteValue(self, cid, bc) :
'''
Save a value to the dialog container.
:param cid: the container id.
:param bc: the container to write to.
:return: bool
'''
if isinstance(bc, c4d.BaseContainer) :
etype = bc.GetType(cid)
if etype == c4d.DTYPE_BOOL:
value = self.GetBool(cid)
if value is not None:
bc.SetBool(cid, bool(value))
return True
elif etype == c4d.DTYPE_STRING:
value = self.GetString(cid)
if value is not None:
bc.SetString(cid, str(value))
return True
elif etype == c4d.DTYPE_LONG:
value = self.GetLong(cid)
if value is not None:
bc.SetLong(cid, int(value))
return True
elif etype == c4d.DTYPE_REAL:
value = self.GetReal(cid)
if value is not None:
bc.SetReal(cid, float(value))
return True
return False