Beispiel #1
0
 def updatebitmap(self, parameters, src1, src2, tmp, dst, dstrgn):
     """Called by the engine when the parameters have changed and the
     destination bitmap has to be recomputed. Also called for other redraw reasons."""
     Qd.CopyBits(src1, dst, self.ltrb, self.ltrb, QuickDraw.srcCopy, dstrgn)
     if self.SHOW_UNIMPLEMENTED_TRANSITION_NAME:
         x0, y0, x1, y1 = self.ltrb
         Qd.MoveTo(x0, y0)
         Qd.LineTo(x1, y1)
         Qd.MoveTo(x0, y1)
         Qd.LineTo(x1, y0)
         Qd.MoveTo(x0, (y0 + y1) / 2)
         Qd.DrawString(
             "%s %s" %
             (self.dict.get('trtype', '???'), self.dict.get('subtype', '')))
Beispiel #2
0
 def _get_button_region(self):
     """Return our region, in global coordinates, if we are active"""
     # XXXX Only rectangulars for now
     if not self._sensitive:
         return None
     if not self._insidetemporal():
         return None
     rgn = Qd.NewRgn()
     if self._shape == 'rect':
         x0, y0 = self._convert_point(self._coordinates[0:2])
         x1, y1 = self._convert_point(self._coordinates[2:4])
         box = x0, y0, x1, y1
         Qd.RectRgn(rgn, box)
     elif self._shape == 'poly':
         Qd.OpenRgn()
         xl, yl = self._convert_point(self._coordinates[-2:])
         Qd.MoveTo(xl, yl)
         for i in range(0, len(self._coordinates), 2):
             x, y = self._convert_point(self._coordinates[i:i + 2])
             Qd.LineTo(x, y)
         Qd.CloseRgn(rgn)
     elif self._shape == 'circle':
         print 'Circle not supported yet'
     elif self._shape == 'ellipse':
         # Note: rx/ry are width/height, not points
         x, y, rx, ry = self._dispobj._window._convert_coordinates(
             self._coordinates)
         Qd.OpenRgn()
         Qd.FrameOval((x - rx, y - ry, x + rx, y + ry))
         Qd.CloseRgn(rgn)
     else:
         print 'Invalid shape type', self._shape
     return rgn
Beispiel #3
0
def drawTextCell(text, cellRect, ascent, theList):
    l, t, r, b = cellRect
    cellwidth = r - l
    Qd.MoveTo(int(l + 2), int(t + ascent))
    condense, text = truncString(text, cellwidth - 3)
    if condense:
        Qd.TextFace(QuickDraw.condense)
    Qd.DrawText(text, 0, len(text))
    Qd.TextFace(0)
 def draw(self, visRgn=None):
     if self._visible:
         l, t, r, b = Qd.InsetRect(self._bounds, 1, 1)
         Qd.RGBForeColor(self._color)
         Qd.PaintRect((l, t, r, b))
         Qd.RGBForeColor(self._darkercolor)
         Qd.MoveTo(l, b)
         Qd.LineTo(r, b)
         Qd.LineTo(r, t)
         Qd.RGBForeColor((0, 0, 0))
Beispiel #5
0
    def listDefDraw(self, selected, cellRect, theCell, dataOffset, dataLen,
                    theList):
        savedPort = Qd.GetPort()
        Qd.SetPort(theList.GetListPort())
        savedClip = Qd.NewRgn()
        Qd.GetClip(savedClip)
        Qd.ClipRect(cellRect)
        savedPenState = Qd.GetPenState()
        Qd.PenNormal()
        Qd.EraseRect(cellRect)

        #draw the cell if it contains data
        ascent, descent, leading, size, hm = Fm.FontMetrics()
        linefeed = ascent + descent + leading

        if dataLen:
            left, top, right, bottom = cellRect
            data = theList.LGetCell(dataLen, theCell)
            lines = data.split("\r")
            line1 = lines[0]
            if len(lines) > 1:
                line2 = lines[1]
            else:
                line2 = ""
            Qd.MoveTo(int(left + 4), int(top + ascent))
            Qd.DrawText(line1, 0, len(line1))
            if line2:
                Qd.MoveTo(int(left + 4), int(top + ascent + linefeed))
                Qd.DrawText(line2, 0, len(line2))
            Qd.PenPat("\x11\x11\x11\x11\x11\x11\x11\x11")
            bottom = top + theList.cellSize[1]
            Qd.MoveTo(left, bottom - 1)
            Qd.LineTo(right, bottom - 1)
        if selected:
            self.listDefHighlight(selected, cellRect, theCell, dataOffset,
                                  dataLen, theList)
        #restore graphics environment
        Qd.SetPort(savedPort)
        Qd.SetClip(savedClip)
        Qd.DisposeRgn(savedClip)
        Qd.SetPenState(savedPenState)
