Exemple #1
0
	def do_mouseDown(self, event):
		(what, message, when, where, modifiers) = event
		partcode, wid = FindWindow(where)

		#
		# Find the correct name.
		#
		if partname.has_key(partcode):
			name = "do_" + partname[partcode]
		else:
			name = "do_%d" % partcode

		if wid == None:
			# No window, or a non-python window	
			try:
				handler = getattr(self, name)
			except AttributeError:
				# Not menubar or something, so assume someone
				# else's window
				MacOS.HandleEvent(event)
				return		
		elif self._windows.has_key(wid):
			# It is a window. Hand off to correct window.
			window = self._windows[wid]
			try:
				handler = getattr(window, name)
			except AttributeError:
				handler = self.do_unknownpartcode
		else:
			# It is a python-toolbox window, but not ours.
			handler = self.do_unknownwindow
		handler(partcode, wid, event)
Exemple #2
0
 def do_unknownpartcode(self, partcode, window, event):
     (what, message, when, where, modifiers) = event
     if DEBUG: print "Mouse down at global:", where
     if DEBUG: print "\tUnknown part code:", partcode
     if DEBUG: print "\tEvent:", self.printevent(event)
     if hasattr(MacOS, 'HandleEvent'):
         MacOS.HandleEvent(event)
Exemple #3
0
    def do_mouseDown(self, event):
        what, message, when, where, modifiers = event
        partcode, wid = FindWindow(where)
        if partcode in partname:
            name = 'do_' + partname[partcode]
        else:
            name = 'do_%d' % partcode
        if wid is None:
            try:
                handler = getattr(self, name)
            except AttributeError:
                if hasattr(MacOS, 'HandleEvent'):
                    MacOS.HandleEvent(event)
                return

        elif wid in self._windows:
            window = self._windows[wid]
            try:
                handler = getattr(window, name)
            except AttributeError:
                handler = self.do_unknownpartcode

        else:
            handler = self.do_unknownwindow
        handler(partcode, wid, event)
        return
Exemple #4
0
 def do_key(self, event):
     (what, message, when, where, modifiers) = event
     c = chr(message & charCodeMask)
     if self.menubar:
         result = MenuEvent(event)
         id = (result >> 16) & 0xffff  # Hi word
         item = result & 0xffff  # Lo word
         if id:
             self.do_rawmenu(id, item, None, event)
             return
         # Otherwise we fall-through
     if modifiers & cmdKey:
         if c == '.':
             raise self
         else:
             if not self.menubar:
                 if hasattr(MacOS, 'HandleEvent'):
                     MacOS.HandleEvent(event)
             return
     else:
         # See whether the front window wants it
         w = MyFrontWindow()
         if w and self._windows.has_key(w):
             window = self._windows[w]
             try:
                 do_char = window.do_char
             except AttributeError:
                 do_char = self.do_char
             do_char(c, event)
Exemple #5
0
    def do_key(self, event):
        what, message, when, where, modifiers = event
        c = chr(message & charCodeMask)
        if self.menubar:
            result = MenuEvent(event)
            id = result >> 16 & 65535
            item = result & 65535
            if id:
                self.do_rawmenu(id, item, None, event)
                return
        if modifiers & cmdKey:
            if c == '.':
                raise self
            else:
                if not self.menubar:
                    if hasattr(MacOS, 'HandleEvent'):
                        MacOS.HandleEvent(event)
                return
        else:
            w = MyFrontWindow()
            if w and w in self._windows:
                window = self._windows[w]
                try:
                    do_char = window.do_char
                except AttributeError:
                    do_char = self.do_char

                do_char(c, event)
        return
Exemple #6
0
    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 _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
Exemple #8
0
	def do_activateEvt(self, event):
		(what, message, when, where, modifiers) = event
		wid = WhichWindow(message)
		if wid and self._windows.has_key(wid):
			window = self._windows[wid]
			window.do_activate(modifiers & 1, event)
		else:
			MacOS.HandleEvent(event)
Exemple #9
0
 def do_activateEvt(self, event):
     what, message, when, where, modifiers = event
     wid = WhichWindow(message)
     if wid and wid in self._windows:
         window = self._windows[wid]
         window.do_activate(modifiers & 1, event)
     elif hasattr(MacOS, 'HandleEvent'):
         MacOS.HandleEvent(event)
