Scott Ayers
11-29-2010, 05:25 PM
In coffee. The Command() function is used to execute a piece of code when a button is pressed.
So the code resides inside of this command function instead of the main() function.
But when I do this with Python. The button code doesn't execute until the dialog window is closed.
Here's two examples:
Coffee version: class MyDialog : GeModalDialog
{
public:
MyDialog();
CreateLayout();
Command(id, msg);
}
MyDialog::MyDialog()
{
super();
}
MyDialog::CreateLayout()
{
AddButton(2004, BFH_SCALE|BFH_FIT, 0, 0, "Apply");
AddDlgGroup(DR_DLGGROUP_OK); // Enter button
AddDlgGroup(DR_DLGGROUP_CANCEL); // Cancel button
return;
}
MyDialog::Command(id, msg)
{
if(id == 2004)
{
println ("hello");
}
return;
}
main(doc,op)
{
var dlg = new(MyDialog);
var result = dlg->Open(-1, -1);
}
Python Version: import c4d
from c4d import gui
class MyDialog(gui.GeDialog):
def CreateLayout(self):
self.AddButton(1001, c4d.BFH_SCALE,initw=150,inith=20,name="Apply")
self.AddButton(1002, c4d.BFH_SCALE,initw=150,inith=10,name="Cancel")
return True
def Command(self,id,msg):
if id == 1001:
print("Hello")
if id == 1002:
self.Close()
return True
def main():
Dlg = MyDialog()
Dlg.Open(c4d.DLG_TYPE_MODAL,defaultw=400)
if __name__=='__main__':
main()
How do I make the python version execute the code without having to close the dialog window?
-ScottA
So the code resides inside of this command function instead of the main() function.
But when I do this with Python. The button code doesn't execute until the dialog window is closed.
Here's two examples:
Coffee version: class MyDialog : GeModalDialog
{
public:
MyDialog();
CreateLayout();
Command(id, msg);
}
MyDialog::MyDialog()
{
super();
}
MyDialog::CreateLayout()
{
AddButton(2004, BFH_SCALE|BFH_FIT, 0, 0, "Apply");
AddDlgGroup(DR_DLGGROUP_OK); // Enter button
AddDlgGroup(DR_DLGGROUP_CANCEL); // Cancel button
return;
}
MyDialog::Command(id, msg)
{
if(id == 2004)
{
println ("hello");
}
return;
}
main(doc,op)
{
var dlg = new(MyDialog);
var result = dlg->Open(-1, -1);
}
Python Version: import c4d
from c4d import gui
class MyDialog(gui.GeDialog):
def CreateLayout(self):
self.AddButton(1001, c4d.BFH_SCALE,initw=150,inith=20,name="Apply")
self.AddButton(1002, c4d.BFH_SCALE,initw=150,inith=10,name="Cancel")
return True
def Command(self,id,msg):
if id == 1001:
print("Hello")
if id == 1002:
self.Close()
return True
def main():
Dlg = MyDialog()
Dlg.Open(c4d.DLG_TYPE_MODAL,defaultw=400)
if __name__=='__main__':
main()
How do I make the python version execute the code without having to close the dialog window?
-ScottA
