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()
def __init__(self, window, rect, name, controlhandler=None): init_waste() self.last_mouse_was_down = 0 self.url = '' self.current_data_loaded = None self.tag_positions = {} self.bary = None self.anchor_offsets = [] self.anchor_hrefs = [] self.must_clear = 0 self.bg_color = (0xffff, 0xffff, 0xffff) self.fg_color = (0, 0, 0) self.an_color = (0xffff, 0, 0) self.font_normal = Fm.GetFNum('Times') self.font_tt = Fm.GetFNum('Courier') self.font_size = 12 self.name = name self.wid = window self.controlhandler = controlhandler l, t, r, b = rect self.rect = rect vr = l + LEFTMARGIN, t + TOPMARGIN, r - RIGHTMARGIN, b - BOTTOMMARGIN dr = (0, 0, vr[2] - vr[0], 0) Qd.SetPort(window) Qd.TextFont(4) Qd.TextSize(9) flags = WASTEconst.weDoAutoScroll | WASTEconst.weDoOutlineHilite self.ted = waste.WENew(dr, vr, flags) self._createscrollbars() self.do_activate()
def getfontsizes(name, sizes): exist = [] num = Fm.GetFNum(name) for sz in sizes: if Fm.RealFont(num, sz): exist.append(1) else: exist.append(0) return exist
def GetFNum(fontname): """Same as Fm.GetFNum(), but maps a missing font to Monaco instead of the system font.""" if fontname <> Fm.GetFontName(0): fontid = Fm.GetFNum(fontname) if fontid == 0: fontid = Fonts.monaco else: fontid = 0 return fontid
def __init__(self, fontname, pointsize): if not _fontmap.has_key(fontname): raise error, 'Font not found: ' + fontname self._fontnum = Fm.GetFNum(_fontmap[fontname][0]) self._fontface = _fontmap[fontname][1] self._pointsize = pointsize + _POINTSIZEOFFSET self._inited = 0
def getruninfo(self): all = (WASTEconst.weDoFont | WASTEconst.weDoFace | WASTEconst.weDoSize) dummy, mode, (font, face, size, color) = self.ted.WEContinuousStyle(all) if not (mode & WASTEconst.weDoFont): font = None else: font = Fm.GetFontName(font) if not (mode & WASTEconst.weDoFace): fact = None if not (mode & WASTEconst.weDoSize): size = None return font, face, size
def new_font(self, font): if font == None: font = (12, 0, 0, 0) font = map(lambda x: x, font) for i in range(len(font)): if font[i] == None: font[i] = self.html_font[i] [size, italic, bold, tt] = font self.html_font = font[:] if tt: font = Fm.GetFNum('Courier') else: font = Fm.GetFNum('Times') if HTML_SIZE.has_key(size): size = HTML_SIZE[size] else: size = 12 face = 0 if bold: face = face | 1 if italic: face = face | 2 face = face | self.html_style self.ted.WESetStyle( WASTEconst.weDoFont | WASTEconst.weDoFace | WASTEconst.weDoSize | WASTEconst.weDoColor, (font, face, size, self.html_color))
def drawtext(what=0): Qd.SetPort(splash) fontID = Fm.GetFNum("Python-Sans") if not fontID: fontID = geneva Qd.TextFont(fontID) Qd.TextSize(9) rect = (10, 115, _about_width - 10, _about_height - 30) if not what: import __main__ abouttxt = nl2return(abouttext1 % (__main__.__version__, sys.version, skipdoublereturns(sys.copyright))) else: import random abouttxt = nl2return(random.choice(flauwekul)) TE.TETextBox(abouttxt, rect, teJustCenter)
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)
def getfontnames(): names = [] for i in range(256): n = Fm.GetFontName(i) if n: names.append(n) return names
def menu_setfont(self, font): font = Fm.GetFNum(font) self.mysetstyle(WASTEconst.weDoFont, (font, 0, 0, (0, 0, 0))) self.parent.updatemenubar()
def GetPortFontSettings(port): return Fm.GetFontName(port.GetPortTextFont()), port.GetPortTextFace( ), port.GetPortTextSize()
tabsize = max(tabsize, 1) self.ted.WESetTabSize(tabsize) self.SetPort() Qd.EraseRect(self.ted.WEGetViewRect()) self.ted.WEUpdate(port.visRgn) def getfontsettings(self): from Carbon import Res (font, style, size, color) = self.ted.WEGetRunInfo(0)[4] font = Fm.GetFontName(font) return (font, style, size, color) def setfontsettings(self, (font, style, size, color)): self.SetPort() if type(font) <> StringType: font = Fm.GetFontName(font) self.fontsettings = (font, style, size, color) fontid = GetFNum(font) readonly = self.ted.WEFeatureFlag(WASTEconst.weFReadOnly, -1) if readonly: self.ted.WEFeatureFlag(WASTEconst.weFReadOnly, 0) try: self.ted.WEFeatureFlag(WASTEconst.weFInhibitRecal, 1) selstart, selend = self.ted.WEGetSelection() self.ted.WESetSelection(0, self.ted.WEGetTextLength()) self.ted.WESetStyle(WASTEconst.weDoFace, (0, 0, 0, (0, 0, 0))) self.ted.WESetStyle( WASTEconst.weDoFace | WASTEconst.weDoColor | WASTEconst.weDoFont | WASTEconst.weDoSize, (fontid, style, size, color)) self.ted.WEFeatureFlag(WASTEconst.weFInhibitRecal, 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)
# A minimal text editor.
def myDrawCell(self, onlyHilite, 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() l, t, r, b = cellRect if not onlyHilite: Qd.EraseRect(cellRect) ascent, descent, leading, size, hm = Fm.FontMetrics() linefeed = ascent + descent + leading if dataLen >= 6: data = theList.LGetCell(dataLen, theCell) iconId, indent, tab = struct.unpack("hhh", data[:6]) try: key, value = data[6:].split("\t", 1) except ValueError: # bogus data, at least don't crash. indent = 0 tab = 0 iconId = 0 key = "" value = data[6:] if iconId: try: theIcon = Icn.GetCIcon(iconId) except Icn.Error: pass else: rect = (0, 0, 16, 16) rect = Qd.OffsetRect(rect, l, t) rect = Qd.OffsetRect(rect, 0, (theList.cellSize[1] - (rect[3] - rect[1])) / 2) Icn.PlotCIcon(rect, theIcon) if len(key) >= 0: cl, ct, cr, cb = cellRect vl, vt, vr, vb = self._viewbounds cl = vl + PICTWIDTH + indent cr = vl + tab if cr > vr: cr = vr if cl < cr: drawTextCell(key, (cl, ct, cr, cb), ascent, theList) cl = vl + tab cr = vr if cl < cr: drawTextCell(value, (cl, ct, cr, cb), ascent, theList) #elif dataLen != 0: # drawTextCell("???", 3, cellRect, ascent, theList) else: return # we have bogus data # draw nice dotted line l, t, r, b = cellRect l = self._viewbounds[0] + tab r = l + 1; if not (theList.cellSize[1] & 0x01) or (t & 0x01): myPat = "\xff\x00\xff\x00\xff\x00\xff\x00" else: myPat = "\x00\xff\x00\xff\x00\xff\x00\xff" Qd.PenPat(myPat) Qd.PenMode(QuickDraw.srcCopy) Qd.PaintRect((l, t, r, b)) Qd.PenNormal() if selected or onlyHilite: l, t, r, b = cellRect l = self._viewbounds[0] + PICTWIDTH r = self._viewbounds[2] Qd.PenMode(hilitetransfermode) Qd.PaintRect((l, t, r, b)) # restore graphics environment Qd.SetPort(savedPort) Qd.SetClip(savedClip) Qd.DisposeRgn(savedClip) Qd.SetPenState(savedPenState)
def getfontsettings(self): from Carbon import Res (font, style, size, color) = self.ted.WEGetRunInfo(0)[4] font = Fm.GetFontName(font) return (font, style, size, color)