def _test(): import img import MacOS Qt.EnterMovies() fss, ok = macfs.PromptGetFile('Video to convert') if not ok: sys.exit(0) path = fss.as_pathname() url = urllib.pathname2url(path) rdr = reader(url) if not rdr: sys.exit(1) dstfss, ok = macfs.StandardPutFile('Name for output folder') if not ok: sys.exit(0) dstdir = dstfss.as_pathname() num = 0 os.mkdir(dstdir) videofmt = rdr.GetVideoFormat() imgfmt = videofmt.getformat() imgw, imgh = videofmt.getsize() timestamp, data = rdr.ReadVideo() while data: fname = 'frame%04.4d.jpg' % num num = num + 1 pname = os.path.join(dstdir, fname) print 'Writing', fname, imgw, imgh, len(data) ## wrt = img.writer(imgfmt, pname) ## wrt.width = imgw ## wrt.height = imgh ## wrt.write(data) timestamp, data = rdr.ReadVideo() ## MacOS.SetCreatorAndType(pname, 'ogle', 'JPEG') if num > 20: break print 'Total frames:', num
def GetFile(message=None): """ Select file dialog. Returns path if one is selected. Otherwise it returns None. Availability: FontLab, Macintosh, PC """ path = None if MAC: if haveMacfs: fss, ok = macfs.PromptGetFile(message) if ok: path = fss.as_pathname() else: from robofab.interface.mac.getFileOrFolder import GetFile path = GetFile(message) elif PC: if inFontLab: if not message: message = '' path = fl.GetFileName(1, message, '', '') else: openFlags = win32con.OFN_FILEMUSTEXIST | win32con.OFN_EXPLORER mode_open = 1 myDialog = win32ui.CreateFileDialog(mode_open, None, None, openFlags) myDialog.SetOFNTitle(message) is_OK = myDialog.DoModal() if is_OK == 1: path = myDialog.GetPathName() else: _raisePlatformError('GetFile') return path
def main(): global DEBUG DEBUG = 1 # Find the template # (there's no point in proceeding if we can't find it) template = findtemplate() if DEBUG: print 'Using template', template # Ask for source text if not specified in sys.argv[1:] if not sys.argv[1:]: srcfss, ok = macfs.PromptGetFile('Select Python source file:', 'TEXT') if not ok: return filename = srcfss.as_pathname() tp, tf = os.path.split(filename) if tf[-3:] == '.py': tf = tf[:-3] else: tf = tf + '.applet' dstfss, ok = macfs.StandardPutFile('Save application as:', tf) if not ok: return process(template, filename, dstfss.as_pathname()) else: # Loop over all files to be processed for filename in sys.argv[1:]: process(template, filename, '')
def test(): import MacOS import macfs import Image fsspec, ok = macfs.PromptGetFile("Image File:") if not ok: return path = fsspec.as_pathname() pm = PixMapWrapper() pm.fromImage(Image.open(path)) pm.blit(20, 20) return pm
def getlist(): if os.name == 'mac': import macfs while 1: fss, ok = macfs.PromptGetFile('Which AI file to use?') if not ok: sys.exit(1) my_file = (fss.as_pathname()) return my_file else: print "Sorry can't do that without a mac"
def _test(): if os.name == 'mac': fss, ok = macfs.PromptGetFile('File to convert:') if not ok: sys.exit(0) fname = fss.as_pathname() else: fname = sys.argv[1] binhex(fname, fname + '.hqx') hexbin(fname + '.hqx', fname + '.viahqx') #hexbin(fname, fname+'.unpacked') sys.exit(1)
def _macGetFile(prompt='pick a file', defaultDir=None): carbon = drawer.isCarbon() if carbon: import EasyDialogs path = EasyDialogs.AskFileForOpen(message=prompt) if path == None: return '', 0 else: return path, 1 else: import macfs fsspec, ok = macfs.PromptGetFile(prompt) if ok != 1: return '', 0 # failure path = fsspec.as_pathname() path = drawer.pathScrub(path) return path, 1
def __init__(self, prompt, directory, filter, file, cb_ok, cb_cancel, existing=0): # We implement this modally for the mac. if directory: try: macfs.SetFolder(os.path.join(directory + ':placeholder')) except macfs.error: pass if existing: fss, ok = macfs.PromptGetFile(prompt) else: if filter and not file: # Guess a filename with correct extension if type(filter) == type([]) or type(filter) == type(()): filter = filter[0] import MMmimetypes ext = MMmimetypes.guess_extension(filter) file = 'Untitled' + ext fss, ok = macfs.StandardPutFile(prompt, file) if ok: filename = fss.as_pathname() try: if cb_ok: ret = cb_ok(filename) except 'xxx': showmessage("Internal error:\nexception %s" % ` sys.exc_info() `) ret = None if ret: if type(ret) is StringType: showmessage(ret) else: try: if cb_cancel: ret = cb_cancel() else: ret = None except: showmessage("Internal error:\nexception %s" % ` sys.exc_info() `) ret = None if ret: if type(ret) is StringType: showmessage(ret)
def selfTest2(onConsole=0): """ Macintosh-based SGF file test""" import macfs print "\n\n********** Self-Test 2 (Mac) **********\n" thefile = macfs.PromptGetFile("Please choose an SGF file:") if not thefile[1]: return srcpath = thefile[0].as_pathname() src = open(srcpath, 'r') sgfdata = src.read() print "Input data:\n" print sgfdata print "\n\nParsed data:" col = SGFParser(sgfdata).parse() print "done\n" print str(col)
"""
QSIZE = 100000
"""PixMapWrapper - defines the PixMapWrapper class, which wraps an opaque
"""Macintosh binhex compression/decompression.
import calldll import macfs import sys import MacOS from Carbon import Res fss, ok = macfs.PromptGetFile("Show me calldll.ppc.slb") lib = calldll.getdiskfragment(fss, 'calldll.ppc.slb') cdll_b_bbbbbbbb = calldll.newcall(lib.cdll_b_bbbbbbbb, 'Byte', 'InByte', 'InByte', 'InByte', 'InByte', 'InByte', 'InByte', 'InByte', 'InByte') cdll_h_hhhhhhhh = calldll.newcall(lib.cdll_h_hhhhhhhh, 'Short', 'InShort', 'InShort', 'InShort', 'InShort', 'InShort', 'InShort', 'InShort', 'InShort') cdll_l_llllllll = calldll.newcall(lib.cdll_l_llllllll, 'Long', 'InLong', 'InLong', 'InLong', 'InLong', 'InLong', 'InLong', 'InLong', 'InLong') cdll_N_ssssssss = calldll.newcall(lib.cdll_N_ssssssss, 'None', 'InString', 'InString', 'InString', 'InString', 'InString', 'InString', 'InString', 'InString') cdll_o_l = calldll.newcall(lib.cdll_o_l, 'OSErr', 'InLong') cdll_N_pp = calldll.newcall(lib.cdll_N_pp, 'None', 'InPstring', 'OutPstring') cdll_N_bb = calldll.newcall(lib.cdll_N_bb, 'None', 'InByte', 'OutByte') cdll_N_hh = calldll.newcall(lib.cdll_N_hh, 'None', 'InShort', 'OutShort') cdll_N_ll = calldll.newcall(lib.cdll_N_ll, 'None', 'InLong', 'OutLong') cdll_N_sH = calldll.newcall(lib.cdll_N_sH, 'None', 'InString', 'InHandle') print 'Test cdll_b_bbbbbbbb' rv = cdll_b_bbbbbbbb(1, 2, 3, 4, 5, 6, 7, 8) if rv == 36: print 'ok.'
"""Utility routines depending on the finder,
"""checktext - Check that a text file has macintosh-style newlines"""
#
"""Create an applet from a Python script.
"""BuildCGIApplet.py -- Create a CGI applet from a Python script.
'''
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
"""macgen_bin - Generate application from shared libraries"""
"""Findmodulefiles - Find out where modules are loaded from.
"""Create a standalone application from a Python script.
"""An attempt at an unweave script.
import calldll import macfs import sys import MacOS from Carbon import Res fss, ok = macfs.PromptGetFile("Show me calldll.ppc.slb") lib = calldll.getdiskfragment(fss, 'calldll.ppc.slb') cdll_b_bbbbbbbb = calldll.newcall(lib.cdll_b_bbbbbbbb, 'Byte', 'InByte', 'InByte', 'InByte', 'InByte','InByte', 'InByte','InByte', 'InByte') cdll_h_hhhhhhhh = calldll.newcall(lib.cdll_h_hhhhhhhh, 'Short', 'InShort', 'InShort', 'InShort', 'InShort','InShort', 'InShort','InShort', 'InShort') cdll_l_llllllll = calldll.newcall(lib.cdll_l_llllllll, 'Long', 'InLong', 'InLong', 'InLong', 'InLong','InLong', 'InLong','InLong', 'InLong') cdll_N_ssssssss = calldll.newcall(lib.cdll_N_ssssssss, 'None', 'InString', 'InString', 'InString', 'InString', 'InString', 'InString', 'InString', 'InString') cdll_o_l = calldll.newcall(lib.cdll_o_l, 'OSErr', 'InLong') cdll_N_pp = calldll.newcall(lib.cdll_N_pp, 'None', 'InPstring', 'OutPstring') cdll_N_bb = calldll.newcall(lib.cdll_N_bb, 'None', 'InByte', 'OutByte') cdll_N_hh = calldll.newcall(lib.cdll_N_hh, 'None', 'InShort', 'OutShort') cdll_N_ll = calldll.newcall(lib.cdll_N_ll, 'None', 'InLong', 'OutLong') cdll_N_sH = calldll.newcall(lib.cdll_N_sH, 'None', 'InString', 'InHandle') print 'Test cdll_b_bbbbbbbb' rv = cdll_b_bbbbbbbb(1, 2, 3, 4, 5, 6, 7, 8)
"""Parse sys/errno.h and Errors.h and create Estr resource"""
"""macfreezegui - The GUI for macfreeze"""