Menu

Custom buttons for message box?

Help
2014-10-08
2014-11-14
  • Irvine_himself

    Irvine_himself - 2014-10-08

    I have written a script that uses a message box to allow the user to decide between three possible actions:

    import re
    def dec_1(m):
        return 'R' + str(int(m.group(1)) - 1)
    
    def add_1(m):
        return 'R' + str(int(m.group(1)) + 1)
    
    # get cursor position
    position = editor.getCurrentPos()
    action = notepad.messageBox('Yes = inc  -------  NO = dec','Inc or Dec',MESSAGEBOXFLAGS.YESNOCANCEL) 
    
    if action == 6:
        # increment
        editor.rereplace('R([0-9]+)',add_1,re.IGNORECASE,position)
    elif action == 7:
        # decrement
        editor.rereplace('R([0-9]+)',dec_1,re.IGNORECASE,position)
    #else cancel
    

    As you can see, because of the way it uses "MESSAGEBOXFLAGS.YESNOCANCEL", it is a bit of a bodge. I noticed in the Enums page of the Wiki that there seems to be support for custom buttons using "MESSAGEBOXFLAGS.DEFBUTTON1", but I can't seem to figure out how it works.

    Any help on how to give the buttons custom names would be appreciated.

    Irvine

     

    Last edit: Irvine_himself 2014-10-08
  • CFrank

    CFrank - 2014-11-14

    Hi,

    not sure if I'm too late to answer but in case someone else has the same question,
    this is a misunderstanding - the MESSAGEBOXFLAGS.DEFBUTTON1, 2, ... flags define
    which button is the default one.

    E.g.

    notepad.messageBox('some message', 'a title', MESSAGEBOXFLAGS.ABORTRETRYIGNORE)
    

    opens a messagebox with three buttons, ABORT, RETRY and IGNORE. The default button
    is ABORT.

    If you use

    notepad.messageBox('some message', 'a title', MESSAGEBOXFLAGS.ABORTRETRYIGNORE | MESSAGEBOXFLAGS.DEFBUTTON2)
    

    Then the same messagebox appears but the default button is now RETRY.

    Cheers
    Claudia

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.