Beispiel #1
0
def PutFile(message=None, fileName=None):
    """
	Save file dialog. Returns path if one is entered. Otherwise it returns None.
	Availability: FontLab, Macintosh, PC
	"""
    path = None
    if MAC:
        if haveMacfs:
            fss, ok = macfs.StandardPutFile(message, fileName)
            if ok:
                path = fss.as_pathname()
        else:
            import EasyDialogs
            path = EasyDialogs.AskFileForSave(message, savedFileName=fileName)
    elif PC:
        if inFontLab:
            if not message:
                message = ''
            if not fileName:
                fileName = ''
            path = fl.GetFileName(0, message, fileName, '')
        else:
            openFlags = win32con.OFN_OVERWRITEPROMPT | win32con.OFN_EXPLORER
            mode_save = 0
            myDialog = win32ui.CreateFileDialog(mode_save, None, fileName,
                                                openFlags)
            myDialog.SetOFNTitle(message)
            is_OK = myDialog.DoModal()
            if is_OK == 1:
                path = myDialog.GetPathName()
    else:
        _raisePlatformError('GetFile')
    return path
Beispiel #2
0
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
Beispiel #3
0
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, '')
Beispiel #4
0
def putfile(prompt, filename, newextension):
    for ext in extensions:
        if filename[-len(ext):] == ext:
            filename = filename[:-len(ext)] + newextension
            break
    else:
        filename = filename + newextension
    fss, ok = macfs.StandardPutFile(prompt, filename)
    if ok:
        return fss.as_pathname()
Beispiel #5
0
def mac_getargs(args):
    inputs = []
    output = None
    commands = None
    ramprefix = None
    switched = 0

    import macfs
    import EasyDialogs
    if args[1:]:
        inputs = args[1:]
    else:
        fss, ok = macfs.StandardGetFile()
        if not ok:
            sys.exit(0)
        inputs = [fss.as_pathname()]
    dir = os.path.split(inputs[0])[0]
    os.chdir(dir)
    for i in range(len(inputs)):
        filename = inputs[i]
        if filename[:len(dir)] == dir:
            inputs[i] = filename[len(dir):]
    if len(inputs) == 1:
        dft = 'g2_' + inputs[0][1:]
        fss, ok = macfs.StandardPutFile("G2 output file", dft)
        if not ok:
            sys.exit(0)
        output = fss.as_pathname()
    fss, ok = macfs.StandardPutFile("Script output (cancel for text)", "Conversion script")
    if ok:
        commands = fss.as_pathname()
    reply = EasyDialogs.AskString("URL prefix for use in .ram file (cancel for no ram file)")
    if reply:
        ramprefix = reply
    reply = EasyDialogs.AskYesNoCancel("Create G2/GRiNS switch statements?")
    if reply > 0:
        switched = 1
    return inputs, output, commands, ramprefix, switched
Beispiel #6
0
 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)
Beispiel #7
0
def interact():
    d = Dlg.GetNewDialog(DIALOG_ID, -1)
    wdir = stdin = stdout = None
    pause = 0

    tp, in_c_h, rect = d.GetDialogItem(STDIN_CONS)
    tp, in_f_h, rect = d.GetDialogItem(STDIN_FILE)
    tp, out_c_h, rect = d.GetDialogItem(STDOUT_CONS)
    tp, out_f_h, rect = d.GetDialogItem(STDOUT_FILE)
    tp, pause_h, rect = d.GetDialogItem(PAUSE)
    in_c_h = in_c_h.as_Control()
    in_f_h = in_f_h.as_Control()
    out_c_h = out_c_h.as_Control()
    out_f_h = out_f_h.as_Control()
    pause_h = pause_h.as_Control()

    while 1:
        in_c_h.SetControlValue(not stdin)
        in_f_h.SetControlValue(not not stdin)
        out_c_h.SetControlValue(not stdout)
        out_f_h.SetControlValue(not not stdout)
        pause_h.SetControlValue(pause)

        n = Dlg.ModalDialog(None)
        if n == OK:
            break
        elif n == CANCEL:
            sys.exit(0)
        elif n == STDIN_CONS:
            stdin = None
        elif n == STDIN_FILE:
            fss, ok = macfs.StandardGetFile('TEXT')
            if ok:
                stdin = fss
        elif n == STDOUT_FILE:
            fss, ok = macfs.StandardPutFile('stdout:')
            if ok:
                stdout = fss
        elif n == WORKING_DIR:
            fss, ok = macfs.GetDirectory()
            if ok:
                wdir = fss
        elif n == PAUSE:
            pause = (not pause)

    tp, h, rect = d.GetDialogItem(SCRIPTNAME)
    name = Dlg.GetDialogItemText(h)
    tp, h, rect = d.GetDialogItem(ARGV)
    argv = Dlg.GetDialogItemText(h)
    return name, argv, stdin, stdout, wdir, pause
