Example #1
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)
Example #2
0
 def open(self):
     self.wid = Win.NewCWindow(self._globalbounds, self.title, self._show,
                               self.windowkind, -1, self.hasclosebox, 0)
     self.SetPort()
     fontname, fontstyle, fontsize, fontcolor = self._fontsettings
     fnum = Fm.GetFNum(fontname)
     if fnum == 0:
         fnum = Fm.GetFNum("Geneva")
     Qd.TextFont(fnum)
     Qd.TextFace(fontstyle)
     Qd.TextSize(fontsize)
     if self._bindings.has_key("<open>"):
         callback = self._bindings["<open>"]
         callback()
     for w in self._widgets:
         w.forall_frombottom("open")
     self._maketabchain()
     if self._tabbable:
         self.bind('tab', self.nextwidget)
         self.bind('shifttab', self.previouswidget)
     else:
         self._hasselframes = 0
     if self._tabchain:
         self._tabchain[0].select(1)
     self.do_postopen()
Example #3
0
def windowbounds(preferredsize, minsize=None):
    "Return sensible window bounds"

    global _windowcounter
    if len(preferredsize) == 4:
        bounds = l, t, r, b = preferredsize
        desktopRgn = Win.GetGrayRgn()
        tempRgn = Qd.NewRgn()
        Qd.RectRgn(tempRgn, bounds)
        union = Qd.UnionRgn(tempRgn, desktopRgn, tempRgn)
        equal = Qd.EqualRgn(tempRgn, desktopRgn)
        Qd.DisposeRgn(tempRgn)
        if equal:
            return bounds
        else:
            preferredsize = r - l, b - t
    if not minsize:
        minsize = preferredsize
    minwidth, minheight = minsize
    width, height = preferredsize

    sl, st, sr, sb = screenbounds = Qd.InsetRect(
        Qd.GetQDGlobalsScreenBits().bounds, 4, 4)
    l, t = getnextwindowpos()
    if (l + width) > sr:
        _windowcounter = 0
        l, t = getnextwindowpos()
    r = l + width
    b = t + height
    if (t + height) > sb:
        b = sb
        if (b - t) < minheight:
            b = t + minheight
    return l, t, r, b
Example #4
0
 def open(self, path, name, data):
     self.path = path
     self.name = name
     r = windowbounds(400, 400)
     w = Win.NewWindow(r, name, 1, 0, -1, 1, 0)
     self.wid = w
     x0, y0, x1, y1 = self.wid.GetWindowPort().GetPortBounds()
     x0 = x0 + 4
     y0 = y0 + 4
     x1 = x1 - 20
     y1 = y1 - 20
     vr = dr = x0, y0, x1, y1
     ##vr = 4, 0, r[2]-r[0]-15, r[3]-r[1]-15
     ##dr = (0, 0, vr[2], 0)
     Qd.SetPort(w)
     Qd.TextFont(4)
     Qd.TextSize(9)
     self.ted = TE.TENew(dr, vr)
     self.ted.TEAutoView(1)
     self.ted.TESetText(data)
     w.DrawGrowIcon()
     self.scrollbars()
     self.changed = 0
     self.do_postopen()
     self.do_activate(1, None)
Example #5
0
def wait():
    from Carbon import Evt
    from Carbon import Events
    global splash
    try:
        splash
    except NameError:
        return
    Qd.InitCursor()
    time = Evt.TickCount()
    whattext = 0
    drawtext(whattext)
    while _keepsplashscreenopen:
        ok, event = Evt.EventAvail(Events.highLevelEventMask)
        if ok:
            # got apple event, back to mainloop
            break
        ok, event = Evt.EventAvail(Events.mDownMask | Events.keyDownMask
                                   | Events.updateMask)
        if ok:
            ok, event = Evt.WaitNextEvent(
                Events.mDownMask | Events.keyDownMask | Events.updateMask, 30)
            if ok:
                (what, message, when, where, modifiers) = event
                if what == Events.updateEvt:
                    if Win.WhichWindow(message) == splash:
                        UpdateSplash(1, whattext)
                else:
                    break
        if Evt.TickCount() - time > 360:
            whattext = not whattext
            drawtext(whattext)
            time = Evt.TickCount()
    del splash
