Python - c4d.gui.ShowPopupDialog



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 14/10/2010 at 17:18, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   R12 
    Platform:   Windows  ;   
    Language(s) :       PYTHON  ;

    ---------
    Im a beginner in Python coding and I stumbled about something I don't understand. Perhaps someone here could enlighten me.

    I don't know if it is a bug in the documentation of the Python SDK or just my inexperience.

    In the Python SDK you find the following about "c4d.gui.ShowPopupDialog":

    [QUOTE]c4d.gui.ShowPopupDialog(x, y, bc, flags=POPUP_RIGHT|POPUP_EXECUTECOMMANDS)

    Displays a popup menu:

    import c4d
        from c4d import gui

    entries = c4d.BaseContainer()
        entries.SetString(0, "Title&d;&") #append &d;& to grey entry out
        entries.SetString(2, "Hello")
        entries.SetString(3, "World!")
        result = gui.ShowPopupDialog(cd=None, bc=entries, x=70, y=90)
        print result

    Parameters:    ° x (int) – The X position.
                            ° y (int) – The Y position.
                            ° bc (BaseContainer) – The container with the elements. The elements has to be of type str. You can optional set a title with the ID 0 or just start with the first element with the ID 2. If you set a title, we recommend you to add the string &d;& to the name of the title (see example) to grey it out. The title cannot be selected, even its not greyed out.
                            ° flags (int) –
                             One of the following flags:
                                      POPUP_ABOVE      Open above mouse.
                                      POPUP_BELOW      Open below mouse.
                                      POPUP_CENTERVERT      Open centered vertically around mouse.
                                      POPUP_LEFT      Open to the left of the mouse.
                                      POPUP_RIGHT      Open to the right of the mouse.
                                      POPUP_CENTERHORIZ      Open centered horizontally around mouse.
                                      POPUP_EXECUTECOMMANDS      Execute commands immediatly.
                                      POPUP_ALLOWUNDOCK      Allow to undock popupmenu.
                                      POPUP_ALLOWUNDOCK_REC      Allow to undock popupmenu for children.

    Return type:         int
    Returns:               The ID of the selected item, or 0 if nothing was selected.
    [/QUOTE]

    In the definition there is nothing about the parameter "cd" but in the example you could find "cd=None" which also seems to be really necessary for this function to work.

    But what does it mean, what is it for and why isn't it mentioned in the definition of this function?

    And what is the precondition to use the flags?
    Cause if I tried to use them I got "NameError"s that the name of the flags wouldn't be defined (I used "import c4d" and "from c4d import gui").



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 14/10/2010 at 17:49, xxxxxxxx wrote:

    Hi Phoenix,

    the argument cd is optional and can be a parent dialog or None. If None, this should work fine though.

    And what is the precondition to use the flags? 
    Cause if I tried to use them I got "NameError"s that the name of the flags wouldn't be defined (I used "import c4d" and "from c4d import gui").

    Can you please post an example?

    Cheers, Sebastian



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 14/10/2010 at 18:16, xxxxxxxx wrote:

    Hi Sebastian,

    thanks for your reply.

    I give you a few examples based on the one from the SDK.

    First, you say "cd" is optional, but if I try:

      
    import c4d   
    from c4d import gui   
      
    entries = c4d.BaseContainer()   
    entries.SetString(0, "Title&d;&")   
    entries.SetString(2, "Hello")   
    entries.SetString(3, "World!")   
    result = gui.ShowPopupDialog(bc=entries, x=500, y=400)   
    print result   
    

    The Python console tells me:

    Traceback (most recent call last) :
    File "<scriptmanager>", line 8, in <module>
    TypeError: Required argument 'cd' (pos 1) not found

    And again, what is "cd" supposed to mean at all?

    And if I try e.g. (the "flags" argument example) :

      
    import c4d   
    from c4d import gui   
      
    entries = c4d.BaseContainer()   
    entries.SetString(0, "Title&d;&")   
    entries.SetString(2, "Hello")   
    entries.SetString(3, "World!")   
    result = gui.ShowPopupDialog(cd=None, bc=entries, x=500, y=400, flags=POPUP_RIGHT)   
    print result   
    

    I get:

    Traceback (most recent call last) :
    File "<scriptmanager>", line 8, in <module>
    NameError: name 'POPUP_RIGHT' is not defined

    Oh and by the way, why is the first useable entry-ID 2 and not 1 (0 is for the title, that's clear so far)?

    And is there no simple way to get a dialog opened just in the center of the screen?
    Shouldn't this be a basic thing?
    In my opinion it should.

    And there are also other errors in the Python SDK, e.G. at the description for c4d.BaseObject there is the following outdated example:

      
    import c4d   
      
    obj = c4d.BaseObject(c4d.Ocube)   
    obj.SetPos(c4d.Vector(20))   
    #now you can insert the object in a document   
    

    But correct it have to be now:

      
    import c4d   
      
    obj = c4d.BaseObject(c4d.Ocube)   
    obj.SetRelPos(c4d.Vector(20))   
    #now you can insert the object in a document   
    

    And I worry that there are surely more goofs of this kind left in the Python SDK.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 14/10/2010 at 22:23, xxxxxxxx wrote:

    Thanks for the report of the bugs in the documentation. Please note, the documentation is still preliminary.

    About ShowPopupDialog: cd  is optional to pass a dialog or None, the argument itself must be set.
    To use POPUP_RIGHT in your case please try c4d.POPUP_RIGHT or import the c4d module via from c4d import * even this is not recommended. All constants of C4D are stored in this module.

    _A string with ID=1 sets the name of the menu: (used for submenus).  _ _IDs in the range 1000 to 899999 inserts a C4D command: (For a list of IDs, see the c4d_symbols.coh file. A special case is the  IDM_CM_CLOSEWINDOW _  ID that will close the current dialog, for this is the 'cd' argument for).
    _
    _
    The IDs that are left, between 900000 (FIRST_POPUP_ID _) and 999999, can be used for your own menu items.  _ _So instead of the IDs in the example (1,2,3) you can use c4d.FIRST_POPUP_ID for the first element,  _ c4d.FIRST_POPUP_ID+1 for the second entry, etc.
    _
    _
    These information will be added in the future to the documentation.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 15/10/2010 at 00:22, xxxxxxxx wrote:

    Ahh, the fog lifted!

    Thank you very much for this detailed explanation.

    And yes, the documentation still needs a little bit of overhauling and it'll be really useful when such informations are added.

    Also a section with some basic syntax comparison especially between C.O.F.F.E.E. (or even C++ ) and Python with concrete code samples would be a nice thing.
    Even though I'm aware that the SDK isn't designed for teaching coding this would be a great and helpful thing.
    Perhaps that's also something for a thread in this forum?

    Kind regards,
    Tom


Log in to reply