Beispiel #8
0
 def do_itemhit(self, item, event):
     if item == MAIN_LIST:
         self.do_listhit(event)
     if item == MAIN_MKDISTR:
         fss, ok = macfs.StandardPutFile('Destination folder:')
         if not ok:
             return
         self.cb_run(fss.as_pathname())
     if item == MAIN_CHECK:
         list = self.cb_check()
         self.setlist(list)
     if item == MAIN_INCLUDE:
         self.do_dclick(self.delgetselection())
     if item == MAIN_EXCLUDE:
         for i in self.delgetselection():
             self.cb_add(('', i, ''))
        if self.volumeMax > 0: waver.SetVolumeMax(self.volumeMax)
        waver.WriteWave()

        fpOut.close()


# main

if sys.platform == "mac":

    # Mac has no command-line (pre OS X)

    fsSpecIn, ok = macfs.StandardGetFile()
    if not ok: sys.exit(1)

    fsSpecOut, ok = macfs.StandardPutFile("Save wave file as:")
    if not ok: sys.exit(1)

    convertor = Convertor(fsSpecIn.as_pathname(), fsSpecOut.as_pathname())

else:

    # a command-line is assumed here

    if len(sys.argv) != 3:
        print "Syntax:", sys.argv[0], "<inputfile.uef> <outputfile.wav>"
        sys.exit(1)

    convertor = Convertor(sys.argv[1], sys.argv[2])

convertor.SetVolumeRange(0x30, 0xC0)
Beispiel #10
0
"""imgconvert - A very simple image converter."""
import img
import sys
import os
# Set trace, so we can see what happens
img.settrace(1)
if os.name == 'mac':
    import macfs
    fss, ok = macfs.StandardGetFile()
    if not ok: sys.exit(0)
    infile = fss.as_pathname()
    fss, ok = macfs.StandardPutFile('Output?')
    if not ok: sys.exit(0)
    outfile = fss.as_pathname()
else:
    if len(sys.argv) <> 3:
        print 'Usage:', sys.argv[0], 'inimage outimage'
        sys.exit(1)
    infile = sys.argv[1]
    outfile = sys.argv[2]
#
# Create a non-converting writer (we do conversion in the reader)
#
writer = img.writer(None, outfile)
#
# Create a reader that converts to the preferred output format
#
reader = img.reader(writer.format, infile)
#
# Set output file parameters
Beispiel #11
0
"""Create a standalone application from a Python script.
Beispiel #12
0
#
# Turn a pyc file into a resource file containing it in 'PYC ' resource form
from Carbon.Res import *
from Carbon import Res
from Carbon.Resources import *
import os
import macfs
import sys
import py_resource
error = 'mkpycresourcefile.error'

def mkpycresourcefile(src, dst):
    """Copy pyc file/dir src to resource file dst."""
    if not os.path.isdir(src) and src[-4:] <> '.pyc':
        raise error, 'I can only handle .pyc files or directories'
    fsid = py_resource.create(dst)
    if os.path.isdir(src):
        handlesubdir(src)
    else:
        id, name = py_resource.frompycfile(src)
        print 'Wrote %d: %s %s' % (id, name, src)
    CloseResFile(fsid)

def handlesubdir(srcdir):
    """Recursively scan a directory for pyc files and copy to resources"""
    src = os.listdir(srcdir)
    for file in src:
        file = os.path.join(srcdir, file)
        if os.path.isdir(file):
            handlesubdir(file)
Beispiel #13
0
"""Parse sys/errno.h and Errors.h and create Estr resource"""
Beispiel #14
0
##     fss, ok = macfs.PromptGetFile('SMIL file (cancel for URL)', 'TEXT')
##     if ok:
##         sys.argv = ["macgrins", fss.as_pathname()]
##     else:
##         import EasyDialogs
##         url = EasyDialogs.AskString("SMIL URL")
##         if url is None:
##             sys.exit(0)
##         sys.argv = ["macgrins", url]

no_exception=0
try:
    try:
        if profile:
            import profile
            fss, ok = macfs.StandardPutFile("Profile output:")
            if not ok: sys.exit(1)
            profile.run("import grins", fss.as_pathname())
        else:
            import grins
        no_exception=1
    except SystemExit:
        no_exception=1
finally:
    if not no_exception:
        splash.splash()
        if quietconsole:
            quietconsole.revert()
        print 'Type return to exit-',
        sys.stdin.readline()
Beispiel #15
0
"""macfreezegui - The GUI for macfreeze"""
Beispiel #16
0
# A minimal text editor.
Beispiel #17
0
def dialog(script=None):

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

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

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

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

    gentype = ITEM_GENSOURCE
    _dialogradiogroup(d, ITEM_GENSOURCE)

    # Interact
    d.GetDialogWindow().SetWTitle("Standalone application creation options")
    d.GetDialogWindow().ShowWindow()
    d.DrawDialog()
    while 1:
        item = Dlg.ModalDialog(None)
        if item == ITEM_OK:
            break
        elif item == ITEM_CANCEL:
            sys.exit(0)
        elif item in RADIO_GROUPING.keys():
            gentype = item
            _dialogradiogroup(d, item)
        elif item == ITEM_SCRIPTBROWSE:
            fss, ok = macfs.PromptGetFile("Script?")
            if ok:
                script = fss.as_pathname()
                _dialogsetfile(d, ITEM_SCRIPTNAME, script)
        elif item == ITEM_SOURCEDIRBROWSE:
            fss, ok = macfs.StandardPutFile("Output folder name", os.path.split(dirname)[1])
            if ok:
                dirname = fss.as_pathname()
                _dialogsetfile(d, ITEM_SOURCEDIRNAME, dirname)
        elif item == ITEM_RESOURCEBROWSE:
            fss, ok = macfs.StandardPutFile("Resource output file", os.path.split(rsrcname)[1])
            if ok:
                rsrcname = fss.as_pathname()
                _dialogsetfile(d, ITEM_RESOURCENAME, rsrcname)
        elif item == ITEM_APPLETBROWSE:
            fss, ok = macfs.StandardPutFile("Applet output file", os.path.split(appletname)[1])
            if ok:
                appletname = fss.as_pathname()
                _dialogsetfile(d, ITEM_APPLETNAME, appletname)
        else:
            pass
    tp, h, rect = d.GetDialogItem(ITEM_DEBUG)
    debug = Dlg.GetDialogItemText(h)
    try:
        debug = string.atoi(string.strip(debug))
    except ValueError:
        EasyDialogs.Message("Illegal debug value %r, set to zero."%(debug,))
        debug = 0
    if gentype == ITEM_GENSOURCE:
        return 'source', script, dirname, debug
    elif gentype == ITEM_GENRESOURCE:
        return 'resource', script, rsrcname, debug
    elif gentype == ITEM_GENAPPLET:
        return 'applet', script, appletname, debug
    elif gentype == ITEM_GENINFO:
        return 'info', script, '', debug
    raise 'Error in gentype', gentype
Beispiel #18
0
"""Import a module while pretending its name is __main__. This
Beispiel #19
0
    writemodule(name, id, open(file, 'rb').read())
    return id + 1


