Jump to content

Sign in to follow this  
Myosis

Button in subgroup?

Recommended Posts

Hi,

Does anyone know why the button is not in/under the foldable subgroup?

import c4d
from c4d import gui

class Fold(gui.GeDialog):
    def CreateLayout(self):
        self.SetTitle('')

        # create a quicktab
        self.GroupBegin(1011, c4d.BFH_SCALEFIT, 0, title = '')
        bc = c4d.BaseContainer()
        bc.SetBool(c4d.QUICKTAB_BAR, True)
        bc.SetString(c4d.QUICKTAB_BARTITLE, 'title')
        bc.SetBool(c4d.QUICKTAB_BARSUBGROUP, True)
        subgroup = self.AddCustomGui(122, c4d.CUSTOMGUI_QUICKTAB, '', c4d.BFH_SCALEFIT, 0, 0, bc)

        #foldable group ?
        self.GroupBegin(122, flags=c4d.BFH_SCALEFIT, cols=1, rows=1, title='', groupflags=0)
        self.AddButton(123, c4d.BFH_SCALEFIT, 0, 0, 'Button')
        self.GroupEnd()
        return True

def main():
    dlg = Fold()
    dlg.Open(c4d.DLG_TYPE_MODAL)


if __name__=='__main__':
    main()
    c4d.EventAdd()

 

 

Share this post


Link to post

The Quicktab is a gadget, not a group. You are using the same ID for the gadget and the group that's folded with it. C4D doesn't do that automatically.

import c4d
from c4d import gui

class Fold(gui.GeDialog):
    
    def CreateLayout(self):
        self.SetTitle('')

        # create a quicktab
        self.GroupBegin(1011, c4d.BFV_SCALEFIT, 0, rows=3, title = '')
        
        bc = c4d.BaseContainer()
        bc.SetBool(c4d.QUICKTAB_BAR, True)
        bc.SetString(c4d.QUICKTAB_BARTITLE, 'title')
        bc.SetBool(c4d.QUICKTAB_BARSUBGROUP, True)
        subgroup = self.AddCustomGui(122, c4d.CUSTOMGUI_QUICKTAB, '', c4d.BFH_SCALEFIT | c4d.BFV_TOP, 0, 0, bc)

        global flagSubgroupClosed
        flagSubgroupClosed = False
        self.GroupBegin(130, flags=c4d.BFH_SCALEFIT | c4d.BFV_TOP, cols=1, rows=2, title='', groupflags=0)
        self.GroupBorderSpace(10, 0, 10, 0)
        self.AddButton(123, c4d.BFH_LEFT, 0, 0, 'Button')
        self.GroupEnd()
        self.AddButton(124, c4d.BFH_LEFT, 0, 0, 'Also a Button')
        return True

    def Command(self, id, msg):
        global flagSubgroupClosed
        if id == 122:
            flagSubgroupClosed = not flagSubgroupClosed
            self.HideElement(130, flagSubgroupClosed)
            self.LayoutChanged(1011)
        return True

def main():
    dlg = Fold()
    dlg.Open(c4d.DLG_TYPE_MODAL)


if __name__=='__main__':
    main()
    c4d.EventAdd()

 

Share this post


Link to post
  • Topic Author
  • Works very nice!

    I couldn't find an example of this online, I'm sure this will help others too, thank you very much! @Cairyn


    When I set the value of: flagSubgroupClosed = False To True it doesn't seem to be folded upon opening. Any idea what might cause that ?

    Side question: Tab groups, and quick tabs, don't work in a DLG_TYPE_ASYNC modal window, do they ?

    Cheers!

    Share this post


    Link to post
    50 minutes ago, Myosis said:

    Works very nice!

    I couldn't find an example of this online, I'm sure this will help others too, thank you very much! @Cairyn


    When I set the value of: flagSubgroupClosed = False To True it doesn't seem to be folded upon opening. Any idea what might cause that ?

    Side question: Tab groups, and quick tabs, don't work in a DLG_TYPE_ASYNC modal window, do they ?

    Cheers!

     

    There is a C++ sample for many things:

    https://github.com/PluginCafe/cinema4d_cpp_sdk/blob/master/source/gui/gedialog_gadgets.cpp

     

    flagSubgroupClosed is not used in the initialization in CreateLayout, so obviously it doesn't have any effect. If you want to have the subdialog closed, you need to do it (again) manually by adding the lines

            self.HideElement(130, flagSubgroupClosed)
            subgroup.Select(0,flagSubgroupClosed)

    at the end of CreateLayout.

     

    As for using ASYNC dialogs (nonmodal), that is not a problem of the tab group but of the lifetime of the objects within a script. If your dialog is modal, the Open command will not return before the dialog is closed; the class Fold will keep existing, and all is fine with the world. The execution loop in C4D will handle nothing else but your dialog. -- If you use an ASYNC dialog, the Open command will happily open your dialog and then return, which returns control to the C4D main message loop, which ends the script, which kills the Python execution context including your class. You can just try to change the DLG_TYPE; you will see that all the dialog content disappears as soon as you try to click something or even resize the dialog. Because your dialog class is kaputt.

     

    If you want nonmodal dialogs, you need a different approach (use a plugin that makes your dialog class permanently accessable for the C4D main message loop and allows C4D to restore the dialog layout if it gets embedded in some user layout.

    (Not going into that topic here - maybe one day I will get to it in my Python: Spoonfed tutorial series.)

    Share this post


    Link to post
  • Topic Author
  • @Cairyn Thank you very much, it worked out great!
    You've helped me on numerous occasions (various topics) and I am very grateful. 

    Been going down a rabbit hole on how to dynamically change the window size for when the group gets folded / unfolded. Figured this is a different topic so made a new thread for this: 

    Cheers 🙂 

    Share this post


    Link to post

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Reply to this topic...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    Sign in to follow this  

    • Recently Browsing   0 members

      No registered users viewing this page.

    ×
    ×
    • Create New...