def AskString(prompt, default='', id=261, ok=None, cancel=None):
    _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(3)
        SetDialogItemText(h, lf2cr(prompt))
        h = d.GetDialogItemAsControl(4)
        SetDialogItemText(h, lf2cr(default))
        d.SelectDialogItemText(4, 0, 999)
        if ok is not None:
            h = d.GetDialogItemAsControl(1)
            h.SetControlTitle(ok)
        if cancel is not None:
            h = d.GetDialogItemAsControl(2)
            h.SetControlTitle(cancel)
        d.SetDialogDefaultItem(1)
        d.SetDialogCancelItem(2)
        d.AutoSizeDialog()
        d.GetDialogWindow().ShowWindow()
        while 1:
            n = ModalDialog(None)
            if n == 1:
                h = d.GetDialogItemAsControl(4)
                return cr2lf(GetDialogItemText(h))
            if n == 2:
                return

        return
Exemplo n.º 2
0
def Message(msg, id=260, ok=None):
    """Display a MESSAGE string.
    
    Return when the user clicks the OK button or presses Return.
    
    The MESSAGE string can be at most 255 characters long.
    """
    _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(2)
        SetDialogItemText(h, lf2cr(msg))
        if ok is not None:
            h = d.GetDialogItemAsControl(1)
            h.SetControlTitle(ok)
        d.SetDialogDefaultItem(1)
        d.AutoSizeDialog()
        d.GetDialogWindow().ShowWindow()
        while 1:
            n = ModalDialog(None)
            if n == 1:
                return

        return
Exemplo n.º 3
0
 def label(self, *newstr):
     """label(text) - Set text in progress box"""
     self.w.BringToFront()
     if newstr:
         self._label = lf2cr(newstr[0])
     text_h = self.d.GetDialogItemAsControl(2)
     SetDialogItemText(text_h, self._label)
Exemplo n.º 4
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
Exemplo n.º 5
0
def AskString(prompt, default='', id=261, ok=None, cancel=None):
    """Display a PROMPT string and a text entry field with a DEFAULT string.
    
    Return the contents of the text entry field when the user clicks the
    OK button or presses Return.
    Return None when the user clicks the Cancel button.
    
    If omitted, DEFAULT is empty.
    
    The PROMPT and DEFAULT strings, as well as the return value,
    can be at most 255 characters long.
    """
    _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(3)
        SetDialogItemText(h, lf2cr(prompt))
        h = d.GetDialogItemAsControl(4)
        SetDialogItemText(h, lf2cr(default))
        d.SelectDialogItemText(4, 0, 999)
        if ok is not None:
            h = d.GetDialogItemAsControl(1)
            h.SetControlTitle(ok)
        if cancel is not None:
            h = d.GetDialogItemAsControl(2)
            h.SetControlTitle(cancel)
        d.SetDialogDefaultItem(1)
        d.SetDialogCancelItem(2)
        d.AutoSizeDialog()
        d.GetDialogWindow().ShowWindow()
        while 1:
            n = ModalDialog(None)
            if n == 1:
                h = d.GetDialogItemAsControl(4)
                return cr2lf(GetDialogItemText(h))
            if n == 2:
                return

        return
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
Exemplo n.º 7
0
def AskPassword(prompt, default='', id=264, ok=None, cancel=None):
    """Display a PROMPT string and a text entry field with a DEFAULT string.
    The string is displayed as bullets only.
    
    Return the contents of the text entry field when the user clicks the
    OK button or presses Return.
    Return None when the user clicks the Cancel button.
    
    If omitted, DEFAULT is empty.
    
    The PROMPT and DEFAULT strings, as well as the return value,
    can be at most 255 characters long.
    """
    _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(3)
        SetDialogItemText(h, lf2cr(prompt))
        pwd = d.GetDialogItemAsControl(4)
        bullets = '\xa5' * len(default)
        SetControlData(pwd, kControlEditTextPart, kControlEditTextPasswordTag,
                       default)
        d.SelectDialogItemText(4, 0, 999)
        Ctl.SetKeyboardFocus(d.GetDialogWindow(), pwd, kControlEditTextPart)
        if ok is not None:
            h = d.GetDialogItemAsControl(1)
            h.SetControlTitle(ok)
        if cancel is not None:
            h = d.GetDialogItemAsControl(2)
            h.SetControlTitle(cancel)
        d.SetDialogDefaultItem(Dialogs.ok)
        d.SetDialogCancelItem(Dialogs.cancel)
        d.AutoSizeDialog()
        d.GetDialogWindow().ShowWindow()
        while 1:
            n = ModalDialog(None)
            if n == 1:
                h = d.GetDialogItemAsControl(4)
                return cr2lf(
                    GetControlData(pwd, kControlEditTextPart,
                                   kControlEditTextPasswordTag))
            if n == 2:
                return

        return