Exemple #10
0
 def do_updateEvt(self, event):
     (what, message, when, where, modifiers) = event
     wid = WhichWindow(message)
     if wid and self._windows.has_key(wid):
         window = self._windows[wid]
         window.do_rawupdate(wid, event)
     else:
         if hasattr(MacOS, 'HandleEvent'):
             MacOS.HandleEvent(event)
Exemple #11
0
 def do_inMenuBar(self, partcode, window, event):
     if not self.menubar:
         if hasattr(MacOS, 'HandleEvent'):
             MacOS.HandleEvent(event)
         return
     (what, message, when, where, modifiers) = event
     result = MenuSelect(where)
     id = (result >> 16) & 0xffff  # Hi word
     if id >= 0x8000:
         id = -65536 + id
     item = result & 0xffff  # Lo word
     self.do_rawmenu(id, item, window, event)
Exemple #12
0
class EchoServer:
	
	suites = ['aevt', 'core']
	
	def __init__(self):
		self.active = 0
		for suite in self.suites:
			AE.AEInstallEventHandler(suite, typeWildCard, self.aehandler)
		self.active = 1
		self.appleid = 1
		Menu.ClearMenuBar()
		self.applemenu = applemenu = Menu.NewMenu(self.appleid, "\024")
		applemenu.AppendMenu("All about echo...;(-")
		applemenu.AddResMenu('DRVR')
		applemenu.InsertMenu(0)
		Menu.DrawMenuBar()
	
	def __del__(self):
		self.close()
	
	def close(self):
		if self.active:
			self.active = 0
			for suite in self.suites:
				AE.AERemoveEventHandler(suite, typeWildCard)
	
	def mainloop(self, mask = everyEvent, timeout = 60*60):
		while 1:
			self.dooneevent(mask, timeout)
	
	def dooneevent(self, mask = everyEvent, timeout = 60*60):
			got, event = Evt.WaitNextEvent(mask, timeout)
			if got:
				self.lowlevelhandler(event)
	
	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!")
		elif what == keyDown:
			c = chr(message & charCodeMask)
			if c == '.' and modifiers & cmdKey:
				raise KeyboardInterrupt, "Command-period"
			MacOS.HandleEvent(event)
Exemple #13
0
 def do_inMenuBar(self, partcode, window, event):
     if not self.menubar:
         if hasattr(MacOS, 'HandleEvent'):
             MacOS.HandleEvent(event)
         return
     what, message, when, where, modifiers = event
     result = MenuSelect(where)
     id = result >> 16 & 65535
     if id >= 32768:
         id = -65536 + id
     item = result & 65535
     self.do_rawmenu(id, item, window, event)
Exemple #14
0
def main():
	global quit
	quit = 0
	while not quit:
		ok, e = Evt.WaitNextEvent(-1, 60)
		if ok:
			print 'Event:', e
			if e[0] == 23: # kHighLevelEvent
				AE.AEProcessAppleEvent(e)
			elif e[0] == keyDown and chr(e[1]&0xff) == '.' and e[4]&cmdKey:
				raise KeyboardInterrupt, "Command-Period"
			else:
				MacOS.HandleEvent(e)
Exemple #15
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
Exemple #16
0
	def do_unknownwindow(self, partcode, window, event):
		if DEBUG: print 'Unknown window:', window
		MacOS.HandleEvent(event)
Exemple #17
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
Exemple #18
0
"""'echo' -- an AppleEvent handler which handles all events the same.
Exemple #19
0
 def do_unknownwindow(self, partcode, window, event):
     if DEBUG:
         print 'Unknown window:', window
     if hasattr(MacOS, 'HandleEvent'):
         MacOS.HandleEvent(event)
Exemple #20
0
 def do_inDesk(self, partcode, window, event):
     if hasattr(MacOS, 'HandleEvent'):
         MacOS.HandleEvent(event)
Exemple #21
0
"""Easy to use dialogs.
                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
        if hasattr(MacOS, 'HandleEvent'):
            MacOS.HandleEvent(event)
        else:
            print "Unhandled event:", event

    def getabouttext(self):
        return self.__class__.__name__

    def getaboutmenutext(self):
        return "About %s\311" % self.__class__.__name__


class AEServer:
    def __init__(self):
        self.ae_handlers = {}

    def installaehandler(self, classe, type, callback):
Exemple #23
0
"A sort of application framework for the Mac"
Exemple #24
0
	def do_inSysWindow(self, partcode, window, event):
		MacOS.HandleEvent(event)
Exemple #25
0
	def do_inDesk(self, partcode, window, event):
		MacOS.HandleEvent(event)