From 32fe01a83df86b6fa0154ec4d6869d0904444f9b Mon Sep 17 00:00:00 2001 From: Alexandre Antonino Gonçalves Martinazzo Date: Fri, 24 Aug 2007 21:49:49 +0000 Subject: 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) --- 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 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') -- cgit v0.9.1