def _update(self, value): maxval = self.maxval if maxval == 0: Ctl.IdleControls(self.w) else: if maxval > 32767: value = int(value / (maxval / 32767.0)) maxval = 32767 maxval = int(maxval) value = int(value) progbar = self.d.GetDialogItemAsControl(3) progbar.SetControlMaximum(maxval) progbar.SetControlValue(value) ready, ev = Evt.WaitNextEvent(Events.mDownMask, 1) if ready: what, msg, when, where, mod = ev part = Win.FindWindow(where)[0] if Dlg.IsDialogEvent(ev): ds = Dlg.DialogSelect(ev) if ds[0] and ds[1] == self.d and ds[-1] == 1: self.w.HideWindow() self.w = None self.d = None raise KeyboardInterrupt, ev elif part == 4: self.w.DragWindow(where, screenbounds) else: MacOS.HandleEvent(ev) return
def do_mouseDown(self, event): (what, message, when, where, modifiers) = event partcode, wid = Win.FindWindow(where) # # Find the correct name. # if FrameWork.partname.has_key(partcode): name = "do_" + FrameWork.partname[partcode] else: name = "do_%d" % partcode if name == "do_inDesk": if hasattr(MacOS, "HandleEvent"): MacOS.HandleEvent(event) else: print 'Unexpected inDesk event:', event return if wid == self.wid: try: handler = getattr(self, name) except AttributeError: handler = self.app.do_unknownpartcode else: #MacOS.HandleEvent(event) if name == 'do_inMenuBar': handler = getattr(self.parent, name) else: return handler(partcode, wid, event)
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
"""MiniAEFrame - A minimal AppleEvent Application framework. There are two classes: AEServer -- a mixin class offering nice AE handling. MiniApplication -- a very minimal alternative to FrameWork.py, only suitable for the simplest of AppleEvent servers. """ import sys import traceback import MacOS from Carbon import AE from Carbon.AppleEvents import * from Carbon import Evt from Carbon.Events import * from Carbon import Menu from Carbon import Win from Carbon.Windows import * from Carbon import Qd import aetools import EasyDialogs kHighLevelEvent = 23 # Not defined anywhere for Python yet? class MiniApplication: """A minimal FrameWork.Application-like class""" def __init__(self): self.quitting = 0 # Initialize menu self.appleid = 1 self.quitid = 2
print 'AE error: ', err print 'in', msg traceback.print_exc() return elif 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) & 0xffff # Hi word item = result & 0xffff # Lo word 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)
def main(): print 'hello world' # XXXX # skip the toolbox initializations, already done # XXXX Should use gestalt here to check for quicktime version Qt.EnterMovies() # Get the movie file fss = EasyDialogs.AskFileForOpen( wanted=File.FSSpec) # Was: QuickTime.MovieFileType if not fss: sys.exit(0) # Open the window bounds = (175, 75, 175 + 160, 75 + 120) theWindow = Win.NewCWindow(bounds, fss.as_tuple()[2], 0, 0, -1, 1, 0) # XXXX Needed? SetGWorld((CGrafPtr)theWindow, nil) Qd.SetPort(theWindow) # Get the movie theMovie = loadMovie(fss) # Relocate to (0, 0) bounds = theMovie.GetMovieBox() bounds = 0, 0, bounds[2] - bounds[0], bounds[3] - bounds[1] theMovie.SetMovieBox(bounds) # Create a controller theController = theMovie.NewMovieController(bounds, QuickTime.mcTopLeftMovie) # Get movie size and update window parameters rv, bounds = theController.MCGetControllerBoundsRect() theWindow.SizeWindow(bounds[2], bounds[3], 0) # XXXX or [3] [2]? Qt.AlignWindow(theWindow, 0) theWindow.ShowWindow() # XXXX MCDoAction(theController, mcActionSetGrowBoxBounds, &maxBounds) theController.MCDoAction(QuickTime.mcActionSetKeysEnabled, '1') # XXXX MCSetActionFilterWithRefCon(theController, movieControllerEventFilter, (long)theWindow) done = 0 while not done: gotone, evt = Evt.WaitNextEvent(0xffff, 0) (what, message, when, where, modifiers) = evt ## print what, message, when, where, modifiers # XXXX if theController.MCIsPlayerEvent(evt): continue if what == Events.mouseDown: part, whichWindow = Win.FindWindow(where) if part == Windows.inGoAway: done = whichWindow.TrackGoAway(where) elif part == Windows.inDrag: Qt.DragAlignedWindow(whichWindow, where, (0, 0, 4000, 4000)) elif what == Events.updateEvt: whichWindow = Win.WhichWindow(message) if not whichWindow: # Probably the console window. Print something, hope it helps. print 'update' else: Qd.SetPort(whichWindow) whichWindow.BeginUpdate() Qd.EraseRect(whichWindow.GetWindowPort().GetPortBounds()) whichWindow.EndUpdate()
"""Easy to use dialogs.
"""'echo' -- an AppleEvent handler which handles all events the same. It replies to each event by echoing the parameter back to the client. This is a good way to find out how the Script Editor formats AppleEvents, especially to figure out all the different forms an object specifier can have (without having to rely on Apple's implementation). """ import sys sys.stdout = sys.stderr import traceback import MacOS from Carbon import AE from Carbon.AppleEvents import * from Carbon import Evt from Carbon.Events import * from Carbon import Menu from Carbon import Dlg from Carbon import Win from Carbon.Windows import * from Carbon import Qd import aetools import EasyDialogs kHighLevelEvent = 23 # Not defined anywhere for Python yet? def mymessage(str): err = AE.AEInteractWithUser(kAEDefaultTimeout) if err: print str EasyDialogs.Message(str) def main():
"""AEservertest - Test AppleEvent server interface (adapted from Guido's 'echo' program). Build an applet from this source, and include the aete resource that you want to test. Use the AEservertest script to try things. """ import sys sys.stdout = sys.stderr import traceback import MacOS from Carbon import AE from Carbon.AppleEvents import * from Carbon import Evt from Carbon.Events import * from Carbon import Menu from Carbon import Dlg from Carbon import Win from Carbon.Windows import * from Carbon import Qd import macfs import aetools import EasyDialogs kHighLevelEvent = 23 # Not defined anywhere for Python yet? Quit = 'Quit' def mymessage(str): err = AE.AEInteractWithUser(kAEDefaultTimeout) if err: print str EasyDialogs.Message(str)
"""VerySimplePlayer converted to python