Beispiel #1
0
 def done(self, item):
     tp, h, rect = self.dlg.GetDialogItem(DLG_SRCPATH)
     src = Dlg.GetDialogItemText(h)
     if item == DLG_OK:
         if self.id == ID_INCLUDE:
             tp, h, rect = self.dlg.GetDialogItem(DLG_DSTPATH)
             dst = Dlg.GetDialogItemText(h)
             rv = (src, dst)
         else:
             rv = (src, None)
     elif item == DLG_EXCLUDE:
         rv = (src, None)
     else:
         rv = self.cancelrv
     self.close()
     self.callback((item in (DLG_OK, DLG_EXCLUDE)), rv)
Beispiel #2
0
    def dolookup(self):
        """Get text entered in the lookup entry area.  Place result of the
           call to dnslookup in the result entry area."""
        tp, h, rect = self.dlg.GetDialogItem(ITEM_LOOKUP_ENTRY)
        txt = Dlg.GetDialogItemText(h)

        tp, h, rect = self.dlg.GetDialogItem(ITEM_RESULT)
        Dlg.SetDialogItemText(h, self.dnslookup(txt))
Beispiel #3
0
 def _getlabel(self, item):
     """Return the text of a static text or edit text"""
     h = self._dialog.GetDialogItemAsControl(item)
     text = Dlg.GetDialogItemText(h)
     if '\r' in text:
         text = string.split(text, '\r')
         text = string.join(text, '\n')
     return text
Beispiel #4
0
 def done(self):
     h = self._dlg.GetDialogItemAsControl(ITEM_INPUT_TEXT)
     name = Dlg.GetDialogItemText(h)
     type = self.type_select.getselectvalue()
     ctl = self._dlg.GetDialogItemAsControl(ITEM_INPUT_OK)
     ctl.HiliteControl(10)
     self._cb(name, type)
     ctl.HiliteControl(0)
     self.close()
Beispiel #5
0
 def _gettext(self):
     h = self._dlg.GetDialogItemAsControl(ITEM_INPUT_TEXT)
     if self._is_passwd_dialog:
         rv = ControlAccessor.GetControlData(
             h, Controls.kControlEditTextPart,
             Controls.kControlEditTextPasswordTag)
     else:
         rv = Dlg.GetDialogItemText(h)
     return rv
Beispiel #6
0
def do_dialog():
    """Post dialog and handle user interaction until quit"""
    my_dlg = Dlg.GetNewDialog(ID_MAIN, -1)
    while 1:
        n = Dlg.ModalDialog(None)
        if n == ITEM_LOOKUP_BUTTON:
            tp, h, rect = my_dlg.GetDialogItem(ITEM_LOOKUP_ENTRY)
            txt = Dlg.GetDialogItemText(h)

            tp, h, rect = my_dlg.GetDialogItem(ITEM_RESULT)
            Dlg.SetDialogItemText(h, dnslookup(txt))
        elif n == ITEM_QUIT_BUTTON:
            break
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
Beispiel #8
0
"""Easy to use dialogs.
Beispiel #9
0
def dialog(script=None):

    # Invent the various names
    if not script:
        fss, ok = macfs.PromptGetFile("Script?", "TEXT")
        if not ok:
            sys.exit(0)
        script = fss.as_pathname()
    basename, ext = os.path.splitext(script)
    if ext:
        appletname = basename
        rsrcname = basename + 'modules.rsrc'
    else:
        appletname = script + '.applet'
        rsrcname = script + 'modules.rsrc'
    dirname, basebase = os.path.split(basename)
    dirname = os.path.join(dirname, 'build.'+basebase)

    # Get the dialog, possibly opening the resource file (if needed)
    macresource.need('DLOG', ID_MAINDIALOG, 'macfreeze.rsrc')
    d = Dlg.GetNewDialog(ID_MAINDIALOG, -1)
    if d == None:
        EasyDialogs.Message("Dialog resource not found or faulty")
        sys.exit(1)

    # Fill the dialog
    d.SetDialogDefaultItem(ITEM_OK)
    d.SetDialogCancelItem(ITEM_CANCEL)

    _dialogsetfile(d, ITEM_SCRIPTNAME, script)
    _dialogsetfile(d, ITEM_SOURCEDIRNAME, dirname)
    _dialogsetfile(d, ITEM_RESOURCENAME, rsrcname)
    _dialogsetfile(d, ITEM_APPLETNAME, appletname)

    gentype = ITEM_GENSOURCE
    _dialogradiogroup(d, ITEM_GENSOURCE)

    # Interact
    d.GetDialogWindow().SetWTitle("Standalone application creation options")
    d.GetDialogWindow().ShowWindow()
    d.DrawDialog()
    while 1:
        item = Dlg.ModalDialog(None)
        if item == ITEM_OK:
            break
        elif item == ITEM_CANCEL:
            sys.exit(0)
        elif item in RADIO_GROUPING.keys():
            gentype = item
            _dialogradiogroup(d, item)
        elif item == ITEM_SCRIPTBROWSE:
            fss, ok = macfs.PromptGetFile("Script?")
            if ok:
                script = fss.as_pathname()
                _dialogsetfile(d, ITEM_SCRIPTNAME, script)
        elif item == ITEM_SOURCEDIRBROWSE:
            fss, ok = macfs.StandardPutFile("Output folder name", os.path.split(dirname)[1])
            if ok:
                dirname = fss.as_pathname()
                _dialogsetfile(d, ITEM_SOURCEDIRNAME, dirname)
        elif item == ITEM_RESOURCEBROWSE:
            fss, ok = macfs.StandardPutFile("Resource output file", os.path.split(rsrcname)[1])
            if ok:
                rsrcname = fss.as_pathname()
                _dialogsetfile(d, ITEM_RESOURCENAME, rsrcname)
        elif item == ITEM_APPLETBROWSE:
            fss, ok = macfs.StandardPutFile("Applet output file", os.path.split(appletname)[1])
            if ok:
                appletname = fss.as_pathname()
                _dialogsetfile(d, ITEM_APPLETNAME, appletname)
        else:
            pass
    tp, h, rect = d.GetDialogItem(ITEM_DEBUG)
    debug = Dlg.GetDialogItemText(h)
    try:
        debug = string.atoi(string.strip(debug))
    except ValueError:
        EasyDialogs.Message("Illegal debug value %r, set to zero."%(debug,))
        debug = 0
    if gentype == ITEM_GENSOURCE:
        return 'source', script, dirname, debug
    elif gentype == ITEM_GENRESOURCE:
        return 'resource', script, rsrcname, debug
    elif gentype == ITEM_GENAPPLET:
        return 'applet', script, appletname, debug
    elif gentype == ITEM_GENINFO:
        return 'info', script, '', debug
    raise 'Error in gentype', gentype
Beispiel #10
0
"""Sample program performing domain name lookups and showing off EasyDialogs,
Beispiel #11
0
import FrameWork
Beispiel #12
0
"""Import a module while pretending its name is __main__. This
Beispiel #13
0
#
Beispiel #14
0
"""macfreezegui - The GUI for macfreeze"""