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