Example #1
0
def AskYesNoCancel(question, default = 0, yes=None, no=None, cancel=None, id=262):
    """Display a QUESTION string which can be answered with Yes or No.

    Return 1 when the user clicks the Yes button.
    Return 0 when the user clicks the No button.
    Return -1 when the user clicks the Cancel button.

    When the user presses Return, the DEFAULT value is returned.
    If omitted, this is 0 (No).

    The QUESTION string can be at most 255 characters.
    """

    _initialize()
    _interact()
    d = GetNewDialog(id, -1)
    if not d:
        print "EasyDialogs: Can't get DLOG resource with id =", id, " (missing resource file?)"
        return
    # Button assignments:
    # 1 = default (invisible)
    # 2 = Yes
    # 3 = No
    # 4 = Cancel
    # The question string is item 5
    h = d.GetDialogItemAsControl(5)
    SetDialogItemText(h, lf2cr(question))
    if yes is not None:
        if yes == '':
            d.HideDialogItem(2)
        else:
            h = d.GetDialogItemAsControl(2)
            h.SetControlTitle(yes)
    if no is not None:
        if no == '':
            d.HideDialogItem(3)
        else:
            h = d.GetDialogItemAsControl(3)
            h.SetControlTitle(no)
    if cancel is not None:
        if cancel == '':
            d.HideDialogItem(4)
        else:
            h = d.GetDialogItemAsControl(4)
            h.SetControlTitle(cancel)
    d.SetDialogCancelItem(4)
    if default == 1:
        d.SetDialogDefaultItem(2)
    elif default == 0:
        d.SetDialogDefaultItem(3)
    elif default == -1:
        d.SetDialogDefaultItem(4)
    d.AutoSizeDialog()
    d.GetDialogWindow().ShowWindow()
    while 1:
        n = ModalDialog(None)
        if n == 1: return default
        if n == 2: return 1
        if n == 3: return 0
        if n == 4: return -1
def AskYesNoCancel(question,
                   default=0,
                   yes=None,
                   no=None,
                   cancel=None,
                   id=262):
    _initialize()
    _interact()
    d = GetNewDialog(id, -1)
    if not d:
        print "EasyDialogs: Can't get DLOG resource with id =", id, ' (missing resource file?)'
        return
    else:
        h = d.GetDialogItemAsControl(5)
        SetDialogItemText(h, lf2cr(question))
        if yes is not None:
            if yes == '':
                d.HideDialogItem(2)
            else:
                h = d.GetDialogItemAsControl(2)
                h.SetControlTitle(yes)
        if no is not None:
            if no == '':
                d.HideDialogItem(3)
            else:
                h = d.GetDialogItemAsControl(3)
                h.SetControlTitle(no)
        if cancel is not None:
            if cancel == '':
                d.HideDialogItem(4)
            else:
                h = d.GetDialogItemAsControl(4)
                h.SetControlTitle(cancel)
        d.SetDialogCancelItem(4)
        if default == 1:
            d.SetDialogDefaultItem(2)
        elif default == 0:
            d.SetDialogDefaultItem(3)
        elif default == -1:
            d.SetDialogDefaultItem(4)
        d.AutoSizeDialog()
        d.GetDialogWindow().ShowWindow()
        while 1:
            n = ModalDialog(None)
            if n == 1:
                return default
            if n == 2:
                return 1
            if n == 3:
                return 0
            if n == 4:
                return -1

        return
Example #3
0
"""Easy to use dialogs.