home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 May / maximum-cd-2010-05.iso / DiscContents / boxee-0.9.20.10711.exe / system / python / Lib / plat-mac / findertools.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-07-20  |  28.1 KB  |  908 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.4)
  3.  
  4. '''Utility routines depending on the finder,
  5. a combination of code by Jack Jansen and erik@letterror.com.
  6.  
  7. Most events have been captured from
  8. Lasso Capture AE and than translated to python code.
  9.  
  10. IMPORTANT
  11. Note that the processes() function returns different values
  12. depending on the OS version it is running on. On MacOS 9
  13. the Finder returns the process *names* which can then be
  14. used to find out more about them. On MacOS 8.6 and earlier
  15. the Finder returns a code which does not seem to work.
  16. So bottom line: the processes() stuff does not work on < MacOS9
  17.  
  18. Mostly written by erik@letterror.com
  19. '''
  20. import Finder
  21. from Carbon import AppleEvents
  22. import aetools
  23. import MacOS
  24. import sys
  25. import Carbon.File as Carbon
  26. import Carbon.Folder as Carbon
  27. import aetypes
  28. from types import *
  29. __version__ = '1.1'
  30. Error = 'findertools.Error'
  31. _finder_talker = None
  32.  
  33. def _getfinder():
  34.     '''returns basic (recyclable) Finder AE interface object'''
  35.     global _finder_talker
  36.     if not _finder_talker:
  37.         _finder_talker = Finder.Finder()
  38.     
  39.     _finder_talker.send_flags = _finder_talker.send_flags | AppleEvents.kAECanInteract | AppleEvents.kAECanSwitchLayer
  40.     return _finder_talker
  41.  
  42.  
  43. def launch(file):
  44.     '''Open a file thru the finder. Specify file by name or fsspec'''
  45.     finder = _getfinder()
  46.     fss = Carbon.File.FSSpec(file)
  47.     return finder.open(fss)
  48.  
  49.  
  50. def Print(file):
  51.     '''Print a file thru the finder. Specify file by name or fsspec'''
  52.     finder = _getfinder()
  53.     fss = Carbon.File.FSSpec(file)
  54.     return finder._print(fss)
  55.  
  56.  
  57. def copy(src, dstdir):
  58.     '''Copy a file to a folder'''
  59.     finder = _getfinder()
  60.     if type(src) == type([]):
  61.         src_fss = []
  62.         for s in src:
  63.             src_fss.append(Carbon.File.FSSpec(s))
  64.         
  65.     else:
  66.         src_fss = Carbon.File.FSSpec(src)
  67.     dst_fss = Carbon.File.FSSpec(dstdir)
  68.     return finder.duplicate(src_fss, to = dst_fss)
  69.  
  70.  
  71. def move(src, dstdir):
  72.     '''Move a file to a folder'''
  73.     finder = _getfinder()
  74.     if type(src) == type([]):
  75.         src_fss = []
  76.         for s in src:
  77.             src_fss.append(Carbon.File.FSSpec(s))
  78.         
  79.     else:
  80.         src_fss = Carbon.File.FSSpec(src)
  81.     dst_fss = Carbon.File.FSSpec(dstdir)
  82.     return finder.move(src_fss, to = dst_fss)
  83.  
  84.  
  85. def sleep():
  86.     '''Put the mac to sleep'''
  87.     finder = _getfinder()
  88.     finder.sleep()
  89.  
  90.  
  91. def shutdown():
  92.     '''Shut the mac down'''
  93.     finder = _getfinder()
  94.     finder.shut_down()
  95.  
  96.  
  97. def restart():
  98.     '''Restart the mac'''
  99.     finder = _getfinder()
  100.     finder.restart()
  101.  
  102.  
  103. def reveal(file):
  104.     '''Reveal a file in the finder. Specify file by name, fsref or fsspec.'''
  105.     finder = _getfinder()
  106.     fsr = Carbon.File.FSRef(file)
  107.     file_alias = fsr.FSNewAliasMinimal()
  108.     return finder.reveal(file_alias)
  109.  
  110.  
  111. def select(file):
  112.     '''select a file in the finder. Specify file by name, fsref or fsspec.'''
  113.     finder = _getfinder()
  114.     fsr = Carbon.File.FSRef(file)
  115.     file_alias = fsr.FSNewAliasMinimal()
  116.     return finder.select(file_alias)
  117.  
  118.  
  119. def update(file):
  120.     '''Update the display of the specified object(s) to match
  121.     their on-disk representation. Specify file by name, fsref or fsspec.'''
  122.     finder = _getfinder()
  123.     fsr = Carbon.File.FSRef(file)
  124.     file_alias = fsr.FSNewAliasMinimal()
  125.     return finder.update(file_alias)
  126.  
  127.  
  128. def comment(object, comment = None):
  129.     """comment: get or set the Finder-comment of the item, displayed in the 'Get Info' window."""
  130.     object = Carbon.File.FSRef(object)
  131.     object_alias = object.FSNewAliasMonimal()
  132.     if comment == None:
  133.         return _getcomment(object_alias)
  134.     else:
  135.         return _setcomment(object_alias, comment)
  136.  
  137.  
  138. def _setcomment(object_alias, comment):
  139.     finder = _getfinder()
  140.     args = { }
  141.     attrs = { }
  142.     aeobj_00 = aetypes.ObjectSpecifier(want = aetypes.Type('cobj'), form = 'alis', seld = object_alias, fr = None)
  143.     aeobj_01 = aetypes.ObjectSpecifier(want = aetypes.Type('prop'), form = 'prop', seld = aetypes.Type('comt'), fr = aeobj_00)
  144.     args['----'] = aeobj_01
  145.     args['data'] = comment
  146.     (_reply, args, attrs) = finder.send('core', 'setd', args, attrs)
  147.     if args.has_key('errn'):
  148.         raise Error, aetools.decodeerror(args)
  149.     
  150.     if args.has_key('----'):
  151.         return args['----']
  152.     
  153.  
  154.  
  155. def _getcomment(object_alias):
  156.     finder = _getfinder()
  157.     args = { }
  158.     attrs = { }
  159.     aeobj_00 = aetypes.ObjectSpecifier(want = aetypes.Type('cobj'), form = 'alis', seld = object_alias, fr = None)
  160.     aeobj_01 = aetypes.ObjectSpecifier(want = aetypes.Type('prop'), form = 'prop', seld = aetypes.Type('comt'), fr = aeobj_00)
  161.     args['----'] = aeobj_01
  162.     (_reply, args, attrs) = finder.send('core', 'getd', args, attrs)
  163.     if args.has_key('errn'):
  164.         raise Error, aetools.decodeerror(args)
  165.     
  166.     if args.has_key('----'):
  167.         return args['----']
  168.     
  169.  
  170.  
  171. def processes():
  172.     '''processes returns a list of all active processes running on this computer and their creators.'''
  173.     finder = _getfinder()
  174.     args = { }
  175.     attrs = { }
  176.     processnames = []
  177.     processnumbers = []
  178.     creators = []
  179.     partitions = []
  180.     used = []
  181.     args['----'] = aetypes.ObjectSpecifier(want = aetypes.Type('prcs'), form = 'indx', seld = aetypes.Unknown('abso', 'all '), fr = None)
  182.     (_reply, args, attrs) = finder.send('core', 'getd', args, attrs)
  183.     if args.has_key('errn'):
  184.         raise Error, aetools.decodeerror(args)
  185.     
  186.     p = []
  187.     if args.has_key('----'):
  188.         p = args['----']
  189.         for proc in p:
  190.             if hasattr(proc, 'seld'):
  191.                 processnames.append(proc.seld)
  192.                 continue
  193.             if hasattr(proc, 'type'):
  194.                 if proc.type == 'psn ':
  195.                     processnumbers.append(proc.data)
  196.                 
  197.             proc.type == 'psn '
  198.         
  199.     
  200.     args = { }
  201.     attrs = { }
  202.     aeobj_0 = aetypes.ObjectSpecifier(want = aetypes.Type('prcs'), form = 'indx', seld = aetypes.Unknown('abso', 'all '), fr = None)
  203.     args['----'] = aetypes.ObjectSpecifier(want = aetypes.Type('prop'), form = 'prop', seld = aetypes.Type('fcrt'), fr = aeobj_0)
  204.     (_reply, args, attrs) = finder.send('core', 'getd', args, attrs)
  205.     if args.has_key('errn'):
  206.         raise Error, aetools.decodeerror(_arg)
  207.     
  208.     if args.has_key('----'):
  209.         p = args['----']
  210.         creators = p[:]
  211.     
  212.     result = []
  213.     if len(processnames) > len(processnumbers):
  214.         data = processnames
  215.     else:
  216.         data = processnumbers
  217.     for i in range(len(creators)):
  218.         result.append((data[i], creators[i]))
  219.     
  220.     return result
  221.  
  222.  
  223. class _process:
  224.     pass
  225.  
  226.  
  227. def isactiveprocess(processname):
  228.     '''Check of processname is active. MacOS9'''
  229.     all = processes()
  230.     ok = 0
  231.     for n, c in all:
  232.         if n == processname:
  233.             return 1
  234.             continue
  235.     
  236.     return 0
  237.  
  238.  
  239. def processinfo(processname):
  240.     '''Return an object with all process properties as attributes for processname. MacOS9'''
  241.     p = _process()
  242.     if processname == 'Finder':
  243.         p.partition = None
  244.         p.used = None
  245.     else:
  246.         p.partition = _processproperty(processname, 'appt')
  247.         p.used = _processproperty(processname, 'pusd')
  248.     p.visible = _processproperty(processname, 'pvis')
  249.     p.frontmost = _processproperty(processname, 'pisf')
  250.     p.file = _processproperty(processname, 'file')
  251.     p.filetype = _processproperty(processname, 'asty')
  252.     p.creatortype = _processproperty(processname, 'fcrt')
  253.     p.accepthighlevel = _processproperty(processname, 'revt')
  254.     p.hasscripting = _processproperty(processname, 'hscr')
  255.     return p
  256.  
  257.  
  258. def _processproperty(processname, property):
  259.     '''return the partition size and memory used for processname'''
  260.     finder = _getfinder()
  261.     args = { }
  262.     attrs = { }
  263.     aeobj_00 = aetypes.ObjectSpecifier(want = aetypes.Type('prcs'), form = 'name', seld = processname, fr = None)
  264.     aeobj_01 = aetypes.ObjectSpecifier(want = aetypes.Type('prop'), form = 'prop', seld = aetypes.Type(property), fr = aeobj_00)
  265.     args['----'] = aeobj_01
  266.     (_reply, args, attrs) = finder.send('core', 'getd', args, attrs)
  267.     if args.has_key('errn'):
  268.         raise Error, aetools.decodeerror(args)
  269.     
  270.     if args.has_key('----'):
  271.         return args['----']
  272.     
  273.  
  274.  
  275. def openwindow(object):
  276.     '''Open a Finder window for object, Specify object by name or fsspec.'''
  277.     finder = _getfinder()
  278.     object = Carbon.File.FSRef(object)
  279.     object_alias = object.FSNewAliasMinimal()
  280.     args = { }
  281.     attrs = { }
  282.     _code = 'aevt'
  283.     _subcode = 'odoc'
  284.     aeobj_0 = aetypes.ObjectSpecifier(want = aetypes.Type('cfol'), form = 'alis', seld = object_alias, fr = None)
  285.     args['----'] = aeobj_0
  286.     (_reply, args, attrs) = finder.send(_code, _subcode, args, attrs)
  287.     if args.has_key('errn'):
  288.         raise Error, aetools.decodeerror(args)
  289.     
  290.  
  291.  
  292. def closewindow(object):
  293.     '''Close a Finder window for folder, Specify by path.'''
  294.     finder = _getfinder()
  295.     object = Carbon.File.FSRef(object)
  296.     object_alias = object.FSNewAliasMinimal()
  297.     args = { }
  298.     attrs = { }
  299.     _code = 'core'
  300.     _subcode = 'clos'
  301.     aeobj_0 = aetypes.ObjectSpecifier(want = aetypes.Type('cfol'), form = 'alis', seld = object_alias, fr = None)
  302.     args['----'] = aeobj_0
  303.     (_reply, args, attrs) = finder.send(_code, _subcode, args, attrs)
  304.     if args.has_key('errn'):
  305.         raise Error, aetools.decodeerror(args)
  306.     
  307.  
  308.  
  309. def location(object, pos = None):
  310.     '''Set the position of a Finder window for folder to pos=(w, h). Specify file by name or fsspec.
  311.     If pos=None, location will return the current position of the object.'''
  312.     object = Carbon.File.FSRef(object)
  313.     object_alias = object.FSNewAliasMinimal()
  314.     if not pos:
  315.         return _getlocation(object_alias)
  316.     
  317.     return _setlocation(object_alias, pos)
  318.  
  319.  
  320. def _setlocation(object_alias, .2):
  321.     '''_setlocation: Set the location of the icon for the object.'''
  322.     (x, y) = .2
  323.     finder = _getfinder()
  324.     args = { }
  325.     attrs = { }
  326.     aeobj_00 = aetypes.ObjectSpecifier(want = aetypes.Type('cfol'), form = 'alis', seld = object_alias, fr = None)
  327.     aeobj_01 = aetypes.ObjectSpecifier(want = aetypes.Type('prop'), form = 'prop', seld = aetypes.Type('posn'), fr = aeobj_00)
  328.     args['----'] = aeobj_01
  329.     args['data'] = [
  330.         x,
  331.         y]
  332.     (_reply, args, attrs) = finder.send('core', 'setd', args, attrs)
  333.     if args.has_key('errn'):
  334.         raise Error, aetools.decodeerror(args)
  335.     
  336.     return (x, y)
  337.  
  338.  
  339. def _getlocation(object_alias):
  340.     '''_getlocation: get the location of the icon for the object.'''
  341.     finder = _getfinder()
  342.     args = { }
  343.     attrs = { }
  344.     aeobj_00 = aetypes.ObjectSpecifier(want = aetypes.Type('cfol'), form = 'alis', seld = object_alias, fr = None)
  345.     aeobj_01 = aetypes.ObjectSpecifier(want = aetypes.Type('prop'), form = 'prop', seld = aetypes.Type('posn'), fr = aeobj_00)
  346.     args['----'] = aeobj_01
  347.     (_reply, args, attrs) = finder.send('core', 'getd', args, attrs)
  348.     if args.has_key('errn'):
  349.         raise Error, aetools.decodeerror(args)
  350.     
  351.     if args.has_key('----'):
  352.         pos = args['----']
  353.         return (pos.h, pos.v)
  354.     
  355.  
  356.  
  357. def label(object, index = None):
  358.     '''label: set or get the label of the item. Specify file by name or fsspec.'''
  359.     object = Carbon.File.FSRef(object)
  360.     object_alias = object.FSNewAliasMinimal()
  361.     if index == None:
  362.         return _getlabel(object_alias)
  363.     
  364.     if index < 0 or index > 7:
  365.         index = 0
  366.     
  367.     return _setlabel(object_alias, index)
  368.  
  369.  
  370. def _getlabel(object_alias):
  371.     '''label: Get the label for the object.'''
  372.     finder = _getfinder()
  373.     args = { }
  374.     attrs = { }
  375.     aeobj_00 = aetypes.ObjectSpecifier(want = aetypes.Type('cobj'), form = 'alis', seld = object_alias, fr = None)
  376.     aeobj_01 = aetypes.ObjectSpecifier(want = aetypes.Type('prop'), form = 'prop', seld = aetypes.Type('labi'), fr = aeobj_00)
  377.     args['----'] = aeobj_01
  378.     (_reply, args, attrs) = finder.send('core', 'getd', args, attrs)
  379.     if args.has_key('errn'):
  380.         raise Error, aetools.decodeerror(args)
  381.     
  382.     if args.has_key('----'):
  383.         return args['----']
  384.     
  385.  
  386.  
  387. def _setlabel(object_alias, index):
  388.     '''label: Set the label for the object.'''
  389.     finder = _getfinder()
  390.     args = { }
  391.     attrs = { }
  392.     _code = 'core'
  393.     _subcode = 'setd'
  394.     aeobj_0 = aetypes.ObjectSpecifier(want = aetypes.Type('prop'), form = 'alis', seld = object_alias, fr = None)
  395.     aeobj_1 = aetypes.ObjectSpecifier(want = aetypes.Type('prop'), form = 'prop', seld = aetypes.Type('labi'), fr = aeobj_0)
  396.     args['----'] = aeobj_1
  397.     args['data'] = index
  398.     (_reply, args, attrs) = finder.send(_code, _subcode, args, attrs)
  399.     if args.has_key('errn'):
  400.         raise Error, aetools.decodeerror(args)
  401.     
  402.     return index
  403.  
  404.  
  405. def windowview(folder, view = None):
  406.     '''windowview: Set the view of the window for the folder. Specify file by name or fsspec.
  407.     0 = by icon (default)
  408.     1 = by name
  409.     2 = by button
  410.     '''
  411.     fsr = Carbon.File.FSRef(folder)
  412.     folder_alias = fsr.FSNewAliasMinimal()
  413.     if view == None:
  414.         return _getwindowview(folder_alias)
  415.     
  416.     return _setwindowview(folder_alias, view)
  417.  
  418.  
  419. def _setwindowview(folder_alias, view = 0):
  420.     '''set the windowview'''
  421.     attrs = { }
  422.     args = { }
  423.     if view == 1:
  424.         _v = aetypes.Type('pnam')
  425.     elif view == 2:
  426.         _v = aetypes.Type('lgbu')
  427.     else:
  428.         _v = aetypes.Type('iimg')
  429.     finder = _getfinder()
  430.     aeobj_0 = aetypes.ObjectSpecifier(want = aetypes.Type('cfol'), form = 'alis', seld = folder_alias, fr = None)
  431.     aeobj_1 = aetypes.ObjectSpecifier(want = aetypes.Type('prop'), form = 'prop', seld = aetypes.Type('cwnd'), fr = aeobj_0)
  432.     aeobj_2 = aetypes.ObjectSpecifier(want = aetypes.Type('prop'), form = 'prop', seld = aetypes.Type('pvew'), fr = aeobj_1)
  433.     aeobj_3 = aetypes.ObjectSpecifier(want = aetypes.Type('prop'), form = 'prop', seld = _v, fr = None)
  434.     _code = 'core'
  435.     _subcode = 'setd'
  436.     args['----'] = aeobj_2
  437.     args['data'] = aeobj_3
  438.     (_reply, args, attrs) = finder.send(_code, _subcode, args, attrs)
  439.     if args.has_key('errn'):
  440.         raise Error, aetools.decodeerror(args)
  441.     
  442.     if args.has_key('----'):
  443.         return args['----']
  444.     
  445.  
  446.  
  447. def _getwindowview(folder_alias):
  448.     '''get the windowview'''
  449.     attrs = { }
  450.     args = { }
  451.     finder = _getfinder()
  452.     args = { }
  453.     attrs = { }
  454.     aeobj_00 = aetypes.ObjectSpecifier(want = aetypes.Type('cfol'), form = 'alis', seld = folder_alias, fr = None)
  455.     aeobj_01 = aetypes.ObjectSpecifier(want = aetypes.Type('prop'), form = 'prop', seld = aetypes.Type('cwnd'), fr = aeobj_00)
  456.     aeobj_02 = aetypes.ObjectSpecifier(want = aetypes.Type('prop'), form = 'prop', seld = aetypes.Type('pvew'), fr = aeobj_01)
  457.     args['----'] = aeobj_02
  458.     (_reply, args, attrs) = finder.send('core', 'getd', args, attrs)
  459.     if args.has_key('errn'):
  460.         raise Error, aetools.decodeerror(args)
  461.     
  462.     views = {
  463.         'iimg': 0,
  464.         'pnam': 1,
  465.         'lgbu': 2 }
  466.     if args.has_key('----'):
  467.         return views[args['----'].enum]
  468.     
  469.  
  470.  
  471. def windowsize(folder, size = None):
  472.     '''Set the size of a Finder window for folder to size=(w, h), Specify by path.
  473.     If size=None, windowsize will return the current size of the window.
  474.     Specify file by name or fsspec.
  475.     '''
  476.     fsr = Carbon.File.FSRef(folder)
  477.     folder_alias = fsr.FSNewAliasMinimal()
  478.     openwindow(fsr)
  479.     if not size:
  480.         return _getwindowsize(folder_alias)
  481.     
  482.     return _setwindowsize(folder_alias, size)
  483.  
  484.  
  485. def _setwindowsize(folder_alias, .2):
  486.     '''Set the size of a Finder window for folder to (w, h)'''
  487.     (w, h) = .2
  488.     finder = _getfinder()
  489.     args = { }
  490.     attrs = { }
  491.     _code = 'core'
  492.     _subcode = 'setd'
  493.     aevar00 = [
  494.         w,
  495.         h]
  496.     aeobj_0 = aetypes.ObjectSpecifier(want = aetypes.Type('cfol'), form = 'alis', seld = folder_alias, fr = None)
  497.     aeobj_1 = aetypes.ObjectSpecifier(want = aetypes.Type('prop'), form = 'prop', seld = aetypes.Type('cwnd'), fr = aeobj_0)
  498.     aeobj_2 = aetypes.ObjectSpecifier(want = aetypes.Type('prop'), form = 'prop', seld = aetypes.Type('ptsz'), fr = aeobj_1)
  499.     args['----'] = aeobj_2
  500.     args['data'] = aevar00
  501.     (_reply, args, attrs) = finder.send(_code, _subcode, args, attrs)
  502.     if args.has_key('errn'):
  503.         raise Error, aetools.decodeerror(args)
  504.     
  505.     return (w, h)
  506.  
  507.  
  508. def _getwindowsize(folder_alias):
  509.     '''Set the size of a Finder window for folder to (w, h)'''
  510.     finder = _getfinder()
  511.     args = { }
  512.     attrs = { }
  513.     aeobj_0 = aetypes.ObjectSpecifier(want = aetypes.Type('cfol'), form = 'alis', seld = folder_alias, fr = None)
  514.     aeobj_1 = aetypes.ObjectSpecifier(want = aetypes.Type('prop'), form = 'prop', seld = aetypes.Type('cwnd'), fr = aeobj_0)
  515.     aeobj_2 = aetypes.ObjectSpecifier(want = aetypes.Type('prop'), form = 'prop', seld = aetypes.Type('posn'), fr = aeobj_1)
  516.     args['----'] = aeobj_2
  517.     (_reply, args, attrs) = finder.send('core', 'getd', args, attrs)
  518.     if args.has_key('errn'):
  519.         raise Error, aetools.decodeerror(args)
  520.     
  521.     if args.has_key('----'):
  522.         return args['----']
  523.     
  524.  
  525.  
  526. def windowposition(folder, pos = None):
  527.     '''Set the position of a Finder window for folder to pos=(w, h).'''
  528.     fsr = Carbon.File.FSRef(folder)
  529.     folder_alias = fsr.FSNewAliasMinimal()
  530.     openwindow(fsr)
  531.     if not pos:
  532.         return _getwindowposition(folder_alias)
  533.     
  534.     if type(pos) == InstanceType:
  535.         pos = (pos.h, pos.v)
  536.     
  537.     return _setwindowposition(folder_alias, pos)
  538.  
  539.  
  540. def _setwindowposition(folder_alias, .2):
  541.     '''Set the size of a Finder window for folder to (w, h).'''
  542.     (x, y) = .2
  543.     finder = _getfinder()
  544.     args = { }
  545.     attrs = { }
  546.     aeobj_0 = aetypes.ObjectSpecifier(want = aetypes.Type('cfol'), form = 'alis', seld = folder_alias, fr = None)
  547.     aeobj_1 = aetypes.ObjectSpecifier(want = aetypes.Type('prop'), form = 'prop', seld = aetypes.Type('cwnd'), fr = aeobj_0)
  548.     aeobj_2 = aetypes.ObjectSpecifier(want = aetypes.Type('prop'), form = 'prop', seld = aetypes.Type('posn'), fr = aeobj_1)
  549.     args['----'] = aeobj_2
  550.     args['data'] = [
  551.         x,
  552.         y]
  553.     (_reply, args, attrs) = finder.send('core', 'setd', args, attrs)
  554.     if args.has_key('errn'):
  555.         raise Error, aetools.decodeerror(args)
  556.     
  557.     if args.has_key('----'):
  558.         return args['----']
  559.     
  560.  
  561.  
  562. def _getwindowposition(folder_alias):
  563.     '''Get the size of a Finder window for folder, Specify by path.'''
  564.     finder = _getfinder()
  565.     args = { }
  566.     attrs = { }
  567.     aeobj_0 = aetypes.ObjectSpecifier(want = aetypes.Type('cfol'), form = 'alis', seld = folder_alias, fr = None)
  568.     aeobj_1 = aetypes.ObjectSpecifier(want = aetypes.Type('prop'), form = 'prop', seld = aetypes.Type('cwnd'), fr = aeobj_0)
  569.     aeobj_2 = aetypes.ObjectSpecifier(want = aetypes.Type('prop'), form = 'prop', seld = aetypes.Type('ptsz'), fr = aeobj_1)
  570.     args['----'] = aeobj_2
  571.     (_reply, args, attrs) = finder.send('core', 'getd', args, attrs)
  572.     if args.has_key('errn'):
  573.         raise Error, aetools.decodeerror(args)
  574.     
  575.     if args.has_key('----'):
  576.         return args['----']
  577.     
  578.  
  579.  
  580. def icon(object, icondata = None):
  581.     '''icon sets the icon of object, if no icondata is given,
  582.     icon will return an AE object with binary data for the current icon.
  583.     If left untouched, this data can be used to paste the icon on another file.
  584.     Development opportunity: get and set the data as PICT.'''
  585.     fsr = Carbon.File.FSRef(object)
  586.     object_alias = fsr.FSNewAliasMinimal()
  587.     if icondata == None:
  588.         return _geticon(object_alias)
  589.     
  590.     return _seticon(object_alias, icondata)
  591.  
  592.  
  593. def _geticon(object_alias):
  594.     '''get the icondata for object. Binary data of some sort.'''
  595.     finder = _getfinder()
  596.     args = { }
  597.     attrs = { }
  598.     aeobj_00 = aetypes.ObjectSpecifier(want = aetypes.Type('cobj'), form = 'alis', seld = object_alias, fr = None)
  599.     aeobj_01 = aetypes.ObjectSpecifier(want = aetypes.Type('prop'), form = 'prop', seld = aetypes.Type('iimg'), fr = aeobj_00)
  600.     args['----'] = aeobj_01
  601.     (_reply, args, attrs) = finder.send('core', 'getd', args, attrs)
  602.     if args.has_key('errn'):
  603.         raise Error, aetools.decodeerror(args)
  604.     
  605.     if args.has_key('----'):
  606.         return args['----']
  607.     
  608.  
  609.  
  610. def _seticon(object_alias, icondata):
  611.     '''set the icondata for object, formatted as produced by _geticon()'''
  612.     finder = _getfinder()
  613.     args = { }
  614.     attrs = { }
  615.     aeobj_00 = aetypes.ObjectSpecifier(want = aetypes.Type('cobj'), form = 'alis', seld = object_alias, fr = None)
  616.     aeobj_01 = aetypes.ObjectSpecifier(want = aetypes.Type('prop'), form = 'prop', seld = aetypes.Type('iimg'), fr = aeobj_00)
  617.     args['----'] = aeobj_01
  618.     args['data'] = icondata
  619.     (_reply, args, attrs) = finder.send('core', 'setd', args, attrs)
  620.     if args.has_key('errn'):
  621.         raise Error, aetools.decodeerror(args)
  622.     
  623.     if args.has_key('----'):
  624.         return args['----'].data
  625.     
  626.  
  627.  
  628. def mountvolume(volume, server = None, username = None, password = None):
  629.     '''mount a volume, local or on a server on AppleTalk.
  630.     Note: mounting a ASIP server requires a different operation.
  631.     server is the name of the server where the volume belongs
  632.     username, password belong to a registered user of the volume.'''
  633.     finder = _getfinder()
  634.     args = { }
  635.     attrs = { }
  636.     if password:
  637.         args['PASS'] = password
  638.     
  639.     if username:
  640.         args['USER'] = username
  641.     
  642.     if server:
  643.         args['SRVR'] = server
  644.     
  645.     args['----'] = volume
  646.     (_reply, args, attrs) = finder.send('aevt', 'mvol', args, attrs)
  647.     if args.has_key('errn'):
  648.         raise Error, aetools.decodeerror(args)
  649.     
  650.     if args.has_key('----'):
  651.         return args['----']
  652.     
  653.  
  654.  
  655. def unmountvolume(volume):
  656.     """unmount a volume that's on the desktop"""
  657.     putaway(volume)
  658.  
  659.  
  660. def putaway(object):
  661.     '''puth the object away, whereever it came from.'''
  662.     finder = _getfinder()
  663.     args = { }
  664.     attrs = { }
  665.     args['----'] = aetypes.ObjectSpecifier(want = aetypes.Type('cdis'), form = 'name', seld = object, fr = None)
  666.     (_reply, args, attrs) = talker.send('fndr', 'ptwy', args, attrs)
  667.     if args.has_key('errn'):
  668.         raise Error, aetools.decodeerror(args)
  669.     
  670.     if args.has_key('----'):
  671.         return args['----']
  672.     
  673.  
  674.  
  675. def volumelevel(level):
  676.     '''set the audio output level, parameter between 0 (silent) and 7 (full blast)'''
  677.     finder = _getfinder()
  678.     args = { }
  679.     attrs = { }
  680.     if level < 0:
  681.         level = 0
  682.     elif level > 7:
  683.         level = 7
  684.     
  685.     args['----'] = level
  686.     (_reply, args, attrs) = finder.send('aevt', 'stvl', args, attrs)
  687.     if args.has_key('errn'):
  688.         raise Error, aetools.decodeerror(args)
  689.     
  690.     if args.has_key('----'):
  691.         return args['----']
  692.     
  693.  
  694.  
  695. def OSversion():
  696.     '''return the version of the system software'''
  697.     finder = _getfinder()
  698.     args = { }
  699.     attrs = { }
  700.     aeobj_00 = aetypes.ObjectSpecifier(want = aetypes.Type('prop'), form = 'prop', seld = aetypes.Type('ver2'), fr = None)
  701.     args['----'] = aeobj_00
  702.     (_reply, args, attrs) = finder.send('core', 'getd', args, attrs)
  703.     if args.has_key('errn'):
  704.         raise Error, aetools.decodeerror(args)
  705.     
  706.     if args.has_key('----'):
  707.         return args['----']
  708.     
  709.  
  710.  
  711. def filesharing():
  712.     '''return the current status of filesharing and whether it is starting up or not:
  713.         -1  file sharing is off and not starting up
  714.         0   file sharing is off and starting up
  715.         1   file sharing is on'''
  716.     status = -1
  717.     finder = _getfinder()
  718.     args = { }
  719.     attrs = { }
  720.     args['----'] = aetypes.ObjectSpecifier(want = aetypes.Type('prop'), form = 'prop', seld = aetypes.Type('fshr'), fr = None)
  721.     (_reply, args, attrs) = finder.send('core', 'getd', args, attrs)
  722.     if args.has_key('errn'):
  723.         raise Error, aetools.decodeerror(args)
  724.     
  725.     if args.has_key('----'):
  726.         if args['----'] == 0:
  727.             status = -1
  728.         else:
  729.             status = 1
  730.     
  731.     args = { }
  732.     attrs = { }
  733.     args['----'] = aetypes.ObjectSpecifier(want = aetypes.Type('prop'), form = 'prop', seld = aetypes.Type('fsup'), fr = None)
  734.     (_reply, args, attrs) = finder.send('core', 'getd', args, attrs)
  735.     if args.has_key('errn'):
  736.         raise Error, aetools.decodeerror(args)
  737.     
  738.     if args.has_key('----'):
  739.         if args['----'] == 1:
  740.             status = 0
  741.         
  742.     
  743.     return status
  744.  
  745.  
  746. def movetotrash(path):
  747.     '''move the object to the trash'''
  748.     fss = Carbon.File.FSSpec(path)
  749.     trashfolder = Carbon.Folder.FSFindFolder(fss.as_tuple()[0], 'trsh', 0)
  750.     move(path, trashfolder)
  751.  
  752.  
  753. def emptytrash():
  754.     '''empty the trash'''
  755.     finder = _getfinder()
  756.     args = { }
  757.     attrs = { }
  758.     args['----'] = aetypes.ObjectSpecifier(want = aetypes.Type('prop'), form = 'prop', seld = aetypes.Type('trsh'), fr = None)
  759.     (_reply, args, attrs) = finder.send('fndr', 'empt', args, attrs)
  760.     if args.has_key('errn'):
  761.         raise aetools.Error, aetools.decodeerror(args)
  762.     
  763.  
  764.  
  765. def _test():
  766.     import EasyDialogs
  767.     print 'Original findertools functionality test...'
  768.     print 'Testing launch...'
  769.     pathname = EasyDialogs.AskFileForOpen('File to launch:')
  770.     if pathname:
  771.         result = launch(pathname)
  772.         if result:
  773.             print 'Result: ', result
  774.         
  775.         print 'Press return-',
  776.         sys.stdin.readline()
  777.     
  778.     print 'Testing print...'
  779.     pathname = EasyDialogs.AskFileForOpen('File to print:')
  780.     if pathname:
  781.         result = Print(pathname)
  782.         if result:
  783.             print 'Result: ', result
  784.         
  785.         print 'Press return-',
  786.         sys.stdin.readline()
  787.     
  788.     print 'Testing copy...'
  789.     pathname = EasyDialogs.AskFileForOpen('File to copy:')
  790.     if pathname:
  791.         destdir = EasyDialogs.AskFolder('Destination:')
  792.         if destdir:
  793.             result = copy(pathname, destdir)
  794.             if result:
  795.                 print 'Result:', result
  796.             
  797.             print 'Press return-',
  798.             sys.stdin.readline()
  799.         
  800.     
  801.     print 'Testing move...'
  802.     pathname = EasyDialogs.AskFileForOpen('File to move:')
  803.     if pathname:
  804.         destdir = EasyDialogs.AskFolder('Destination:')
  805.         if destdir:
  806.             result = move(pathname, destdir)
  807.             if result:
  808.                 print 'Result:', result
  809.             
  810.             print 'Press return-',
  811.             sys.stdin.readline()
  812.         
  813.     
  814.     print 'Testing sleep...'
  815.     if EasyDialogs.AskYesNoCancel('Sleep?') > 0:
  816.         result = sleep()
  817.         if result:
  818.             print 'Result:', result
  819.         
  820.         print 'Press return-',
  821.         sys.stdin.readline()
  822.     
  823.     print 'Testing shutdown...'
  824.     if EasyDialogs.AskYesNoCancel('Shut down?') > 0:
  825.         result = shutdown()
  826.         if result:
  827.             print 'Result:', result
  828.         
  829.         print 'Press return-',
  830.         sys.stdin.readline()
  831.     
  832.     print 'Testing restart...'
  833.     if EasyDialogs.AskYesNoCancel('Restart?') > 0:
  834.         result = restart()
  835.         if result:
  836.             print 'Result:', result
  837.         
  838.         print 'Press return-',
  839.         sys.stdin.readline()
  840.     
  841.  
  842.  
  843. def _test2():
  844.     print '\nmorefindertools version %s\nTests coming up...' % __version__
  845.     import os
  846.     import random
  847.     print '\tfilesharing on?', filesharing()
  848.     print '\tOS version', OSversion()
  849.     print '\tSystem beep volume'
  850.     for i in range(0, 7):
  851.         volumelevel(i)
  852.         MacOS.SysBeep()
  853.     
  854.     open('@findertoolstest', 'w')
  855.     f = '@findertoolstest'
  856.     reveal(f)
  857.     select(f)
  858.     (base, file) = os.path.split(f)
  859.     closewindow(base)
  860.     openwindow(base)
  861.     windowview(base, 1)
  862.     label(f, 2)
  863.     print '\tlabel', label(f)
  864.     print 'Random locations for an icon'
  865.     windowview(base, 0)
  866.     windowsize(base, (600, 600))
  867.     for i in range(50):
  868.         location(f, (random.randint(10, 590), random.randint(10, 590)))
  869.     
  870.     windowsize(base, (200, 400))
  871.     windowview(base, 1)
  872.     orgpos = windowposition(base)
  873.     print 'Animated window location'
  874.     for i in range(10):
  875.         pos = (100 + i * 10, 100 + i * 10)
  876.         windowposition(base, pos)
  877.         print '\twindow position', pos
  878.     
  879.     windowposition(base, orgpos)
  880.     print 'Put a comment in file', f, ':'
  881.     print '\t', comment(f)
  882.     s = 'This is a comment no one reads!'
  883.     comment(f, s)
  884.  
  885.  
  886. def _test3():
  887.     print 'MacOS9 or better specific functions'
  888.     pr = processes()
  889.     print 'Return a list of current active processes:'
  890.     for p in pr:
  891.         print '\t', p
  892.     
  893.     print 'Attributes of the first process in the list:'
  894.     pinfo = processinfo(pr[0][0])
  895.     print '\t', pr[0][0]
  896.     print '\t\tmemory partition', pinfo.partition
  897.     print '\t\tmemory used', pinfo.used
  898.     print '\t\tis visible', pinfo.visible
  899.     print '\t\tis frontmost', pinfo.frontmost
  900.     print '\t\thas scripting', pinfo.hasscripting
  901.     print '\t\taccepts high level events', pinfo.accepthighlevel
  902.  
  903. if __name__ == '__main__':
  904.     _test()
  905.     _test2()
  906.     _test3()
  907.  
  908.