Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > PYTHON Development
  New Posts New Posts
  FAQ FAQ  Forum Search

Multiple SubDialogs

Page  12>
Author
Message
  Topic Search Topic Search
ShawnFrueh View Drop Down
Member
Member
Avatar

Joined: 2013 Jan 26
Location: Minneapolis
Online Status: Offline
Posts: 136
Direct Link To This Post Topic: Multiple SubDialogs
    Posted: 2014 Apr 02 at 10:33am
Is there a way to have multiple subdialogs open at the same time. When I open a second one the first dialog becomes locked. 

I have tried using a subid with gui.GeDialog and gui.SubDialog, neither one works. Is there a specific way to set this up? 
Back to Top
NiklasR View Drop Down
Member
Member


Joined: 2010 Dec 13
Location: Germany
Online Status: Offline
Posts: 2575
Direct Link To This Post Posted: 2014 Apr 02 at 1:28pm
Do you mean a SubDialog being embedded into another dialog (which is actually what a SubDialog
is for, and is not possible with Python) or a Dialog that opens when the users clicks a button in the
main dialog?

For the latter, open the dialog asynchronous.

-Niklas
Back to Top
ShawnFrueh View Drop Down
Member
Member
Avatar

Joined: 2013 Jan 26
Location: Minneapolis
Online Status: Offline
Posts: 136
Direct Link To This Post Posted: 2014 Apr 02 at 2:30pm
The Dialogs are basically just simple tools of the main plugin that I want to display in a separate window. I am using DLG_TYPE_ASYNC for the SubDialogs. I have also found that with having multiple Dialogs in the plugin you can not save them into your layout and the window displays "Plugin is missing."

Is there a way to do this without having to make a separate plugin for each separate window? 
Back to Top
NiklasR View Drop Down
Member
Member


Joined: 2010 Dec 13
Location: Germany
Online Status: Offline
Posts: 2575
Direct Link To This Post Posted: 2014 Apr 03 at 1:07pm
Use subids to open the dialogs. You can get the subid in CommandData::RestoreLayout() from the "secret" parameter.

-Niklas


Edited by NiklasR - 2014 Apr 04 at 12:19pm
Back to Top
ShawnFrueh View Drop Down
Member
Member
Avatar

Joined: 2013 Jan 26
Location: Minneapolis
Online Status: Offline
Posts: 136
Direct Link To This Post Posted: 2014 Apr 04 at 8:47am
Thanks for the help Niklas, 

I realized I was calling my subdialogs by the same name, so opening one killed the other. 

This is how I am calling the main dialog/window:
return self.dialog.Restore(pluginid = PLUGIN_ID, secret = sec_ref)

How do I use the "secret" to restore the submenus? I can't seen to find any information about that parameter. 


Back to Top
ShawnFrueh View Drop Down
Member
Member
Avatar

Joined: 2013 Jan 26
Location: Minneapolis
Online Status: Offline
Posts: 136
Direct Link To This Post Posted: 2014 Apr 04 at 9:35am
This is the best information I have found so far but I cant seam to convert it to python correctly. 


When I save my layout they plugin windows go blank. 
Back to Top
NiklasR View Drop Down
Member
Member


Joined: 2010 Dec 13
Location: Germany
Online Status: Offline
Posts: 2575
Direct Link To This Post Posted: 2014 Apr 04 at 12:24pm
Try print the "secret". It's no longer cryptic when you see its actually a dictionary.

-Niklas
Back to Top
ShawnFrueh View Drop Down
Member
Member
Avatar

Joined: 2013 Jan 26
Location: Minneapolis
Online Status: Offline
Posts: 136
Direct Link To This Post Posted: 2014 Apr 04 at 1:01pm
I think I am confusing myself. The fact that this attribute is called "secret" makes it impossible to search for with Google. 

I tried to print the attribute but of course the secret is not defined. (I am pretty sure I am going about this the wrong way.) Do you know where I can find an example of a python plugin consisting of 2 or more windows?
Back to Top
NiklasR View Drop Down
Member
Member


