Ticket #2708: save-restore-brush-properties.patch
File save-restore-brush-properties.patch, 16.0 KB (added by humitos, 11 years ago) |
---|
-
Area.py
diff --git a/Area.py b/Area.py index d953005..eb346b1 100644
a b class Area(gtk.DrawingArea): 917 917 @param color -- a gdk.Color object 918 918 919 919 """ 920 921 logging.debug('Area.set_stroke_color called: %s' % color) 922 920 923 self.gc_line.set_foreground(color) 921 924 self.gc_line.set_line_attributes(1, gtk.gdk.LINE_ON_OFF_DASH, 922 925 gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND) … … class Area(gtk.DrawingArea): 1279 1282 'fill': a Boolean value 1280 1283 'vertices': a integer 1281 1284 ''' 1282 # logging.debug('Area.set_tool %s', tool)1283 self.tool = tool1284 try:1285 if self.tool['line size'] is not None:1286 self.configure_line(self.tool['line size'])1287 1285 1288 if self.tool['fill color'] is not None: 1289 self.set_fill_color(self.tool['fill color']) 1290 else: 1291 # use black 1292 self.set_fill_color(self.black) 1286 logging.debug('Area.set_tool %s', tool) 1287 self.tool = tool 1288 if self.tool['line size'] is not None: 1289 self.configure_line(self.tool['line size']) 1293 1290 1294 if self.tool['strokecolor'] is not None:1295 self.set_stroke_color(self.tool['strokecolor'])1296 1297 1298 self.set_stroke_color(self.black)1291 if self.tool['fill color'] is not None: 1292 self.set_fill_color(self.tool['fill color']) 1293 else: 1294 # use black 1295 self.set_fill_color(self.black) 1299 1296 1300 except AttributeError: 1301 pass 1297 if self.tool['stroke color'] is not None: 1298 self.set_stroke_color(self.tool['stroke color']) 1299 else: 1300 # use black 1301 self.set_stroke_color(self.black) 1302 1302 1303 1303 self.set_tool_cursor() 1304 1304 -
OficinaActivity.py
diff --git a/OficinaActivity.py b/OficinaActivity.py index a74b7c1..ac594d5 100644
a b Walter Bender (walter@laptop.org) 64 64 import gtk 65 65 import logging 66 66 67 import simplejson 68 67 69 from sugar.activity import activity 68 70 from sugar.graphics import style 69 71 … … class OficinaActivity(activity.Activity): 157 159 self.area.loadImageFromJournal(pixbuf) 158 160 self.center_area() 159 161 162 # README: we need to modify: 163 # 1. GUI 164 # 2. Area 165 # if not, the Are changes will not take effect 166 167 # MODIFY THE GUI 168 # select the correct tool on the GUI 169 name = self.state_restored['name'] 170 if name in ('brush', 'eraser', 'bucket'): # 'stamp' 171 tool = getattr(self.get_toolbar_box().tools_builder, 172 '_tool_' + name) 173 elif name in ('ellipse', 'rectangle', 174 'line', 'freeform', 175 'polygon_regular', 'heart', 176 'parallelogram', 'arrow', 177 'star', 'trapezoid', 178 'triangle'): 179 if name == 'polygon_regular': 180 name = 'polygon' 181 tool = getattr(self.get_toolbar_box().shapes_button.props.page, 182 '_shape_' + name) 183 elif name in ('text', ): 184 tool = getattr(self.get_toolbar_box().fonts_button.props.page, 185 '_shape_' + name) 186 logging.debug('self.tool_group: %s' % self.tool_group) 187 tool.set_active(True) 188 self.tool_group = tool 189 190 toolbar_box = self.get_toolbar_box() 191 toolbar_box._stroke_color.size_spinbutton.set_value(\ 192 self.state_restored['line size']) 193 194 # brush shape 195 toolbar_box.brush_button.set_brush_shape(\ 196 self.state_restored['line shape']) 197 # brush size 198 toolbar_box.brush_button.set_brush_size(\ 199 self.state_restored['line size']) 200 toolbar_box.brush_button.set_stamp_size(\ 201 self.state_restored['stamp size']) 202 203 # brush color 204 if self.state_restored['stroke color'] is not None: 205 toolbar_box.brush_button.set_color(\ 206 self.state_restored['stroke color']) 207 # fill color 208 if self.state_restored['fill color'] is not None: 209 toolbar_box.shapes_button.props.page._fill_color.set_color(\ 210 self.state_restored['fill color']) 211 212 toolbar_box.shapes_button.props.page._fill_color.spin_sides.set_value(self.state_restored['vertices']) 213 214 # brush checkbutton shape (circle, square) 215 if self.state_restored['line shape'] == 'square': 216 # toolbar_box._stroke_color.circle_radio_button.set_active(False) 217 toolbar_box._stroke_color.square_radio_button.set_active(True) 218 else: 219 # toolbar_box._stroke_color.square_radio_button.set_active(False) 220 toolbar_box._stroke_color.circle_radio_button.set_active(True) 221 222 223 # TODO: check fonts 224 # Modify GUI using toolbox.py 225 # TextToolbar (__bold_bt_cb, __italic_bt_cb) 226 227 # MODIFY THE AREA 228 # set the stroke and fill color for the Area drawing 229 colormap = self.area.get_colormap() 230 if self.state_restored['stroke color'] is not None: 231 stroke_color = colormap.alloc_color(\ 232 self.state_restored['stroke color'].to_string(), 233 True, True) 234 self.area.set_stroke_color(stroke_color) 235 if self.state_restored['fill color'] is not None: 236 fill_color = colormap.alloc_color(\ 237 self.state_restored['fill color'].to_string(), 238 True, True) 239 self.area.set_fill_color(fill_color) 240 241 # TODO: check fonts 242 # Modify Area using toolbox.py 243 # TextToolbar (__bold_bt_cb, __italic_bt_cb) 244 245 160 246 self.canvas.add_with_viewport(self.fixed) 161 247 # to remove the border, we need set the shadowtype 162 248 # in the viewport child of the scrolledwindow … … class OficinaActivity(activity.Activity): 176 262 self.metadata['title'] = title 177 263 logging.error('title: %s', self.metadata['title']) 178 264 265 self.state_restored = simplejson.loads(self.metadata['state']) 266 for k in ('fill color', 'stroke color'): 267 if self.state_restored[k] != None: 268 self.state_restored[k] = \ 269 gtk.gdk.color_parse(self.state_restored[k]) 270 logging.debug('OficinaActivity.read_file') 271 self.area.tool = self.state_restored 272 273 # colormap = self.area.get_colormap() 274 # colormap.alloc_color(color.red, color.green, color.blue) 275 logging.debug('Loaded data state: %s' % self.state_restored) 276 179 277 def write_file(self, file_path): 180 278 '''Save file on Sugar Journal. ''' 181 279 … … class OficinaActivity(activity.Activity): 193 291 self.metadata['mime_type'] = 'image/png' 194 292 pixbuf.save(file_path, 'png', {}) 195 293 294 # TODO: here we should save brushes data, color, font, and all 295 # those settings that we change 296 state = {} 297 for k in self.area.tool.keys(): 298 if k in ('fill color', 'stroke color'): 299 if self.area.tool[k] != None: 300 state[k] = self.area.tool[k].to_string() 301 else: 302 state[k] = None 303 else: 304 state[k] = self.area.tool[k] 305 self.metadata['state'] = simplejson.dumps(state) 306 logging.debug('Wrote data state: %s' % state) 307 196 308 def _get_area_displacement(self): 197 309 """Return the point to use as top left corner in order to move 198 310 the drawing area and center it on the canvas. -
toolbox.py
diff --git a/toolbox.py b/toolbox.py index 25248ad..58dfb85 100644
a b class DrawToolbarBox(ToolbarBox): 103 103 104 104 self._activity.tool_group = None 105 105 106 tools_builder = ToolsToolbarBuilder(self.toolbar, self._activity)106 self.tools_builder = ToolsToolbarBuilder(self.toolbar, self._activity) 107 107 108 s hapes_button = ToolbarButton()109 s hapes_button.props.page = ShapesToolbar(self._activity)110 s hapes_button.props.icon_name = 'shapes'111 s hapes_button.props.label = _('Shapes')112 self.toolbar.insert(s hapes_button, -1)108 self.shapes_button = ToolbarButton() 109 self.shapes_button.props.page = ShapesToolbar(self._activity) 110 self.shapes_button.props.icon_name = 'shapes' 111 self.shapes_button.props.label = _('Shapes') 112 self.toolbar.insert(self.shapes_button, -1) 113 113 114 fonts_button = ToolbarButton()115 fonts_button.props.page = TextToolbar(self._activity)116 fonts_button.props.icon_name = 'format-text-size'117 fonts_button.props.label = _('Fonts')118 self.toolbar.insert( fonts_button, -1)114 self.fonts_button = ToolbarButton() 115 self.fonts_button.props.page = TextToolbar(self._activity) 116 self.fonts_button.props.icon_name = 'format-text-size' 117 self.fonts_button.props.label = _('Fonts') 118 self.toolbar.insert(self.fonts_button, -1) 119 119 120 120 image_button = ToolbarButton() 121 121 image_button.props.page = ImageToolbar(self._activity) … … class DrawToolbarBox(ToolbarBox): 134 134 135 135 # TODO: workaround 136 136 # the BrushButton does not starts 137 brush_button = tools_builder._stroke_color.color_button 138 brush_button.set_brush_shape(self._activity.area.tool['line shape']) 139 brush_button.set_brush_size(self._activity.area.tool['line size']) 140 brush_button.set_stamp_size(self._activity.area.tool['stamp size']) 137 self._stroke_color = self.tools_builder._stroke_color 138 self.brush_button = self.tools_builder._stroke_color.color_button 139 self.brush_button.set_brush_shape(self._activity.area.tool['line shape']) 140 self.brush_button.set_brush_size(self._activity.area.tool['line size']) 141 self.brush_button.set_stamp_size(self._activity.area.tool['stamp size']) 141 142 if self._activity.area.tool['stroke color'] is not None: 142 brush_button.set_color(self._activity.area.tool['stroke color'])143 self.brush_button.set_color(self._activity.area.tool['stroke color']) 143 144 144 145 145 146 ##Make the Edit Toolbar … … class ToolsToolbarBuilder(): 243 244 #self._stroke_color.set_icon_name('icon-stroke') 244 245 self._stroke_color.set_title(_('Brush properties')) 245 246 self._stroke_color.connect('notify::color', self._color_button_cb) 247 246 248 item = gtk.ToolItem() 247 249 item.add(self._stroke_color) 248 250 toolbar.insert(item, -1) … … class ButtonFillColor(ColorToolButton): 357 359 self.properties = self._activity.area.tool 358 360 self.connect('notify::color', self._color_button_cb) 359 361 362 self.spin_sides = None 363 360 364 def _color_button_cb(self, widget, pspec): 361 365 color = self.get_color() 362 366 self.set_fill_color(color) … … class ButtonFillColor(ColorToolButton): 392 396 content_box.pack_start(keep_aspect_checkbutton) 393 397 394 398 # We want choose the number of sides to our polygon 395 s pin= gtk.SpinButton()399 self.spin_sides = gtk.SpinButton() 396 400 397 401 # This is where we set restrictions for sides in Regular Polygon: 398 402 # Initial value, minimum value, maximum value, step 399 403 adj = gtk.Adjustment(self.properties['vertices'], 3.0, 50.0, 1.0) 400 s pin.set_adjustment(adj)401 s pin.set_numeric(True)404 self.spin_sides.set_adjustment(adj) 405 self.spin_sides.set_numeric(True) 402 406 403 407 label = gtk.Label(_('Sides: ')) 404 408 #For stars … … class ButtonFillColor(ColorToolButton): 407 411 hbox = gtk.HBox() 408 412 hbox.show_all() 409 413 hbox.pack_start(label) 410 hbox.pack_start(s pin)414 hbox.pack_start(self.spin_sides) 411 415 412 416 content_box.pack_start(hbox) 413 417 hbox.show_all() 414 spin.connect('value-changed', self._on_vertices_value_changed) 418 self.spin_sides.connect('value-changed', 419 self._on_vertices_value_changed) 415 420 416 421 color_palette_hbox.pack_start(gtk.VSeparator(), 417 422 padding=style.DEFAULT_SPACING) -
widgets.py
diff --git a/widgets.py b/widgets.py index c1833fa..10dcb86 100644
a b class ButtonStrokeColor(gtk.ToolItem): 187 187 # Replace it with a ColorButton 188 188 self.color_button = BrushButton(has_invoker=False) 189 189 self.add(self.color_button) 190 191 192 190 193 self.color_button.set_brush_size(2) 191 194 self.color_button.set_brush_shape('circle') 192 195 self.color_button.set_stamp_size(20) … … class ButtonStrokeColor(gtk.ToolItem): 221 224 222 225 def alloc_color(self, color): 223 226 colormap = self._activity.area.get_colormap() 227 # import logging 228 # logging.debug('COLORMAP') 229 # logging.debug(colormap) 230 # logging.debug(color) 224 231 return colormap.alloc_color(color.red, color.green, color.blue) 225 232 226 233 def create_palette(self): … … class ButtonStrokeColor(gtk.ToolItem): 246 253 self.size_spinbutton.connect('value-changed', self._on_value_changed) 247 254 248 255 # User is able to choose Shapes for 'Brush' and 'Eraser' 249 item1= gtk.RadioButton(None, _('Circle'))250 item1.set_active(True)256 self.circle_radio_button = gtk.RadioButton(None, _('Circle')) 257 self.circle_radio_button.set_active(True) 251 258 image1 = gtk.Image() 252 259 pixbuf1 = gtk.gdk.pixbuf_new_from_file_at_size( 253 260 './icons/tool-shape-ellipse.svg', 254 261 style.SMALL_ICON_SIZE, 255 262 style.SMALL_ICON_SIZE) 256 263 image1.set_from_pixbuf(pixbuf1) 257 item1.set_image(image1)264 self.circle_radio_button.set_image(image1) 258 265 259 item2 = gtk.RadioButton(item1, _('Square')) 266 self.square_radio_button = gtk.RadioButton(self.circle_radio_button, 267 _('Square')) 260 268 image2 = gtk.Image() 261 269 pixbuf2 = gtk.gdk.pixbuf_new_from_file_at_size( 262 270 './icons/tool-shape-rectangle.svg', 263 271 style.SMALL_ICON_SIZE, 264 272 style.SMALL_ICON_SIZE) 265 273 image2.set_from_pixbuf(pixbuf2) 266 item2.set_image(image2)274 self.square_radio_button.set_image(image2) 267 275 268 item1.connect('toggled', self._on_toggled, self.properties, 'circle') 269 item2.connect('toggled', self._on_toggled, self.properties, 'square') 276 self.circle_radio_button.connect('toggled', self._on_toggled, 277 self.properties, 'circle') 278 self.square_radio_button.connect('toggled', self._on_toggled, 279 self.properties, 'square') 270 280 271 281 label = gtk.Label(_('Shape')) 272 282 273 283 self.vbox_brush_options.pack_start(label) 274 self.vbox_brush_options.pack_start( item1)275 self.vbox_brush_options.pack_start( item2)284 self.vbox_brush_options.pack_start(self.circle_radio_button) 285 self.vbox_brush_options.pack_start(self.square_radio_button) 276 286 277 287 keep_aspect_checkbutton = gtk.CheckButton(_('Keep aspect')) 278 288 ratio = self._activity.area.keep_aspect_ratio … … class ButtonStrokeColor(gtk.ToolItem): 330 340 else: 331 341 self.properties['line size'] = size 332 342 self.color_button.set_brush_size(self.properties['line size']) 343 import logging 344 logging.debug(self.properties) 333 345 self._activity.area.set_tool(self.properties) 334 346 335 347 def _on_toggled(self, radiobutton, tool, shape):