Creating a Clickable Floating GUI Dialog?



  • Hi,

    I have this old script that works well with DLG_TYPE_MODAL_RESIZEABLE but with this mode I am locked into the UI until I click exit. I wanted a floating dialog with what DLG_TYPE_ASYNC provides. The problem is the button does not work.

    When you click the button, a string is printed in the console.

    Is there a way around this?

    Thank you for looking at my problem.

    You can see the code below:

    import c4d
    from c4d import gui 
     
    class Colorizer(gui.GeDialog):
        
        def CreateLayout(self):
            
            self.SetTitle('Colorizer')
            
            # Prepare a red bitmap for the button.
            w = 50
            h = 50
            bmpRed = c4d.bitmaps.BaseBitmap()
            bmpRed.Init(w, h)
            for y in xrange(w):
                for x in xrange(h):
                    bmpRed.SetPixel(x, y, 255, 0, 0)
            # BitmapButton configuration
            bcBitmapButton = c4d.BaseContainer()
            bcBitmapButton[c4d.BITMAPBUTTON_BUTTON] = True
    
            # Add a BitmapButton to the dialog.
            # _bitmapButton is a member variable of the dialog class
            buttonId = 2000
            _bitmapButton = self.AddCustomGui(buttonId, c4d.CUSTOMGUI_BITMAPBUTTON, "", c4d.BFH_CENTER|c4d.BFV_CENTER, w, h, bcBitmapButton)
            if _bitmapButton is None:
                print "Handle this error!"
            # Assign the image to the button.
            # Note: Let it create an internal copy as the created bitmap will be free'd, when scope is left.
            _bitmapButton.SetImage(bmpRed, True)
    
        def Command(self, id, msg):
            if id==2000: # corresponds to the button ID used in the code snippet in the first answer in this thread
                print "My Bitmap Button"
            return True
                             
    def main():
        dialog = Colorizer()
        dialog.Open(c4d.DLG_TYPE_ASYNC, defaultw=300,defaulth=100)
        #dialog.Open(c4d.DLG_TYPE_MODAL_RESIZEABLE, defaultw=300,defaulth=100) # Works but I can't click on the interface. Basically, I'm locked until I click exit. '
         
    if __name__=='__main__':
        main()
    


  • Stupid me. I already asked the same question a year ago here:
    https://plugincafe.maxon.net/topic/11472/dialogue-box-manager-through-plug-in-vs-vanilla-script/5

    Anyhow, for anyone interested on the working plug-in code. Here it is

    import c4d
    from c4d import bitmaps, documents, gui, plugins, threading, utils
    
    PLUGIN_ID   = 1011323
    
    class MyDialog(gui.GeDialog):
    
        def CreateLayout(self):
    
            #self.SetTitle('Colorizer')
            
            # Prepare a red bitmap for the button.
            w = 50
            h = 50
            bmpRed = c4d.bitmaps.BaseBitmap()
            bmpRed.Init(w, h)
            for y in xrange(w):
                for x in xrange(h):
                    bmpRed.SetPixel(x, y, 255, 0, 0)
            # BitmapButton configuration
            bcBitmapButton = c4d.BaseContainer()
            bcBitmapButton[c4d.BITMAPBUTTON_BUTTON] = True
    
            # Add a BitmapButton to the dialog.
            # _bitmapButton is a member variable of the dialog class
            buttonId = 2000
            _bitmapButton = self.AddCustomGui(buttonId, c4d.CUSTOMGUI_BITMAPBUTTON, "", c4d.BFH_CENTER|c4d.BFV_CENTER, w, h, bcBitmapButton)
            if _bitmapButton is None:
                print "Handle this error!"
            # Assign the image to the button.
            # Note: Let it create an internal copy as the created bitmap will be free'd, when scope is left.
            _bitmapButton.SetImage(bmpRed, True)
    
        def Command(self, id, msg):
            if id==2000: # corresponds to the button ID used in the code snippet in the first answer in this thread
                print "My Bitmap Button"
            return True
    
    class MyMenuPlugin(plugins.CommandData):
    
        dialog = None
        def Execute(self, doc):
        # create the dialog
           if self.dialog is None:
              self.dialog = MyDialog()
    
           return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=PLUGIN_ID, defaultw=200, defaulth=150, xpos=-1, ypos=-1)
    
        def RestoreLayout(self, sec_ref):
        # manage the dialog
           if self.dialog is None:
              self.dialog = MyDialog()
           return self.dialog.Restore(pluginid=PLUGIN_ID, secret=sec_ref)
    
    if __name__ == "__main__":
    
        okyn = plugins.RegisterCommandPlugin(PLUGIN_ID, "Cubey",0, None, "Cubey initialized", MyMenuPlugin())
        if (okyn):
            print "Cubey initialized"
    
    

Log in to reply