Joined: 2010 Dec 13
Location: Germany
Online Status: Offline
Posts: 2575
Direct Link To This Post Posted: 2014 Apr 04 at 2:48pm
Sorry, the C++ docs refer to it as "secret", but the Python docs say "sec_ref". I was talking about this parameter, it is the only one passed to RestoreLayout() besides "self".

print sec_ref
# {'subid': 0, 'ptr': <PYCObject ...>}

See? Theres the subid.

-Niklas
Back to Top
ScottA View Drop Down
Member
Member


Joined: 2011 Jan 07
Online Status: Offline
Posts: 2288
Direct Link To This Post Posted: 2014 Apr 05 at 10:12am
I'm interested in knowing the answer to this one too.
Since it's much easier to communicate using a working example. Here's a very basic working example showing the problem of not being able to dock a sub dialog:
import c4d,os,sys
from c4d import gui, plugins, bitmaps, documents, utils

PLUGIN_ID = 1000003    #The plugin's ID#
MAINDLG   = 1000040    #An ID to be assigned to the main dialog
SUBDLG    = 1000041    #An ID to be assigned to the sub dialog


###### The sub dialog ######
class MySubDialog(gui.GeDialog):

    def CreateLayout(self):
        self.SetTitle("Sub Dialog")       

        self.GroupBegin(0, c4d.BFH_SCALEFIT, 2, 0, "MyGroup")
        self.GroupBorderSpace(5, 5, 5, 5)
        self.GroupBorder(c4d.BORDER_BLACK)
        self.AddStaticText(1111, c4d.BFH_LEFT, 0, 0, "Hello World", 0)
        self.AddEditSlider(2222, c4d.BFH_SCALEFIT, 500, 0)
        self.GroupEnd()      
        return True

    def InitValues(self):
        self.SetReal(id = 2222, value = 5.0, min = 0.0, max = 100.0, step = 1.0, format = c4d.FORMAT_METER)
        return True

    def Command(self, id, msg):
        if (id == 2222):
            print self.GetReal(2222)   #Print the value of the slider      
        return True


###### The main dialog ######
class MyMainDialog(gui.GeDialog):

    subdlg = MySubDialog()

    def CreateLayout(self):
        self.SetTitle("Main Dialog")
        self.AddButton(10001, c4d.BFH_CENTER, 150, 0, "Open SubDlg")  
        return True  

    def InitValues(self):  
        return True

    def Command(self, id, msg):
      
        if (id == 10001):
            self.subdlg.Open(dlgtype = c4d.DLG_TYPE_ASYNC, pluginid = SUBDLG, defaultw = 200, defaulth = 100)
          
        c4d.EventAdd()
        return True

class Dialog_CD(c4d.plugins.CommandData):

    mainDialog = None
    subDialog = None

    def Init(self, op):
        return True

    def Execute(self, doc):
        if self.mainDialog is None and self.subDialog is None:
            self.mainDialog = MyMainDialog()
            self.subDialog = MySubDialog()
           
        self.mainDialog.Open(c4d.DLG_TYPE_ASYNC, PLUGIN_ID, -1, -1, 0, 0, MAINDLG)
        #self.subDialog.Open(c4d.DLG_TYPE_ASYNC, PLUGIN_ID, -1, -1, 0, 0, SUBDLG)  #For reference only...We don't want to open both dialogs here
        return True
       
       
##### This does not work!!!! ########
#The function stops after it finds the mainDialog. And only restores that dialog!!!
#The sub dialog results in "plugin not found" in the layout!!!
    def RestoreLayout(self, sec_ref):
 
        subid = sec_ref["subid"]
        object = sec_ref["ptr"]
   
        if self.mainDialog is None:
            self.mainDialog = MyMainDialog()
            print subid
            if subid == MAINDLG:
                print "subid == MAINDLG"
                self.mainDialog.Restore(MAINDLG, sec_ref)

        if self.subDialog is None:
            self.subDialog = MySubDialog()
            print subid
            if subid == SUBDLG:
                print "subid == SUBDLG"
                self.subDialog.Restore(SUBDLG, sec_ref)
               
        return True
     
