def expose( self, *args ): """Draw the widget """ if self.freeze_count > 0: return if not (self.flags() & gtk.REALIZED): return if not (self.flags() & gtk.MAPPED): return geom = self._area.get_allocation() pix = gtk.create_pixmap( self._area.get_window(), geom[2], geom[3] ) style = self.get_style() gtk.draw_rectangle(pix, style.white_gc, gtk.TRUE, 0, 0, geom[2], geom[3]) gtk.draw_rectangle(pix, style.black_gc, gtk.FALSE, 0, 0, geom[2], geom[3]) font = self.get_style().font v_offset = 0 for line in self.contents[self.start_line:]: v_offset = v_offset + self.line_height gtk.draw_string( pix, font, style.black_gc, 3, v_offset, line[self.start_col:] ) if v_offset > geom[3]: break self._area.draw_pixmap(style.white_gc, pix, 0, 0, 0, 0, geom[2]-1, geom[3]-1 ) return gtk.FALSE
def expose(self, *args): """Draw the widget """ if self.freeze_count > 0: return if not (self.flags() & gtk.REALIZED): return if not (self.flags() & gtk.MAPPED): return geom = self._area.get_allocation() pix = gtk.create_pixmap(self._area.get_window(), geom[2], geom[3]) style = self.get_style() gtk.draw_rectangle(pix, style.white_gc, gtk.TRUE, 0, 0, geom[2], geom[3]) gtk.draw_rectangle(pix, style.black_gc, gtk.FALSE, 0, 0, geom[2], geom[3]) font = self.get_style().font v_offset = 0 for line in self.contents[self.start_line:]: v_offset = v_offset + self.line_height gtk.draw_string(pix, font, style.black_gc, 3, v_offset, line[self.start_col:]) if v_offset > geom[3]: break self._area.draw_pixmap(style.white_gc, pix, 0, 0, 0, 0, geom[2] - 1, geom[3] - 1) return gtk.FALSE
def draw_background(self, win, pixmap): """draw the background. win is the window to use for defaults and pixmap is the pixmap to draw the back ground on. """ gtk.draw_rectangle(pixmap, win.get_style().black_gc, gtk.TRUE, 0, 0, win.get_window().width, win.get_window().height)
def configure_event(widget, event): global pixmap x, y, width, height = widget.get_allocation() pixmap = gtk.create_pixmap(widget.get_window(), width, height, -1) gtk.draw_rectangle(pixmap, widget.get_style().white_gc, gtk.TRUE, 0, 0, width, height) return gtk.TRUE
def draw(self, color): global pixmap global pixmapGC global drawingArea x = self.loc.x * WINDOW_WIDTH y = self.loc.y * WINDOW_HEIGHT pixmapGC.foreground = color pixmapGC.line_width = 2 gtk.draw_rectangle(pixmap, pixmapGC, gtk.FALSE, x-3, y-3, 6, 6) pixmapGC.foreground = whiteColor gtk.draw_string(pixmap, gtk.load_font("fixed"), pixmapGC, x+3, y-5, str(self.id)) drawingArea.queue_draw()
def draw(self, color): if (self.loc == None): print 'Cannot draw '+self.tostring() return global pixmap global pixmapGC global drawingArea x = (self.getlocation().x / SCALING) * WINDOW_WIDTH y = (self.getlocation().y / SCALING) * WINDOW_HEIGHT pixmapGC.foreground = color pixmapGC.line_width = 2 gtk.draw_rectangle(pixmap, pixmapGC, gtk.FALSE, x-3, y-3, 6, 6) pixmapGC.foreground = whiteColor gtk.draw_string(pixmap, gtk.load_font("fixed"), pixmapGC, x+3, y-5, str(self.id)) drawingArea.queue_draw()
def paint(self, region): area = self.area gc = area.get_window().new_gc() colormap = area.get_colormap() gc.foreground = colormap.alloc(0, 0, 0) _, _, aw, ah = area.get_allocation() if region: x, y, w, h = region else: w, h = aw, ah x = y = 0 self.createTransforms(aw, ah) gtk.draw_rectangle(self.scratch, gc, gtk.TRUE, x, y, w, h) mapSize = self.model.options.size inv = self.getInverse() if region: upleft = Point(x, y + h) downright = Point(x + w, y) else: upleft = Point(0, ah) downright = Point(aw, 0) min = inv(upleft) max = inv(downright) view = Rectangle(min.x, min.y, max.x - min.x, max.y - min.y) self.view = view os = self.model.objects[:] os.reverse() di = DrawInfo() di.gc = gc di.area = self.scratch di.scale = self.scale di.colormap = colormap di.canvas = self di.white_gc = area.get_style().white_gc tx2 = self.getTransform() for o in os: for wrap in self.wrapOffsets(view, o.getBounds()): tx = copy.copy(tx2) tx.translate(*wrap) di.tx = tx o.paint(di) area.draw_pixmap(area.get_style().fg_gc[gtk.STATE_NORMAL], self.scratch, x, y, x, y, w, h) return gtk.TRUE
def expose( self, *args ): """Draw the widget """ if not (self.flags() & gtk.REALIZED): return if len(self.col_widths) != len(self.titles): self.max_width = self.cell_full self.col_widths=[] for title in self.titles: col_width = self.title_font.width( title ) self.col_widths.append( col_width ) self.max_width = self.max_width + col_width + self.cell_full self. max_length = self.cell_full + \ ( len(self.titles) * ( self.row_height + self.cell_full ) ) # # pre-calculate half a cell spacing because we use it a lot # cell_half = self.cell_half cell_full = self.cell_full # # create a memory pixmap to render into # win = self._area.get_window() width = win.width height = win.height pix = self._pixmap # # prefetch the style # style = self.get_style() # # clear the pixmap # gtk.draw_rectangle( pix, style.white_gc, gtk.TRUE, 0, 0, width, height ) if self.source == None or self.source._o == None or len(self.source) == 0: msg = "NO DATA TO DISPLAY" msg_width = self.title_font.width( msg ) msg_height = self.title_font.height( msg ) msg_x = (width / 2) - (msg_width / 2) msg_y = (height / 2) + (msg_height / 2 ) gtk.draw_text( pix, self.title_font, style.fg_gc[gtk.STATE_INSENSITIVE], msg_x, msg_y, msg ) self._area.draw_pixmap(style.white_gc, self._pixmap, 0, 0, 0, 0, width, height ) return gtk.FALSE # # track changes in column width because of wide columns # bResetAdj = gtk.FALSE # # calculate the number of rows to draw # base_height = height title_height = self.title_height data_height = base_height - title_height disp_rows = int(data_height / ( self.row_height + 3 )) # # starting x for the the first column # x = cell_half first_row = self.start_row last_row = first_row + disp_rows first_col = self.start_col last_col = len(self.titles) # # loop through a column at a time # for i in range( first_col, last_col ): # # don't bother drawing if we're going to start past the right edge # if x > width: continue # # pre-calculate the column width for this draw # and remember the text values to draw # cells = [] # Info on whether or not shapes are selected (1 if selected) cell_is_selected = [] for j in range( first_row, last_row ): idx = self.grid2src(j) if idx == -1: continue txt = self.source[idx].get_property( self.titledict[self.titles[i]] ) if txt is None: txt = "" cell_width = self.cell_font.width( txt ) cells.append( (txt, cell_width) ) cell_is_selected.append(self.selected_shapes[idx]) if cell_width > self.col_widths[i]: bResetAdj = gtk.TRUE self.col_widths[i] = cell_width # # figure out the size and placement of the title text # y = self.title_height + cell_half title_width = self.title_font.width( self.titles[i] ) self.col_widths[i] = max( self.col_widths[i], title_width ) # # draw the 'button' # bx = x - cell_half + 1 by = y - self.title_height - cell_half bw = self.col_widths[i] + cell_full - 1 bh = self.title_height + cell_full gtk.draw_rectangle( pix, style.bg_gc[gtk.STATE_NORMAL], gtk.TRUE, bx, by, bw, bh) gtk.draw_line( pix, style.bg_gc[gtk.STATE_PRELIGHT], bx, by, bx, by + bh - 1 ) gtk.draw_line( pix, style.bg_gc[gtk.STATE_PRELIGHT], bx, by, bx + bw, by ) # # draw the title # tx = x + ( ( self.col_widths[i] - title_width ) / 2 ) gtk.draw_text( pix, self.title_font, style.fg_gc[gtk.STATE_NORMAL], tx, y, self.titles[i] ) # # draw the horizontal line below the title # ly = y + cell_half + 1 lx = x + self.col_widths[i] + cell_half - 1 gtk.draw_line( pix, style.fg_gc[gtk.STATE_INSENSITIVE], 0, ly - 1, lx, ly - 1 ) # Calculate total width of all cells sum_col_widths=0.0 for cwidth in self.col_widths: sum_col_widths = sum_col_widths + cwidth + self.cell_full # # draw the contents of the cells # for j in range( len(cells) ): if cell_is_selected[j] == 1 and i == first_col: gtk.draw_rectangle( pix, style.bg_gc[gtk.STATE_PRELIGHT], gtk.TRUE, 0, y + cell_half, sum_col_widths, self.row_height + cell_full ) elif self.current_row is not None and \ self.current_col is not None and \ self.current_row != 0 and \ self.current_col == i and \ j + max(self.start_row-1,0) == self.current_row - 1: gtk.draw_rectangle( pix, style.bg_gc[gtk.STATE_PRELIGHT], gtk.TRUE, x - cell_half, y + cell_half, self.col_widths[i] + cell_full, self.row_height + cell_full ) y = y + self.row_height + cell_full cx = x + self.col_widths[i] - cells[j][1] gtk.draw_text(pix, self.cell_font, style.fg_gc[gtk.STATE_NORMAL], cx, y, cells[j][0]) # # only draw the line under each row once, when we are drawing # the last column # if x + self.col_widths[i] + cell_full > width or \ i == last_col - 1: ly = y + cell_half + 1 lx = x + self.col_widths[i] + cell_half - 1 gtk.draw_line( pix, style.fg_gc[gtk.STATE_INSENSITIVE], 0, ly - 1, lx, ly - 1) # # where does the line go # ly = y + cell_half + 1 lx = x + self.col_widths[i] + cell_half # # special case for first column, start under the title row # if i == 0: gtk.draw_line( pix, style.fg_gc[gtk.STATE_INSENSITIVE], 0, bh , 0, ly - 1 ) # # draw the vertical lines to the right of each column # gtk.draw_line( pix, style.fg_gc[gtk.STATE_INSENSITIVE], lx, 1, lx , y + cell_half ) # #advance to next column # x = x + self.col_widths[i] + cell_full #draw the backing pixmap onto the screen self._area.draw_pixmap(style.white_gc, self._pixmap, 0, 0, 0, 0, width, height ) if bResetAdj or self.bCalcAdjustments: self.calc_adjustments() return gtk.FALSE
def draw_brush(widget, x, y): rect = (x - 5, y - 5, 10, 10) gtk.draw_rectangle(pixmap, widget.get_style().black_gc, gtk.TRUE, rect[0], rect[1], rect[2], rect[3]) widget.draw(rect)
def paint(self, di): c = copy.copy(self).transform(di.tx) gtk.draw_rectangle(di.area, di.gc, gtk.FALSE, c.x, c.y, c.width, c.height)
def clear(): pixmapGC.foreground = blackColor gtk.draw_rectangle(pixmap, pixmapGC, gtk.TRUE, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT) drawingArea.queue_draw()
def paint(self, di): gc = di.gc colormap = di.colormap tx = di.tx trans = [tx(p) for p in self.polygon.points] bounds = self.polygon.getBounds() if max(bounds.width, bounds.height) * di.canvas.scale > 30000: # gtk doesn't like getting coordinates bigger than 32767. # Those cause an illogical error message # "TypeError: sequence member not a 2-tuple" for p in trans: if p.x > 30000: p.x = 30000 elif p.x < -30000: p.x = -30000 if p.y > 30000: p.y = 30000 elif p.y < -30000: p.y = -30000 points = [(t.x, t.y) for t in trans] nofill = 1 if self.style.textured and di.canvas.textured: if self.style.texture.scalable: gc.tile = self.style.texture.image[di.scale * 64] else: gc.tile = self.style.texture.image[1] # !@# Should align the texture gc.fill = GDK.TILED nofill = 0 elif self.style.filled and di.canvas.filled: gc.foreground = colormap.alloc(*gcolor(self.style.color)) nofill = 0 if not nofill: gtk.draw_polygon(di.area, gc, gtk.TRUE, points) gc.fill = GDK.SOLID if self.edgeStyles is None: df = self.style.defaultEdgeStyle if df.style != LineStyle.STYLE_HIDDEN or nofill: gc.foreground = colormap.alloc(*gcolor(df.color)) gtk.draw_polygon(di.area, gc, gtk.FALSE, points) # !@# dashed lines, width missing here else: si = 0 cs = self.edgeStyles[0] for i in range(1, len(points)): if self.edgeStyles[i] == cs: continue lstyle = cs or self.style.defaultEdgeStyle if lstyle.style != LineStyle.STYLE_HIDDEN or nofill: gc.foreground = colormap.alloc(*gcolor(lstyle.color)) gtk.draw_lines(di.area, gc, points[si:i + 1]) si = i cs = self.edgeStyles[i] points2 = points[si:] points2.append(points[0]) lstyle = cs or self.style.defaultEdgeStyle if lstyle.style != LineStyle.STYLE_HIDDEN or nofill: gc.foreground = colormap.alloc(*gcolor(lstyle.color)) gtk.draw_lines(di.area, gc, points2) if di.canvas.showPoints: for p in points: gtk.draw_rectangle(di.area, di.white_gc, gtk.FALSE, p[0] - 1, p[1] - 1, 2, 2)
def paint(self, di): gc = di.gc colormap = di.colormap tx = di.tx trans = [tx(p) for p in self.polygon.points] bounds = self.polygon.getBounds() if max(bounds.width, bounds.height) * di.canvas.scale > 30000: # gtk doesn't like getting coordinates bigger than 32767. # Those cause an illogical error message # "TypeError: sequence member not a 2-tuple" for p in trans: if p.x > 30000: p.x = 30000 elif p.x < -30000: p.x = -30000 if p.y > 30000: p.y = 30000 elif p.y < -30000: p.y = -30000 points = [(t.x, t.y) for t in trans] nofill = 1 if self.style.textured and di.canvas.textured: if self.style.texture.scalable: gc.tile = self.style.texture.image[di.scale * 64] else: gc.tile = self.style.texture.image[1] # !@# Should align the texture gc.fill = GDK.TILED nofill = 0 elif self.style.filled and di.canvas.filled: gc.foreground = colormap.alloc(*gcolor(self.style.color)) nofill = 0 if not nofill: gtk.draw_polygon(di.area, gc, gtk.TRUE, points) gc.fill = GDK.SOLID if self.edgeStyles is None: df = self.style.defaultEdgeStyle if df.style != LineStyle.STYLE_HIDDEN or nofill: gc.foreground = colormap.alloc(*gcolor(df.color)) gtk.draw_polygon(di.area, gc, gtk.FALSE, points) # !@# dashed lines, width missing here else: si = 0 cs = self.edgeStyles[0] for i in range(1, len(points)): if self.edgeStyles[i] == cs: continue lstyle = cs or self.style.defaultEdgeStyle if lstyle.style != LineStyle.STYLE_HIDDEN or nofill: gc.foreground = colormap.alloc(*gcolor(lstyle.color)) gtk.draw_lines(di.area, gc, points[si:i+1]) si = i cs = self.edgeStyles[i] points2 = points[si:] points2.append(points[0]) lstyle = cs or self.style.defaultEdgeStyle if lstyle.style != LineStyle.STYLE_HIDDEN or nofill: gc.foreground = colormap.alloc(*gcolor(lstyle.color)) gtk.draw_lines(di.area, gc, points2) if di.canvas.showPoints: for p in points: gtk.draw_rectangle(di.area, di.white_gc, gtk.FALSE, p[0] - 1, p[1] - 1, 2, 2)
def expose(self, *args): """Draw the widget """ if not (self.flags() & gtk.REALIZED): return if len(self.col_widths) != len(self.titles): self.max_width = self.cell_full self.col_widths = [] for title in self.titles: col_width = self.title_font.width(title) self.col_widths.append(col_width) self.max_width = self.max_width + col_width + self.cell_full self. max_length = self.cell_full + \ ( len(self.titles) * ( self.row_height + self.cell_full ) ) # # pre-calculate half a cell spacing because we use it a lot # cell_half = self.cell_half cell_full = self.cell_full # # create a memory pixmap to render into # win = self._area.get_window() width = win.width height = win.height pix = self._pixmap # # prefetch the style # style = self.get_style() # # clear the pixmap # gtk.draw_rectangle(pix, style.white_gc, gtk.TRUE, 0, 0, width, height) if self.source == None or self.source._o == None or len( self.source) == 0: msg = "NO DATA TO DISPLAY" msg_width = self.title_font.width(msg) msg_height = self.title_font.height(msg) msg_x = (width / 2) - (msg_width / 2) msg_y = (height / 2) + (msg_height / 2) gtk.draw_text(pix, self.title_font, style.fg_gc[gtk.STATE_INSENSITIVE], msg_x, msg_y, msg) self._area.draw_pixmap(style.white_gc, self._pixmap, 0, 0, 0, 0, width, height) return gtk.FALSE # # track changes in column width because of wide columns # bResetAdj = gtk.FALSE # # calculate the number of rows to draw # base_height = height title_height = self.title_height data_height = base_height - title_height disp_rows = int(data_height / (self.row_height + 3)) # # starting x for the the first column # x = cell_half first_row = self.start_row last_row = first_row + disp_rows first_col = self.start_col last_col = len(self.titles) # # loop through a column at a time # for i in range(first_col, last_col): # # don't bother drawing if we're going to start past the right edge # if x > width: continue # # pre-calculate the column width for this draw # and remember the text values to draw # cells = [] # Info on whether or not shapes are selected (1 if selected) cell_is_selected = [] for j in range(first_row, last_row): idx = self.grid2src(j) if idx == -1: continue txt = self.source[idx].get_property( self.titledict[self.titles[i]]) if txt is None: txt = "" cell_width = self.cell_font.width(txt) cells.append((txt, cell_width)) cell_is_selected.append(self.selected_shapes[idx]) if cell_width > self.col_widths[i]: bResetAdj = gtk.TRUE self.col_widths[i] = cell_width # # figure out the size and placement of the title text # y = self.title_height + cell_half title_width = self.title_font.width(self.titles[i]) self.col_widths[i] = max(self.col_widths[i], title_width) # # draw the 'button' # bx = x - cell_half + 1 by = y - self.title_height - cell_half bw = self.col_widths[i] + cell_full - 1 bh = self.title_height + cell_full gtk.draw_rectangle(pix, style.bg_gc[gtk.STATE_NORMAL], gtk.TRUE, bx, by, bw, bh) gtk.draw_line(pix, style.bg_gc[gtk.STATE_PRELIGHT], bx, by, bx, by + bh - 1) gtk.draw_line(pix, style.bg_gc[gtk.STATE_PRELIGHT], bx, by, bx + bw, by) # # draw the title # tx = x + ((self.col_widths[i] - title_width) / 2) gtk.draw_text(pix, self.title_font, style.fg_gc[gtk.STATE_NORMAL], tx, y, self.titles[i]) # # draw the horizontal line below the title # ly = y + cell_half + 1 lx = x + self.col_widths[i] + cell_half - 1 gtk.draw_line(pix, style.fg_gc[gtk.STATE_INSENSITIVE], 0, ly - 1, lx, ly - 1) # Calculate total width of all cells sum_col_widths = 0.0 for cwidth in self.col_widths: sum_col_widths = sum_col_widths + cwidth + self.cell_full # # draw the contents of the cells # for j in range(len(cells)): if cell_is_selected[j] == 1 and i == first_col: gtk.draw_rectangle(pix, style.bg_gc[gtk.STATE_PRELIGHT], gtk.TRUE, 0, y + cell_half, sum_col_widths, self.row_height + cell_full) elif self.current_row is not None and \ self.current_col is not None and \ self.current_row != 0 and \ self.current_col == i and \ j + max(self.start_row-1,0) == self.current_row - 1: gtk.draw_rectangle(pix, style.bg_gc[gtk.STATE_PRELIGHT], gtk.TRUE, x - cell_half, y + cell_half, self.col_widths[i] + cell_full, self.row_height + cell_full) y = y + self.row_height + cell_full cx = x + self.col_widths[i] - cells[j][1] gtk.draw_text(pix, self.cell_font, style.fg_gc[gtk.STATE_NORMAL], cx, y, cells[j][0]) # # only draw the line under each row once, when we are drawing # the last column # if x + self.col_widths[i] + cell_full > width or \ i == last_col - 1: ly = y + cell_half + 1 lx = x + self.col_widths[i] + cell_half - 1 gtk.draw_line(pix, style.fg_gc[gtk.STATE_INSENSITIVE], 0, ly - 1, lx, ly - 1) # # where does the line go # ly = y + cell_half + 1 lx = x + self.col_widths[i] + cell_half # # special case for first column, start under the title row # if i == 0: gtk.draw_line(pix, style.fg_gc[gtk.STATE_INSENSITIVE], 0, bh, 0, ly - 1) # # draw the vertical lines to the right of each column # gtk.draw_line(pix, style.fg_gc[gtk.STATE_INSENSITIVE], lx, 1, lx, y + cell_half) # #advance to next column # x = x + self.col_widths[i] + cell_full #draw the backing pixmap onto the screen self._area.draw_pixmap(style.white_gc, self._pixmap, 0, 0, 0, 0, width, height) if bResetAdj or self.bCalcAdjustments: self.calc_adjustments() return gtk.FALSE