Beispiel #6
0
    def idle(self, event):
        if self.active:
            self.active.do_idle(event)
        else:
            Qd.SetCursor(Qd.GetQDGlobalsArrow())

    def newRuler(self, obj):
        """Insert a new ruler. Make it as wide as the window minus 2 pxls"""
        ted = obj.WEGetObjectOwner()
        l, t, r, b = ted.WEGetDestRect()
        return r - l, 4

    def drawRuler(self, (l, t, r, b), obj):
        y = (t + b) / 2
        Qd.MoveTo(l + 2, y)
        Qd.LineTo(r - 2, y)
        return 0


class MyHTMLParser(htmllib.HTMLParser):
    def anchor_bgn(self, href, name, type):
        self.anchor = href
        if self.anchor:
            self.anchorlist.append(href)
            self.formatter.push_style('anchor')

    def anchor_end(self):
        if self.anchor:
            self.anchor = None
            self.formatter.pop_style()
Beispiel #7
0
import Printing
from Carbon import Qd
from Carbon import Fm
from Carbon import Res
# some constants
PostScriptBegin = 190	# Set driver state to PostScript	
PostScriptEnd = 191	# Restore QuickDraw state	
PostScriptHandle = 192	# PostScript data referenced in handle
CHUNK_SIZE = 0x8000 # max size of PicComment
def PostScript(text):
	"""embed text as plain PostScript in print job."""
	handle = Res.Resource('')
	Qd.PicComment(PostScriptBegin, 0, handle)
	while text:
		chunk = text[:CHUNK_SIZE]
		text = text[CHUNK_SIZE:]
		handle.data = chunk
		Qd.PicComment(PostScriptHandle, len(chunk), handle)
	handle.data = ''
	Qd.PicComment(PostScriptEnd, 0, handle)
# create a new print record
printrecord = Printing.NewTPrintRecord()
# open the printer
Printing.PrOpen()
try:
	# initialize print record with default values
	Printing.PrintDefault(printrecord)
	
	# page setup, ok is 0 when user cancelled
	ok = Printing.PrStlDialog(printrecord)