if __name__ == "__main__":
    bmp = c4d.bitmaps.BaseBitmap()
    dir, file = os.path.split(__file__)
    fn = os.path.join(dir, "res", "icon.tif")
    bmp.InitWith(fn)
    result = plugins.RegisterCommandPlugin(PLUGIN_ID, "Dockable SubDialogs", 0, bmp, "Dockable SubDialogs", Dialog_CD())



-ScottA
Back to Top
NiklasR View Drop Down
Member
Member


Joined: 2010 Dec 13
Location: Germany
Online Status: Offline
Posts: 2575
Direct Link To This Post Posted: 2014 Apr 06 at 9:29am
Hello,

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.

Also,

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
    # ...

Best,
-Niklas



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()


Edited by NiklasR - 2014 Apr 06 at 9:31am
Back to Top
ScottA View Drop Down
Member
Member


Joined: 2011 Jan 07
Online Status: Offline
Posts: 2288
Direct Link To This Post Posted: 2014 Apr 06 at 11:24am
Thanks Niklas.
I never thought about using Restore() in the main GeDialog class like that.

-ScottA
Back to Top
NiklasR View Drop Down
Member
Member


Joined: 2010 Dec 13
Location: Germany
Online Status: Offline
Posts: 2575
Direct Link To This Post Posted: 2014 Apr 07 at 9:29am
You're welcome, Scott.

You can also find the code at the GitHub py-cinema4sdk repository under gui/restore-sub-dialog.pyp!
Do also take a look at the respective readme file at gui/restore-sub-dialog.md.

Best,
-Niklas
Back to Top
ShawnFrueh View Drop Down
Member
Member
Avatar

Joined: 2013 Jan 26
Location: Minneapolis
Online Status: Offline
Posts: 136
Direct Link To This Post Posted: 2014 Apr 07 at 11:19am
Thanks for the help guys, however I still have a few problems. Using Kiklas' method I got the SubDialogs to behave correctly when I re-open them while they are open and the window becomes active. I still get a Plugin not found while restoring a layout, I think this reason is due to having more than one sub dialog.

here is the code:
def Restore(self, PLUGIN_ID, secref):
     if secref['subid'] == 1:
          return self.sub_dialog1.Restore(PLUGIN_ID,secref)
     elif secref['subid'] == 2:
          return self.sub_dialog2.Restore(PLUGIN_ID,secref)
     else:
          return super(MainDialog, self).Restore(PLUGIN_ID,secref)

How do I correctly look for both subdialogs.
Back to Top
NiklasR View Drop Down
Member
Member


Joined: 2010 Dec 13
Location: Germany
Online Status: Offline
Posts: 2575
Direct Link To This Post Posted: 2014 Apr 07 at 11:23am
How do you open the subdialogs?
Back to Top
ShawnFrueh View Drop Down
Member
Member
Avatar

Joined: 2013 Jan 26
Location: Minneapolis
Online Status: Offline
Posts: 136
Direct Link To This Post Posted: 2014 Apr 07 at 11:26am
if id == 10017: # Get Render Time
     self.sub_dialog2.Open(c4d.DLG_TYPE_ASYNC, defaulth=200, defaultw=300, subid = 2)

Oh wait, I think I just figured it out, This has to have the plugin ID as well correct? 


Back to Top
ShawnFrueh View Drop Down
Member
Member
Avatar

Joined: 2013 Jan 26
Location: Minneapolis
Online Status: Offline
Posts: 136
Direct Link To This Post Posted: 2014 Apr 07 at 11:41am
No that did not work. Here is what my @properties look like

@property
def sub_dialog1(self):
     if not hasattr(self, '_sub_dialog1'):
          self._sub_dialog1 = ColorDialog()
     return self._sub_dialog1
@property
def sub_dialog2(self):
     if not hasattr(self, '_sub_dialog2'):
          self._sub_dialog2 = RenderTimeDialog()
     return self._sub_dialog2


Back to Top
ShawnFrueh View Drop Down
Member
Member
Avatar

