def interact(list, pythondir): """Let the user interact with the dialog""" opythondir = pythondir try: # Try to go to the "correct" dir for GetDirectory os.chdir(pythondir.as_pathname()) except os.error: pass d = GetNewDialog(DIALOG_ID, -1) tp, h, rect = d.GetDialogItem(1) SetDialogItemText(h, string.joinfields(list, '\r')) while 1: n = ModalDialog(None) if n == OK_ITEM: break if n == CANCEL_ITEM: return None if n == REVERT_ITEM: return [], pythondir if n == DIR_ITEM: fss, ok = macfs.GetDirectory('Select python home folder:') if ok: pythondir = fss tmp = string.splitfields(GetDialogItemText(h), '\r') rv = [] for i in tmp: if i: rv.append(i) return rv, pythondir
def GetFolder(message=None): """ Select folder dialog. Returns path if one is selected. Otherwise it returns None. Availability: FontLab, Macintosh, PC """ path = None if MAC: if haveMacfs: fss, ok = macfs.GetDirectory(message) if ok: path = fss.as_pathname() else: from robofab.interface.mac.getFileOrFolder import GetFileOrFolder # This _also_ allows the user to select _files_, but given the # package/folder dichotomy, I think we have no other choice. path = GetFileOrFolder(message) elif PC: if inFontLab: if not message: message = '' path = fl.GetPathName('', message) else: myTuple = shell.SHBrowseForFolder(0, None, message, 64) try: path = shell.SHGetPathFromIDList(myTuple[0]) except: pass else: _raisePlatformError('GetFile') return path
def main(): # Ask the user for the plugins directory dir, ok = macfs.GetDirectory('Where is the PlugIns folder?') if not ok: sys.exit(0) os.chdir(dir.as_pathname()) # Remove old .slb aliases and collect a list of .slb files if EasyDialogs.AskYesNoCancel('Proceed with removing old aliases?') <= 0: sys.exit(0) LibFiles = [] allfiles = os.listdir(':') for f in allfiles: if f[-4:] == '.slb': finfo = macfs.FSSpec(f).GetFInfo() if finfo.Flags & 0x8000: os.unlink(f) else: LibFiles.append(f) print LibFiles # Create the new aliases. if EasyDialogs.AskYesNoCancel('Proceed with creating new ones?') <= 0: sys.exit(0) for dst, src in goals: if src in LibFiles: macostools.mkalias(src, dst) else: EasyDialogs.Message(dst + ' not created: ' + src + ' not found') EasyDialogs.Message('All done!')
def main(): dir, ok = macfs.GetDirectory('Python source folder:') if not ok: sys.exit(0) dir = dir.as_pathname() for routine, arg, list in INSTRUCTIONS: routine(dir, arg, list) print "All done!" sys.exit(1)
def __init__(self): InitUI() fss, ok = macfs.GetDirectory('Source directory:') if not ok: sys.exit(0) os.chdir(fss.as_pathname()) self.typedist = GetType() print 'TYPE', self.typedist self.inc = IncMatcher(self.typedist, '(MkDistr.include)') self.exc = ExcMatcher(self.typedist, '(MkDistr.exclude)') self.ui = MkDistrUI(self) self.ui.mainloop()
def __init__(self): InitUI() dir, ok = macfs.GetDirectory('Cvsgui source folder:') if not ok: sys.exit(0) self.root = dir.as_pathname() os.chdir(self.root) if not os.path.isdir(':MacCvs:Distrib'): os.mkdir(':MacCvs:Distrib') self.typedist = GetType() self.inc = IncMatcher(':MacCvs:Distrib:%s.include'%self.typedist) self.exc = ExcMatcher(':MacCvs:Distrib:%s.exclude'%self.typedist) self.ui = MkDistrUI(self) self.ui.mainloop()
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
def _macGetDirectory(prompt='select a directory'): carbon = drawer.isCarbon() if carbon: import EasyDialogs path = EasyDialogs.AskFolder(message=prompt) if path == None: return '', 0 else: return path, 1 else: import macfs fsspec, ok = macfs.GetDirectory(prompt) if ok != 1: return '', 0 # failure path = fsspec.as_pathname() drawer.pathScrub(path) return path, 1
def main(): if len(sys.argv) != 2: if sys.platform == 'mac': import macfs fss, ok = macfs.GetDirectory("Where are the interop documents?") if not ok: sys.exit(0) dirname = fss.as_pathname() else: print >> sys.stderr, "Usage: %s interopdirname" % sys.argv[0] sys.exit(1) else: dirname = sys.argv[1] files = getsmilfiles(dirname) for testlog in TESTLOGS: updatetestlog(testlog, files[:])
def main(): if len(sys.argv) > 1: for dir in sys.argv[1:]: dodir(dir) elif os.name == 'mac': import macfs dir, ok = macfs.GetDirectory('Folder to search:') if not ok: sys.exit(0) dodir(dir.as_pathname()) else: print 'Usage: hexbintree dir ...' sys.exit(1) if os.name == 'mac': sys.exit(1) # Keep window else: sys.exit(0)
# fixgusidir - Modify filenames in the CWGUSI source tree, so
# # 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)
""" ***DANGEROUS*** script to remove all results of a build process. ***Don't*** run this if you are ***not*** building Python from the source !!! """ import macfs import os import sys import re sweepfiletypes = [ 'APPL', # applications 'Atmp', # applet template 'shlb', # shared libs 'MPSY', # SYM and xSYM files 'PYC ', # .pyc files ] sweepfolderre = re.compile(r"(.*) Data$") def remove(top): if os.path.isdir(top): for name in os.listdir(top): path = os.path.join(top, name) remove(path) os.remove(top)
"""Easy to use dialogs.
"""findgremlins - Search through a folder and subfolders for
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...
"""
def run(change): fss, ok = macfs.GetDirectory('Folder to search:') if not ok: sys.exit(0) walktree(fss.as_pathname(), change)
# Extract files from a SHAR archive.
#
"""Utility routines depending on the finder,
"""Edit the Python Preferences file."""
# Zap .pyc files
# Test List module.
"""Import a module while pretending its name is __main__. This