Beispiel #8
0
    def _render_one(self, entry):
        cmd = entry[0]

        if cmd == 'clear':
            if self._bgcolor != None:
                r = self._getredrawguarantee(skipclear=1)
                if r:
                    r2 = Qd.NewRgn()
                    Qd.RectRgn(r2, self._window.qdrect())
                    Qd.DiffRgn(r2, r, r2)
                    Qd.EraseRgn(r2)
                    Qd.DisposeRgn(r)
                    Qd.DisposeRgn(r2)
                else:
                    Qd.EraseRect(self._window.qdrect())
        elif cmd == 'fg':
            self._setfgcolor(entry[1])
        elif cmd == 'font':
            entry[1]._setfont(self._render_grafport)
        elif cmd == 'text':
            x, y, w, h = self._convert_coordinates(entry[1:5])
            if not self._render_overlaprgn((x, y - h, x + w, y)):
                return
            Qd.MoveTo(x, y)
            # XXXX Incorrect for long strings:
            Qd.DrawText(entry[5], 0, len(entry[5]))
        elif cmd == 'icon':
            icon = entry[2]
            if icon == None:
                return
            rect = self._convert_coordinates(entry[1])
            if not self._render_overlaprgn(rect):
                return
            x0, y0, x1, y1 = rect
            if x1 - x0 < ICONSIZE_PXL:
                leftextra = (ICONSIZE_PXL - (x1 - x0)) / 2
                x0 = x0 + leftextra
                x1 = x0 + ICONSIZE_PXL
            if y1 - y0 < ICONSIZE_PXL:
                topextra = (ICONSIZE_PXL - (y1 - y0)) / 2
                y0 = y0 + topextra
                y1 = y0 + ICONSIZE_PXL
            Icn.PlotCIcon((x0, y0, x1, y1), icon)
        elif cmd == 'image':
            mask, image, srcx, srcy, coordinates, w, h, units = entry[1:]
            dstx, dsty = self._convert_coordinates(coordinates[:2],
                                                   units=units)
            dstrect = dstx, dsty, dstx + w, dsty + h
            if not self._render_overlaprgn(dstrect):
                return
            w = dstrect[2] - dstrect[0]
            h = dstrect[3] - dstrect[1]
            srcrect = srcx, srcy, srcx + w, srcy + h
            self._setblackwhitecolors()
            clip = self._window._mac_getclip()
            if mask:
                # XXXX We should also take note of the clip here.
                Qd.CopyMask(image[0], mask[0],
                            self._render_grafport.GetPortBitMapForCopyBits(),
                            srcrect, srcrect, dstrect)
            else:
                Qd.CopyBits(image[0],
                            self._render_grafport.GetPortBitMapForCopyBits(),
                            srcrect, dstrect,
                            QuickDraw.srcCopy + QuickDraw.ditherCopy, clip)
            self._restorecolors()
        elif cmd == 'line':
            color = entry[1]
            points = entry[2]
            self._setfgcolor(color)
            x, y = self._convert_coordinates(points[0])
            Qd.MoveTo(x, y)
            for np in points[1:]:
                x, y = self._convert_coordinates(np)
                Qd.LineTo(x, y)
            self._restorecolors()
        elif cmd == '3dhline':
            color1, color2, x0, x1, y = entry[1:]
            fgcolor = self._render_grafport.rgbFgColor
            self._setfgcolor(color1)
            x0, y0 = self._convert_coordinates((x0, y))
            x1, y1 = self._convert_coordinates((x1, y))
            if not self._render_overlaprgn((x0, y0, x1, y1 + 1)):
                return
            Qd.MoveTo(x0, y0)
            Qd.LineTo(x1, y1)
            self._setfgcolor(color2)
            Qd.MoveTo(x0, y0 + 1)
            Qd.LineTo(x1, y1 + 1)
            self._setfgcolor(fgcolor)
            self._restorecolors()
        elif cmd == 'box':
            rect = self._convert_coordinates(entry[1])
            if not self._render_overlaprgn(rect):
                return
            Qd.FrameRect(rect)
        elif cmd == 'fbox':
            color = entry[1]
            units = entry[3]
            rect = self._convert_coordinates(entry[2], units)
            if not self._render_overlaprgn(rect):
                return
            self._setfgcolor(color)
            Qd.PaintRect(rect)
            self._restorecolors()
        elif cmd == 'linewidth':
            Qd.PenSize(entry[1], entry[1])
        elif cmd == 'fpolygon':
            polyhandle = self._polyhandle(entry[2],
                                          cliprgn=self._render_cliprgn)
            if not polyhandle:
                return
            self._setfgcolor(entry[1])
            Qd.PaintPoly(polyhandle)
            self._restorecolors()
        elif cmd == '3dbox':
            rect = self._convert_coordinates(entry[2])
            if not self._render_overlaprgn(rect):
                return
            l, t, r, b = rect
            cl, ct, cr, cb = entry[1]
            clt = _colormix(cl, ct)
            ctr = _colormix(ct, cr)
            crb = _colormix(cr, cb)
            cbl = _colormix(cb, cl)
            ##             print '3Dbox', (l, t, r, b) # DBG
            ##             print 'window', self._window.qdrect() # DBG
            # l, r, t, b are the corners
            l3 = l + SIZE_3DBORDER
            t3 = t + SIZE_3DBORDER
            r3 = r - SIZE_3DBORDER
            b3 = b - SIZE_3DBORDER
            # draw left side
            self._setfgcolor(cl)
            polyhandle = self._polyhandle([(l, t), (l3, t3), (l3, b3), (l, b)],
                                          conv=0)
            if polyhandle: Qd.PaintPoly(polyhandle)
            # draw top side
            self._setfgcolor(ct)
            polyhandle = self._polyhandle([(l, t), (r, t), (r3, t3), (l3, t3)],
                                          conv=0)
            if polyhandle: Qd.PaintPoly(polyhandle)
            # draw right side
            self._setfgcolor(cr)
            polyhandle = self._polyhandle([(r3, t3), (r, t), (r, b), (r3, b3)],
                                          conv=0)
            if polyhandle: Qd.PaintPoly(polyhandle)
            # draw bottom side
            self._setfgcolor(cb)
            polyhandle = self._polyhandle([(l3, b3), (r3, b3), (r, b), (l, b)],
                                          conv=0)
            if polyhandle: Qd.PaintPoly(polyhandle)
            # draw topleft
            self._setfgcolor(clt)
            Qd.PaintRect((l, t, l3, t3))
            # draw topright
            self._setfgcolor(ctr)
            Qd.PaintRect((r3, t, r, t3))
            # draw botright
            self._setfgcolor(crb)
            Qd.PaintRect((r3, b3, r, b))
            # draw leftbot
            self._setfgcolor(cbl)
            Qd.PaintRect((l, b3, l3, b))

            self._restorecolors()
        elif cmd == 'diamond':
            rect = self._convert_coordinates(entry[1])
            if not self._render_overlaprgn(rect):
                return
            x, y, x1, y1 = rect
            w = x1 - x
            h = y1 - y
            Qd.MoveTo(x, y + h / 2)
            Qd.LineTo(x + w / 2, y)
            Qd.LineTo(x + w, y + h / 2)
            Qd.LineTo(x + w / 2, y + h)
            Qd.LineTo(x, y + h / 2)
        elif cmd == 'fdiamond':
            rect = self._convert_coordinates(entry[2])
            if not self._render_overlaprgn(rect):
                return
            x, y, x1, y1 = rect
            w = x1 - x
            h = y1 - y
            self._setfgcolor(entry[1])
            polyhandle = self._polyhandle([(x, y + h / 2), (x + w / 2, y),
                                           (x + w, y + h / 2),
                                           (x + w / 2, y + h), (x, y + h / 2)])
            if polyhandle: Qd.PaintPoly(polyhandle)
            self._restorecolors()
        elif cmd == '3ddiamond':
            rect = self._convert_coordinates(entry[2])
            if not self._render_overlaprgn(rect):
                return
            l, t, r, b = rect
            cl, ct, cr, cb = entry[1]
            w = r - l
            h = b - t
            r = l + w
            b = t + h
            x = l + w / 2
            y = t + h / 2
            n = int(3.0 * w / h + 0.5)
            ll = l + n
            tt = t + 3
            rr = r - n
            bb = b - 3

            self._setfgcolor(cl)
            polyhandle = self._polyhandle([(l, y), (x, t), (x, tt), (ll, y)],
                                          conv=0)
            if polyhandle: Qd.PaintPoly(polyhandle)

            self._setfgcolor(ct)
            polyhandle = self._polyhandle([(x, t), (r, y), (rr, y), (x, tt)],
                                          conv=0)
            if polyhandle: Qd.PaintPoly(polyhandle)

            self._setfgcolor(cr)
            polyhandle = self._polyhandle([(r, y), (x, b), (x, bb), (rr, y)],
                                          conv=0)
            if polyhandle: Qd.PaintPoly(polyhandle)

            self._setfgcolor(cb)
            polyhandle = self._polyhandle([(l, y), (ll, y), (x, bb), (x, b)],
                                          conv=0)
            if polyhandle: Qd.PaintPoly(polyhandle)

            self._restorecolors()
        elif cmd == 'arrow':
            color = entry[1]
            src = entry[2]
            dst = entry[3]
            x0, y0, x1, y1, points = self._arrowdata(src, dst)
            if not self._render_overlaprgn((x0, y0, x1, y1)):
                return

            self._setfgcolor(color)

            Qd.MoveTo(x0, y0)
            Qd.LineTo(x1, y1)
            polyhandle = self._polyhandle(points)
            if polyhandle: Qd.PaintPoly(polyhandle)
            self._restorecolors()
        else:
            raise 'Unknown displaylist command', cmd
        self._dbg_did = self._dbg_did + 1