예제 #1
0
    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
예제 #2
0
"""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
예제 #3
0
파일: echo.py 프로젝트: mcyril/ravel-ftn
"""'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():
         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)
         return
 # Anything not handled is passed to Python/SIOUX
예제 #5
0
"""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)