Example #6
0
 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
Example #7
0
    def open(self, width, height, pixmap, data):
        self.pixmap = pixmap
        self.data = data
        self.pictrect = (0, 0, width, height)
        bounds = (LEFT, TOP, LEFT + width, TOP + height)

        self.wid = Win.NewCWindow(bounds, "Picture", 1, 0, -1, 1, 0)
        self.do_postopen()
Example #8
0
 def open(self, path, name, data):
     self.path = path
     self.name = name
     r = windowbounds(400, 400)
     w = Win.NewWindow(r, name, 1, 0, -1, 1, 0)
     self.wid = w
     flags = MacTextEditor.kTXNDrawGrowIconMask|MacTextEditor.kTXNWantHScrollBarMask| \
                     MacTextEditor.kTXNWantVScrollBarMask
     self.ted, self.frameid = Mlte.TXNNewObject(
         None, w, None, flags, MacTextEditor.kTXNTextEditStyleFrameType,
         MacTextEditor.kTXNTextFile, MacTextEditor.kTXNMacOSEncoding)
     self.ted.TXNSetData(MacTextEditor.kTXNTextData, data, 0, 0x7fffffff)
     self.changed = 0
     self.do_postopen()
     self.do_activate(1, None)
Example #9
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
Example #10
0
class ICONwindow(FrameWork.Window):
	def open(self, (resid, resname)):
		if not resname:
			resname = '#'+`resid`
		self.resid = resid
		self.picture = Icn.GetIcon(self.resid)
		l, t, r, b = 0, 0, 32, 32
		self.pictrect = (l, t, r, b)
		width = r-l
		height = b-t
		if width < MINWIDTH: width = MINWIDTH
		elif width > MAXWIDTH: width = MAXWIDTH
		if height < MINHEIGHT: height = MINHEIGHT
		elif height > MAXHEIGHT: height = MAXHEIGHT
		bounds = (LEFT, TOP, LEFT+width, TOP+height)
		
		self.wid = Win.NewWindow(bounds, resname, 1, 0, -1, 1, 0)
		self.do_postopen()
Example #11
0
class PICTwindow(FrameWork.Window):
    def open(self, (resid, resname)):
        if not resname:
            resname = '#%r' % (resid, )
        self.resid = resid
        self.picture = Qd.GetPicture(self.resid)
        # Get rect for picture
        sz, t, l, b, r = struct.unpack('hhhhh', self.picture.data[:10])
        self.pictrect = (l, t, r, b)
        width = r - l
        height = b - t
        if width < MINWIDTH: width = MINWIDTH
        elif width > MAXWIDTH: width = MAXWIDTH
        if height < MINHEIGHT: height = MINHEIGHT
        elif height > MAXHEIGHT: height = MAXHEIGHT
        bounds = (LEFT, TOP, LEFT + width, TOP + height)

        self.wid = Win.NewWindow(bounds, resname, 1, 0, -1, 1, 0)
        self.do_postopen()
Example #12
0
 def open(self, path, name, data):
     self.path = path
     self.name = name
     r = windowbounds(400, 400)
     w = Win.NewWindow(r, name, 1, 0, -1, 1, 0)
     self.wid = w
     vr = 0, 0, r[2] - r[0] - 15, r[3] - r[1] - 15
     dr = (0, 0, 10240, 0)
     Qd.SetPort(w)
     Qd.TextFont(4)
     Qd.TextSize(9)
     flags = WASTEconst.weDoAutoScroll | WASTEconst.weDoOutlineHilite | \
      WASTEconst.weDoMonoStyled | WASTEconst.weDoUndo
     self.ted = waste.WENew(dr, vr, flags)
     self.tedtexthandle = Res.Resource(data)
     self.ted.WEUseText(self.tedtexthandle)
     self.ted.WECalText()
     w.DrawGrowIcon()
     self.scrollbars()
     self.changed = 0
     self.do_postopen()
     self.do_activate(1, None)
