Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandre Antonino Gonçalves Martinazzo <alexandremartinazzo@gmail.com>2007-08-24 21:49:49 (GMT)
committer Alexandre Antonino Gonçalves Martinazzo <alexandremartinazzo@gmail.com>2007-08-24 21:49:49 (GMT)
commit32fe01a83df86b6fa0154ec4d6869d0904444f9b (patch)
tree96e458d021f3e373c1dc15070e3768f6ed5fd5dc
parentfc1f549a9711d6d5d91558295906fbc0f813f927 (diff)
Minor modifications on Palettes
Changed some palette's layout User can choose number of points in Star shape Star shape modified (by andremossinato) New move-selection, activate copy button only when selected (by pekayatt) Inserted base Resize code (by barbolo)
-rw-r--r--Area.py151
-rw-r--r--Desenho.py136
-rw-r--r--NEWS5
-rw-r--r--toolbox.py150
4 files changed, 262 insertions, 180 deletions
diff --git a/Area.py b/Area.py
index 3d9499a..9c72ae4 100644
--- a/Area.py
+++ b/Area.py
@@ -122,7 +122,7 @@ class Area(gtk.DrawingArea):
self.pixmap = None
self.pixmap_temp = None
self.pixmap_sel = None
- self.pixmap_copy = None
+ self.pixbuf_sel = None
self.desenho = []
self.textos = []
self.estadoTexto = 0
@@ -175,33 +175,29 @@ class Area(gtk.DrawingArea):
self.pixmap_sel = gtk.gdk.Pixmap(win, width, height, -1)
self.pixmap_sel.draw_rectangle(widget.get_style().white_gc, True, 0, 0, width, height)
- self.gc = widget.window.new_gc()
- self.gc_eraser = widget.window.new_gc()
+ self.gc = win.new_gc()
+ self.gc_eraser = win.new_gc()
colormap = self.get_colormap()
white = colormap.alloc_color('#ffffff', True, True) # white
self.gc_eraser.set_foreground(white)
- self.gc_rainbow = widget.window.new_gc()
+ self.gc_rainbow = win.new_gc()
- self.gc_brush = widget.window.new_gc()
+ self.gc_brush = win.new_gc()
self.gc_brush.set_foreground(white)
- self.gc_line = widget.window.new_gc()
+ self.gc_line = win.new_gc()
- self.gc_selection = widget.window.new_gc()
+ self.gc_selection = win.new_gc()
self.gc_selection.set_line_attributes(1, gtk.gdk.LINE_ON_OFF_DASH, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND)
black = colormap.alloc_color('#000000', True, True) # black
self.gc_selection.set_foreground(black)
- self.gc_selection1 = widget.window.new_gc() #this make another white line out of the black line
+ self.gc_selection1 = win.new_gc() #this make another white line out of the black line
self.gc_selection1.set_line_attributes(1, gtk.gdk.LINE_ON_OFF_DASH, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND)
self.gc_selection1.set_foreground(white)
self.enableUndo(widget)
- # forcing self.undo_times to zero; self.enableUndo() increases it
- # wrongly at this point... bad hacking, I know.
- #self.undo_times = 0
- #self.emit('undo')
return True
@@ -271,11 +267,11 @@ class Area(gtk.DrawingArea):
self.janela._textview.hide()
if not self.selmove or self.tool != 'marquee-rectangular':
- self.oldx = int(event.x)
- self.oldy = int(event.y)
+ self.oldx, self.oldy = coords
if self.selmove and self.tool != 'marquee-rectangular': #get out of the func selection
self.pixmap.draw_drawable(self.gc, self.pixmap_temp, 0,0,0,0, width, height)
self.selmove = False
+ self.pixbuf_sel = None
self.enableUndo(widget)
if self.tool == 'eraser':
self.last = -1, -1
@@ -289,16 +285,21 @@ class Area(gtk.DrawingArea):
self.last = -1, -1
self.d.rainbow(widget, coords, self.last, self.rainbow_counter,self.line_size, self.brush_shape)
self.last = coords
+ if self.tool == 'polygon':
+ self.configure_line(self.line_size)
x , y, state = event.window.get_pointer()
x0, y0, x1, y1 = self.get_selection_bounds()
- if (state & gtk.gdk.BUTTON3_MASK) or not (x0<x<x1 and y0<y<y1):
+ if (state & gtk.gdk.BUTTON3_MASK):
self.sel_get_out = True
- self.pixmap.draw_drawable(self.gc, self.pixmap_temp, 0,0,0,0, width, height)
self.pixmap_sel.draw_drawable(self.gc, self.pixmap_temp, 0,0,0,0, width, height)
- if state & gtk.gdk.BUTTON1_MASK:
- self.pixmap_temp.draw_drawable(self.gc, self.pixmap, 0,0,0,0, width, height)
+ elif state & gtk.gdk.BUTTON1_MASK:
+ if not (x0<x<x1 and y0<y<y1) and self.selmove:
+ self.sel_get_out = True
+ self.pixmap_sel.draw_drawable(self.gc, self.pixmap_temp, 0,0,0,0, width, height)
+ else:
+ self.pixmap_temp.draw_drawable(self.gc, self.pixmap, 0,0,0,0, width, height)
widget.queue_draw()
self.desenha = True
@@ -355,7 +356,10 @@ class Area(gtk.DrawingArea):
self._set_selection_bounds(x1, y1, x2, y2)
# selection
elif self.tool == 'marquee-rectangular' and self.selmove:
- self.d.moveSelection(widget,coords)
+ if self.pixbuf_sel!=None:
+ self.d.moveSelection(widget,coords,True,self.pixbuf_sel)
+ else:
+ self.d.moveSelection(widget,coords)
#polygon
elif self.tool == 'polygon':
self.configure_line(self.line_size)
@@ -385,7 +389,8 @@ class Area(gtk.DrawingArea):
elif self.tool == 'star':
self.configure_line(self.line_size)
#self.d.star(widget,coords,True,True)
- self.d.star(widget,coords,True,self.fill)
+ #self.d.star(widget,coords,True,self.fill)
+ self.d.star(widget,coords,self.polygon_sides,True,self.fill)
#polygon regular
elif self.tool == 'polygon_regular':
self.configure_line(self.line_size)
@@ -431,18 +436,18 @@ class Area(gtk.DrawingArea):
# FIXME: Adicionar cursor formato selecao
if self.selmove == False:
self.pixmap_temp.draw_drawable(self.gc,self.pixmap, 0,0,0,0, width, height)
- self.pixmap_sel.draw_drawable(self.gc,self.pixmap, 0,0,0,0, width, height)#avoid blink
- self.sx = int (event.x)
- self.sy = int(event.y)
+ self.pixmap_sel.draw_drawable(self.gc,self.pixmap, 0,0,0,0, width, height)
+ self.sx, self.sy = coords
self.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.FLEUR))
self.selmove = True
self.sel_get_out = False
+ self.emit('selected')
elif self.sel_get_out: #get out of the func selection
self.pixmap.draw_drawable(self.gc, self.pixmap_temp, 0,0,0,0, width, height)
self.selmove = False
+ self.pixbuf_sel = None
self.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.TCROSS))
- self.oldx = event.x
- self.oldy = event.y
+ self.oldx, self.oldy = coords
self.enableUndo(widget)
self.emit('selected')
# polygon
@@ -482,7 +487,8 @@ class Area(gtk.DrawingArea):
#star
elif self.tool == 'star':
#self.d.star(widget,coords,False,True)
- self.d.star(widget,coords,False,self.fill)
+ #self.d.star(widget,coords,False,self.fill)
+ self.d.star(widget,coords,self.polygon_sides,False,self.fill)
self.enableUndo(widget)
#polygon regular
elif self.tool == 'polygon_regular':
@@ -525,7 +531,7 @@ class Area(gtk.DrawingArea):
#print "Drawing undo[%d]" %(self.undo_times)
self.pixmap.draw_drawable(self.gc, self.undo_list[self.undo_times], 0,0,0,0, width, height)
except:
- print "Can't draw"
+ logging.debug('Cant draw')
pass
self.queue_draw()
else:
@@ -568,7 +574,7 @@ class Area(gtk.DrawingArea):
#print "Drawing undo[%d]" %(self.undo_times)
self.pixmap.draw_drawable(self.gc, self.undo_list[self.undo_times], 0,0,0,0, width, height)
except:
- print "Can't draw"
+ logging.debug('Cant draw')
self.undo_times-=1
self.queue_draw()
@@ -608,7 +614,6 @@ class Area(gtk.DrawingArea):
if self.undo_times==12:
self.undo_list.pop(0)
self.undo_times-=1
- #print "estourou"
# emits 'undo' and 'redo' signals only in case of first action,
# (first undo or first redo) or no actions available
@@ -645,23 +650,18 @@ class Area(gtk.DrawingArea):
else:
y = self.sy
- w = self.sx - self.oldx
- if w < 0:
- w = - w
-
- h = self.sy - self.oldy
- if h < 0:
- h = - h
+ w = math.fabs(self.sx - self.oldx)
+ h = math.fabs(self.sy - self.oldy)
pixbuf_copy = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, w, h)
pixbuf_copy.get_from_drawable(self.pixmap, gtk.gdk.colormap_get_system(), x, y, 0, 0, w, h)
pixbuf_copy.save(tempPath,'png')
- #gtk.Clipboard().set_with_data( [('text/uri-list', 0, 0)], self._copyGetFunc, self._copyClearFunc, tempPath )
+ #gtk.Clipboard().set_with_data( [('text/uri-list', 0, 0)], self._copyGetFunc, self._copyClearFunc, tempPath ) this make the icon seens right, but with none data
clipBoard.set_image(pixbuf_copy)
else :
- print "Please select some area first"
+ logging.debug('Area.copy(self): Please select some area first')
def _copyGetFunc( self, clipboard, selection_data, info, data ):
selection_data.set( "text/uri-list", 8, data)
@@ -674,7 +674,7 @@ class Area(gtk.DrawingArea):
def past(self):
""" Past image.
- Past image that is in pixmap_copy
+ Past image that is in pixmap
Keyword arguments:
self -- the Area object (GtkDrawingArea)
@@ -687,18 +687,24 @@ class Area(gtk.DrawingArea):
clipBoard = gtk.Clipboard()
if clipBoard.wait_is_image_available():
- pixbuf_copy = clipBoard.wait_for_image()
- self.pixmap.draw_pixbuf(self.gc, pixbuf_copy, 0, 0, 0, 0, width=-1, height=-1, dither=gtk.gdk.RGB_DITHER_NORMAL, x_dither=0, y_dither=0)
- self.queue_draw()
+ self.pixbuf_sel = clipBoard.wait_for_image()
+ size = (int)(self.pixbuf_sel.get_width()), (int)(self.pixbuf_sel.get_height())
+ self.pixmap_sel.draw_pixbuf(self.gc, self.pixbuf_sel, 0, 0, 0, 0, size[0], size[1], dither=gtk.gdk.RGB_DITHER_NORMAL, x_dither=0, y_dither=0)
+ self.selmove = True
+ self.desenha = True
+ self.sel_get_out = False
+ self.oldx, self.oldy = 0,0
+ x1, y1, x2, y2 = self.d.selection(self, size, True, False)
+ self._set_selection_bounds(x1, y1, x2, y2)
+ self.pixmap_sel.draw_rectangle(self.gc_selection, False ,0,0,size[0],size[1])
+ self.sx, self.sy = size
+ self.tool = 'marquee-rectangular'
+ self.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.FLEUR))
+ self.emit('selected')
else:
- self.d.loadImage(tempPath, self)
-
- #to get out of sel func
- if self.tool == 'marquee-rectangular':
- self.pixmap_sel.draw_drawable(self.gc, self.pixmap_copy, 0,0,0,0, width, height)
- #self.enableUndo(self)
- self.sel_get_out = True
- self.selmove = False
+ self.loadImage(tempPath, self, True)
+
+ self.queue_draw()
def _set_fill_color(self, color):
"""Set fill color.
@@ -791,15 +797,20 @@ class Area(gtk.DrawingArea):
self.enableUndo(widget)
else :
- print "Please select some area first"
+ logging.debug('Please select some area first')
def can_undo(self):
'''
Indicate if is there some action to undo
'''
- logging.debug('Area.can_undo(self)')
+# logging.debug('Area.can_undo(self)')
- if self.undo_times < 1:
+ undo_times = self.undo_times
+
+ if self.first_undo:
+ undo_times-=1
+
+ if undo_times < 1:
return False
else:
return True
@@ -815,6 +826,18 @@ class Area(gtk.DrawingArea):
else:
return True
+ def is_selected(self):
+ '''
+ Indicate if there is some thing selected
+ '''
+
+ logging.debug('Area.is_selected(self)')
+
+ if self.selmove:
+ return True
+ else:
+ return False
+
def _set_selection_bounds(self, x1, y1, x2, y2):
self._selection_corners = (x1, y1, x2, y2)
@@ -829,27 +852,29 @@ class Area(gtk.DrawingArea):
name -- string (image file path)
"""
- pixbuf = gtk.gdk.pixbuf_new_from_file(name)
- size = (int)(pixbuf.get_width()), (int)(pixbuf.get_height())
-
- self.pixmap.draw_pixbuf(self.gc, pixbuf, 0, 0, 0, 0, size[0], size[1], dither=gtk.gdk.RGB_DITHER_NORMAL, x_dither=0, y_dither=0)
- self.pixmap_temp.draw_pixbuf(self.gc, pixbuf, 0, 0, 0, 0, size[0], size[1], dither=gtk.gdk.RGB_DITHER_NORMAL, x_dither=0, y_dither=0)
- self.pixmap_sel.draw_pixbuf(self.gc, pixbuf, 0, 0, 0, 0, size[0], size[1], dither=gtk.gdk.RGB_DITHER_NORMAL, x_dither=0, y_dither=0)
-
+ self.pixbuf_sel = gtk.gdk.pixbuf_new_from_file(name)
+ size = (int)(self.pixbuf_sel.get_width()), (int)(self.pixbuf_sel.get_height())
+ width, height = self.window.get_size()
+ self.pixmap_sel.draw_drawable(self.gc,self.pixmap,0,0,0,0, width, height)
+ self.pixmap_sel.draw_pixbuf(self.gc, self.pixbuf_sel, 0, 0, 0, 0, size[0], size[1], dither=gtk.gdk.RGB_DITHER_NORMAL, x_dither=0, y_dither=0)
if not load_selected :
+ self.undo_times -= 1
self.enableUndo(widget)
+ pass
else :
+ self.sel_get_out = False
self.selmove = True
self.desenha = True
self.oldx, self.oldy = 0,0
- self.d.selection(self, size, True, False)
- self.pixmap_sel.draw_rectangle(self.gc_selection, True ,0,0,size[0],size[1])
+ x0, y0, x1, y1 = self.d.selection(self, size, True, False)
+ self._set_selection_bounds(x0, y0, x1, y1)
+ self.pixmap_sel.draw_rectangle(self.gc_selection, False ,0,0,size[0],size[1])
self.sx, self.sy = size
self.tool = 'marquee-rectangular'
self.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.FLEUR))
-
+ self.emit('selected')
self.queue_draw()
def clear(self):
diff --git a/Desenho.py b/Desenho.py
index 05f7919..c73d62d 100644
--- a/Desenho.py
+++ b/Desenho.py
@@ -328,13 +328,15 @@ class Desenho:
widget.queue_draw()
- def star(self, widget, coords, temp, fill):
- """Draw a arrow.
+ 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
"""
if temp == True:
@@ -345,21 +347,21 @@ class Desenho:
x = coords[0] - self.d.oldx
y = coords[1] - self.d.oldy
-
- points = [(self.d.oldx,self.d.oldy),\
-(self.d.oldx+int(x*0.25), self.d.oldy+int(y*0.4)),\
-(self.d.oldx+int(x), self.d.oldy+int(y*0.4)),\
-(self.d.oldx+int(x*0.35), self.d.oldy+int(y*0.6)),\
-(self.d.oldx+int(x*0.6), self.d.oldy+y),\
-(self.d.oldx, self.d.oldy+int(y*0.75)),\
-(self.d.oldx-int(x*0.6), self.d.oldy+y),\
-(self.d.oldx-int(x*0.35), self.d.oldy+int(y*0.6)),\
-(self.d.oldx-int(x), self.d.oldy+int(y*0.4)),\
-(self.d.oldx-int(x*0.25), self.d.oldy+int(y*0.4))]
+ 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)))]
+ 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))))
+ tp = tuple(p)
+
pixmap.draw_drawable(self.d.gc,self.d.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(self.d.gc,True,tp)
+ pixmap.draw_polygon(self.d.gc_line,False,tp)
widget.queue_draw()
@@ -572,28 +574,29 @@ class Desenho:
pixmap = self.d.pixmap
width, height = self.d.window.get_size()
- dx = math.fabs(coords[0] - self.d.oldx)
- dy = math.fabs(coords[1] - self.d.oldy)
+ dx = int(math.fabs(coords[0] - self.d.oldx))
+ dy = int(math.fabs(coords[1] - self.d.oldy))
if coords[0] < self.d.oldx:
- x = coords[0]
+ x = int(coords[0])
else:
x = self.d.oldx
if coords[1] < self.d.oldy:
- y = coords[1]
+ y = int(coords[1])
else:
y = self.d.oldy
pixmap.draw_drawable(self.d.gc,self.d.pixmap,0,0,0,0,width,height)
- if fill == True:
- pixmap.draw_rectangle(self.d.gc,True,int(x),int(y),int(dx),int(dy))
+ if fill:
+ pixmap.draw_rectangle(self.d.gc,True,x,y,dx,dy)
- pixmap.draw_rectangle(self.d.gc_selection,False,int(x),int(y),int(dx),int(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)
widget.queue_draw()
- #return self.d.oldx, self.d.oldy, coords[0], coords[1]
+
return x,y,x+dx,y+dy
- def moveSelection(self, widget, coords):
+ def moveSelection(self, widget, coords, mvcopy=False, pixbuf_copy=None):
"""Move the selection.
Keyword arguments:
@@ -603,41 +606,86 @@ class Desenho:
"""
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)
if self.d.sx > self.d.oldx:
- x0 = self.d.oldx
+ x0 = int(self.d.oldx)
else:
- x0 = self.d.sx
+ x0 = int(self.d.sx)
if self.d.sy > self.d.oldy:
- y0 = self.d.oldy
+ y0 = int(self.d.oldy)
else:
- y0 = self.d.sy
-
- w = self.d.sx - self.d.oldx
- if w < 0:
- w = - w
+ y0 = int(self.d.sy)
- h = self.d.sy - self.d.oldy
- if h < 0:
- h = - h
+ w = int(math.fabs(self.d.sx - self.d.oldx))
+ h = int(math.fabs(self.d.sy - self.d.oldy))
- self.d._set_selection_bounds(coords[0]-w/2, coords[1]-h/2, coords[0]+w/2, coords[1]+h/2)
-
-
- self.d.pixmap_sel.draw_rectangle(self.d.get_style().white_gc, True, x0, y0, w, h)
- 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)
+ self.d._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)
- #to draw the selection black and white line rectangle
+ 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)
+ 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)
+
+ #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.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
+
+ """
+ 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)
+
+ if self.d.sx > self.d.oldx:
+ x0 = int(self.d.oldx)
+ else:
+ x0 = int(self.d.sx)
+
+ if self.d.sy > self.d.oldy:
+ y0 = int(self.d.oldy)
+ else:
+ y0 = int(self.d.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
+
+ 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 = 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)
+
+ #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.queue_draw()
+
def polygon(self, widget, coords, temp, fill):
"""Draw polygon.
diff --git a/NEWS b/NEWS
index 3d265db..1fe2f8b 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,11 @@
* Bug #2147 fixed (alexandre)
* Build as Paint not oficina
* Clean up NEWS file - please use setup.py release to do releases
+* toolbar use button copy only when something is selected (pekayatt)
+* New move_selection function, now past and import are really nice (pekayatt)
+* Sel functions improved, import and past now select the image, and can_undo fixed for first undo(pekayatt)
+* Fixed bug with brush and selection, and you can not undo when file is resumed in Journal(pekayatt)
+
6
diff --git a/toolbox.py b/toolbox.py
index 536070b..b32d576 100644
--- a/toolbox.py
+++ b/toolbox.py
@@ -131,6 +131,7 @@ class DrawEditToolbar(EditToolbar):
self._activity._area.connect('undo', self._on_signal_undo_cb)
self._activity._area.connect('redo', self._on_signal_redo_cb)
+ self._activity._area.connect('selected', self._on_signal_copy_cb)
self._activity._area.connect('action-saved', self._on_signal_action_saved_cb)
@@ -151,6 +152,9 @@ class DrawEditToolbar(EditToolbar):
def _on_signal_redo_cb(self, widget, data=None):
self._verify_sensitive_buttons()
+
+ def _on_signal_copy_cb(self, widget, data=None):
+ self._verify_sensitive_buttons()
def _on_signal_action_saved_cb(self, widget, data=None):
self._verify_sensitive_buttons()
@@ -158,6 +162,7 @@ class DrawEditToolbar(EditToolbar):
def _verify_sensitive_buttons(self):
self.undo.set_sensitive( self._activity._area.can_undo() )
self.redo.set_sensitive( self._activity._area.can_redo() )
+ self.copy.set_sensitive( self._activity._area.is_selected() )
#TODO: it is not possible to verify these yet.
#self.copy.set_sensitive( self._activity._area.can_copy() )
#self.paste.set_sensitive( self._activity._area.can_paste() )
@@ -241,7 +246,11 @@ class ToolsToolbar(gtk.Toolbar):
self.insert(self._tool_polygon, -1)
self._tool_polygon.show()
self._tool_polygon.set_tooltip(_('Polygon'))
-
+ try:
+ self._configure_palette(self._tool_polygon, self._TOOL_POLYGON)
+ except:
+ logging.debug('Could not create palette for tool Polygon')
+
self._tool_bucket = ToolButton('tool-bucket')
self.insert(self._tool_bucket, -1)
self._tool_bucket.show()
@@ -286,7 +295,7 @@ class ToolsToolbar(gtk.Toolbar):
def _configure_palette(self, widget, tool=None):
'''Set palette for a tool
- widget - the widget which Palette will be set
+ widget - the widget which Palette will be set, a ToolButton object
tool - the reference tool for Palette creation. Its values are
restricted to Class constants
'''
@@ -315,6 +324,20 @@ class ToolsToolbar(gtk.Toolbar):
item_1.show()
item_2.show()
+
+ elif tool is self._TOOL_POLYGON:
+ # Create a simple palette with an CheckButton named "Fill".
+
+ fill_checkbutton = gtk.CheckButton(_('Fill'))
+ fill_checkbutton.show()
+ fill_checkbutton.set_active(self._activity._area.fill)
+
+ fill_checkbutton.connect('toggled', self._on_fill_checkbutton_toggled, widget)
+
+ fill_checkbutton.connect('map', self._on_fill_checkbutton_map)
+
+ palette.set_content(fill_checkbutton)
+
def set_shape(self, widget, tool, shape):
'''
@@ -354,6 +377,20 @@ class ToolsToolbar(gtk.Toolbar):
def _on_icon_stroke_clicked(self, widget, data=None):
self._stroke_color.clicked()
+ def _on_fill_checkbutton_toggled(self, checkbutton, button=None):
+ logging.debug('Checkbutton is Active: %s', checkbutton.get_active() )
+
+ self._activity._area.fill = checkbutton.get_active()
+ try:
+ button.emit('clicked')
+ except:
+ pass
+
+ def _on_fill_checkbutton_map(self, checkbutton, data=None):
+ '''
+ Update checkbutton condition to agree with Area.Area object; this prevents tools to have fill checked but be drawed not filled.
+ '''
+ self._activity._area.fill = checkbutton.get_active()
class ComboFillColors(ToolComboBox):
@@ -681,7 +718,6 @@ class ShapesToolbar(gtk.Toolbar):
self._shape_polygon.show()
self._shape_polygon.set_tooltip(_('Polygon'))
try:
- #self._configure_palette(self._shape_polygon, self._SHAPE_POLYGON)
self._configure_palette_shape_polygon()
except:
logging.debug('Could not create palette for Regular Polygon')
@@ -796,67 +832,18 @@ class ShapesToolbar(gtk.Toolbar):
def _on_icon_fill_clicked(self, widget, data=None):
self._fill_color.clicked()
- def _configure_palette(self, widget, tool=None):
- '''Configure palette for a given tool
- widget - the widget which Palette will be set
- tool - the reference tool for Palette creation. Its values are
- restricted to Class constants
- '''
-
- logging.debug('setting a palette for %s', tool)
-
- palette = widget.get_palette()
- vbox = gtk.VBox()
- vbox.show()
- palette.action_bar.pack_start(vbox)
-
- if tool is None:
- logging.debug('Trying to configure Palette, but there is no tool!')
- raise TypeError
-
- elif tool is self._SHAPE_POLYGON:
- spin = gtk.SpinButton()
- spin.show()
-
- # When inserted in a Palette, a spinbutton does not display text in black
- black = gtk.gdk.Color(0,0,0)
- spin.modify_text(gtk.STATE_NORMAL, black)
-
- # This is where we set restrictions for Regular Polygon:
- # Initial value, minimum value, maximum value, step
- try:
- initial = float(self._activity._area.polygon_sides)
- except:
- initial = 5.0
- adj = gtk.Adjustment(initial, 3.0, 50.0, 1.0)
- spin.set_adjustment(adj)
- spin.set_numeric(True)
-
- frame = gtk.Frame(_('Sides'))
- frame.add(spin)
- frame.show()
-
- vbox.pack_start(frame)
- spin.connect('value-changed', self._on_value_changed)
-
- separator1 = gtk.HSeparator()
- vbox.pack_start(separator1)
- separator1.show()
-
- checkbutton = gtk.CheckButton(_('Fill'))
- checkbutton.connect('toggled', self._on_checkbutton_toggled)
- vbox.pack_start(checkbutton)
- checkbutton.show()
- checkbutton.set_active(True)
-
def _on_value_changed(self, spinbutton, data=None):
self._activity._area.polygon_sides = spinbutton.get_value_as_int()
- self.set_tool(self._shape_polygon, self._SHAPE_POLYGON)
+
+ if data is self._SHAPE_POLYGON:
+ self.set_tool(self._shape_polygon, self._SHAPE_POLYGON)
+ elif data is self._SHAPE_STAR:
+ self.set_tool(self._shape_star, self._SHAPE_STAR)
def _on_fill_checkbutton_toggled(self, checkbutton, button=None):
logging.debug('Checkbutton is Active: %s', checkbutton.get_active() )
- #TODO: this is not connected to any Area method. Should set filling in regular polygon
+
self._activity._area.fill = checkbutton.get_active()
try:
button.emit('clicked')
@@ -878,10 +865,6 @@ class ShapesToolbar(gtk.Toolbar):
palette = self._shape_polygon.get_palette()
- vbox = gtk.VBox()
- vbox.show()
- #palette.action_bar.pack_start(vbox)
- #palette.set_content(vbox)
spin = gtk.SpinButton()
spin.show()
@@ -900,18 +883,12 @@ class ShapesToolbar(gtk.Toolbar):
spin.set_adjustment(adj)
spin.set_numeric(True)
-# separator1 = gtk.HSeparator()
-# vbox.pack_start(separator1)
-# separator1.show()
-
- frame = gtk.Frame(_('Sides'))
- frame.add(spin)
- frame.show()
-
- #vbox.pack_start(frame)
- palette.set_content(frame)
- spin.connect('value-changed', self._on_value_changed)
+ label = gtk.Label(_('Sides: '))
+ label.show()
+ palette.action_bar.pack_start(label)
+ palette.action_bar.pack_start(spin)
+ spin.connect('value-changed', self._on_value_changed, self._SHAPE_POLYGON)
def _configure_palette_shape_heart(self):
@@ -929,6 +906,33 @@ class ShapesToolbar(gtk.Toolbar):
def _configure_palette_shape_star(self):
logging.debug('Creating palette to shape star')
self._create_simple_palette(self._shape_star)
+
+ palette = self._shape_star.get_palette()
+
+ spin = gtk.SpinButton()
+ spin.show()
+
+ # When inserted in a Palette, a spinbutton does not display text in black
+ black = gtk.gdk.Color(0,0,0)
+ spin.modify_text(gtk.STATE_NORMAL, black)
+
+ # This is where we set restrictions for Star:
+ # Initial value, minimum value, maximum value, step
+ try:
+ initial = float(self._activity._area.polygon_sides)
+ except:
+ initial = 5.0
+ adj = gtk.Adjustment(initial, 3.0, 50.0, 1.0)
+ spin.set_adjustment(adj)
+ spin.set_numeric(True)
+
+ label = gtk.Label(_('Sides: '))
+ label.show()
+ palette.action_bar.pack_start(label)
+ palette.action_bar.pack_start(spin)
+
+ # It is connected to the same method that Regular Polygon's Palette is because they use the same property in Area
+ spin.connect('value-changed', self._on_value_changed, self._SHAPE_STAR)
def _configure_palette_shape_trapezoid(self):
logging.debug('Creating palette to shape trapezoid')