Update GeDialog When Button is Pressed?



  • Hi,

    I have a dialog that reads images from a folder directory. Every now and then, images are either added or removed in the directory.

    Currently, I have to reload the plug-in and reopen the plug-in for the changes to reflect. Is there a way to have GeDialog reflect the changes when a button is pressed.

    So far I have this code, but the problem is when the layout is flushed, it doesn't return back.
    You can see the problem here:
    https://www.dropbox.com/s/9ckr4dad6vf9f3x/c4d198_update_gui_dialog_when_button_is_pressed.mp4?dl=0

    def Command(self, id, msg):
    
            if id==10001: # When button is pressed
                save_image()
                self.LayoutFlushGroup(9002)
                self.LayoutChanged(9002)
    
            return True
    
    

    Is there a way around this?



  • Yes, when Layout is flushed, it is flushed. :)
    You have to add your controls again, between LayoutFlushGroup() and LayoutChanged(). This is the most common way to build dynamic layouts.

    Create a helper function to create your layout. Then, you can call it when needed (CreateLayout(), MyUpdateRoutine() and so on.)



  • Hi @bentraje as @mp5gosu you need to recreate the UI by yourself.

    LayoutFlushGroup As the documentation says:
    Removes all controls from a group and places the control insertion point within the group.

    So it removes everything.

    And the note of LayoutFlushGroup also says:
    After all, components are added call LayoutChanged() with the group ID.

    So you need to call LayoutChanged once you have re-inserted your Gadget.
    You can find an example in C++ in gedialog_gadgets.cpp.

    Cheers,
    Maxime.



  • @mp5gosu @m_adam

    Thanks for the response.

    I'm not sure how to do this "add your controls again".
    By controls, do you mean the statictext, addedittext etc, which I guess it is based on the C++ code referenced before with the AddDynamicElement C++ function?

    If so,

    I revised the code to but it still gives me the same result in the initial video. Or are you referring to a different control?

    def Command(self, id, msg):
    
            if id==10001: # When button is pressed
                save_image()
                self.LayoutFlushGroup(9002)
    
                #THE GROUP THAT SHOWS THE GRID OF THE PICTURES
                self.GroupBegin(id=9002, flags=c4d.BFH_SCALEFIT, groupflags = c4d.BFV_GRIDGROUP_EQUALCOLS, cols=4, rows=4,initw=0, inith=0)
                self.GroupSpace(0, 0)
                for image in images:
                    image_bmp = c4d.bitmaps.BaseBitmap()
                    image_copy = os.path.join(image_path, image)
                    image_bmp.InitWith(image_copy)
                    bitmapButton = self.AddCustomGui(buttonId, c4d.CUSTOMGUI_BITMAPBUTTON, "", c4d.BFV_CENTER , w, h, bcBitmapButton)
                    bitmapButton.SetImage(image_bmp, True)
    
                self.GroupEnd()
    
                self.LayoutChanged(9002)
    
            return True
    


  • @bentraje said in Update GeDialog When Button is Pressed?:

    AddDynamicElement

    Is specific to this example that will draw an element according to the value of the combo box. you can actually replace this line by GeDialog::AddStaticText or whatever gadget addition you want to.

    You don't need to recreate the group by itself only it's content.

    So if it recreates the same things it is probably because images are not local to your class but only to your function, so if you redraw in the same order it will change of course nothing.

    Cheers,
    Maxime.



  • RE: So if it recreates the same things it is probably because images are not local to your class but only to your function,
    Ah, gotcha. Thanks for the heads up. Works now as expected :)


Log in to reply