def Message(msg, id=260, ok=None):
    _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(2)
        SetDialogItemText(h, lf2cr(msg))
        if ok is not None:
            h = d.GetDialogItemAsControl(1)
            h.SetControlTitle(ok)
        d.SetDialogDefaultItem(1)
        d.AutoSizeDialog()
        d.GetDialogWindow().ShowWindow()
        while 1:
            n = ModalDialog(None)
            if n == 1:
                return

        return
def AskPassword(prompt, default='', id=264, ok=None, cancel=None):
    _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(3)
        SetDialogItemText(h, lf2cr(prompt))
        pwd = d.GetDialogItemAsControl(4)
        bullets = '\xa5' * len(default)
        SetControlData(pwd, kControlEditTextPart, kControlEditTextPasswordTag,
                       default)
        d.SelectDialogItemText(4, 0, 999)
        Ctl.SetKeyboardFocus(d.GetDialogWindow(), pwd, kControlEditTextPart)
        if ok is not None:
            h = d.GetDialogItemAsControl(1)
            h.SetControlTitle(ok)
        if cancel is not None:
            h = d.GetDialogItemAsControl(2)
            h.SetControlTitle(cancel)
        d.SetDialogDefaultItem(Dialogs.ok)
        d.SetDialogCancelItem(Dialogs.cancel)
        d.AutoSizeDialog()
        d.GetDialogWindow().ShowWindow()
        while 1:
            n = ModalDialog(None)
            if n == 1:
                h = d.GetDialogItemAsControl(4)
                return cr2lf(
                    GetControlData(pwd, kControlEditTextPart,
                                   kControlEditTextPasswordTag))
            if n == 2:
                return

        return
