PDA

View Full Version : Execution problem with Python dialogs


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

Scott Ayers
11-29-2010, 11:10 PM
After a lot more experimenting. I think this is happening because the dialog is modal.
I've re-created the same condition with a python plugin using the res folder structure. And the same thing happens when I use a modal dialog. But it works as expected (like the coffee version) with a non modal dialog.

Does anyone know how to make a script based dialog that's non modal?

*Edit- After searching around I was shocked to learn that asynchronous dialogs are not possible in python scripts. And they only work in python plugins.:sad:

-ScottA

donelgreeko
12-05-2010, 07:58 PM
Hi Scott, the code is executed, just the console window isn't updated properly while a modal dialog is open.

Scott Ayers
12-05-2010, 11:10 PM
I thought that was the case too. But the code doesn't execute while the dialog is open for other things besides the console.
Here's an example where the x-ray option doesn't execute until the dialog is closed: 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):
obj = doc.GetActiveObject()
if id == 1001:
obj[c4d.ID_BASEOBJECT_XRAY]=1
c4d.EventAdd()

if id == 1002:
self.Close()
return True

def main():

Dlg = MyDialog()
Dlg.Open(c4d.DLG_TYPE_MODAL,defaultw=400)
c4d.EventAdd()
if __name__=='__main__':
main()

I have noticed that this problem does not seem to happen when executing the gizmos.
If I execute one of the "self" items (the gizmos) they seem to update properly without having to close my dialog window first.

-ScottA

CGTalk Moderation
12-05-2010, 11:10 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.