Hide a tab group of a resource-based GeDialog



  • Hi,

    I have a dialog with a tab group here. All the dialog contents is defined via a .res file.
    When the Dialog opens, I want to hide one of the tab groups and change the dialog title, depending on a bool value.

    The tab group is defined in the .res file like this (I shortened it a little):

    TAB DLG_TAB_GROUP
    {
    	SELECTION_TABS;
    	SCALE_H; SCALE_V;
    
    	GROUP DLG_TAB_GROUP_0
    	{
    		NAME DLG_TAB_GROUP_0_TITLE;
    		SCALE_H; SCALE_V;
    		BORDERSIZE 10,10,10,10;
    		COLUMNS 1;
    
    		STATICTEXT DLG_TAB_0_HELP1 { NAME DLG_TAB_0_HELP1; }
    		STATICTEXT DLG_TAB_0_HELP2 { NAME DLG_TAB_0_HELP2; }
    		STATICTEXT DLG_TAB_0_HELP3 { NAME DLG_TAB_0_HELP3; }
    	}
    
    	GROUP DLG_TAB_GROUP_1
    	{
    		NAME DLG_TAB_GROUP_1_TITLE;
    		ALIGN_TOP; SCALE_H; SCALE_V;
    		BORDERSIZE 10,10,10,10;
    		COLUMNS 1;
    
    		STATICTEXT DLG_TAB_1_HELP1 { NAME DLG_TAB_1_HELP1; }
    		STATICTEXT DLG_TAB_1_HELP2 { NAME DLG_TAB_1_HELP2; }
    		STATICTEXT DLG_TAB_1_HELP3 { NAME DLG_TAB_1_HELP3; }
    	}
    
    	GROUP DLG_TAB_GROUP_2
    	{
    		NAME DLG_TAB_GROUP_2_NAME;
    		ALIGN_TOP; SCALE_H; SCALE_V;
    		BORDERSIZE 10,10,10,10;
    		COLUMNS 1;
    
    		STATICTEXT DLG_TAB_2_HELP1 { NAME DLG_TAB_2_HELP1; }
    		STATICTEXT DLG_TAB_2_HELP2 { NAME DLG_TAB_2_HELP2; }
    		STATICTEXT DLG_TAB_2_HELP3 { NAME DLG_TAB_2_HELP3; }
    	}
    }
    

    The code looks like this:

    Bool SomeDialog::CreateLayout()
    {
    	if (!GeDialog::CreateLayout())
    		return false;
    
    	// load dialog from resource file
    	if (!LoadDialogResource(DLG_SOMEDIALOG, nullptr, 0))
    		return false;
    
    	if (_showFirstTab)
    	{
    		SetTitle(GeLoadString(IDS_SOMETITLE));
    	}
    	else
    	{
    		SetTitle(GeLoadString(IDS_SOMEOTHERTITLE));
    		HideElement(DLG_TAB_GROUP_0, true);
    	}
    	return true;
    }
    

    Changing the title works fine. But the tab group is not hidden, it's still visible.

    Any tips or advice?

    Cheers & greetings,
    Frank



  • Maybe you have to call LayoutChanged() after that. See gedialog_gadgets.cpp.



  • Oh, right, I'll check that. Thanks!



  • Not sure why this was marked as solved. It's not.
    I have added the call LayoutChanged(DLG_TAB_GROUP); as suggested, but it changed nothing.

    So, the question remains: How do I hide a TAB in a TAB group defined in a .res file?

    Bool SomeDialog::CreateLayout()
    {
    	if (!GeDialog::CreateLayout())
    		return false;
    
    	// load dialog from resource file
    	if (!LoadDialogResource(DLG_SOMEDIALOG, nullptr, 0))
    		return false;
    
    	if (_showFirstTab)
    	{
    		SetTitle(GeLoadString(IDS_SOMETITLE));
    	}
    	else
    	{
    		SetTitle(GeLoadString(IDS_SOMEOTHERTITLE));
    		HideElement(DLG_TAB_GROUP_0, true);
    		LayoutChanged(DLG_TAB_GROUP);
    	}
    	return true;
    }
    

    I also tried LayoutChanged(DLG_TAB_GROUP_0) and LayoutChanged(DLG_SOMEDIALOG), with no effect whatsoever.

    Cheers,
    Frank



  • @PluginStudent said in Hide a tab group of a resource-based GeDialog:

    Maybe you have to call LayoutChanged() after that. See gedialog_gadgets.cpp.

    Thanks for that example! However, in that code, hiding the group is done in Command(), so on user interaction. I need to hide it when the dialog is opened. The second (and probably most significant) difference is that it's a dialog which creates its complete layout in CreateLayout(). My dialog was like that before, and hiding the tab group worked just fine. But now I changed my dialog to load its layout from a .res file, and since then the group does not hide anymore.



  • Hi @fwilleke80 sorry for the trouble I thought the answers by Sebastian solved your issue, so I set it to fixed sorry.

    Regarding the problem, I have to dig into it more on Monday, but I guess this is due that LoadDialogResource actually creates a new dialog that is embedded within the original dialog, but of course, nothing you can change, so I have to see if it's a bug of something else missing :)

    Cheers,
    Maxime.



  • Thanks, that would be nice. If you find out that it's not possible to do dynamic changes to a .res file-based dialog, I have to undo quite some changes here ;-)



  • Hi Frank sorry for the delay needed for this issue,

    I get the time to look at it, and this is the thing I should have checked first, but either in a GeDialog with a Layout created in a script, I'm not able to hide a tab.
    Since you said it was working previously, could you confirm you don't want to hide only the content (in your case the 3 StaticText) but also the tab in the tab entry, isn't? If yes could you provide a code sample because I would say even in a normal case I'm not able to reproduce.

    import c4d
    
    class Dlg(c4d.gui.GeDialog):
        def CreateLayout(self):
            
            if self.TabGroupBegin(10001, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, tabtype=c4d.TAB_TABS):
                
                if self.GroupBegin(10010, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 0, title="First Tab"):
                    self.AddStaticText(10011, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, name="Text01")
                    self.GroupEnd()
                    
                if self.GroupBegin(10020, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 0, title="Second Tab"):
                    self.AddStaticText(10021, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, name="Text02")
                    self.GroupEnd()
    
            self.GroupEnd()
            self.AddButton(10030, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, name="Remove First Tab")
            
            return True
        
        def Command(self, id, msg):
            if id == 10030:
                print self.HideElement(10010, True)
                print self.LayoutChanged(10001)
                
            return True
        
    def main():
        global dlg
        dlg = Dlg()
        dlg.Open(c4d.DLG_TYPE_ASYNC)
    
    # Execute main()
    if __name__=='__main__':
        main()
    

    To me, the only way to remove a tab is to flush the complete group master of the TabGroup and re-add tabs except for the one you don't want.

    Cheers,
    Maxime.