diff options
Diffstat (limited to 'Desenho.py')
-rw-r--r-- | Desenho.py | 695 |
1 files changed, 350 insertions, 345 deletions
@@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- """ -Desenho.py +@namespace Desenho -Pixmap manipulation + Pixmap manipulation Copyright 2007, NATE-LSI-EPUSP @@ -64,100 +64,99 @@ import pango WIDTH = 1195 HEIGHT = 800 - +##Pixmap manipulation class Desenho: - def __init__(self, d_): + def __init__(self, widget): """Initialize Desenho object. - Keyword arguments: - self -- Desenho.Desenho instance - d_ -- Area object (GtkDrawingArea) + @param self -- Desenho.Desenho instance + @param widget -- Area object (GtkDrawingArea) """ - self.d = d_ + #self.d = widget def line(self, widget, coords): """Draw line. - Keyword arguments: - self -- Desenho.Desenho instance - widget -- Area object (GtkDrawingArea) - coords -- Two value tuple + @param self -- Desenho.Desenho instance + @param widget -- Area object (GtkDrawingArea) + @param coords -- Two value tuple """ - width, height = self.d.window.get_size() - self.d.pixmap_temp.draw_drawable(self.d.gc,self.d.pixmap, 0 , 0 ,0,0, width, height) - self.d.pixmap_temp.draw_line(self.d.gc_line,self.d.oldx,self.d.oldy,coords[0],coords[1]) - #self.d.newx = coords[0] - #self.d.newy = coords[1] + width, height = widget.window.get_size() + widget.pixmap_temp.draw_drawable(widget.gc,widget.pixmap, 0 , 0 ,0,0, width, height) + widget.pixmap_temp.draw_line(widget.gc_line,widget.oldx,widget.oldy,coords[0],coords[1]) + #widget.newx = coords[0] + #widget.newy = coords[1] widget.queue_draw() def eraser(self, widget, coords, last, size = 30, shape = 'circle'): """Erase part of the drawing. - Keyword arguments: - self -- Desenho.Desenho instance - widget -- Area object (GtkDrawingArea) - coords -- Two value tuple - size -- integer (default 30) - shape -- string (default 'circle') + @param self -- Desenho.Desenho instance + @param last -- last of oldx + @param widget -- Area object (GtkDrawingArea) + @param coords -- Two value tuple + @param size -- integer (default 30) + @param shape -- string (default 'circle') """ - self.d.desenha = False + widget.desenha = False if(shape == 'circle'): - self.d.pixmap.draw_arc(self.d.gc_eraser, True, coords[0], coords[1], size, size, 0, 360*64) + widget.pixmap.draw_arc(widget.gc_eraser, True, coords[0], coords[1], size, size, 0, 360*64) if last[0] != -1: - self.d.gc_eraser.set_line_attributes(size, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND) - self.d.pixmap.draw_line(self.d.gc_eraser,last[0]+size/2,last[1]+size/2,coords[0]+size/2,coords[1]+size/2) - self.d.gc_eraser.set_line_attributes(0, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND) + widget.gc_eraser.set_line_attributes(size, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND) + widget.pixmap.draw_line(widget.gc_eraser,last[0]+size/2,last[1]+size/2,coords[0]+size/2,coords[1]+size/2) + widget.gc_eraser.set_line_attributes(0, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND) if(shape == 'square'): - self.d.pixmap.draw_rectangle(self.d.gc_eraser, True, coords[0], coords[1], size, size) + widget.pixmap.draw_rectangle(widget.gc_eraser, True, coords[0], coords[1], size, size) if last[0] != -1: points = [coords, last, (last[0]+size,last[1]+size), (coords[0]+size,coords[1]+size)] - self.d.pixmap.draw_polygon(self.d.gc_eraser,True,points) + widget.pixmap.draw_polygon(widget.gc_eraser,True,points) points = [(last[0]+size,last[1]), (coords[0]+size,coords[1]), (coords[0],coords[1]+size), (last[0],last[1]+size)] - self.d.pixmap.draw_polygon(self.d.gc_eraser,True,points) + widget.pixmap.draw_polygon(widget.gc_eraser,True,points) widget.queue_draw() def brush(self, widget, coords, last, size = 5, shape = 'circle'): """Paint with brush. - Keyword arguments: - self -- Desenho.Desenho instance - widget -- Area object (GtkDrawingArea) - coords -- Two value tuple - size -- integer (default 30) - shape -- string (default 'circle') + @param self -- Desenho.Desenho instance + @param last -- last of oldx + @param widget -- Area object (GtkDrawingArea) + @param coords -- Two value tuple + @param size -- integer (default 30) + @param shape -- string (default 'circle') """ - self.d.desenha = False + widget.desenha = False if(shape == 'circle'): - self.d.pixmap.draw_arc(self.d.gc_brush, True, coords[0], coords[1], size, size, 0, 360*64) + widget.pixmap.draw_arc(widget.gc_brush, True, coords[0], coords[1], size, size, 0, 360*64) if last[0] != -1: - self.d.gc_brush.set_line_attributes(size, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND) - self.d.pixmap.draw_line(self.d.gc_brush,last[0]+size/2,last[1]+size/2,coords[0]+size/2,coords[1]+size/2) - self.d.gc_brush.set_line_attributes(0, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND) + widget.gc_brush.set_line_attributes(size, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND) + widget.pixmap.draw_line(widget.gc_brush,last[0]+size/2,last[1]+size/2,coords[0]+size/2,coords[1]+size/2) + widget.gc_brush.set_line_attributes(0, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND) if(shape == 'square'): - self.d.pixmap.draw_rectangle(self.d.gc_brush, True, coords[0], coords[1], size, size) + widget.pixmap.draw_rectangle(widget.gc_brush, True, coords[0], coords[1], size, size) if last[0] != -1: points = [coords, last, (last[0]+size,last[1]+size), (coords[0]+size,coords[1]+size)] - self.d.pixmap.draw_polygon(self.d.gc_brush,True,points) + widget.pixmap.draw_polygon(widget.gc_brush,True,points) points = [(last[0]+size,last[1]), (coords[0]+size,coords[1]), (coords[0],coords[1]+size), (last[0],last[1]+size)] - self.d.pixmap.draw_polygon(self.d.gc_brush,True,points) + widget.pixmap.draw_polygon(widget.gc_brush,True,points) widget.queue_draw() def rainbow(self, widget, coords, last, color, size = 5, shape = 'circle'): """Paint with rainbow. - Keyword arguments: - self -- Desenho.Desenho instance - widget -- Area object (GtkDrawingArea) - coords -- Two value tuple - size -- integer (default 30) - shape -- string (default 'circle') + @param self -- Desenho.Desenho instance + @param last -- last of oldx + @param widget -- Area object (GtkDrawingArea) + @param color -- select the color adress + @param coords -- Two value tuple + @param size -- integer (default 30) + @param shape -- string (default 'circle') """ - colormap = self.d.get_colormap() + colormap = widget.get_colormap() rainbow_colors = [
colormap.alloc_color('#ff0000', True, True), # vermelho
colormap.alloc_color('#ff8000', True, True), # laranja
@@ -173,275 +172,278 @@ class Desenho: colormap.alloc_color('#ff0080', True, True), # violeta ] - self.d.gc_rainbow.set_foreground(rainbow_colors[color]) - self.d.desenha = False + widget.gc_rainbow.set_foreground(rainbow_colors[color]) + widget.desenha = False if(shape == 'circle'): - self.d.pixmap.draw_arc(self.d.gc_rainbow, True, coords[0], coords[1], size, size, 0, 360*64) + widget.pixmap.draw_arc(widget.gc_rainbow, True, coords[0], coords[1], size, size, 0, 360*64) if last[0] != -1: - self.d.gc_rainbow.set_line_attributes(size, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND) - self.d.pixmap.draw_line(self.d.gc_rainbow,last[0]+size/2,last[1]+size/2,coords[0]+size/2,coords[1]+size/2) - self.d.gc_rainbow.set_line_attributes(0, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND) + widget.gc_rainbow.set_line_attributes(size, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND) + widget.pixmap.draw_line(widget.gc_rainbow,last[0]+size/2,last[1]+size/2,coords[0]+size/2,coords[1]+size/2) + widget.gc_rainbow.set_line_attributes(0, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND) if(shape == 'square'): if last[0] != -1: - self.d.pixmap.draw_rectangle(self.d.gc_rainbow, True, last[0], last[1], size, size) + widget.pixmap.draw_rectangle(widget.gc_rainbow, True, last[0], last[1], size, size) points = [coords, last, (last[0]+size,last[1]+size), (coords[0]+size,coords[1]+size)] - self.d.pixmap.draw_polygon(self.d.gc_rainbow,True,points) + widget.pixmap.draw_polygon(widget.gc_rainbow,True,points) points = [(last[0]+size,last[1]), (coords[0]+size,coords[1]), (coords[0],coords[1]+size), (last[0],last[1]+size)] - self.d.pixmap.draw_polygon(self.d.gc_rainbow,True,points) - self.d.pixmap.draw_rectangle(self.d.gc_rainbow, True, coords[0], coords[1], size, size) + widget.pixmap.draw_polygon(widget.gc_rainbow,True,points) + widget.pixmap.draw_rectangle(widget.gc_rainbow, True, coords[0], coords[1], size, size) widget.queue_draw() def square(self, widget, coords, temp, fill): """Draw a square. - Keyword arguments: - self -- Desenho.Desenho instance - widget -- Area object (GtkDrawingArea) - coords -- Two value tuple + @param self -- Desenho.Desenho instance + @param widget -- Area object (GtkDrawingArea) + @param coords -- Two value tuple + @param temp -- switch between pixmap and pixmap_temp + @param fill -- Fill object """ if temp == True: - pixmap = self.d.pixmap_temp + pixmap = widget.pixmap_temp else: - pixmap = self.d.pixmap - width, height = self.d.window.get_size() + pixmap = widget.pixmap + width, height = widget.window.get_size() - dx = math.fabs(coords[0] - self.d.oldx) - dy = math.fabs(coords[1] - self.d.oldy) + dx = math.fabs(coords[0] - widget.oldx) + dy = math.fabs(coords[1] - widget.oldy) - if coords[0] < self.d.oldx: + if coords[0] < widget.oldx: x = coords[0] else: - x = self.d.oldx - if coords[1] < self.d.oldy: + x = widget.oldx + if coords[1] < widget.oldy: y = coords[1] else: - y = self.d.oldy + y = widget.oldy - pixmap.draw_drawable(self.d.gc,self.d.pixmap,0,0,0,0,width,height) + pixmap.draw_drawable(widget.gc,widget.pixmap,0,0,0,0,width,height) if fill == True: - pixmap.draw_rectangle(self.d.gc,True,x,y,dx,dy) - pixmap.draw_rectangle(self.d.gc_line,False,x,y,dx,dy) + pixmap.draw_rectangle(widget.gc,True,x,y,dx,dy) + pixmap.draw_rectangle(widget.gc_line,False,x,y,dx,dy) widget.queue_draw() def triangle(self, widget, coords, temp, fill): """Draw a triangle. - Keyword arguments: - self -- Desenho.Desenho instance - widget -- Area object (GtkDrawingArea) - coords -- Two value tuple + @param self -- Desenho.Desenho instance + @param widget -- Area object (GtkDrawingArea) + @param coords -- Two value tuple + @param temp -- switch between pixmap and pixmap_temp + @param fill -- Fill object """ if temp == True: - pixmap = self.d.pixmap_temp + pixmap = widget.pixmap_temp else: - pixmap = self.d.pixmap - width, height = self.d.window.get_size() + pixmap = widget.pixmap + width, height = widget.window.get_size() - points = [(self.d.oldx,self.d.oldy), (self.d.oldx+int((coords[0]-self.d.oldx)/2),coords[1]), (coords[0],self.d.oldy)] - pixmap.draw_drawable(self.d.gc,self.d.pixmap,0,0,0,0,width,height) + points = [(widget.oldx,widget.oldy), (widget.oldx+int((coords[0]-widget.oldx)/2),coords[1]), (coords[0],widget.oldy)] + pixmap.draw_drawable(widget.gc,widget.pixmap,0,0,0,0,width,height) if fill == True: - pixmap.draw_polygon(self.d.gc,True,points) - pixmap.draw_polygon(self.d.gc_line,False,points) + pixmap.draw_polygon(widget.gc,True,points) + pixmap.draw_polygon(widget.gc_line,False,points) widget.queue_draw() def trapezoid(self, widget, coords, temp, fill): """Draw a trapezoid. - Keyword arguments: - self -- Desenho.Desenho instance - widget -- Area object (GtkDrawingArea) - coords -- Two value tuple + @param self -- Desenho.Desenho instance + @param widget -- Area object (GtkDrawingArea) + @param coords -- Two value tuple + @param temp -- switch between pixmap and pixmap_temp + @param fill -- Fill object """ if temp == True: - pixmap = self.d.pixmap_temp + pixmap = widget.pixmap_temp else: - pixmap = self.d.pixmap - width, height = self.d.window.get_size() + pixmap = widget.pixmap + width, height = widget.window.get_size() - dif = int((coords[0] - self.d.oldx)/4) - points = [(self.d.oldx, self.d.oldy), (self.d.oldx+dif, coords[1]), (coords[0]-dif, coords[1]) , (coords[0],self.d.oldy)] - pixmap.draw_drawable(self.d.gc,self.d.pixmap,0,0,0,0,width,height) + dif = int((coords[0] - widget.oldx)/4) + points = [(widget.oldx, widget.oldy), (widget.oldx+dif, coords[1]), (coords[0]-dif, coords[1]) , (coords[0],widget.oldy)] + pixmap.draw_drawable(widget.gc,widget.pixmap,0,0,0,0,width,height) if fill == True: - pixmap.draw_polygon(self.d.gc, True, points) - pixmap.draw_polygon(self.d.gc_line,False,points) + pixmap.draw_polygon(widget.gc, True, points) + pixmap.draw_polygon(widget.gc_line,False,points) widget.queue_draw() def arrow(self, widget, coords, temp, fill): """Draw a arrow. - Keyword arguments: - self -- Desenho.Desenho instance - widget -- Area object (GtkDrawingArea) - coords -- Two value tuple + @param self -- Desenho.Desenho instance + @param widget -- Area object (GtkDrawingArea) + @param coords -- Two value tuple + @param temp -- switch between pixmap and pixmap_temp + @param fill -- Fill object """ if temp == True: - pixmap = self.d.pixmap_temp + pixmap = widget.pixmap_temp else: - pixmap = self.d.pixmap - width, height = self.d.window.get_size() - - x = coords[0] - self.d.oldx - y = coords[1] - self.d.oldy - points = [(self.d.oldx,self.d.oldy),\ -(self.d.oldx+int(x/6),self.d.oldy+y),\ -(self.d.oldx+int(x/6),self.d.oldy+int(y/3)),\ -(self.d.oldx+x,self.d.oldy+int(y/3)),\ -(self.d.oldx+x,self.d.oldy-int(y/3)),\ -(self.d.oldx+int(x/6),self.d.oldy-int(y/3)),\ -(self.d.oldx+int(x/6),self.d.oldy-y)] - pixmap.draw_drawable(self.d.gc,self.d.pixmap,0,0,0,0,width,height) + pixmap = widget.pixmap + width, height = widget.window.get_size() + + x = coords[0] - widget.oldx + y = coords[1] - widget.oldy + points = [(widget.oldx,widget.oldy),\ +(widget.oldx+int(x/6),widget.oldy+y),\ +(widget.oldx+int(x/6),widget.oldy+int(y/3)),\ +(widget.oldx+x,widget.oldy+int(y/3)),\ +(widget.oldx+x,widget.oldy-int(y/3)),\ +(widget.oldx+int(x/6),widget.oldy-int(y/3)),\ +(widget.oldx+int(x/6),widget.oldy-y)] + pixmap.draw_drawable(widget.gc,widget.pixmap,0,0,0,0,width,height) if fill == True: - pixmap.draw_polygon(self.d.gc,True,points) - pixmap.draw_polygon(self.d.gc_line,False,points) + pixmap.draw_polygon(widget.gc,True,points) + pixmap.draw_polygon(widget.gc_line,False,points) widget.queue_draw() def parallelogram(self, widget, coords, temp, fill): """Draw a parallelogram. - Keyword arguments: - self -- Desenho.Desenho instance - widget -- Area object (GtkDrawingArea) - coords -- Two value tuple - + @param self -- Desenho.Desenho instance + @param widget -- Area object (GtkDrawingArea) + @param coords -- Two value tuple + @param temp -- switch between pixmap and pixmap_temp + @param fill -- Fill object """ if temp == True: - pixmap = self.d.pixmap_temp + pixmap = widget.pixmap_temp else: - pixmap = self.d.pixmap - width, height = self.d.window.get_size() + pixmap = widget.pixmap + width, height = widget.window.get_size() - x = int((coords[0] - self.d.oldx)/4) - points = [(self.d.oldx,self.d.oldy), (coords[0]-x, self.d.oldy), (coords[0],coords[1]), (self.d.oldx+x,coords[1])] - pixmap.draw_drawable(self.d.gc,self.d.pixmap,0,0,0,0,width,height) + x = int((coords[0] - widget.oldx)/4) + points = [(widget.oldx,widget.oldy), (coords[0]-x, widget.oldy), (coords[0],coords[1]), (widget.oldx+x,coords[1])] + pixmap.draw_drawable(widget.gc,widget.pixmap,0,0,0,0,width,height) if fill == True: - pixmap.draw_polygon(self.d.gc,True,points) - pixmap.draw_polygon(self.d.gc_line,False,points) + pixmap.draw_polygon(widget.gc,True,points) + pixmap.draw_polygon(widget.gc_line,False,points) widget.queue_draw() def star(self, widget, coords, n, temp, fill): """Draw polygon with n sides. - Keyword arguments: - self -- Desenho.Desenho instance - widget -- Area object (GtkDrawingArea) - coords -- Two value tuple - n -- number of sides - temp -- switch between pixmap and pixmap_temp + @param self -- Desenho.Desenho instance + @param widget -- Area object (GtkDrawingArea) + @param coords -- Two value tuple + @param n -- number of sides + @param temp -- switch between pixmap and pixmap_temp + @param fill -- Fill object """ if temp == True: - pixmap = self.d.pixmap_temp + pixmap = widget.pixmap_temp else: - pixmap = self.d.pixmap - width, height = self.d.window.get_size() + pixmap = widget.pixmap + width, height = widget.window.get_size() - x = coords[0] - self.d.oldx - y = coords[1] - self.d.oldy + x = coords[0] - widget.oldx + y = coords[1] - widget.oldy A = math.atan2(y,x) dA = 2*math.pi/n r = math.hypot(y,x) - p = [(self.d.oldx+int(r*math.cos(A)),self.d.oldy+int(r*math.sin(A))),\ - (self.d.oldx+int(0.4*r*math.cos(A+dA/2)),self.d.oldy+int(0.4*r*math.sin(A+dA/2)))] + p = [(widget.oldx+int(r*math.cos(A)),widget.oldy+int(r*math.sin(A))),\ + (widget.oldx+int(0.4*r*math.cos(A+dA/2)),widget.oldy+int(0.4*r*math.sin(A+dA/2)))] for i in range(n-1): A = A+dA - p.append((self.d.oldx+int(r*math.cos(A)),self.d.oldy+int(r*math.sin(A)))) - p.append((self.d.oldx+int(0.4*r*math.cos(A+dA/2)),self.d.oldy+int(0.4*r*math.sin(A+dA/2)))) + p.append((widget.oldx+int(r*math.cos(A)),widget.oldy+int(r*math.sin(A)))) + p.append((widget.oldx+int(0.4*r*math.cos(A+dA/2)),widget.oldy+int(0.4*r*math.sin(A+dA/2)))) tp = tuple(p) - pixmap.draw_drawable(self.d.gc,self.d.pixmap,0,0,0,0,width,height) + pixmap.draw_drawable(widget.gc,widget.pixmap,0,0,0,0,width,height) if fill == True: - pixmap.draw_polygon(self.d.gc,True,tp) - pixmap.draw_polygon(self.d.gc_line,False,tp) + pixmap.draw_polygon(widget.gc,True,tp) + pixmap.draw_polygon(widget.gc_line,False,tp) widget.queue_draw() def polygon_regular(self, widget, coords, n, temp, fill): """Draw polygon with n sides. - Keyword arguments: - self -- Desenho.Desenho instance - widget -- Area object (GtkDrawingArea) - coords -- Two value tuple - n -- number of sides - temp -- switch between pixmap and pixmap_temp + @param self -- Desenho.Desenho instance + @param widget -- Area object (GtkDrawingArea) + @param coords -- Two value tuple + @param n -- number of sides + @param temp -- switch between pixmap and pixmap_temp + @param fill -- Fill object """ if temp == True: - pixmap = self.d.pixmap_temp + pixmap = widget.pixmap_temp else: - pixmap = self.d.pixmap - width, height = self.d.window.get_size() + pixmap = widget.pixmap + width, height = widget.window.get_size() - x = coords[0] - self.d.oldx - y = coords[1] - self.d.oldy + x = coords[0] - widget.oldx + y = coords[1] - widget.oldy A = math.atan2(y,x) dA = 2*math.pi/n r = math.hypot(y,x) - p = [(self.d.oldx+int(r*math.cos(A)),self.d.oldy+int(r*math.sin(A)))] + p = [(widget.oldx+int(r*math.cos(A)),widget.oldy+int(r*math.sin(A)))] for i in range(n-1): A = A+dA - p.append((self.d.oldx+int(r*math.cos(A)),self.d.oldy+int(r*math.sin(A)))) + p.append((widget.oldx+int(r*math.cos(A)),widget.oldy+int(r*math.sin(A)))) tp = tuple(p) - pixmap.draw_drawable(self.d.gc,self.d.pixmap,0,0,0,0,width,height) + pixmap.draw_drawable(widget.gc,widget.pixmap,0,0,0,0,width,height) if fill == True: - pixmap.draw_polygon(self.d.gc,True,tp) - pixmap.draw_polygon(self.d.gc_line,False,tp) + pixmap.draw_polygon(widget.gc,True,tp) + pixmap.draw_polygon(widget.gc_line,False,tp) widget.queue_draw() def heart(self, widget, coords, temp, fill): """Draw polygon with n sides. - Keyword arguments: - self -- Desenho.Desenho instance - widget -- Area object (GtkDrawingArea) - coords -- Two value tuple - n -- number of sides - temp -- switch between pixmap and pixmap_temp + @param self -- Desenho.Desenho instance + @param widget -- Area object (GtkDrawingArea) + @param coords -- Two value tuple + @param temp -- switch between pixmap and pixmap_temp + @param fill -- Fill object """ if temp == True: - pixmap = self.d.pixmap_temp + pixmap = widget.pixmap_temp else: - pixmap = self.d.pixmap - width, height = self.d.window.get_size() + pixmap = widget.pixmap + width, height = widget.window.get_size() - if coords[0] < self.d.oldx: + if coords[0] < widget.oldx: x = coords[0] else: - x = self.d.oldx - if coords[1] < self.d.oldy: + x = widget.oldx + if coords[1] < widget.oldy: y = coords[1] else: - y = self.d.oldy + y = widget.oldy - dx = math.fabs(coords[0] - self.d.oldx) - dy = math.fabs(coords[1] - self.d.oldy) + dx = math.fabs(coords[0] - widget.oldx) + dy = math.fabs(coords[1] - widget.oldy) w=int(4*dx) e=int(4*dx/math.sqrt(3)) - pixmap.draw_drawable(self.d.gc,self.d.pixmap,0,0,0,0,width,height) + pixmap.draw_drawable(widget.gc,widget.pixmap,0,0,0,0,width,height) if fill == True: - pixmap.draw_arc(self.d.gc,True,int(self.d.oldx-dx),int(self.d.oldy-e/2),w,e,180*64,60*64) - pixmap.draw_arc(self.d.gc,True,int(self.d.oldx-3*dx),int(self.d.oldy-e/2),w,e,300*64,60*64) - pixmap.draw_arc(self.d.gc,True,int(self.d.oldx-dx*0.2),int(self.d.oldy-0.6*dx+2),int(1.2*dx),int(1.2*dx),0,180*64) - pixmap.draw_arc(self.d.gc,True,int(self.d.oldx-dx),int(self.d.oldy-0.6*dx+2),int(1.2*dx),int(1.2*dx),0,180*64) - pixmap.draw_arc(self.d.gc_line,False,int(self.d.oldx-dx),int(self.d.oldy-e/2),w,e,180*64,60*64) - pixmap.draw_arc(self.d.gc_line,False,int(self.d.oldx-dx-w/2),int(self.d.oldy-e/2),w,e,300*64,60*64) - pixmap.draw_arc(self.d.gc_line,False,int(self.d.oldx-dx*0.2),int(self.d.oldy-0.6*dx+2),int(1.2*dx),int(1.2*dx),0,132*64) - pixmap.draw_arc(self.d.gc_line,False,int(self.d.oldx-dx),int(self.d.oldy-0.6*dx+2),int(1.2*dx),int(1.2*dx),48*64,132*64) + pixmap.draw_arc(widget.gc,True,int(widget.oldx-dx),int(widget.oldy-e/2),w,e,180*64,60*64) + pixmap.draw_arc(widget.gc,True,int(widget.oldx-3*dx),int(widget.oldy-e/2),w,e,300*64,60*64) + pixmap.draw_arc(widget.gc,True,int(widget.oldx-dx*0.2),int(widget.oldy-0.6*dx+2),int(1.2*dx),int(1.2*dx),0,180*64) + pixmap.draw_arc(widget.gc,True,int(widget.oldx-dx),int(widget.oldy-0.6*dx+2),int(1.2*dx),int(1.2*dx),0,180*64) + pixmap.draw_arc(widget.gc_line,False,int(widget.oldx-dx),int(widget.oldy-e/2),w,e,180*64,60*64) + pixmap.draw_arc(widget.gc_line,False,int(widget.oldx-dx-w/2),int(widget.oldy-e/2),w,e,300*64,60*64) + pixmap.draw_arc(widget.gc_line,False,int(widget.oldx-dx*0.2),int(widget.oldy-0.6*dx+2),int(1.2*dx),int(1.2*dx),0,132*64) + pixmap.draw_arc(widget.gc_line,False,int(widget.oldx-dx),int(widget.oldy-0.6*dx+2),int(1.2*dx),int(1.2*dx),48*64,132*64) widget.queue_draw() @@ -449,113 +451,109 @@ class Desenho: def circle(self, widget, coords, temp, fill): """Draw a circle. - Keyword arguments: - self -- Desenho.Desenho instance - widget -- Area object (GtkDrawingArea) - coords -- Two value tuple + @param self -- Desenho.Desenho instance + @param widget -- Area object (GtkDrawingArea) + @param coords -- Two value tuple + @param temp -- switch between pixmap and pixmap_temp + @param fill -- Fill object """ if temp == True: - pixmap = self.d.pixmap_temp + pixmap = widget.pixmap_temp else: - pixmap = self.d.pixmap - width, height = self.d.window.get_size() + pixmap = widget.pixmap + width, height = widget.window.get_size() - if coords[0] < self.d.oldx: + if coords[0] < widget.oldx: x = coords[0] else: - x = self.d.oldx - if coords[1] < self.d.oldy: + x = widget.oldx + if coords[1] < widget.oldy: y = coords[1] else: - y = self.d.oldy + y = widget.oldy - dx = math.fabs(coords[0] - self.d.oldx) - dy = math.fabs(coords[1] - self.d.oldy) + dx = math.fabs(coords[0] - widget.oldx) + dy = math.fabs(coords[1] - widget.oldy) - pixmap.draw_drawable(self.d.gc,self.d.pixmap,0,0,0,0,width,height) + pixmap.draw_drawable(widget.gc,widget.pixmap,0,0,0,0,width,height) if fill == True: - pixmap.draw_arc(self.d.gc,True,x,y,dx,dy,0,360*64) - pixmap.draw_arc(self.d.gc_line,False,x,y,dx,dy,0,360*64) + pixmap.draw_arc(widget.gc,True,x,y,dx,dy,0,360*64) + pixmap.draw_arc(widget.gc_line,False,x,y,dx,dy,0,360*64) widget.queue_draw() def pencil(self, widget, coords): """Draw a pencil. - Keyword arguments: - self -- Desenho.Desenho instance - widget -- Area object (GtkDrawingArea) - coords -- Two value tuple + @param self -- Desenho.Desenho instance + @param widget -- Area object (GtkDrawingArea) + @param coords -- Two value tuple """ - width, height = self.d.window.get_size() - self.d.pixmap_temp.draw_drawable(self.d.gc,self.d.pixmap, 0 , 0 ,0,0, width, height) - self.d.pixmap.draw_line(self.d.gc_line,self.d.oldx,self.d.oldy,coords[0],coords[1]) - self.d.oldx = coords[0] - self.d.oldy = coords[1] + width, height = widget.window.get_size() + widget.pixmap_temp.draw_drawable(widget.gc,widget.pixmap, 0 , 0 ,0,0, width, height) + widget.pixmap.draw_line(widget.gc_line,widget.oldx,widget.oldy,coords[0],coords[1]) + widget.oldx = coords[0] + widget.oldy = coords[1] widget.queue_draw() def clear(self): """Clear the drawing. - Keyword arguments: - self -- Desenho.Desenho instance + @param self -- Desenho.Desenho instance """ width, height = self.d.window.get_size() - self.d.desenho = [] - self.d.textos = [] - self.d.pixmap.draw_rectangle(self.d.get_style().white_gc, True,0, 0, width, height) - self.d.pixmap_temp.draw_rectangle(self.d.get_style().white_gc, True,0, 0, width, height) - self.d.queue_draw() + widget.desenho = [] + widget.textos = [] + widget.pixmap.draw_rectangle(widget.get_style().white_gc, True,0, 0, width, height) + widget.pixmap_temp.draw_rectangle(widget.get_style().white_gc, True,0, 0, width, height) + widget.queue_draw() def text(self,widget,event): - """Make a selection. + """Display and draw text in the drawing area. - Keyword arguments: - self -- Desenho.Desenho instance - widget -- Area object (GtkDrawingArea) - event -- GdkEvent + @param self -- Desenho.Desenho instance + @param widget -- Area object (GtkDrawingArea) + @param event -- GdkEvent """ - - #print self.d.estadoTexto - if self.d.estadoTexto == 0: - self.d.estadoTexto = 1 + if widget.estadoTexto == 0: + widget.estadoTexto = 1 - self.d.janela._fixed.move(self.d.janela._textview, int(event.x)+200, int(event.y)+100) + widget.janela._fixed.move(widget.janela._textview, int(event.x)+200, int(event.y)+100) # Area size has changed... - #self.d.janela._fixed.move(self.d.janela._textview, int(event.x), int(event.y)) - self.d.janela._textview.show() - self.d.janela._textview.grab_focus() + #widget.janela._fixed.move(widget.janela._textview, int(event.x), int(event.y)) + widget.janela._textview.show() + widget.janela._textview.grab_focus() else: - self.d.estadoTexto = 0 + widget.estadoTexto = 0 try: # This works for a gtk.Entry - text = self.d.janela._textview.get_text() + text = widget.janela._textview.get_text() except AttributeError: # This works for a gtk.TextView - buf = self.d.janela._textview.get_buffer() + buf = widget.janela._textview.get_buffer() start, end = buf.get_bounds() text = buf.get_text(start, end) - layout = self.d.create_pango_layout(text) - #layout.set_font_description(self.d.font) + layout = widget.create_pango_layout(text) + #layout.set_font_description(widget.font) - self.d.pixmap.draw_layout(self.d.gc, self.d.oldx, self.d.oldy, layout) - self.d.pixmap_temp.draw_layout(self.d.gc, self.d.oldx, self.d.oldy, layout) - self.d.janela._textview.hide() + widget.pixmap.draw_layout(widget.gc, widget.oldx, widget.oldy, layout) + widget.pixmap_temp.draw_layout(widget.gc, widget.oldx, widget.oldy, layout) + widget.janela._textview.hide() try: - self.d.janela._textview.set_text('') + widget.janela._textview.set_text('') except AttributeError: buf.set_text('') - self.d.enableUndo(widget) + widget.enableUndo(widget) widget.queue_draw() @@ -563,178 +561,185 @@ class Desenho: def selection(self, widget, coords, temp, fill): """Make a selection. - Keyword arguments: - self -- Desenho.Desenho instance - widget -- Area object (GtkDrawingArea) - coords -- Two value tuple + @param self -- Desenho.Desenho instance + @param widget -- Area object (GtkDrawingArea) + @param coords -- Two value tuple + @param temp -- switch between pixmap and pixmap_temp + @param fill -- Fill object + + @return (x0,y0,x1,y1) -- coords of corners """ if temp == True: - pixmap = self.d.pixmap_temp + pixmap = widget.pixmap_temp else: - pixmap = self.d.pixmap - width, height = self.d.window.get_size() + pixmap = widget.pixmap + width, height = widget.window.get_size() - dx = int(math.fabs(coords[0] - self.d.oldx)) - dy = int(math.fabs(coords[1] - self.d.oldy)) + dx = int(math.fabs(coords[0] - widget.oldx)) + dy = int(math.fabs(coords[1] - widget.oldy)) - if coords[0] < self.d.oldx: + if coords[0] < widget.oldx: x = int(coords[0]) else: - x = self.d.oldx - if coords[1] < self.d.oldy: + x = widget.oldx + if coords[1] < widget.oldy: y = int(coords[1]) else: - y = self.d.oldy + y = widget.oldy - pixmap.draw_drawable(self.d.gc,self.d.pixmap,0,0,0,0,width,height) + pixmap.draw_drawable(widget.gc,widget.pixmap,0,0,0,0,width,height) if fill: - pixmap.draw_rectangle(self.d.gc,True,x,y,dx,dy) + pixmap.draw_rectangle(widget.gc,True,x,y,dx,dy) - pixmap.draw_rectangle(self.d.gc_selection,False,x,y,dx,dy) - pixmap.draw_rectangle(self.d.gc_selection1,False,x-1,y-1,dx+2,dy+2) + pixmap.draw_rectangle(widget.gc_selection,False,x,y,dx,dy) + pixmap.draw_rectangle(widget.gc_selection1,False,x-1,y-1,dx+2,dy+2) widget.queue_draw() return x,y,x+dx,y+dy def moveSelection(self, widget, coords, mvcopy=False, pixbuf_copy=None): + self.draw_widget = widget """Move the selection. - Keyword arguments: - self -- Desenho.Desenho instance - widget -- Area object (GtkDrawingArea) - coords -- Two value tuple + @param self -- Desenho.Desenho instance + @param widget -- Area object (GtkDrawingArea) + @param coords -- Two value tuple + @param mvcopy -- Copy or Move + @param pixbuf_copy -- For import image """ - width, height = self.d.window.get_size() + width, height = widget.window.get_size() - self.d.pixmap_sel.draw_drawable(self.d.gc,self.d.pixmap,0,0,0,0, width, height) + widget.pixmap_sel.draw_drawable(widget.gc,widget.pixmap,0,0,0,0, width, height) - if self.d.sx > self.d.oldx: - x0 = int(self.d.oldx) + if widget.sx > widget.oldx: + x0 = int(widget.oldx) else: - x0 = int(self.d.sx) + x0 = int(widget.sx) - if self.d.sy > self.d.oldy: - y0 = int(self.d.oldy) + if widget.sy > widget.oldy: + y0 = int(widget.oldy) else: - y0 = int(self.d.sy) + y0 = int(widget.sy) - w = int(math.fabs(self.d.sx - self.d.oldx)) - h = int(math.fabs(self.d.sy - self.d.oldy)) + w = int(math.fabs(widget.sx - widget.oldx)) + h = int(math.fabs(widget.sy - widget.oldy)) - self.d._set_selection_bounds(coords[0]-w/2, coords[1]-h/2, coords[0]+w/2, coords[1]+h/2) + widget._set_selection_bounds(coords[0]-w/2, coords[1]-h/2, coords[0]+w/2, coords[1]+h/2) if not mvcopy: - self.d.pixmap_sel.draw_rectangle(self.d.get_style().white_gc, True, x0, y0, w, h) + widget.pixmap_sel.draw_rectangle(widget.get_style().white_gc, True, x0, y0, w, h) - if pixbuf_copy!=None: #to import or past image - self.d.pixmap_sel.draw_pixbuf(self.d.gc, pixbuf_copy, 0, 0, coords[0] - w/2, coords[1]- h/2, w, h, dither=gtk.gdk.RGB_DITHER_NORMAL, x_dither=0, y_dither=0) - self.d.pixmap_temp.draw_pixbuf(self.d.gc, pixbuf_copy, 0, 0, coords[0] - w/2, coords[1]- h/2, w, h, dither=gtk.gdk.RGB_DITHER_NORMAL, x_dither=0, y_dither=0) + if pixbuf_copy!=None: #to import or paste image + widget.pixmap_sel.draw_pixbuf(widget.gc, pixbuf_copy, 0, 0, coords[0] - w/2, coords[1]- h/2, w, h, dither=gtk.gdk.RGB_DITHER_NORMAL, x_dither=0, y_dither=0) + widget.pixmap_temp.draw_pixbuf(widget.gc, pixbuf_copy, 0, 0, coords[0] - w/2, coords[1]- h/2, w, h, dither=gtk.gdk.RGB_DITHER_NORMAL, x_dither=0, y_dither=0) else: - self.d.pixmap_sel.draw_drawable(self.d.gc, self.d.pixmap, x0, y0, coords[0] - w/2, coords[1]- h/2, w, h) - self.d.pixmap_temp.draw_drawable(self.d.gc, self.d.pixmap_sel,0,0,0,0, width, height) + widget.pixmap_sel.draw_drawable(widget.gc, widget.pixmap, x0, y0, coords[0] - w/2, coords[1]- h/2, w, h) + widget.pixmap_temp.draw_drawable(widget.gc, widget.pixmap_sel,0,0,0,0, width, height) #to draw the selection black and white line rectangle - self.d.pixmap_sel.draw_rectangle(self.d.gc_selection, False ,coords[0] - w/2, coords[1]- h/2, w, h) - self.d.pixmap_sel.draw_rectangle(self.d.gc_selection1, False ,coords[0] - w/2-1, coords[1]- h/2-1, w+2, h+2) + widget.pixmap_sel.draw_rectangle(widget.gc_selection, False ,coords[0] - w/2, coords[1]- h/2, w, h) + widget.pixmap_sel.draw_rectangle(widget.gc_selection1, False ,coords[0] - w/2-1, coords[1]- h/2-1, w+2, h+2) widget.queue_draw() def resizeSelection(self, widget, width_percent, height_percent): """Resize the selection. - Keyword arguments: - self -- Desenho.Desenho instance - widget -- Area object (GtkDrawingArea) - coords -- Two value tuple + @param self -- Desenho.Desenho instance + @param width_percent -- Percent of x scale + @param height_percent -- Percent of y scale """ - width, height = self.d.window.get_size() - - self.d.pixmap_sel.draw_drawable(self.d.gc,self.d.pixmap,0,0,0,0, width, height) + #widget = self.draw_widget + width, height = widget.window.get_size() - if self.d.sx > self.d.oldx: - x0 = int(self.d.oldx) + + widget.pixmap.draw_drawable(widget.gc,widget.pixmap_temp,0,0,0,0, width, height) + + if widget.sx > widget.oldx: + x0 = int(widget.oldx) else: - x0 = int(self.d.sx) + x0 = int(widget.sx) - if self.d.sy > self.d.oldy: - y0 = int(self.d.oldy) + if widget.sy > widget.oldy: + y0 = int(widget.oldy) else: - y0 = int(self.d.sy) + y0 = int(widget.sy) - w = int(math.fabs(self.d.sx - self.d.oldx)) - h = int(math.fabs(self.d.sy - self.d.oldy)) - - width_percent, height_percent = 2,2 + w = int(math.fabs(widget.sx - widget.oldx)) + h = int(math.fabs(widget.sy - widget.oldy)) - delta_x = int( w*(width_percent-1)/2 ) - delta_y = int( h*(height_percent-1)/2 ) + #delta_x = int( w*(width_percent-1)/2 ) + #delta_y = int( h*(height_percent-1)/2 ) pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, w, h)
- pixbuf.get_from_drawable(self.d.pixmap, gtk.gdk.colormap_get_system(), x0, y0, 0, 0, w, h) + pixbuf.get_from_drawable(widget.pixmap_temp, gtk.gdk.colormap_get_system(), x0, y0, 0, 0, w, h) pixbuf = pixbuf.scale_simple(int(w*width_percent), int(h*height_percent), gtk.gdk.INTERP_BILINEAR) - - #self.d.pixmap_sel.draw_rectangle(self.d.get_style().white_gc, True, x0 - delta_x/2, x1 - delta_y/2, int(w*width_percent), int(h*height_percent)) - self.d.pixmap_sel.draw_rectangle(self.d.get_style().white_gc, True, x0 - delta_x, y0 - delta_y, int(w*width_percent), int(h*height_percent)) - self.d.pixmap_sel.draw_pixbuf(self.d.get_style().white_gc,pixbuf,0,0,x0 - delta_x, y0 - delta_y,int(w*width_percent), int(h*height_percent)) - - self.d.pixmap_temp.draw_drawable(self.d.gc, self.d.pixmap_sel,0,0,0,0, width, height) + widget.pixmap.draw_rectangle(widget.get_style().white_gc, True, x0 , y0 , int(w*width_percent), int(h*height_percent)) + widget.pixmap.draw_pixbuf(widget.get_style().white_gc,pixbuf,0,0,x0 , y0 ,int(w*width_percent), int(h*height_percent)) + + #widget.pixmap_temp.draw_drawable(widget.gc, widget.pixmap_sel,0,0,0,0, width, height) #to draw the selection black and white line rectangle - self.d.pixmap_sel.draw_rectangle(self.d.gc_selection, False ,x0- delta_x, y0- delta_y-4,2*w+1, 2*h+1) - self.d.pixmap_sel.draw_rectangle(self.d.gc_selection1, False ,x0- delta_x, y0- delta_y-5,2*w +2, 2*h +2) - + #widget.pixmap_sel.draw_rectangle(widget.gc_selection, False ,x0, y0-2,int(width_percent*w+1), int(height_percent*h+1)) + #widget.pixmap_sel.draw_rectangle(widget.gc_selection1, False ,x0, y0-3,int(width_percent*w +2), int(height_percent*h +2)) + + + #widget.pixmap.draw_drawable(widget.gc, widget.pixmap_temp, 0,0,0,0, width, height) + widget.queue_draw() + widget.enableUndo(widget) def polygon(self, widget, coords, temp, fill): """Draw polygon. - Keyword arguments: - self -- Desenho.Desenho instance - widget -- Area object (GtkDrawingArea) - coords -- Two value tuple + @param self -- Desenho.Desenho instance + @param widget -- Area object (GtkDrawingArea) + @param coords -- Two value tuple + @param temp -- switch between pixmap and pixmap_temp + @param fill -- Fill object """ if temp == True: - pixmap = self.d.pixmap_temp + pixmap = widget.pixmap_temp else: - pixmap = self.d.pixmap - width, height = self.d.window.get_size() + pixmap = widget.pixmap + width, height = widget.window.get_size() - pixmap.draw_drawable(self.d.gc, self.d.pixmap, 0, 0, 0, 0, width, height) + pixmap.draw_drawable(widget.gc, widget.pixmap, 0, 0, 0, 0, width, height) - if self.d.polygon_start == True: # Starting a new polygon ? + if widget.polygon_start == True: # Starting a new polygon ? if temp == True: - pixmap.draw_line(self.d.gc_line,self.d.oldx,self.d.oldy, coords[0], coords[1]) + pixmap.draw_line(widget.gc_line,widget.oldx,widget.oldy, coords[0], coords[1]) else: - pixmap.draw_line(self.d.gc_line,self.d.oldx,self.d.oldy, coords[0], coords[1]) - self.d.enableUndo(widget) - self.d.last = coords - self.d.first = self.d.oldx, self.d.oldy - self.d.polygon_start = False - self.d.points = [self.d.first, coords] + pixmap.draw_line(widget.gc_line,widget.oldx,widget.oldy, coords[0], coords[1]) + widget.enableUndo(widget) + widget.last = coords + widget.first = widget.oldx, widget.oldy + widget.polygon_start = False + widget.points = [widget.first, coords] else: if temp == True: - pixmap.draw_line(self.d.gc_line,self.d.last[0],self.d.last[1],coords[0],coords[1]) + pixmap.draw_line(widget.gc_line,widget.last[0],widget.last[1],coords[0],coords[1]) else: - x = coords[0] - self.d.first[0] - y = coords[1] - self.d.first[1] + x = coords[0] - widget.first[0] + y = coords[1] - widget.first[1] d = math.hypot(x,y) if d > 20: # close the polygon ? - pixmap.draw_line(self.d.gc_line,self.d.last[0],self.d.last[1],coords[0],coords[1]) - self.d.last = coords - self.d.points.append(coords) + pixmap.draw_line(widget.gc_line,widget.last[0],widget.last[1],coords[0],coords[1]) + widget.last = coords + widget.points.append(coords) else: - tp = tuple(self.d.points) + tp = tuple(widget.points) if fill == True: - pixmap.draw_polygon(self.d.gc, True, tp) - pixmap.draw_polygon(self.d.gc_line, False, tp) - self.d.last = -1, -1 - self.d.polygon_start = True - self.d.undo_times -= 1#destroy the undo screen of polygon start - self.d.enableUndo(widget) + pixmap.draw_polygon(widget.gc, True, tp) + pixmap.draw_polygon(widget.gc_line, False, tp) + widget.last = -1, -1 + widget.polygon_start = True + widget.undo_times -= 1#destroy the undo screen of polygon start + widget.enableUndo(widget) widget.queue_draw() |