Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Desenho.py
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@sugarlabs.org>2010-10-19 20:55:22 (GMT)
committer Gonzalo Odiard <godiard@sugarlabs.org>2010-10-19 20:55:22 (GMT)
commit91582d534849f1fb3fdbbe158ec7f35274042086 (patch)
tree231ac7428bc211c5fd672bcc2d144271bda155cd /Desenho.py
parent231b58a3da0e71866102521a5b6a63a2a5f6c85e (diff)
make Desenho.py pep8 complaint
Diffstat (limited to 'Desenho.py')
-rw-r--r--Desenho.py520
1 files changed, 302 insertions, 218 deletions
diff --git a/Desenho.py b/Desenho.py
index c9a134b..5dc3d6c 100644
--- a/Desenho.py
+++ b/Desenho.py
@@ -7,16 +7,16 @@
Copyright 2007, NATE-LSI-EPUSP
-Oficina is developed in Brazil at Escola Politécnica of
+Oficina is developed in Brazil at Escola Politécnica of
Universidade de São Paulo. NATE is part of LSI (Integrable
Systems Laboratory) and stands for Learning, Work and Entertainment
-Research Group. Visit our web page:
+Research Group. Visit our web page:
www.lsi.usp.br/nate
Suggestions, bugs and doubts, please email oficina@lsi.usp.br
Oficina is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation version 2 of
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation version 2 of
the License.
Oficina is distributed in the hope that it will be useful,
@@ -26,9 +26,9 @@ General Public License for more details.
You should have received a copy of the GNU General Public
License along with Oficina; if not, write to the
-Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Boston, MA 02110-1301 USA.
-The copy of the GNU General Public License is found in the
+The copy of the GNU General Public License is found in the
COPYING file included in the source distribution.
@@ -65,7 +65,9 @@ Walter Bender (walter@laptop.org)
import pygtk
pygtk.require('2.0')
import gtk
-import sys, gobject, logging
+import sys
+import gobject
+import logging
from gtk import gdk
import math
import pango
@@ -74,6 +76,7 @@ import gc
##Pixmap manipulation
class Desenho:
+
def __init__(self, widget):
"""Initialize Desenho object.
@@ -82,7 +85,7 @@ class Desenho:
"""
#self.d = widget
-
+
def line(self, widget, coords):
"""Draw line.
@@ -92,13 +95,15 @@ class Desenho:
"""
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.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'):
+
+ def eraser(self, widget, coords, last, size=30, shape='circle'):
"""Erase part of the drawing.
@param self -- Desenho.Desenho instance
@@ -110,10 +115,10 @@ class Desenho:
"""
widget.desenha = False
- self._trace(widget,widget.gc_eraser, coords, last, size, shape)
+ self._trace(widget, widget.gc_eraser, coords, last, size, shape)
#widget.queue_draw()
-
- def brush(self, widget, coords, last, size = 5, shape = 'circle'):
+
+ def brush(self, widget, coords, last, size=5, shape='circle'):
"""Paint with brush.
@param self -- Desenho.Desenho instance
@@ -125,11 +130,9 @@ class Desenho:
"""
widget.desenha = False
- self._trace(widget,widget.gc_brush, coords, last, size, shape)
-
+ self._trace(widget, widget.gc_brush, coords, last, size, shape)
-
- def rainbow(self, widget, coords, last, color, size = 5, shape = 'circle'):
+ def rainbow(self, widget, coords, last, color, size=5, shape='circle'):
"""Paint with rainbow.
@param self -- Desenho.Desenho instance
@@ -159,40 +162,46 @@ class Desenho:
widget.gc_rainbow.set_foreground(rainbow_colors[color])
widget.desenha = False
- self._trace(widget,widget.gc_rainbow, coords, last, size, shape)
-
+ self._trace(widget, widget.gc_rainbow, coords, last, size, shape)
- def _trace(self, widget,gc, coords, last, size, shape):
+ def _trace(self, widget, gc, coords, last, size, shape):
if(shape == 'circle'):
- widget.pixmap.draw_arc(gc, True, coords[0] - size/2, coords[1] - size/2, size, size, 0, 360*64)
+ widget.pixmap.draw_arc(gc, True,
+ coords[0] - size / 2, coords[1] - size / 2,
+ size, size, 0, 360 * 64)
if last:
- gc.set_line_attributes(size, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND)
- widget.pixmap.draw_line(gc, last[0], last[1], coords[0], coords[1])
- gc.set_line_attributes(0, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND)
+ gc.set_line_attributes(size, gtk.gdk.LINE_SOLID,
+ gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND)
+ widget.pixmap.draw_line(gc,
+ last[0], last[1], coords[0], coords[1])
+ gc.set_line_attributes(0, gtk.gdk.LINE_SOLID,
+ gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND)
if(shape == 'square'):
- widget.pixmap.draw_rectangle(gc, True, coords[0] - size/2, coords[1] - size/2, size, size)
+ widget.pixmap.draw_rectangle(gc, True,
+ coords[0] - size / 2, coords[1] - size / 2, size, size)
if last:
- points = [(last[0] - size/2,last[1] - size/2), (coords[0] - size/2, coords[1] - size/2),
- (coords[0] + size/2, coords[1] + size/2) , (last[0] + size/2,last[1] + size/2)]
- widget.pixmap.draw_polygon(gc,True,points)
- points = [(last[0] + size/2,last[1] - size/2), (coords[0] + size/2, coords[1] - size/2),
- (coords[0] - size/2, coords[1] + size/2) , (last[0] - size/2,last[1] + size/2)]
- widget.pixmap.draw_polygon(gc,True,points)
-
+ points = [(last[0] - size / 2, last[1] - size / 2),
+ (coords[0] - size / 2, coords[1] - size / 2),
+ (coords[0] + size / 2, coords[1] + size / 2),
+ (last[0] + size / 2, last[1] + size / 2)]
+ widget.pixmap.draw_polygon(gc, True, points)
+ points = [(last[0] + size / 2, last[1] - size / 2),
+ (coords[0] + size / 2, coords[1] - size / 2),
+ (coords[0] - size / 2, coords[1] + size / 2),
+ (last[0] - size / 2, last[1] + size / 2)]
+ widget.pixmap.draw_polygon(gc, True, points)
if last:
x = min(coords[0], last[0])
width = max(coords[0], last[0]) - x
y = min(coords[1], last[1])
- height = max(coords[1] , last[1]) - y
- widget.queue_draw_area(x-size, y-size, width+size*2, height+size*2) # We add size to avoid drawing dotted lines
+ height = max(coords[1], last[1]) - y
+ # We add size to avoid drawing dotted lines
+ widget.queue_draw_area(x - size, y - size,
+ width + size * 2, height + size * 2)
else:
widget.queue_draw()
-
-
-
-
def square(self, widget, event, coords, temp, fill):
"""Draw a square.
@@ -207,15 +216,16 @@ class Desenho:
else:
pixmap = widget.pixmap
width, height = widget.window.get_size()
-
- x, y, dx, dy, = self.adjust(widget,coords)
-
- pixmap.draw_drawable(widget.gc,widget.pixmap,0,0,0,0,width,height)
+
+ x, y, dx, dy, = self.adjust(widget, coords)
+
+ pixmap.draw_drawable(widget.gc, widget.pixmap, 0, 0, 0, 0,
+ width, height)
if fill == True:
- pixmap.draw_rectangle(widget.gc,True,x,y,dx,dy)
- pixmap.draw_rectangle(widget.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.
@@ -232,15 +242,17 @@ class Desenho:
else:
pixmap = widget.pixmap
width, height = widget.window.get_size()
-
- 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)
+
+ 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(widget.gc,True,points)
- pixmap.draw_polygon(widget.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.
@@ -258,15 +270,16 @@ class Desenho:
pixmap = widget.pixmap
width, height = widget.window.get_size()
- 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)
+ 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(widget.gc, True, points)
- pixmap.draw_polygon(widget.gc_line,False,points)
+ pixmap.draw_polygon(widget.gc_line, False, points)
widget.queue_draw()
-
-
+
def arrow(self, widget, coords, temp, fill):
"""Draw a arrow.
@@ -285,20 +298,20 @@ class Desenho:
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)
+ 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(widget.gc,True,points)
- pixmap.draw_polygon(widget.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.
@@ -314,15 +327,16 @@ class Desenho:
pixmap = widget.pixmap
width, height = widget.window.get_size()
- 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)
+ 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(widget.gc,True,points)
- pixmap.draw_polygon(widget.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.
@@ -339,27 +353,31 @@ class Desenho:
else:
pixmap = widget.pixmap
width, height = widget.window.get_size()
-
+
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 = [(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((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))))
+ A = math.atan2(y, x)
+ dA = 2 * math.pi / n
+ r = math.hypot(y, x)
+ 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((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(widget.gc,widget.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(widget.gc,True,tp)
- pixmap.draw_polygon(widget.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.
@@ -376,25 +394,27 @@ class Desenho:
else:
pixmap = widget.pixmap
width, height = widget.window.get_size()
-
+
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 = [(widget.oldx+int(r*math.cos(A)),widget.oldy+int(r*math.sin(A)))]
+ A = math.atan2(y, x)
+ dA = 2 * math.pi / n
+ r = math.hypot(y, x)
+ 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((widget.oldx+int(r*math.cos(A)),widget.oldy+int(r*math.sin(A))))
+ A = A + dA
+ p.append((widget.oldx + int(r * math.cos(A)), \
+ widget.oldy + int(r * math.sin(A))))
tp = tuple(p)
-
- pixmap.draw_drawable(widget.gc,widget.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(widget.gc,True,tp)
- pixmap.draw_polygon(widget.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.
@@ -419,27 +439,47 @@ class Desenho:
y = coords[1]
else:
y = widget.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(widget.gc,widget.pixmap,0,0,0,0,width,height)
+ w = int(4 * dx)
+ e = int(4 * dx / math.sqrt(3))
+
+ pixmap.draw_drawable(widget.gc, widget.pixmap, 0, 0, 0, 0,
+ width, height)
if fill == True:
- 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)
-
+ 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()
-
def circle(self, widget, coords, temp, fill):
"""Draw a circle.
@@ -457,12 +497,13 @@ class Desenho:
pixmap = widget.pixmap
width, height = widget.window.get_size()
- x, y, dx, dy = self.adjust(widget,coords)
-
- pixmap.draw_drawable(widget.gc,widget.pixmap,0,0,0,0,width,height)
+ x, y, dx, dy = self.adjust(widget, coords)
+
+ pixmap.draw_drawable(widget.gc, widget.pixmap, 0, 0, 0, 0,
+ width, height)
if fill == True:
- 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)
+ 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 clear(self, widget):
@@ -472,34 +513,41 @@ class Desenho:
@param widget -- Area object (GtkDrawingArea)
"""
logging.debug('Desenho.clear')
-
+
widget.desenho = []
widget.textos = []
-
+
# try to clear a selected area first
if widget.is_selected():
try:
width, height = widget.pixmap_sel.get_size()
-
+
# Clear the selected area
- widget.pixmap_sel.draw_rectangle(widget.get_style().white_gc, True,0, 0, width, height)
+ widget.pixmap_sel.draw_rectangle(widget.get_style().white_gc,
+ True, 0, 0, width, height)
# Draw the selected area in the displayed pixmap
- widget.pixmap_temp.draw_drawable(widget.gc,widget.pixmap_sel,0,0,widget.orig_x,widget.orig_y, width, height)
+ widget.pixmap_temp.draw_drawable(widget.gc, widget.pixmap_sel,
+ 0, 0, widget.orig_x, widget.orig_y, width, height)
# Draw the selection rectangle
- widget.pixmap_temp.draw_rectangle(widget.gc_selection, False, widget.orig_x,widget.orig_y, width, height)
- widget.pixmap_temp.draw_rectangle(widget.gc_selection1,False, widget.orig_x-1,widget.orig_y-1, width+2, height+2)
-
+ widget.pixmap_temp.draw_rectangle(widget.gc_selection, False,
+ widget.orig_x, widget.orig_y, width, height)
+ widget.pixmap_temp.draw_rectangle(widget.gc_selection1, False,
+ widget.orig_x - 1, widget.orig_y - 1,
+ width + 2, height + 2)
+
except NameError, message:
logging.debug(message)
except Exception, message:
logging.debug('Unexpected error: %s', message)
else:
width, height = widget.window.get_size()
- 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):
+ 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):
"""Display and draw text in the drawing area.
@param self -- Desenho.Desenho instance
@@ -507,19 +555,21 @@ class Desenho:
@param event -- GdkEvent
"""
-
+
if widget.estadoTexto == 0:
widget.estadoTexto = 1
-
- #widget.janela.fixed.move(widget.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...
- widget.janela.fixed.move(widget.janela.textview, int(event.x), int(event.y))
+ widget.janela.fixed.move(widget.janela.textview,
+ int(event.x), int(event.y))
widget.janela.textview.show()
widget.janela.textview.grab_focus()
-
- else:
- widget.estadoTexto = 0
-
+
+ else:
+ widget.estadoTexto = 0
+
try:
# This works for a gtk.Entry
text = widget.janela.textview.get_text()
@@ -528,23 +578,24 @@ class Desenho:
buf = widget.janela.textview.get_buffer()
start, end = buf.get_bounds()
text = buf.get_text(start, end)
-
+
layout = widget.create_pango_layout(text)
#layout.set_font_description(widget.font)
-
- widget.pixmap.draw_layout(widget.gc, widget.oldx, widget.oldy, layout)
- widget.pixmap_temp.draw_layout(widget.gc, widget.oldx, widget.oldy, layout)
+
+ 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:
widget.janela.textview.set_text('')
except AttributeError:
buf.set_text('')
widget.enableUndo(widget)
-
+
widget.queue_draw()
-
def selection(self, widget, coords, temp=True):
"""Make a selection.
@@ -554,32 +605,41 @@ class Desenho:
@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
- """
-
+
+ @return (x0,y0,x1,y1) -- coords of corners
+ """
+
width, height = widget.window.get_size()
- x, y, dx, dy = self.adjust(widget,coords,True)
+ x, y, dx, dy = self.adjust(widget, coords, True)
- widget.pixmap_temp.draw_drawable(widget.gc,widget.pixmap,0,0,0,0,width,height)
+ widget.pixmap_temp.draw_drawable(widget.gc, widget.pixmap,
+ 0, 0, 0, 0, width, height)
if temp:
- widget.pixmap_temp.draw_rectangle(widget.gc_selection,False,x,y,dx,dy)
- widget.pixmap_temp.draw_rectangle(widget.gc_selection1,False,x-1,y-1,dx+2,dy+2)
+ widget.pixmap_temp.draw_rectangle(widget.gc_selection, False,
+ x, y, dx, dy)
+ widget.pixmap_temp.draw_rectangle(widget.gc_selection1, False,
+ x - 1, y - 1, dx + 2, dy + 2)
else:
try:
del (widget.pixmap_sel)
- except: pass
- widget.pixmap_sel = gtk.gdk.Pixmap(widget.window,dx,dy,-1)
- widget.pixmap_sel.draw_drawable(widget.gc,widget.pixmap,x,y,0,0,dx,dy)
- widget.pixmap.draw_rectangle(widget.get_style().white_gc,True,x,y,dx,dy)
+ except:
+ pass
+
+ widget.pixmap_sel = gtk.gdk.Pixmap(widget.window, dx, dy, -1)
+ widget.pixmap_sel.draw_drawable(widget.gc, widget.pixmap,
+ x, y, 0, 0, dx, dy)
+ widget.pixmap.draw_rectangle(widget.get_style().white_gc, True,
+ x, y, dx, dy)
widget.orig_x = x
widget.orig_y = y
- widget.pixmap_temp.draw_rectangle(widget.gc_selection,False,x,y,dx,dy)
- widget.pixmap_temp.draw_rectangle(widget.gc_selection1,False,x-1,y-1,dx+2,dy+2)
+ widget.pixmap_temp.draw_rectangle(widget.gc_selection, False,
+ x, y, dx, dy)
+ widget.pixmap_temp.draw_rectangle(widget.gc_selection1, False,
+ x - 1, y - 1, dx + 2, dy + 2)
widget.queue_draw()
-
+
def moveSelection(self, widget, coords):
"""Move the selection.
@@ -593,17 +653,22 @@ class Desenho:
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_drawable(widget.gc, widget.pixmap,
+ 0, 0, 0, 0, width, height)
+
+ dx = int(coords[0] - widget.oldx)
+ dy = int(coords[1] - widget.oldy)
- dx = int(coords[0]-widget.oldx)
- dy = int(coords[1]-widget.oldy)
-
size = widget.pixmap_sel.get_size()
- widget.pixmap_temp.draw_drawable(widget.gc,widget.pixmap_sel,0,0,widget.orig_x+dx,widget.orig_y+dy, size[0], size[1])
-
- widget.pixmap_temp.draw_rectangle(widget.gc_selection, False ,widget.orig_x+dx,widget.orig_y+dy, size[0], size[1])
- widget.pixmap_temp.draw_rectangle(widget.gc_selection1,False,widget.orig_x+dx-1,widget.orig_y+dy-1,size[0]+2,size[1]+2)
+ widget.pixmap_temp.draw_drawable(widget.gc, widget.pixmap_sel,
+ 0, 0, widget.orig_x + dx, widget.orig_y + dy, size[0], size[1])
+
+ widget.pixmap_temp.draw_rectangle(widget.gc_selection, False,
+ widget.orig_x + dx, widget.orig_y + dy, size[0], size[1])
+ widget.pixmap_temp.draw_rectangle(widget.gc_selection1, False,
+ widget.orig_x + dx-1, widget.orig_y + dy - 1,
+ size[0] + 2, size[1] + 2)
widget.queue_draw()
@@ -614,44 +679,52 @@ class Desenho:
@param width_percent -- Percent of x scale
@param height_percent -- Percent of y scale
- """
+ """
width, height = widget.window.get_size()
widget.desenha = True
widget.selmove = True
-
+
gc.collect()
#Create the pixbuf for future resizes
try:
self.pixbuf_resize
except:
size = widget.pixmap_sel.get_size()
- self.pixbuf_resize = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,size[0],size[1])
- self.pixbuf_resize.get_from_drawable(widget.pixmap_sel,gtk.gdk.colormap_get_system(),0,0,0,0,size[0],size[1])
+ self.pixbuf_resize = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False,
+ 8, size[0], size[1])
+ self.pixbuf_resize.get_from_drawable(widget.pixmap_sel,
+ gtk.gdk.colormap_get_system(), 0, 0, 0, 0, size[0], size[1])
w = self.pixbuf_resize.get_width()
h = self.pixbuf_resize.get_height()
- wr = int(w*width_percent)
- hr = int(h*height_percent)
-
- resized = self.pixbuf_resize.scale_simple(wr,hr,gtk.gdk.INTERP_HYPER)
+ wr = int(w * width_percent)
+ hr = int(h * height_percent)
+
+ resized = self.pixbuf_resize.scale_simple(wr, hr, gtk.gdk.INTERP_HYPER)
#Copy the resized picture to pixmap_sel
try:
del (widget.pixmap_sel)
- except: pass
- widget.pixmap_sel = gtk.gdk.Pixmap(widget.window,wr,hr,-1)
- widget.pixmap_sel.draw_pixbuf(widget.get_style().white_gc,resized,0,0,0,0,wr,hr)
-
+ except:
+ pass
+ widget.pixmap_sel = gtk.gdk.Pixmap(widget.window, wr, hr, -1)
+ widget.pixmap_sel.draw_pixbuf(widget.get_style().white_gc, resized,
+ 0, 0, 0, 0, wr, hr)
+
#Draw the new pixmap_sel
- widget.pixmap_temp.draw_drawable(widget.gc,widget.pixmap,0,0,0,0,width,height)
- widget.pixmap_temp.draw_drawable(widget.gc,widget.pixmap_sel,0,0,widget.orig_x,widget.orig_y,wr,hr)
- widget.pixmap_temp.draw_rectangle(widget.gc_selection,False,widget.orig_x,widget.orig_y,wr,hr)
- widget.pixmap_temp.draw_rectangle(widget.gc_selection1,False,widget.orig_x-1,widget.orig_y-1,wr+2,hr+2)
+ widget.pixmap_temp.draw_drawable(widget.gc, widget.pixmap,
+ 0, 0, 0, 0, width, height)
+ widget.pixmap_temp.draw_drawable(widget.gc, widget.pixmap_sel,
+ 0, 0, widget.orig_x, widget.orig_y, wr, hr)
+ widget.pixmap_temp.draw_rectangle(widget.gc_selection, False,
+ widget.orig_x, widget.orig_y, wr, hr)
+ widget.pixmap_temp.draw_rectangle(widget.gc_selection1, False,
+ widget.orig_x - 1, widget.orig_y - 1, wr + 2, hr + 2)
widget.queue_draw()
gc.collect()
-
- def polygon(self, widget, coords, temp, fill, param = None):
+
+ def polygon(self, widget, coords, temp, fill, param=None):
"""Draw polygon.
@param self -- Desenho.Desenho instance
@@ -668,54 +741,65 @@ class Desenho:
pixmap = widget.pixmap
width, height = widget.window.get_size()
- pixmap.draw_drawable(widget.gc, widget.pixmap, 0, 0, 0, 0, width, height)
+ pixmap.draw_drawable(widget.gc, widget.pixmap, 0, 0, 0, 0,
+ width, height)
if param == "moving":
# mouse not pressed moving
if not widget.polygon_start:
- pixmap.draw_line(widget.gc_line,widget.last[0],widget.last[1], coords[0], coords[1])
+ pixmap.draw_line(widget.gc_line,
+ widget.last[0], widget.last[1], coords[0], coords[1])
elif widget.polygon_start == True: # Starting a new polygon ?
if param == "motion":
# first press
try:
- pixmap.draw_line(widget.gc_line,widget.last[0],widget.last[1], coords[0], coords[1])
- widget.pixmap.draw_line(widget.gc_line,widget.last[0],widget.last[1], coords[0], coords[1])
+ pixmap.draw_line(widget.gc_line,
+ widget.last[0], widget.last[1], coords[0], coords[1])
+ widget.pixmap.draw_line(widget.gc_line,
+ widget.last[0], widget.last[1], coords[0], coords[1])
widget.points.append(coords)
except:
- pixmap.draw_line(widget.gc_line,widget.oldx,widget.oldy, coords[0], coords[1])
- widget.pixmap.draw_line(widget.gc_line,widget.oldx,widget.oldy, coords[0], coords[1])
+ pixmap.draw_line(widget.gc_line, widget.oldx, widget.oldy,
+ coords[0], coords[1])
+ widget.pixmap.draw_line(widget.gc_line,
+ widget.oldx, widget.oldy, coords[0], coords[1])
widget.first = widget.oldx, widget.oldy
widget.points = [widget.first, coords]
widget.enableUndo(widget)
- widget.last = coords
+ widget.last = coords
else: # param == "release"
# first release
try:
widget.first
widget.points.append(coords)
- widget.pixmap.draw_line(widget.gc_line,widget.last[0],widget.last[1], coords[0], coords[1])
+ widget.pixmap.draw_line(widget.gc_line,
+ widget.last[0], widget.last[1], coords[0], coords[1])
except:
widget.first = widget.oldx, widget.oldy
- widget.points = [widget.first, coords]
- widget.pixmap.draw_line(widget.gc_line,widget.oldx,widget.oldy, coords[0], coords[1])
+ widget.points = [widget.first, coords]
+ widget.pixmap.draw_line(widget.gc_line,
+ widget.oldx, widget.oldy, coords[0], coords[1])
widget.enableUndo(widget)
widget.last = coords
widget.polygon_start = False
else:
if param == "motion":
- # print "press"
- pixmap.draw_line(widget.gc_line,widget.last[0],widget.last[1],coords[0],coords[1])
- widget.pixmap.draw_line(widget.gc_line,widget.last[0],widget.last[1], coords[0], coords[1])
+ # print "press"
+ pixmap.draw_line(widget.gc_line,
+ widget.last[0], widget.last[1], coords[0], coords[1])
+ widget.pixmap.draw_line(widget.gc_line,
+ widget.last[0], widget.last[1], coords[0], coords[1])
widget.enableUndo(widget)
widget.last = coords
widget.points.append(coords)
elif param == "release":
- # print "release"
+ # print "release"
x = coords[0] - widget.first[0]
y = coords[1] - widget.first[1]
- d = math.hypot(x,y)
+ d = math.hypot(x, y)
if d > 20: # close the polygon ?
- pixmap.draw_line(widget.gc_line,widget.last[0],widget.last[1],coords[0],coords[1])
+ pixmap.draw_line(widget.gc_line,
+ widget.last[0], widget.last[1], coords[0], coords[1])
widget.last = coords
widget.points.append(coords)
else:
@@ -725,7 +809,8 @@ class Desenho:
pixmap.draw_polygon(widget.gc_line, False, tp)
widget.last = []
widget.polygon_start = True
- widget.undo_times -= 1#destroy the undo screen of polygon start
+ #destroy the undo screen of polygon start
+ widget.undo_times -= 1
widget.enableUndo(widget)
elif param == "bug":
tp = tuple(widget.points)
@@ -734,10 +819,11 @@ class Desenho:
pixmap.draw_polygon(widget.gc_line, False, tp)
widget.last = []
widget.polygon_start = True
- widget.undo_times -= 1#destroy the undo screen of polygon start
+ #destroy the undo screen of polygon start
+ widget.undo_times -= 1
widget.enableUndo(widget)
widget.queue_draw()
-
+
def adjust(self, widget, coords, locked=False):
width, height = widget.window.get_size()
if widget.oldx > int(coords[0]):
@@ -753,7 +839,7 @@ class Desenho:
else:
yi = widget.oldy
yf = int(coords[1])
-
+
if locked == True:
if xi < 0:
xi = 0
@@ -764,8 +850,6 @@ class Desenho:
if yf > height:
yf = height
- dx = xf-xi
- dy = yf-yi
+ dx = xf - xi
+ dy = yf - yi
return xi, yi, dx, dy
-
-