Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > PYTHON Development
  New Posts New Posts
  FAQ FAQ  Forum Search   Register Register  Login Login

LinkBoxGui Accept or Refuse in GeDialog

 Post Reply Post Reply
Author
Message
joebuck View Drop Down
Member
Member


Joined: 2011 Oct 26
Location: Burbank, CA
Online Status: Offline
Posts: 81
Post Options Post Options   Quote joebuck Quote  Post ReplyReply Direct Link To This Post Topic: LinkBoxGui Accept or Refuse in GeDialog
    Posted: 2014 Jul 08 at 1:31pm
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


Back to Top
NiklasR View Drop Down
Member
Member


Joined: 2010 Dec 13
Location: Germany
Online Status: Offline
Posts: 2573
Post Options Post Options   Quote NiklasR Quote  Post ReplyReply Direct Link To This Post Posted: 2014 Jul 09 at 5:42am
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
Back to Top
joebuck View Drop Down
Member
Member


Joined: 2011 Oct 26
Location: Burbank, CA
Online Status: Offline
Posts: 81
Post Options Post Options   Quote joebuck Quote  Post ReplyReply Direct Link To This Post Posted: 2014 Jul 09 at 11:07am
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


Edited by joebuck - 2014 Jul 09 at 11:07am
Back to Top
NiklasR View Drop Down
Member
Member


Joined: 2010 Dec 13
Location: Germany
Online Status: Offline
Posts: 2573
Post Options Post Options   Quote NiklasR Quote  Post ReplyReply Direct Link To This Post Posted: 2014 Jul 10 at 1:38am
Originally posted by joebuck

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
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.094 seconds.