Joined: 2013 Jan 26
Location: Minneapolis
Online Status: Offline
Posts: 136
Direct Link To This Post Posted: 2014 Apr 07 at 11:58am
Here is the code from your exaple made to have 2 sub dialogs: Same problem. 

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
    @property
    def sub_dialog2(self):
        if not hasattr(self, '_sub_dialog2'):
            self._sub_dialog2 = SubDialog2()
        return self._sub_dialog2
    # 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)
            self.sub_dialog2.Open(c4d.DLG_TYPE_ASYNC, PLUGIN_ID, subid=2)
        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)
        elif secref['subid'] == 2:
            return self.sub_dialog2.Restore(pluginid, secref)
        else:
            return super(MainDialog, self).Restore(pluginid, secref)

class SubDialog(c4d.gui.GeDialog):

    def CreateLayout(self):
        self.SetTitle('Sub-Dialog')
        self.AddStaticText(1000, 0, name="This is the sub-dialog.")
        return True
class SubDialog2(c4d.gui.GeDialog):

    def CreateLayout(self):
        self.SetTitle('Sub-Dialog2')
        self.AddStaticText(1000, 0, name="This is the sub-dialog2.")
        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()
Back to Top
ShawnFrueh View Drop Down
Member
Member
Avatar

Joined: 2013 Jan 26
Location: Minneapolis
Online Status: Offline
Posts: 136
Direct Link To This Post Posted: 2014 Apr 07 at 1:45pm
OK I got the example to work. 
however I cannot get my plugin to work. could it be that my main window uses a .res file?

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
    @property
    def sub_dialog2(self):
        if not hasattr(self, '_sub_dialog2'):
            self._sub_dialog2 = SubDialog2()
        return self._sub_dialog2
    # 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)
            self.sub_dialog2.Open(c4d.DLG_TYPE_ASYNC, PLUGIN_ID, subid=2)
        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:
            print "yes"
            return self.sub_dialog.Restore(pluginid, secref)
        if secref['subid'] == 2:
            return self.sub_dialog2.Restore(pluginid, secref)
        else:
            return super(MainDialog, self).Restore(pluginid, secref)

class SubDialog(c4d.gui.GeDialog):

    def CreateLayout(self):
        self.SetTitle('Sub-Dialog')
        self.AddStaticText(1000, 0, name="This is the sub-dialog.")
        return True
        
class SubDialog2(c4d.gui.GeDialog):

    def CreateLayout(self):
        self.SetTitle('Sub-Dialog2')
        self.AddStaticText(1000, 0, name="This is the sub-dialog2.")
        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()
Back to Top
ShawnFrueh View Drop Down
Member
Member
Avatar

Joined: 2013 Jan 26
Location: Minneapolis
Online Status: Offline
Posts: 136
Direct Link To This Post Posted: 2014 Apr 08 at 2:11pm
I think the problem with my plugin has something to do with the main command class, the "RestoreLayout" does not get called at all. I added some print functions to see and nothing. However the example prints just fine. Here is my main command code: 

class RenderBuddy(c4d.plugins.CommandData):

    @property
    def RBdialog(self):
        if not hasattr(self, '_RBdialog'):
            self._RBdialog = BuddyDialog()
        return self._RBdialog
        
    def Register(self):
        return c4d.plugins.RegisterCommandPlugin(PLUGIN_ID, "Render Buddy (Beta)",0, bmp, "", self)
                
    def Execute(self, doc):
        return self.RBdialog.Open(c4d.DLG_TYPE_ASYNC,PLUGIN_ID)
        
    def RestorLayout(self, secref):
        print "RB_Main"
        return self.RBdialog.Restore(PLUGIN_ID, secref)
    
if __name__ == "__main__":
    
    path, fn = os.path.split(__file__)
    bmp = bitmaps.BaseBitmap()  
    bmp.InitWith(os.path.join(path, "res/icons/", "icon.tif"))
     
    RenderBuddy().Register()

Everything seems to be right, but the RestoreLayout does not get called. 
Back to Top
Page  12>

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.110 seconds.