示例#1
0
 def __ensure_size(self, width, height):
     if not (width and height):
         return
     old_width, old_height = self.__buffer_size
     width = max(width, old_width)
     height = max(height, old_height)
     if not self.__setup:
         w = self.__area.get_window()
         self.__gc = w.new_gc()
         self.__cmap = w.colormap
         self.__setup = 1
         # surely there's a better way to get this?
         self.__depth = 24
     if (width, height) != self.__buffer_size or not self.__buffer:
         new_pixmap = _gtk.gdk_pixmap_new(
             None, width, height, self.__depth)
         gc = self.__gc
         if self.backgroundColor == piddle.transparent:
             self.backgroundColor = piddle.white
         c = self.__get_color(self.backgroundColor)
         gc.foreground = c
         y = (height + 1) / 2
         gc.line_width = int(y * 2)
         _gtk.gdk_draw_line(new_pixmap, gc, 0, y, width, y)
         if self.__buffer:
             # copy from old buffer to new buffer
             _gtk.gdk_draw_pixmap(new_pixmap, gc, self.__buffer,
                                  0, 0, 0, 0, old_width, old_height)
         self.__buffer = new_pixmap
         self.__buffer_size = self.size = (width, height)
         return new_pixmap
     else:
         return self.__buffer
示例#2
0
 def drawString(self, s, x, y, font=None, color=None, angle=0.0):
     if color == piddle.transparent:
         return
     if color is None:
         color = self.defaultLineColor
         if color == piddle.transparent:
             return
     if "\n" in s or "\r" in s:
         self.drawMultiLineString(s, x, y, font, color, angle)
         return
     angle = int(round(angle))
     if angle != 0:
         raise NotImplementedError, "rotated text not implemented"
     if font is None:
         font = self.defaultFont
     lines = string.split(s, "\n")
     gdk_font = _font_to_gdkfont(font)
     textwidth = gdk_font.measure(s)
     width = max(x, x + textwidth)
     height = max(y, y + gdk_font.descent)
     buffer = self.__ensure_size(width, height)
     gc = self.__gc
     gc.foreground = self.__get_color(color)
     #gc.font = gdk_font
     _gtk.gdk_draw_text(buffer, gdk_font, gc, x, y, s)
     if font.underline:
         gc.line_width = 1
         y = y + gdk_font.descent
         _gtk.gdk_draw_line(buffer, gc, x, y, x + textwidth, y)
示例#3
0
 def drawLine(self, x1, y1, x2, y2, color=None, width=None):
     # We could just call drawLines(), or drawLines() could call here,
     # but that would just get slow.
     if color == piddle.transparent:
         return
     if color is None:
         color = self.defaultLineColor
         if color == piddle.transparent:
             return
     if width is None:
         width = self.defaultLineWidth
     buffer = self.__ensure_size(x2+width, y2+width)
     gc = self.__gc
     gc.foreground = self.__get_color(color)
     gc.line_width = width
     _gtk.gdk_draw_line(buffer, gc, x1, y1, x2, y2)