Exemplo n.º 10
0
def GetArgv(optionlist=None,
            commandlist=None,
            addoldfile=1,
            addnewfile=1,
            addfolder=1,
            id=ARGV_ID):
    _initialize()
    _interact()
    d = GetNewDialog(id, -1)
    if not d:
        print "EasyDialogs: Can't get DLOG resource with id =", id, ' (missing resource file?)'
        return
    else:
        if optionlist:
            _setmenu(d.GetDialogItemAsControl(ARGV_OPTION_GROUP), optionlist)
            _selectoption(d, optionlist, 0)
        else:
            d.GetDialogItemAsControl(ARGV_OPTION_GROUP).DeactivateControl()
        if commandlist:
            _setmenu(d.GetDialogItemAsControl(ARGV_COMMAND_GROUP), commandlist)
            if type(commandlist[0]) == type(()) and len(commandlist[0]) > 1:
                help = commandlist[0][-1]
                h = d.GetDialogItemAsControl(ARGV_COMMAND_EXPLAIN)
                Dlg.SetDialogItemText(h, help)
        else:
            d.GetDialogItemAsControl(ARGV_COMMAND_GROUP).DeactivateControl()
        if not addoldfile:
            d.GetDialogItemAsControl(ARGV_ADD_OLDFILE).DeactivateControl()
        if not addnewfile:
            d.GetDialogItemAsControl(ARGV_ADD_NEWFILE).DeactivateControl()
        if not addfolder:
            d.GetDialogItemAsControl(ARGV_ADD_FOLDER).DeactivateControl()
        d.SetDialogDefaultItem(ARGV_ITEM_OK)
        d.SetDialogCancelItem(ARGV_ITEM_CANCEL)
        d.GetDialogWindow().ShowWindow()
        d.DrawDialog()
        if hasattr(MacOS, 'SchedParams'):
            appsw = MacOS.SchedParams(1, 0)
        try:
            while 1:
                stringstoadd = []
                n = ModalDialog(None)
                if n == ARGV_ITEM_OK:
                    break
                elif n == ARGV_ITEM_CANCEL:
                    raise SystemExit
                elif n == ARGV_OPTION_GROUP:
                    idx = d.GetDialogItemAsControl(
                        ARGV_OPTION_GROUP).GetControlValue() - 1
                    _selectoption(d, optionlist, idx)
                elif n == ARGV_OPTION_VALUE:
                    pass
                elif n == ARGV_OPTION_ADD:
                    idx = d.GetDialogItemAsControl(
                        ARGV_OPTION_GROUP).GetControlValue() - 1
                    if 0 <= idx < len(optionlist):
                        option = optionlist[idx]
                        if type(option) == type(()):
                            option = option[0]
                        if option[-1] == '=' or option[-1] == ':':
                            option = option[:-1]
                            h = d.GetDialogItemAsControl(ARGV_OPTION_VALUE)
                            value = Dlg.GetDialogItemText(h)
                        else:
                            value = ''
                        if len(option) == 1:
                            stringtoadd = '-' + option
                        else:
                            stringtoadd = '--' + option
                        stringstoadd = [stringtoadd]
                        if value:
                            stringstoadd.append(value)
                    else:
                        MacOS.SysBeep()
                elif n == ARGV_COMMAND_GROUP:
                    idx = d.GetDialogItemAsControl(
                        ARGV_COMMAND_GROUP).GetControlValue() - 1
                    if 0 <= idx < len(commandlist) and type(
                            commandlist[idx]) == type(
                                ()) and len(commandlist[idx]) > 1:
                        help = commandlist[idx][-1]
                        h = d.GetDialogItemAsControl(ARGV_COMMAND_EXPLAIN)
                        Dlg.SetDialogItemText(h, help)
                elif n == ARGV_COMMAND_ADD:
                    idx = d.GetDialogItemAsControl(
                        ARGV_COMMAND_GROUP).GetControlValue() - 1
                    if 0 <= idx < len(commandlist):
                        command = commandlist[idx]
                        if type(command) == type(()):
                            command = command[0]
                        stringstoadd = [command]
                    else:
                        MacOS.SysBeep()
                elif n == ARGV_ADD_OLDFILE:
                    pathname = AskFileForOpen()
                    if pathname:
                        stringstoadd = [pathname]
                elif n == ARGV_ADD_NEWFILE:
                    pathname = AskFileForSave()
                    if pathname:
                        stringstoadd = [pathname]
                elif n == ARGV_ADD_FOLDER:
                    pathname = AskFolder()
                    if pathname:
                        stringstoadd = [pathname]
                elif n == ARGV_CMDLINE_DATA:
                    pass
                else:
                    raise RuntimeError, 'Unknown dialog item %d' % n
                for stringtoadd in stringstoadd:
                    if '"' in stringtoadd or "'" in stringtoadd or ' ' in stringtoadd:
                        stringtoadd = repr(stringtoadd)
                    h = d.GetDialogItemAsControl(ARGV_CMDLINE_DATA)
                    oldstr = GetDialogItemText(h)
                    if oldstr and oldstr[-1] != ' ':
                        oldstr = oldstr + ' '
                    oldstr = oldstr + stringtoadd
                    if oldstr[-1] != ' ':
                        oldstr = oldstr + ' '
                    SetDialogItemText(h, oldstr)
                    d.SelectDialogItemText(ARGV_CMDLINE_DATA, 32767, 32767)

            h = d.GetDialogItemAsControl(ARGV_CMDLINE_DATA)
            oldstr = GetDialogItemText(h)
            tmplist = string.split(oldstr)
            newlist = []
            while tmplist:
                item = tmplist[0]
                del tmplist[0]
                if item[0] == '"':
                    while item[-1] != '"':
                        if not tmplist:
                            raise RuntimeError, 'Unterminated quoted argument'
                        item = item + ' ' + tmplist[0]
                        del tmplist[0]

                    item = item[1:-1]
                if item[0] == "'":
                    while item[-1] != "'":
                        if not tmplist:
                            raise RuntimeError, 'Unterminated quoted argument'
                        item = item + ' ' + tmplist[0]
                        del tmplist[0]

                    item = item[1:-1]
                newlist.append(item)

            return newlist
        finally:
            if hasattr(MacOS, 'SchedParams'):
                MacOS.SchedParams(*appsw)
            del d

        return
Exemplo n.º 11
0
"""Easy to use dialogs.
 def label(self, *newstr):
     self.w.BringToFront()
     if newstr:
         self._label = lf2cr(newstr[0])
     text_h = self.d.GetDialogItemAsControl(2)
     SetDialogItemText(text_h, self._label)