Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/toolbox.py
diff options
context:
space:
mode:
authorAlexandre Antonino Gonçalves Martinazzo <alexandremartinazzo@gmail.com>2007-09-12 22:23:50 (GMT)
committer Alexandre Antonino Gonçalves Martinazzo <alexandremartinazzo@gmail.com>2007-09-12 22:23:50 (GMT)
commit44959deec8d6fd9349ea9a6390ce8389af22a496 (patch)
treee1e9c7dd40b5c67fd76afd2a8164294a95ee144f /toolbox.py
parent01cbd87929d18cf495d86ea17a00313efad68249 (diff)
Many internal changes in palettes; size now is only choosen inside tool palette
User may choose 'line shape' in rainbow effect All tools are described by dicts, default values adjusted in toolbox.py Default tool moved to Area.configure_event due to cursor loading problems 'Insert Image' feature is strange: imported image is cleared if selection is NOT moved.
Diffstat (limited to 'toolbox.py')
-rw-r--r--toolbox.py649
1 files changed, 327 insertions, 322 deletions
diff --git a/toolbox.py b/toolbox.py
index 3de6395..3af9b4d 100644
--- a/toolbox.py
+++ b/toolbox.py
@@ -63,7 +63,8 @@ from sugar.graphics.toggletoolbutton import ToggleToolButton
from sugar.graphics.combobox import ComboBox
from sugar.graphics.palette import Palette
from sugar.graphics.menuitem import MenuItem
-#Create toolbars for the activity
+
+##Create toolbars for the activity
class Toolbox(ActivityToolbox):
## The Constructor
def __init__(self, activity):
@@ -163,6 +164,7 @@ class DrawEditToolbar(EditToolbar):
def _on_signal_action_saved_cb(self, widget, data=None):
self._verify_sensitive_buttons()
+
##define when a button is active
def _verify_sensitive_buttons(self):
self.undo.set_sensitive( self._activity._area.can_undo() )
@@ -174,106 +176,98 @@ class DrawEditToolbar(EditToolbar):
def _clear_all_cb(self, widget, data=None):
self._activity._area.clear()
+
##Determine Tools of the Toolbar
class ToolsToolbar(gtk.Toolbar):
#Tool default definitions
_TOOL_PENCIL = {
'name' : 'pencil',
- 'size' : 2,
+ 'line size' : 2,
'fill color' : None,
'stroke color' : None,
- 'shape' : 'circle',
+ 'line shape' : 'circle',
'fill' : True,
- 'sides' : None,
- 'points' : None
+ 'vertices' : None
}
_TOOL_BRUSH = {
'name' : 'brush',
- 'size' : 5,
+ 'line size' : 10,
'fill color' : None,
'stroke color' : None,
- 'shape' : 'circle',
+ 'line shape' : 'circle',
'fill' : True,
- 'sides' : None,
- 'points' : None
+ 'vertices' : None
}
##The Constructor
_TOOL_ERASER = {
'name' : 'eraser',
- 'size' : 20,
+ 'line size' : 20,
'fill color' : None,
'stroke color' : None,
- 'shape' : 'circle',
+ 'line shape' : 'circle',
'fill' : True,
- 'sides' : None,
- 'points' : None
+ 'vertices' : None
}
_TOOL_POLYGON = {
'name' : 'polygon',
- 'size' : 2,
+ 'line size' : 2,
'fill color' : None,
'stroke color' : None,
- 'shape' : 'circle',
+ 'line shape' : 'circle',
'fill' : True,
- 'sides' : None,
- 'points' : None
+ 'vertices' : None
}
_TOOL_BUCKET = {
'name' : 'bucket',
- 'size' : None,
+ 'line size' : None,
'fill color' : None,
'stroke color' : None,
- 'shape' : None,
+ 'line shape' : None,
'fill' : None,
- 'sides' : None,
- 'points' : None
+ 'vertices' : None
}
_TOOL_MARQUEE_ELLIPTICAL = {
'name' : 'marquee-elliptical',
- 'size' : None,
+ 'line size' : None,
'fill color' : None,
'stroke color' : None,
- 'shape' : None,
+ 'line shape' : None,
'fill' : None,
- 'sides' : None,
- 'points' : None
+ 'vertices' : None
}
_TOOL_MARQUEE_FREEFORM = {
'name' : 'marquee-freeform',
- 'size' : None,
+ 'line size' : None,
'fill color' : None,
'stroke color' : None,
- 'shape' : None,
+ 'line shape' : None,
'fill' : None,
- 'sides' : None,
- 'points' : None
+ 'vertices' : None
}
_TOOL_MARQUEE_RECTANGULAR = {
'name' : 'marquee-rectangular',
- 'size' : None,
+ 'line size' : None,
'fill color' : None,
'stroke color' : None,
- 'shape' : None,
+ 'line shape' : None,
'fill' : None,
- 'sides' : None,
- 'points' : None
+ 'vertices' : None
}
_TOOL_MARQUEE_SMART = {
'name' : 'marquee-smart',
- 'size' : None,
+ 'line size' : None,
'fill color' : None,
'stroke color' : None,
- 'shape' : None,
+ 'line shape' : None,
'fill' : None,
- 'sides' : None,
- 'points' : None
+ 'vertices' : None
}
@@ -427,7 +421,7 @@ class ToolsToolbar(gtk.Toolbar):
# This is where we set restrictions for size:
# Initial value, minimum value, maximum value, step
- adj = gtk.Adjustment(tool['size'], 1.0, 100.0, 1.0)
+ adj = gtk.Adjustment(tool['line size'], 1.0, 100.0, 1.0)
size_spinbutton.set_adjustment(adj)
size_spinbutton.set_numeric(True)
@@ -445,22 +439,6 @@ class ToolsToolbar(gtk.Toolbar):
tool['name'] is self._TOOL_ERASER['name']:
# Changing to gtk.RadioButton
-# item_1 = MenuItem(_('Square'), 'rectangle')
-# item_2 = MenuItem(_('Circle'), 'ellipse')
-#
-# logging.debug('Menu Items created')
-#
-# for menu_item in palette.menu.get_children():
-# palette.menu.remove(menu_item)
-#
-# palette.menu.append(item_1)
-# palette.menu.append(item_2)
-#
-# item_1.connect('activate', self.set_shape, tool, 'square')
-# item_2.connect('activate', self.set_shape, tool, 'circle')
-#
-# item_1.show()
-# item_2.show()
# TODO: insert images to represent shapes
item1 = gtk.RadioButton(None, _('Circle'))
item1.show()
@@ -481,11 +459,11 @@ class ToolsToolbar(gtk.Toolbar):
vbox.pack_start(label)
vbox.pack_start(item1)
vbox.pack_start(item2)
- #palette.action_bar.pack_start(vbox)
+
palette.set_content(vbox)
separator = gtk.HSeparator()
- vbox.pack_end(separator1)
+ vbox.pack_end(separator)
separator.show()
# User is able to fill or not a polygon, and its fill color
@@ -523,7 +501,7 @@ class ToolsToolbar(gtk.Toolbar):
@param shape -- Determine which shape Brush and Erase will use
"""
- tool['shape'] = shape
+ tool['line shape'] = shape
self.set_tool(tool=tool)
def set_tool(self, widget=None, tool=None):
@@ -543,15 +521,7 @@ class ToolsToolbar(gtk.Toolbar):
self._activity._area.set_tool(tool)
- # Moving this to Area
- #setting cursor
-# try:
-# pixbuf = gtk.gdk.pixbuf_new_from_file('./images/' + tool['name'] + '.png')
-# cursor = gtk.gdk.Cursor(gtk.gdk.display_get_default() , pixbuf, 6, 21)
-# except:
-# cursor = None
-#
-# self._activity._area.window.set_cursor(cursor)
+ #setting cursor: Moved to Area
def _on_icon_stroke_clicked(self, widget, data=None):
self._stroke_color.clicked()
@@ -584,137 +554,14 @@ class ToolsToolbar(gtk.Toolbar):
def _on_value_changed(self, spinbutton, tool):
size = spinbutton.get_value_as_int()
- tool['size'] = size
+ tool['line size'] = size
self.set_tool(tool=tool)
def _on_toggled(self, radiobutton, tool, shape):
if radiobutton.get_active():
self.set_shape(tool=tool, shape=shape)
-'''
-##Class to manage Fill colors
-class ComboFillColors(ToolComboBox):
- ## The Constructor
- def __init__(self, activity):
- ToolComboBox.__init__(self)
- self._activity = activity
-
- self._fill_color = self.combo
- self._fill_color.append_item(self.alloc_color('#000000'), 'Black')
- self._fill_color.append_item(self.alloc_color('#ffffff'), 'White')
- self._fill_color.append_item(self.alloc_color('#800000'), 'Maroon')
- self._fill_color.append_item(self.alloc_color('#ff0000'), 'Red')
- self._fill_color.append_item(self.alloc_color('#808000'), 'Olive')
- self._fill_color.append_item(self.alloc_color('#ffff00'), 'Yellow')
- self._fill_color.append_item(self.alloc_color('#008000'), 'Green')
- self._fill_color.append_item(self.alloc_color('#00ff00'), 'Lime')
- self._fill_color.append_item(self.alloc_color('#008080'), 'Teal')
- self._fill_color.append_item(self.alloc_color('#00ffff'), 'Aqua')
- self._fill_color.append_item(self.alloc_color('#000080'), 'Navy')
- self._fill_color.append_item(self.alloc_color('#0000ff'), 'Blue')
- self._fill_color.append_item(self.alloc_color('#800080'), 'Purple')
- self._fill_color.append_item(self.alloc_color('#ff00ff'), 'Fuchsia')
-
- self._fill_color.set_active(0)
- self._fill_color.connect('changed', self._combo_changed_cb)
-
- def alloc_color(self, color):
- """Alloc new color.
- @param self -- gtk.Toolbar
- @param color -- hexadecimal number
-
- @return gdk.Color object
-
- """
- colormap = self.get_colormap()
- _COLOR_ = colormap.alloc_color(color, True, True)
- return _COLOR_
-
- def _combo_changed_cb(self, combo):
- color = self.get_color()
- self.set_fill_color(color)
-
- def set_fill_color(self, color):
- """Set the fill color in Area
- @param self -- gtk.Toolbar
- @param color -- a gdk.Color object
-
- """
- self._activity._area._set_fill_color(color)
-
- def get_color(self):
- """Get the fill color from combobox
- @param self -- gtk.Toolbar
-
- @return gdk.Color object
-
- """
- model = self.combo.get_model()
- active = self.combo.get_active()
- return model[active][0]
-
-##Class to manage Stroke colors
-class ComboStrokeColors(ToolComboBox):
- ##The Constructor
- def __init__(self, activity):
-
- ToolComboBox.__init__(self)
- self._activity = activity
-
- self._stroke_color = self.combo
- self._stroke_color.append_item(self.alloc_color('#000000'), 'Black')
- self._stroke_color.append_item(self.alloc_color('#ffffff'), 'White')
- self._stroke_color.append_item(self.alloc_color('#800000'), 'Maroon')
- self._stroke_color.append_item(self.alloc_color('#ff0000'), 'Red')
- self._stroke_color.append_item(self.alloc_color('#808000'), 'Olive')
- self._stroke_color.append_item(self.alloc_color('#ffff00'), 'Yellow')
- self._stroke_color.append_item(self.alloc_color('#008000'), 'Green')
- self._stroke_color.append_item(self.alloc_color('#00ff00'), 'Lime')
- self._stroke_color.append_item(self.alloc_color('#008080'), 'Teal')
- self._stroke_color.append_item(self.alloc_color('#00ffff'), 'Aqua')
- self._stroke_color.append_item(self.alloc_color('#000080'), 'Navy')
- self._stroke_color.append_item(self.alloc_color('#0000ff'), 'Blue')
- self._stroke_color.append_item(self.alloc_color('#800080'), 'Purple')
- self._stroke_color.append_item(self.alloc_color('#ff00ff'), 'Fuchsia')
-
- self._stroke_color.set_active(0)
- self._stroke_color.connect('changed', self._combo_changed_cb)
-
- def alloc_color(self, color):
- """Alloc new color.
- @param self -- gtk.Toolbar
- @param color -- hexadecimal number
-
- @return gdk.Color object
-
- """
- colormap = self.get_colormap()
- _COLOR_ = colormap.alloc_color(color, True, True)
- return _COLOR_
-
- def _combo_changed_cb(self, combo):
- color = self.get_color()
- self.set_stroke_color(color)
-
- def get_color(self):
- """Get the fill color from combobox
- @param self -- gtk.Toolbar
-
- @return a gdk.Color object
-
- """
- model = self.combo.get_model()
- active = self.combo.get_active()
- return model[active][0]
-
- def set_stroke_color(self, color):
- """Set the fill color in Area
- @param self -- gtk.Toolbar
- @param color -- a gdk.Color object
- """
- self._activity._area._set_stroke_color(color)
-'''
##Class to manage Stroke Size
class ComboStrokeSize(ToolComboBox):
@@ -818,18 +665,115 @@ class ButtonStrokeColor(gtk.ColorButton):
##Make the Shapes Toolbar
class ShapesToolbar(gtk.Toolbar):
- _SHAPE_ARROW = 'arrow'
- _SHAPE_CURVE = 'curve'
- _SHAPE_ELLIPSE = 'ellipse'
- _SHAPE_FREEFORM = 'freeform'
- _SHAPE_HEART = 'heart'
- _SHAPE_LINE = 'line'
- _SHAPE_PARALLELOGRAM = 'parallelogram'
- _SHAPE_POLYGON = 'polygon_regular'
- _SHAPE_RECTANGLE = 'rectangle'
- _SHAPE_STAR = 'star'
- _SHAPE_TRAPEZOID = 'trapezoid'
- _SHAPE_TRIANGLE = 'triangle'
+ _SHAPE_ARROW = {
+ 'name' : 'arrow',
+ 'line size' : 5,
+ 'fill color' : None,
+ 'stroke color' : None,
+ 'line shape' : 'circle',
+ 'fill' : True,
+ 'vertices' : 5
+ }
+ _SHAPE_CURVE = {
+ 'name' : 'curve',
+ 'line size' : 2,
+ 'fill color' : None,
+ 'stroke color' : None,
+ 'line shape' : 'circle',
+ 'fill' : True,
+ 'vertices' : None
+ }
+ _SHAPE_ELLIPSE = {
+ 'name' : 'ellipse',
+ 'line size' : 2,
+ 'fill color' : None,
+ 'stroke color' : None,
+ 'line shape' : 'circle',
+ 'fill' : True,
+ 'vertices' : None
+ }
+ _SHAPE_FREEFORM = {
+ 'name' : 'freeform',
+ 'line size' : 2,
+ 'fill color' : None,
+ 'stroke color' : None,
+ 'line shape' : 'circle',
+ 'fill' : True,
+ 'vertices' : None
+ }
+ _SHAPE_HEART = {
+ 'name' : 'heart',
+ 'line size' : 2,
+ 'fill color' : None,
+ 'stroke color' : None,
+ 'line shape' : 'circle',
+ 'fill' : True,
+ 'vertices' : None
+ }
+ _SHAPE_LINE = {
+ 'name' : 'line',
+ 'line size' : 2,
+ 'fill color' : None,
+ 'stroke color' : None,
+ 'line shape' : 'circle',
+ 'fill' : True,
+ 'vertices' : None
+ }
+ _SHAPE_PARALLELOGRAM = {
+ 'name' : 'parallelogram',
+ 'line size' : 2,
+ 'fill color' : None,
+ 'stroke color' : None,
+ 'line shape' : 'circle',
+ 'fill' : True,
+ 'vertices' : None
+ }
+ _SHAPE_POLYGON = {
+ 'name' : 'polygon_regular',
+ 'line size' : 2,
+ 'fill color' : None,
+ 'stroke color' : None,
+ 'line shape' : 'circle',
+ 'fill' : True,
+ 'vertices' : None
+ }
+ _SHAPE_RECTANGLE = {
+ 'name' : 'rectangle',
+ 'line size' : 2,
+ 'fill color' : None,
+ 'stroke color' : None,
+ 'line shape' : 'circle',
+ 'fill' : True,
+ 'vertices' : None
+ }
+ _SHAPE_STAR = {
+ 'name' : 'star',
+ 'line size' : 2,
+ 'fill color' : None,
+ 'stroke color' : None,
+ 'line shape' : 'circle',
+ 'fill' : True,
+ 'vertices' : 5
+ }
+ _SHAPE_TRAPEZOID = {
+ 'name' : 'trapezoid',
+ 'line size' : 2,
+ 'fill color' : None,
+ 'stroke color' : None,
+ 'line shape' : 'circle',
+ 'fill' : True,
+ 'vertices' : None
+ }
+ _SHAPE_TRIANGLE = {
+ 'name' : 'triangle',
+ 'line size' : 2,
+ 'fill color' : None,
+ 'stroke color' : None,
+ 'line shape' : 'circle',
+ 'fill' : True,
+ 'vertices' : None
+ }
+
##The Constructor
def __init__(self, activity):
gtk.Toolbar.__init__(self)
@@ -861,10 +805,10 @@ class ShapesToolbar(gtk.Toolbar):
self.insert(item, -1)
item.show()
-
- self._stroke_size = ComboStrokeSize(activity)
- self.insert(self._stroke_size, -1)
- self._stroke_size.show()
+ # Line size is now choosen into tool's palette
+# self._stroke_size = ComboStrokeSize(activity)
+# self.insert(self._stroke_size, -1)
+# self._stroke_size.show()
separator = gtk.SeparatorToolItem()
separator.set_draw(True)
@@ -893,6 +837,10 @@ class ShapesToolbar(gtk.Toolbar):
self.insert(self._shape_line, -1)
self._shape_line.show()
self._shape_line.set_tooltip(_('Line'))
+ try:
+ self._configure_palette_shape_line()
+ except:
+ logging.debug('Could not create palette for Shape Line')
self._shape_polygon = ToolButton('tool-shape-polygon')
self.insert(self._shape_polygon, -1)
@@ -983,29 +931,20 @@ class ShapesToolbar(gtk.Toolbar):
self._shape_trapezoid.connect('clicked', self.set_tool, self._SHAPE_TRAPEZOID)
self._shape_triangle.connect('clicked', self.set_tool, self._SHAPE_TRIANGLE)
- def set_tool(self, widget, tool):
-
- # setting tool
- self._activity._area.tool = tool
-
- # setting size and color
- size = self._stroke_size.get_size()
- self._stroke_size.set_stroke_size(size)
+ def set_tool(self, widget=None, tool=None):
+ # New method to set tools; using dict
+ # Color must be allocated; if not, it will be displayed as black
stroke_color = self._stroke_color.get_color()
- self._stroke_color.set_stroke_color(stroke_color)
+ tool['stroke color'] = self._stroke_color.alloc_color(stroke_color)
fill_color = self._fill_color.get_color()
- self._fill_color.set_fill_color(fill_color)
+ tool['fill color'] = self._fill_color.alloc_color(fill_color)
- #setting cursor
- try:
- pixbuf = gtk.gdk.pixbuf_new_from_file('./images/' + tool + '.png')
- cursor = gtk.gdk.Cursor(gtk.gdk.display_get_default() , pixbuf, 6, 21)
- except:
- cursor = None
+ self._activity._area.set_tool(tool)
+
+ #setting cursor: moved to Area
- self._activity._area.window.set_cursor(cursor)
def _on_icon_stroke_clicked(self, widget, data=None):
self._stroke_color.clicked()
@@ -1014,39 +953,39 @@ class ShapesToolbar(gtk.Toolbar):
self._fill_color.clicked()
- def _on_value_changed(self, spinbutton, data=None):
- self._activity._area.polygon_sides = spinbutton.get_value_as_int()
+ def _on_vertices_value_changed(self, spinbutton, tool):
+ #self._activity._area.polygon_sides = spinbutton.get_value_as_int()
+ tool['vertices'] = spinbutton.get_value_as_int()
+ self.set_tool(tool=tool)
- 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_line_size_value_changed(self, spinbutton, tool):
+ tool['line size'] = spinbutton.get_value_as_int()
+ self.set_tool(tool=tool)
- def _on_fill_checkbutton_toggled(self, checkbutton, button=None):
+ def _on_fill_checkbutton_toggled(self, checkbutton, tool):
logging.debug('Checkbutton is Active: %s', checkbutton.get_active() )
- self._activity._area.fill = checkbutton.get_active()
- try:
- button.emit('clicked')
- except:
- pass
+ #self._activity._area.fill = checkbutton.get_active()
+ tool['fill'] = checkbutton.get_active()
+ self.set_tool(tool=tool)
def _configure_palette_shape_ellipse(self):
logging.debug('Creating palette to shape ellipse')
- self._create_simple_palette(self._shape_ellipse)
+ self._create_simple_palette(self._shape_ellipse, self._SHAPE_ELLIPSE)
def _configure_palette_shape_rectangle(self):
logging.debug('Creating palette to shape rectangle')
- self._create_simple_palette(self._shape_rectangle)
+ self._create_simple_palette(self._shape_rectangle, self._SHAPE_RECTANGLE)
def _configure_palette_shape_polygon(self):
logging.debug('Creating palette to shape polygon')
- self._create_simple_palette(self._shape_polygon)
+ # Enable 'Size' and 'Fill' option
+ self._create_simple_palette(self._shape_polygon, self._SHAPE_POLYGON)
+ # We want choose the number of sides to our polygon
palette = self._shape_polygon.get_palette()
-
-
+
spin = gtk.SpinButton()
spin.show()
@@ -1054,13 +993,9 @@ class ShapesToolbar(gtk.Toolbar):
black = gtk.gdk.Color(0,0,0)
spin.modify_text(gtk.STATE_NORMAL, black)
- # This is where we set restrictions for Regular Polygon:
+ # This is where we set restrictions for sides in 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)
+ adj = gtk.Adjustment(self._SHAPE_POLYGON['vertices'], 3.0, 50.0, 1.0)
spin.set_adjustment(adj)
spin.set_numeric(True)
@@ -1069,25 +1004,28 @@ class ShapesToolbar(gtk.Toolbar):
palette.action_bar.pack_start(label)
palette.action_bar.pack_start(spin)
- spin.connect('value-changed', self._on_value_changed, self._SHAPE_POLYGON)
+ spin.connect('value-changed', self._on_vertices_value_changed, self._SHAPE_POLYGON)
def _configure_palette_shape_heart(self):
logging.debug('Creating palette to shape heart')
- self._create_simple_palette(self._shape_heart)
+ self._create_simple_palette(self._shape_heart, self._SHAPE_HEART)
def _configure_palette_shape_parallelogram(self):
logging.debug('Creating palette to shape parallelogram')
- self._create_simple_palette(self._shape_parallelogram)
+ self._create_simple_palette(self._shape_parallelogram, self._SHAPE_PARALLELOGRAM)
def _configure_palette_shape_arrow(self):
logging.debug('Creating palette to shape arrow')
- self._create_simple_palette(self._shape_arrow)
+ self._create_simple_palette(self._shape_arrow, self._SHAPE_ARROW)
def _configure_palette_shape_star(self):
logging.debug('Creating palette to shape star')
- self._create_simple_palette(self._shape_star)
+ # Enable 'Size' and 'Fill' option
+ self._create_simple_palette(self._shape_star, self._SHAPE_STAR)
+
+ # We want choose the number of sides to our star
palette = self._shape_star.get_palette()
spin = gtk.SpinButton()
@@ -1099,11 +1037,7 @@ class ShapesToolbar(gtk.Toolbar):
# 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)
+ adj = gtk.Adjustment(self._SHAPE_STAR['vertices'], 3.0, 50.0, 1.0)
spin.set_adjustment(adj)
spin.set_numeric(True)
@@ -1112,54 +1046,84 @@ class ShapesToolbar(gtk.Toolbar):
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)
+ spin.connect('value-changed', self._on_vertices_value_changed, self._SHAPE_STAR)
def _configure_palette_shape_trapezoid(self):
logging.debug('Creating palette to shape trapezoid')
- self._create_simple_palette(self._shape_trapezoid)
+ self._create_simple_palette(self._shape_trapezoid, self._SHAPE_TRAPEZOID)
def _configure_palette_shape_triangle(self):
logging.debug('Creating palette to shape triangle')
- self._create_simple_palette(self._shape_triangle)
+ self._create_simple_palette(self._shape_triangle, self._SHAPE_TRIANGLE)
- def _create_simple_palette(self, button):
+ def _create_simple_palette(self, button, tool, line_size_only=False):
"""
- Create a simple palette with an CheckButton named "Fill". Most tools use only this.
- @param self -- gtk.Toolbar
+ Create a simple palette with an CheckButton named "Fill" and a SpinButton to represent the line size. Most tools use only this.
+ @param self -- toolbox.ShapesToolbar
@param button -- a ToolButton to associate the palette.
+ @param tool -- a dictionnary describing tool's properties.
+ @param line_size_only -- indicates if palette should only display Line Size option. Default value is False.
"""
palette = button.get_palette()
- fill_checkbutton = gtk.CheckButton(_('Fill'))
- fill_checkbutton.show()
- fill_checkbutton.set_active(self._activity._area.fill)
+ # Fill option
+ if not line_size_only:
+ fill_checkbutton = gtk.CheckButton(_('Fill'))
+ fill_checkbutton.show()
+ fill_checkbutton.set_active(tool['fill'])
+
+ fill_checkbutton.connect('toggled', self._on_fill_checkbutton_toggled, tool)
+
+ palette.set_content(fill_checkbutton)
+
+ size_spinbutton = gtk.SpinButton()
+ size_spinbutton.show()
- fill_checkbutton.connect('toggled', self._on_fill_checkbutton_toggled, button)
+ # When inserted in a Palette, a spinbutton does not display text in black
+ black = gtk.gdk.Color(0,0,0)
+ size_spinbutton.modify_text(gtk.STATE_NORMAL, black)
- fill_checkbutton.connect('map', self._on_fill_checkbutton_map)
-# widget.connect_after('clicked', self._on_fill_checkbutton_after_clicked, fill_checkbutton)
+ # This is where we set restrictions for size:
+ # Initial value, minimum value, maximum value, step
+ adj = gtk.Adjustment(tool['line size'], 1.0, 100.0, 1.0)
+ size_spinbutton.set_adjustment(adj)
- palette.set_content(fill_checkbutton)
-
- 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.
+ size_spinbutton.set_numeric(True)
- @param self -- gtk.Toolbar
- @param checkbutton
- @param data
- """
- self._activity._area.fill = checkbutton.get_active()
+ label = gtk.Label(_('Size: '))
+ label.show()
+
+ palette.action_bar.pack_start(label)
+ palette.action_bar.pack_start(size_spinbutton)
+
+ size_spinbutton.connect('value-changed', self._on_line_size_value_changed, tool)
-# def _on_fill_checkbutton_after_clicked(self, widget, checkbutton):
-# # Trying to prevent same condition described at self._on_fill_checkbutton_map
+# 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.
+#
+# @param self -- gtk.Toolbar
+# @param checkbutton
+# @param data
+# """
# self._activity._area.fill = checkbutton.get_active()
+ def _configure_palette_shape_line(self):
+ logging.debug('Creating palette to shape line')
+ self._create_simple_palette(self._shape_line, self._SHAPE_LINE, True)
+
##Make the Text Toolbar
class TextToolbar(gtk.Toolbar):
- _ACTION_TEXT = 'text'
+ _ACTION_TEXT = {
+ 'name' : 'text',
+ 'line size' : None,
+ 'fill color' : None,
+ 'stroke color' : None,
+ 'line shape' : None,
+ 'fill' : True,
+ 'vertices' : None
+ }
##The Constructor
def __init__(self, activity):
gtk.Toolbar.__init__(self)
@@ -1219,16 +1183,20 @@ class TextToolbar(gtk.Toolbar):
def set_tool(self, widget, tool):
#FIXME: this callback must change as others buttons get enabled
- self._activity._area.tool = tool
+# self._activity._area.tool = tool
+#
+# color = self._text_color.get_color()
+# self._text_color.set_fill_color(color)
+#
+# # setting cursor
+# pixbuf = gtk.gdk.pixbuf_new_from_file('./images/text.png')
+# cursor = gtk.gdk.Cursor(gtk.gdk.display_get_default() , pixbuf, 6, 21)
+# self._activity._area.window.set_cursor(cursor)
+ new_color = self._text_color.get_color()
+ tool['fill color'] = self._text_color.alloc_color(new_color)
+ self._activity._area.set_tool(tool)
- color = self._text_color.get_color()
- self._text_color.set_fill_color(color)
- # setting cursor
- pixbuf = gtk.gdk.pixbuf_new_from_file('./images/text.png')
- cursor = gtk.gdk.Cursor(gtk.gdk.display_get_default() , pixbuf, 6, 21)
- self._activity._area.window.set_cursor(cursor)
-
##Make the Images Toolbar
class ImageToolbar(gtk.Toolbar):
@@ -1357,7 +1325,18 @@ class ImageToolbar(gtk.Toolbar):
class EffectsToolbar(gtk.Toolbar):
_EFFECT_GRAYSCALE = 'grayscale'
- _EFFECT_RAINBOW = 'rainbow'
+ # Rainbow acts as a tool in Area, and it has to be described as a dict
+ _EFFECT_RAINBOW = {
+ 'name' : 'rainbow',
+ 'line size' : 10,
+ 'fill color' : None,
+ 'stroke color' : None,
+ 'line shape' : 'circle',
+ 'fill' : True,
+ 'vertices' : None
+ }
+
+
##The Constructor
def __init__(self, activity):
gtk.Toolbar.__init__(self)
@@ -1397,69 +1376,95 @@ class EffectsToolbar(gtk.Toolbar):
"""
self._effect_grayscale.connect('clicked', self.grayscale)
self._effect_rainbow.connect('clicked', self.rainbow)
+
##Make the colors be in grayscale
def grayscale(self, widget):
self._activity._area.grayscale(widget)
+
##Like the brush, but change it color when painting
def rainbow(self, widget):
- self._activity._area.tool = self._EFFECT_RAINBOW
+ self._activity._area.set_tool(self._EFFECT_RAINBOW)
- # setting cursor
- try:
- pixbuf = gtk.gdk.pixbuf_new_from_file('./images/rainbow.png')
- cursor = gtk.gdk.Cursor(gtk.gdk.display_get_default() , pixbuf, 6, 21)
-
- except:
- cursor = None
-
- self._activity._area.window.set_cursor(cursor)
+ # setting cursor: moved to Area
-
- def _configure_palette(self, widget, tool=None):
+ def _configure_palette(self, button, tool=None):
"""Set palette for a tool
- @param self -- gtk.Toolbar
- @param widget - the widget which Palette will be set
- @param tool - the reference tool for Palette creation. Its values are restricted to Class constants
+ @param self -- toolbox.EffectsToolbar
+ @param widget - the ToolButton which Palette will be set
+ @param tool -- a dictionnary describing tool's properties.
"""
logging.debug('setting a palette for %s', tool)
- palette = widget.get_palette()
+ palette = button.get_palette()
if tool is None:
return
elif tool is self._EFFECT_RAINBOW:
- spin = gtk.SpinButton()
- spin.show()
+ # We can adjust 'Line Size' and 'Line Shape' here
- black = gtk.gdk.Color(0,0,0)
- #white = gtk.gdk.Color(255,255,255)
+ # Line Size
+ size_spinbutton = gtk.SpinButton()
+ size_spinbutton.show()
- #spin.modify_base(gtk.STATE_NORMAL, black)
- #spin.modify_base(gtk.STATE_ACTIVE, white)
- spin.modify_text(gtk.STATE_NORMAL, black)
+ black = gtk.gdk.Color(0,0,0)
+ size_spinbutton.modify_text(gtk.STATE_NORMAL, black)
# This is where we set restrictions for Rainbow:
# Initial value, minimum value, maximum value, step
- adj = gtk.Adjustment(5.0, 1.0, 100.0, 1.0)
- spin.set_adjustment(adj)
+ adj = gtk.Adjustment(tool['line size'], 1.0, 100.0, 1.0)
+ size_spinbutton.set_adjustment(adj)
- spin.set_numeric(True)
+ size_spinbutton.set_numeric(True)
label = gtk.Label(_('Size: '))
label.show()
palette.action_bar.pack_start(label)
- palette.action_bar.pack_start(spin)
+ palette.action_bar.pack_start(size_spinbutton)
- spin.connect('value-changed', self._on_value_changed)
+ size_spinbutton.connect('value-changed', self._on_size_value_changed, tool)
- def _on_value_changed(self, spinbutton, data=None):
- size = spinbutton.get_value_as_int()
- self._activity._area.configure_line(size)
+ # Line Shape
+ # TODO: insert images to represent shapes
+ item1 = gtk.RadioButton(None, _('Circle'))
+ item1.show()
+ item1.set_active(True)
+
+ item2 = gtk.RadioButton(item1, _('Square'))
+ item2.show()
+
+ item1.connect('toggled', self._on_radio_toggled, tool, 'circle')
+ item2.connect('toggled', self._on_radio_toggled, tool, 'square')
+
+ label = gtk.Label(_('Shape'))
+ label.show()
+
+ vbox = gtk.VBox()
+ vbox.show()
+
+ vbox.pack_start(label)
+ vbox.pack_start(item1)
+ vbox.pack_start(item2)
+
+ separator = gtk.HSeparator()
+ vbox.pack_end(separator)
+ separator.show()
+
+ palette.set_content(vbox)
+
+ def _on_size_value_changed(self, spinbutton, tool):
+# size = spinbutton.get_value_as_int()
+# self._activity._area.configure_line(size)
+ tool['line size'] = spinbutton.get_value_as_int()
self.rainbow(self._effect_rainbow)
+ def _on_radio_toggled(self, radiobutton, tool, shape):
+ if radiobutton.get_active():
+ tool['line shape'] = shape
+ self.rainbow(self._effect_rainbow)
+
##Make the View Toolbar
class ViewToolbar(gtk.Toolbar):