def handlesubdir(handle, id, srcdir):
    """Recursively scan a directory for pyc files and copy to resources"""
    print 'Directory', srcdir
    src = os.listdir(srcdir)
    for file in src:
        file = os.path.join(srcdir, file)
        if os.path.isdir(file):
            id = handlesubdir(handle, id, file)
        elif file[-4:] == '.pyc':
            id = handleonepycfile(handle, id, file)
    return id


if __name__ == '__main__':
    args = sys.argv[1:]
    if not args:
        ifss, ok = macfs.GetDirectory('Select root of tree to pack:')
        if not ok:
            sys.exit(0)
        args = [ifss.as_pathname()]
    for ifn in args:
        ofss, ok = macfs.StandardPutFile('Output for ' + os.path.split(ifn)[1])
        if not ok:
            sys.exit(0)
        mkpycresourcefile(ifn, ofss.as_pathname())
    sys.exit(1)  # So we can see something...
Beispiel #20
0
"""Create an applet from a Python script.
Beispiel #21
0
# A minimal text editor.
Beispiel #22
0
"""BuildCGIApplet.py -- Create a CGI applet from a Python script.
Beispiel #23
0
"""
Beispiel #24
0
# A minimal text editor.
Beispiel #25
0
"""Easy to use dialogs.
Beispiel #26
0
# Video file reader, using QuickTime
Beispiel #27
0
#
Beispiel #28
0
"""Findmodulefiles - Find out where modules are loaded from.
Beispiel #29
0
#
# Create attrdefs resource file
#
import os
import sys
import string
import macfs
from Carbon import Res
import py_resource

# For now:
progdir = os.path.split(sys.argv[0])[0]
CMIFDIR = os.path.split(progdir)[0]

ATTRDEFPATH = CMIFDIR + ':lib:Attrdefs.atc'

fp = open(ATTRDEFPATH, 'rb')
data = fp.read()
fp.close()

fss, ok = macfs.StandardPutFile('Attrdef resource output file:')
if not ok: sys.exit(0)

fsid = py_resource.create(fss.as_pathname(), creator='RSED')

py_resource.writemodule('Attrdefs', 512, data, 'CMat')

Res.CloseResFile(fsid)
print 'Wrote', ATTRDEFPATH, 'to', fss.as_pathname()
sys.exit(1)
Beispiel #30
0
# A minimal text editor using MLTE. Based on wed.py.