Example #13
0
class PICTwindow(FrameWork.Window):
    def open(self, (resid, resname)):
        if not resname:
            resname = '#%r' % (resid, )
        self.resid = resid
        picture = Qd.GetPicture(self.resid)
        # Get rect for picture
        print repr(picture.data[:16])
        sz, t, l, b, r = struct.unpack('hhhhh', picture.data[:10])
        print 'pict:', t, l, b, r
        width = r - l
        height = b - t
        if width < 64: width = 64
        elif width > 480: width = 480
        if height < 64: height = 64
        elif height > 320: height = 320
        bounds = (LEFT, TOP, LEFT + width, TOP + height)
        print 'bounds:', bounds

        self.wid = Win.NewWindow(bounds, resname, 1, 0, -1, 1, 0)
        self.wid.SetWindowPic(picture)
        self.do_postopen()
Example #14
0
def main():
    # skip the toolbox initializations, already done
    # XXXX Should use gestalt here to check for quicktime version
    Qt.EnterMovies()

    # Get the movie file
    if len(sys.argv) > 1:
        filename = sys.argv[1]
    else:
        filename = EasyDialogs.AskFileForOpen()  # Was: QuickTime.MovieFileType
    if not filename:
        sys.exit(0)

    # Open the window
    bounds = (175, 75, 175 + 160, 75 + 120)
    theWindow = Win.NewCWindow(bounds,
                               os.path.split(filename)[1], 1, 0, -1, 0, 0)
    Qd.SetPort(theWindow)
    # XXXX Needed? SetGWorld((CGrafPtr)theWindow, nil)

    playMovieInWindow(theWindow, filename,
                      theWindow.GetWindowPort().GetPortBounds())
Example #15
0
 def open(self, path, name, data):
     self.path = path
     self.name = name
     r = windowbounds(400, 400)
     w = Win.NewWindow(r, name, 1, 0, -1, 1, 0)
     self.wid = w
     vr = LEFTMARGIN, 0, r[2] - r[0] - 15, r[3] - r[1] - 15
     dr = (0, 0, vr[2], 0)
     Qd.SetPort(w)
     Qd.TextFont(4)
     Qd.TextSize(9)
     flags = WASTEconst.weDoAutoScroll | WASTEconst.weDoOutlineHilite | \
             WASTEconst.weDoMonoStyled | WASTEconst.weDoUndo
     self.ted = waste.WENew(dr, vr, flags)
     self.ted.WEInstallTabHooks()
     style, soup = self.getstylesoup(self.path)
     self.ted.WEInsert(data, style, soup)
     self.ted.WESetSelection(0, 0)
     self.ted.WECalText()
     self.ted.WEResetModCount()
     w.DrawGrowIcon()
     self.scrollbars()
     self.do_postopen()
     self.do_activate(1, None)
Example #16
0
# A minimal text editor.
Example #17
0
# A minimal text editor.
Example #18
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
         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)
Example #20
0
"""browsepict - Display all "cicn" resources found"""
Example #21
0
"""MovieInWindow converted to python
Example #22
0
"""browsepict - Display all "PICT" resources found"""
Example #23
0
"""VerySimplePlayer converted to python
Example #24
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)
Example #25
0
"""Easy to use dialogs.
Example #26
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()
Example #27
0
"""'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():
Example #28
0
# A minimal text editor using MLTE. Based on wed.py.
Example #29
0
# A minimal text editor.
Example #30
0
"""imgbrowse - Display pictures using img"""