예제 #1
0
def _selectoption(d, optionlist, idx):
    if idx < 0 or idx >= len(optionlist):
        MacOS.SysBeep()
        return
    option = optionlist[idx]
    if type(option) == type(()):
        if len(option) == 4:
            help = option[2]
        elif len(option) > 1:
            help = option[-1]
        else:
            help = ''
    else:
        help = ''
    h = d.GetDialogItemAsControl(ARGV_OPTION_EXPLAIN)
    if help and len(help) > 250:
        help = help[:250] + '...'
    Dlg.SetDialogItemText(h, help)
    hasvalue = 0
    if type(option) == type(()):
        label = option[0]
    else:
        label = option
    if label[-1] == '=' or label[-1] == ':':
        hasvalue = 1
    h = d.GetDialogItemAsControl(ARGV_OPTION_VALUE)
    Dlg.SetDialogItemText(h, '')
    if hasvalue:
        d.ShowDialogItem(ARGV_OPTION_VALUE)
        d.SelectDialogItemText(ARGV_OPTION_VALUE, 0, 0)
    else:
        d.HideDialogItem(ARGV_OPTION_VALUE)
예제 #2
0
def beep_speaker():
    """ tries several beep methods for
		different platforms and frameworks
		and returns if one method was
		successful.
	"""
    try:
        import winsound
        return winsound.Beep(30, 1)
    except:
        pass

    try:
        import MacOS
        # not in 64 bit
        return MacOS.SysBeep()
    except:
        pass

    try:
        return gtk.gdk.beep()
    except:
        pass

    try:
        tty = file("/dev/tty", "w")
        tty.write(chr(7))
        tty.close()
        return None
    except:
        pass
예제 #3
0
파일: PyDocSearch.py 프로젝트: mmrvka/xbmc
 def search(self):
     hits = dosearch(self.docpath, self.w.searchtext.get(),
                     self.getsettings())
     if hits:
         Results(hits)
     elif hasattr(MacOS, 'SysBeep'):
         MacOS.SysBeep(0)
예제 #4
0
def _test2():
    print '\nmorefindertools version %s\nTests coming up...' % __version__
    import os
    import random

    # miscellaneous
    print '\tfilesharing on?', filesharing(
    )  # is file sharing on, off, starting up?
    print '\tOS version', OSversion()  # the version of the system software

    # set the soundvolume in a simple way
    print '\tSystem beep volume'
    for i in range(0, 7):
        volumelevel(i)
        MacOS.SysBeep()

    # Finder's windows, file location, file attributes
    open("@findertoolstest", "w")
    f = "@findertoolstest"
    reveal(f)  # reveal this file in a Finder window
    select(f)  # select this file

    base, file = os.path.split(f)
    closewindow(base)  # close the window this file is in  (opened by reveal)
    openwindow(base)  # open it again
    windowview(base, 1)  # set the view by list

    label(f, 2)  # set the label of this file to something orange
    print '\tlabel', label(f)  # get the label of this file

    # the file location only works in a window with icon view!
    print 'Random locations for an icon'
    windowview(base, 0)  # set the view by icon
    windowsize(base, (600, 600))
    for i in range(50):
        location(f, (random.randint(10, 590), random.randint(10, 590)))

    windowsize(base, (200, 400))
    windowview(base, 1)  # set the view by icon

    orgpos = windowposition(base)
    print 'Animated window location'
    for i in range(10):
        pos = (100 + i * 10, 100 + i * 10)
        windowposition(base, pos)
        print '\twindow position', pos
    windowposition(base, orgpos)  # park it where it was before

    print 'Put a comment in file', f, ':'
    print '\t', comment(f)  # print the Finder comment this file has
    s = 'This is a comment no one reads!'
    comment(f, s)  # set the Finder comment
예제 #5
0
def _test2():
    print '\nmorefindertools version %s\nTests coming up...' % __version__
    import os
    import random
    print '\tfilesharing on?', filesharing()
    print '\tOS version', OSversion()
    print '\tSystem beep volume'
    for i in range(0, 7):
        volumelevel(i)
        MacOS.SysBeep()

    open('@findertoolstest', 'w')
    f = '@findertoolstest'
    reveal(f)
    select(f)
    base, file = os.path.split(f)
    closewindow(base)
    openwindow(base)
    windowview(base, 1)
    label(f, 2)
    print '\tlabel', label(f)
    print 'Random locations for an icon'
    windowview(base, 0)
    windowsize(base, (600, 600))
    for i in range(50):
        location(f, (random.randint(10, 590), random.randint(10, 590)))

    windowsize(base, (200, 400))
    windowview(base, 1)
    orgpos = windowposition(base)
    print 'Animated window location'
    for i in range(10):
        pos = (100 + i * 10, 100 + i * 10)
        windowposition(base, pos)
        print '\twindow position', pos

    windowposition(base, orgpos)
    print 'Put a comment in file', f, ':'
    print '\t', comment(f)
    s = 'This is a comment no one reads!'
    comment(f, s)
예제 #6
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
예제 #7
0
"""Easy to use dialogs.
예제 #8
0
"""Utility routines depending on the finder,
예제 #9
0
"""Edit the Python Preferences file."""