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 lowlevelhandler(self, event): what, message, when, where, modifiers = event h, v = where if what == kHighLevelEvent: msg = "High Level Event: %s %s" % \ (`code(message)`, `code(h | (v<<16))`) try: AE.AEProcessAppleEvent(event) except AE.Error, err: EasyDialogs.Message(msg + "\015AEProcessAppleEvent error: %s" % str(err)) traceback.print_exc() else: EasyDialogs.Message(msg + "\015OK!")
def handle_xml_file(self, path): prefs = getprefs() makesuitcase = int(prefs.get("makesuitcases", 0)) dstfolder = prefs.get("ttoutput", DEFAULTTTOUTPUT) if not os.path.exists(dstfolder): os.mkdir(dstfolder) srcfilename = dstfilename = os.path.basename(path) if dstfilename[-4:] in (".ttx", ".xml"): dstfilename = dstfilename[:-4] if dstfilename[-4:] not in (".TTF", ".ttf"): dstfilename = dstfilename + ".TTF" dst = os.path.join(dstfolder, dstfilename) if makesuitcase: try: # see if the destination file is writable, # otherwise we'll get an error waaay at the end of # the parse procedure testref = Res.FSpOpenResFile(macfs.FSSpec(dst), 3) # read-write except Res.Error, why: if why[0] <> -43: # file not found EasyDialogs.Message( "Can't create '%s'; file already open" % dst) return else: Res.CloseResFile(testref)
def GetType(): """Ask user for distribution type""" while 1: d = Dlg.GetNewDialog(ID_DTYPE, -1) d.SetDialogDefaultItem(DTYPE_EXIST) d.SetDialogCancelItem(DTYPE_CANCEL) while 1: rv = ModalDialog(None) if rv in (DTYPE_EXIST, DTYPE_NEW, DTYPE_CANCEL): break del d if rv == DTYPE_CANCEL: sys.exit(0) if rv == DTYPE_EXIST: ## macfs.SetFolder(':(MkDistr)') fss, ok = macfs.StandardGetFile('TEXT') if not ok: sys.exit(0) path = fss.as_pathname() basename = os.path.split(path)[-1] if basename[-8:] <> '.include': EasyDialogs.Message('That is not a distribution include file') else: return basename[:-8] else: name = EasyDialogs.AskString('Distribution name:') if name: return name sys.exit(0)
def main(): try: buildapplet() except buildtools.BuildError, detail: if EasyDialogs is None: print detail else: EasyDialogs.Message(detail)
def Message(text): import EasyDialogs, string from Carbon import Qd Qd.InitCursor() text = string.replace(text, "\n", "\r") if not text: text = '<Alert text not specified>' EasyDialogs.Message(text)
def main(): pathname = EasyDialogs.AskFileForOpen(message='File to check end-of-lines in:') if not pathname: sys.exit(0) fp = open(pathname, 'rb') try: data = fp.read() except MemoryError: EasyDialogs.Message('Sorry, file is too big.') sys.exit(0) if len(data) == 0: EasyDialogs.Message('File is empty.') sys.exit(0) number_cr = string.count(data, '\r') number_lf = string.count(data, '\n') if number_cr == number_lf == 0: EasyDialogs.Message('File contains no lines.') if number_cr == 0: EasyDialogs.Message('File has unix-style line endings') elif number_lf == 0: EasyDialogs.Message('File has mac-style line endings') elif number_cr == number_lf: EasyDialogs.Message('File probably has MSDOS-style line endings') else: EasyDialogs.Message('File has no recognizable line endings (binary file?)') sys.exit(0)
def opendoc(self, *args): pathname = EasyDialogs.AskFileForOpen() # Any file type if not pathname: return bar = EasyDialogs.ProgressBar('Reading and converting...') try: rdr = img.reader(imgformat.macrgb16, pathname) except img.error, arg: EasyDialogs.Message(repr(arg)) return
def showMessage(message=''): if len(sys.argv) == 1: if myos == 'win32': EasyDialogs.Message(message) return None if myos == 'darwin': easygui.msgbox(message) return None else: print(str(message)+"\n") return None
def insertfile(self, *args): if self.active: path = EasyDialogs.AskFileForOpen(typeList=('TEXT', )) if not path: return try: fp = open(path, 'rb') # NOTE binary, we need cr as end-of-line except IOError, arg: EasyDialogs.Message("IOERROR: %r" % (args, )) return self.active.menu_insert(fp)
def inserthtml(self, *args): if self.active: path = EasyDialogs.AskFileForOpen(typeList=('TEXT', )) if not path: return try: fp = open(path, 'r') except IOError, arg: EasyDialogs.Message("IOERROR: %r" % (arg, )) return self.active.menu_insert_html(fp)
def showmessages(self, messages): if messages: # To be on the safe side we always show the hidden packages, # they may be referred to in the error messages. if not self.w.hidden_button.get(): self.w.hidden_button.set(1) self.updatestatus() if type(messages) == list: messages = '\n'.join(messages) if self.w.verbose_button.get(): sys.stdout.write(messages + '\n') EasyDialogs.Message(messages)
def Message(message, title='RoboFab'): """ A simple message dialog. Availability: FontLab, Macintosh """ if inFontLab: _FontLabDialogMessage(message, title).Run() elif MAC: import EasyDialogs EasyDialogs.Message(message) else: _raisePlatformError('Message')
def mac_version(required): import EasyDialogs as ed import sys if required > _mac_version: message = "This version of the Ren'Py launcher is too old to run this game. You have version %d.%d.%d, while the game requires version %d.%d.%d.\n\nPlease go to http://www.bishoujo.us/renpy/mac.html, and download the latest version of the launcher." % \ (_mac_version[0], _mac_version[1], _mac_version[2], required[0], required[1], required[2]) ed.Message(message) sys.exit(0)
def _open(self, askfile): if askfile: path = EasyDialogs.AskFileForOpen(typeList=('TEXT', )) if not path: return name = os.path.split(path)[-1] try: fp = open(path, 'rb') # NOTE binary, we need cr as end-of-line data = fp.read() fp.close() except IOError, arg: EasyDialogs.Message("IOERROR: %r" % (arg, )) return
def mainloop(self, mask=FrameWork.everyEvent, wait=0): self.quitting = 0 while not self.quitting: try: self.do1event(mask, wait) except self.__class__: # D'OH! FrameWork tries to quit us on cmd-.! pass except KeyboardInterrupt: pass except ttLib.xmlImport.xml_parse_error, why: EasyDialogs.Message( "An error occurred while parsing the XML file:\n" + why) except:
def macGetArgs(): import EasyDialogs EasyDialogs.Message("""\ Use the next dialog to build a command line: 1. Choose an output format from the [Option] list 2. Click [Add] 3. Choose an input file: [Add existing file...] 4. Save the output: [Add new file...] 5. [OK]""") optionlist = [(longopt, description) for (longopt, shortopt, description) in options] argv = EasyDialogs.GetArgv(optionlist=optionlist, addfolder=0) return posixGetArgs(argv)
def replaceall(self): editor = findeditor(self) if not editor: return if self.visible: self.getparmsfromwindow() W.SetCursor("watch") find = self.parms["find"] if not find: return findlen = len(find) replace = self.parms["replace"] replacelen = len(replace) Text = editor.get() if not self.parms["casesens"]: find = string.lower(find) text = string.lower(Text) else: text = Text newtext = "" pos = 0 counter = 0 while 1: if self.parms["wholeword"]: wholewordRE = _makewholewordpattern(find) match = wholewordRE.search(text, pos) if match: pos = match.start(1) else: pos = -1 else: pos = string.find(text, find, pos) if pos < 0: break counter = counter + 1 text = text[:pos] + replace + text[pos + findlen:] Text = Text[:pos] + replace + Text[pos + findlen:] pos = pos + replacelen W.SetCursor("arrow") if counter: self.hide() from Carbon import Res editor.textchanged() editor.selectionchanged() editor.set(Text) EasyDialogs.Message("Replaced %d occurrences" % counter)
def lowlevelhandler(self, event): what, message, when, where, modifiers = event h, v = where if what == kHighLevelEvent: msg = 'High Level Event: %r %r' % (code(message), code(h | v << 16)) try: AE.AEProcessAppleEvent(event) except AE.Error as err: print 'AE error: ', err print 'in', msg traceback.print_exc() return if what == keyDown: c = chr(message & charCodeMask) if modifiers & cmdKey: if c == '.': raise KeyboardInterrupt, 'Command-period' if c == 'q': if hasattr(MacOS, 'OutputSeen'): MacOS.OutputSeen() self.quitting = 1 return elif what == mouseDown: partcode, window = Win.FindWindow(where) if partcode == inMenuBar: result = Menu.MenuSelect(where) id = result >> 16 & 65535 item = result & 65535 if id == self.appleid: if item == 1: EasyDialogs.Message(self.getabouttext()) elif item > 1 and hasattr(Menu, 'OpenDeskAcc'): name = self.applemenu.GetMenuItemText(item) Menu.OpenDeskAcc(name) elif id == self.quitid and item == 1: if hasattr(MacOS, 'OutputSeen'): MacOS.OutputSeen() self.quitting = 1 Menu.HiliteMenu(0) return if hasattr(MacOS, 'HandleEvent'): MacOS.HandleEvent(event) else: print 'Unhandled event:', event
#!/usr/bin/env python # encoding: utf-8 # # Copyright (c) 2008 Doug Hellmann All rights reserved. # """ """ __version__ = "$Id$" #end_pymotw_header import EasyDialogs EasyDialogs.Message('This is a Message dialog')
def selsizesmaller(self, *rest): if self.active: self.active.menu_incsize(-2) else: EasyDialogs.Message("No active window?")
def selsize(self, id, item, *rest): if self.active: size = SIZES[item - 1] self.active.menu_setsize(size) else: EasyDialogs.Message("No active window?")
def selfacenormal(self, *rest): if self.active: self.active.menu_setface(0) else: EasyDialogs.Message("No active window?")
def clear(self, *args): if self.active: self.active.menu_clear() else: EasyDialogs.Message("No active window?")
def message(self, message): return EasyDialogs.Message(message)
def paste(self, *args): if self.active: self.active.menu_paste() else: EasyDialogs.Message("No active window?")
def undo(self, *args): if self.active: self.active.menu_undo() else: EasyDialogs.Message("No active window?")
def saveas(self, *args): if self.active: self.active.menu_save_as() else: EasyDialogs.Message("No active window?")
def closewin(self, *args): if self.active: self.active.close() else: EasyDialogs.Message("No active window?")
def do_about(self, id, item, window, event): EasyDialogs.Message("A simple single-font text editor based on WASTE")