def _redrawimage(self, rect, image_data): w, h, (pixmap, dataref) = image_data dl, dt, dr, db = rect # # If there is enough room center the image # if dr - dl > w: dl = dl + ((dr - dl) - w) / 2 dr = dl + w if db - dt > h: dt = dt + ((db - dt) - h) / 2 db = dt + h srcrect = 0, 0, w, h dstrect = dl, dt, dr, db fgcolor = self.wid.GetWindowPort().rgbFgColor bgcolor = self.wid.GetWindowPort().rgbBkColor Qd.RGBBackColor((0xffff, 0xffff, 0xffff)) Qd.RGBForeColor((0, 0, 0)) Qd.CopyBits(pixmap, self.wid.GetWindowPort().GetPortBitMapForCopyBits(), srcrect, dstrect, QuickDraw.srcCopy + QuickDraw.ditherCopy, None) Qd.RGBBackColor(bgcolor) Qd.RGBForeColor(fgcolor)
def draw(self, visRgn=None): if self._visible: (font, style, size, color) = self.fontsettings fontid = GetFNum(font) savestate = Qd.GetPenState() Qd.TextFont(fontid) Qd.TextFace(style) Qd.TextSize(size) Qd.RGBForeColor(color) Qd.RGBBackColor(self._backgroundcolor) TE.TETextBox(self.text, self._bounds, self.align) Qd.RGBBackColor((0xffff, 0xffff, 0xffff)) Qd.SetPenState(savestate)
def do_click(self, down, local, evt): (what, message, when, where, modifiers) = evt Qd.SetPort(self.wid) Qd.RGBBackColor(self.bg_color) if down: # Check for control ptype, ctl = Ctl.FindControl(local, self.wid) if ptype and ctl: if ptype in TRACKED_PARTS: dummy = ctl.TrackControl(local, self._scrollbarcallback) else: part = ctl.TrackControl(local) if part: self._scrollbarcallback(ctl, part) return # Remember, so we react to mouse-up next time self.last_mouse_was_down = 1 else: if not self.last_mouse_was_down: # Two ups in a row, # probably due to window-raise or something return self.last_mouse_was_down = 0 # Check for anchor if not self._cbanchor: return off, edge = self.ted.WEGetOffset(local) for i in range(len(self.anchor_offsets)): p0, p1 = self.anchor_offsets[i] if p0 <= off < p1: href = self.anchor_hrefs[i] self._cbanchor(href) return
def insert_plaintext(self, data): if data == '': self.must_clear = 1 self.wid.InvalWindowRect(self.rect) return self.must_clear = 0 Qd.SetPort(self.wid) Qd.RGBBackColor(self.bg_color) self.current_data_loaded = None # Remember where we are, and don't update Qd.SetPort(self.wid) self.ted.WESetSelection(0, 0x3fffffff) self.ted.WEDelete() self.ted.WEFeatureFlag(WASTEconst.weFInhibitRecal, 1) self.html_init() self.new_font([0, 0, 0, 1]) # Set typewriter font self.send_literal_data(data) # And insert the data. self.anchor_hrefs = [] pos = 0 self.ted.WESetSelection(pos, pos) ## self.ted.WESetSelection(0, 0) self.ted.WEFeatureFlag(WASTEconst.weFInhibitRecal, 0) self.wid.InvalWindowRect(self.rect) self._createscrollbars(reset=1)
def _doredraw(self, mustredraw): """Internal: do the actual computation, iff anything has changed since last time""" oldparameters = self.currentparameters self.currentparameters = self.transitiontype.computeparameters( self.value) if self.currentparameters == oldparameters and not mustredraw: return # All windows in the transition share their bitmaps, so we can pick any of them w = self.windows[0] dst = w._mac_getoswindowpixmap(mw_globals.BM_ONSCREEN) src_active = w._mac_getoswindowpixmap(mw_globals.BM_DRAWING) src_passive = w._mac_getoswindowpixmap(mw_globals.BM_PASSIVE) tmp = w._mac_getoswindowpixmap(mw_globals.BM_TEMP) if self.outtransition: src_old = src_active src_new = src_passive else: src_old = src_passive src_new = src_active w._mac_setwin(mw_globals.BM_ONSCREEN) Qd.RGBBackColor((0xffff, 0xffff, 0xffff)) Qd.RGBForeColor((0, 0, 0)) self.transitiontype.updatebitmap(self.currentparameters, src_new, src_old, tmp, dst, self.dstrgn) if self.verbatimrgn: Qd.CopyBits(src_active, dst, self.ltrb, self.ltrb, QuickDraw.srcCopy, self.verbatimrgn)
def do_moveresize(self, rect): l, t, r, b = rect self.rect = rect Qd.SetPort(self.wid) Qd.RGBBackColor(self.bg_color) vr = l + LEFTMARGIN, t + TOPMARGIN, r - RIGHTMARGIN, b - BOTTOMMARGIN self.ted.WESetViewRect(vr) self.wid.InvalWindowRect(self.rect) self._createscrollbars()
def _clear_html(self): Qd.SetPort(self.wid) Qd.RGBBackColor(self.bg_color) self.ted.WEFeatureFlag(WASTEconst.weFInhibitRecal, 1) self.ted.WESetSelection(0, 0x3fffffff) self.ted.WEDelete() self.ted.WEFeatureFlag(WASTEconst.weFInhibitRecal, 0) self.wid.InvalWindowRect(self.rect) self._createscrollbars(reset=1) self.anchor_offsets = [] self.current_data_loaded = None self.must_clear = 0
def do_update(self): if self.must_clear: self._clear_html() visregion = self.wid.GetWindowPort().visRgn myregion = Qd.NewRgn() Qd.RectRgn(myregion, self.rect) # or is it self.ted.WEGetViewRect() ? Qd.SectRgn(myregion, visregion, myregion) # Waste doesn't honour the clipping region, do it ourselves clipregion = Qd.NewRgn() Qd.GetClip(clipregion) Qd.SectRgn(myregion, clipregion, myregion) if Qd.EmptyRgn(myregion): return Qd.RGBBackColor(self.bg_color) Qd.RGBForeColor((0, 0xffff, 0)) # DBG Qd.EraseRgn(visregion) self.ted.WEUpdate(myregion)
def redraw(self, ctl, part): try: Qd.SetPort(self.wid) Qd.RGBBackColor((0xffff, 0xffff, 0xffff)) if self._background_image: self._redrawimage(self.rect, self._background_image) else: Qd.EraseRect(self.rect) Qd.RGBForeColor((0x7fff, 0x7fff, 0x7fff)) Qd.FrameRect(self.rect) for r in self.otherrects: Qd.RGBForeColor((0x0, 0x7fff, 0x7fff)) Qd.FrameRect(r) self.drawourrect() except: import traceback, sys exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, None) traceback.print_tb(exc_traceback)
def insert_html(self, data, url, tag=None): if data == '': self.must_clear = 1 self.wid.InvalWindowRect(self.rect) return self.must_clear = 0 Qd.SetPort(self.wid) Qd.RGBBackColor(self.bg_color) if data == self.current_data_loaded: self._position_html(tag) return self.current_data_loaded = data f = MyFormatter(self) # Remember where we are, and don't update Qd.SetPort(self.wid) self.ted.WESetSelection(0, 0x3fffffff) self.ted.WEDelete() self.ted.WEFeatureFlag(WASTEconst.weFInhibitRecal, 1) self.html_init() self.tag_positions = {} p = MyHTMLParser(f) p.url = url # Tell it the URL, for relative images p.feed(data) self.anchor_hrefs = p.anchorlist[:] # Restore updating, recalc, set focus if tag and self.tag_positions.has_key(tag): pos = self.tag_positions[tag] ## print 'DBG: start', tag, pos else: if tag: print 'Warning: no tag named', tag pos = 0 self.ted.WESetSelection(pos, pos) ## self.ted.WESetSelection(0, 0) self.ted.WEFeatureFlag(WASTEconst.weFInhibitRecal, 0) self.wid.InvalWindowRect(self.rect) self._createscrollbars(reset=1)
from Carbon import Qt
def newGIF(obj): handle = obj.WEGetObjectDataHandle() width, height, pixmap = _gifkeeper.get(handle.data) return width + 2 * IMAGEBORDER, height + 2 * IMAGEBORDER def drawGIF((l, t, r, b), obj): handle = obj.WEGetObjectDataHandle() width, height, pixmap = _gifkeeper.get(handle.data) srcrect = 0, 0, width, height dstrect = l + IMAGEBORDER, t + IMAGEBORDER, r - IMAGEBORDER, b - IMAGEBORDER port = Qd.GetPort() bg = port.rgbBkColor fg = port.rgbFgColor Qd.RGBBackColor((0xffff, 0xffff, 0xffff)) Qd.RGBForeColor((0, 0, 0)) ## Qd.CopyBits(pixmap, port.GetPortBitMapForCopyBits(), srcrect, dstrect, ## QuickDraw.srcCopy+QuickDraw.ditherCopy, None) Qd.CopyBits(pixmap, port.GetPortBitMapForCopyBits(), srcrect, dstrect, QuickDraw.srcCopy, None) Qd.RGBBackColor(bg) Qd.RGBForeColor(fg) # XXXX paste pixmap on screen return 0 def freeGIF(obj): handle = obj.WEGetObjectDataHandle() _gifkeeper.delete(handle.data) return 0
def _setblackwhitecolors(self): # For image draw Qd.RGBBackColor((0xffff, 0xffff, 0xffff)) Qd.RGBForeColor((0, 0, 0))
def _restorecolors(self): self._setfgcolor(self._fgcolor) bgcolor = self._bgcolor if bgcolor is None: bgcolor = (0, 0, 0) Qd.RGBBackColor(bgcolor)
'''