LinkBoxGui Accept or Refuse in GeDialog

On 08/07/2014 at 13:31, xxxxxxxx wrote:

Hello Forum,

I have a CommandData plugin that opens a GeDialog containing a LinkBoxGui gadget.  I would like to check the type of object being dragged into the LinkBox and either accept of refuse it.

Here is the code I have so far:

import c4d
import c4d.gui
import c4d.plugins
  
PLUGIN_ID = 1032474
LINKBOX_GUI = 2000
  
  
class LinkBoxDlg(c4d.gui.GeDialog) :
    def CreateLayout(self) :
        self.GroupBegin(0, c4d.BFH_SCALEFIT, 2, 1, "", 0, 0)
        self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Find")
        self.AddCustomGui(LINKBOX_GUI, c4d.CUSTOMGUI_LINKBOX, "", c4d.BFH_SCALEFIT, 0, 0)
        self.GroupEnd()
        return True
  
    def Message(self, msg, result) :
        if msg.GetId() == c4d.MSG_DESCRIPTION_CHECKDRAGANDDROP:
            if msg.GetLong(c4d.LINKBOX_ACCEPT_MESSAGE_CONTROL_ID) == LINKBOX_GUI:
                print "*"
                print "TYPE: ", msg[c4d.LINKBOX_ACCEPT_MESSAGE_TYPE]
                print "ELEMENT: ", msg[c4d.LINKBOX_ACCEPT_MESSAGE_ELEMENT]
                print "ACCEPT: ", msg[c4d.LINKBOX_ACCEPT_MESSAGE_ACCEPT]
                print "CONTROL_ID: ", msg[c4d.LINKBOX_ACCEPT_MESSAGE_CONTROL_ID]
                print "#"
  
        return c4d.gui.GeDialog.Message(self, msg, result)
  
  
class LinkBoxGuiAccept(c4d.plugins.CommandData) :
    dialog = None
    def Execute(self, doc) :
        if self.dialog is None:
            self.dialog = LinkBoxDlg()
  
        return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=PLUGIN_ID, defaultw=0, defaulth=0)
  
  
if __name__ == "__main__":
    c4d.plugins.RegisterCommandPlugin(id=PLUGIN_ID,
                                  str="LinkBoxGui Accept Test",
                                  info=0,
                                  help="Command Data Plugin Test",
                                  dat=LinkBoxGuiAccept(),
                                  icon=None)

Here is the console output:

*
TYPE:  201
ELEMENT:  <PyCObject object at 0x000000000CB4E378>
ACCEPT:  <PyCObject object at 0x000000000CB4E378>
CONTROL_ID:  2000
#

When accessing the BaseContainer's values received in GeDialog.Message(), PyCObjects are returned for the object(ELEMENT) and Bool(ACCEPT) values.  ID 201(DRAGTYPE_ATOMARRAY i'm guessing ) is also always returned for TYPE.

I know that it is not possible to set ACCEPT and REFUSE flags in a Dialog Resource file for LinkBoxGui in C++, so I'm assuming that it is not possible in Python.

I found this link explaining how to get an integer from a PyCObject.

Is it possible to convert a PyCObject to BaseList2D?
Is it possible to set a PyCObject to Bool?

Perhaps there is a smarter way to accept or refuse a drag and drop in GeDialog?

Thanks for you help,

Joe Buck

On 09/07/2014 at 05:42, xxxxxxxx wrote:

Hi joebuck,

GeDialog.Command() is called after the parameter in the LinkBox changed. You can retrieve the
link and check its type, and clear the LinkBox if the type is not accepted.

Best,
-Niklas

On 09/07/2014 at 11:07, xxxxxxxx wrote:

Hi Niklas,

Thanks for the quick reply.  I was hoping for a PyCObject conversion so I could get a FORBIDDEN cursor over the LinkBoxGui, but if this is the way it's done in Python GeDialog, it works for me.

Thank you for your time and help,

Joe Buck

On 10/07/2014 at 01:38, xxxxxxxx wrote:

Originally posted by xxxxxxxx

I was hoping for a PyCObject conversion so I could get a FORBIDDEN cursor over the LinkBoxGui, but if this is the way it's done in Python GeDialog, it works for me.

It's a limitation of the Python API unfortunately.

-Niklas