From e21f28bf444dca0fc097802e97bd7b9fa36f9f78 Mon Sep 17 00:00:00 2001 From: Wade Brainerd Date: Sun, 30 Nov 2008 17:17:14 +0000 Subject: Keyboard as a brush palette. Save brushes using Ctrl+AnyKey, restore using AnyKey. --- diff --git a/_colorsc.so b/_colorsc.so index 99a5994..ad99ed7 100755 --- a/_colorsc.so +++ b/_colorsc.so Binary files differ diff --git a/colors.py b/colors.py index 8c6e52f..c7eb3b4 100755 --- a/colors.py +++ b/colors.py @@ -408,8 +408,8 @@ class Colors(activity.Activity, ExportedGObject): # Now that we have a canvas, connect the rest of the events. self.easelarea.connect('expose-event', self.on_canvasarea_expose) - self.easelarea.connect('key-press-event', self.on_key_event) - self.easelarea.connect('key-release-event', self.on_key_event) + self.connect('key-press-event', self.on_key_event) + self.connect('key-release-event', self.on_key_event) self.easelarea.connect('button-press-event', self.on_mouse_button) self.easelarea.connect('button-release-event', self.on_mouse_button) self.easelarea.connect('motion-notify-event', self.on_mouse_motion) @@ -882,12 +882,16 @@ class Colors(activity.Activity, ExportedGObject): else: self.pending_release = self.pending_release | button - return False else: + # Not a known key. Try to store / retrieve a brush. if self.cur_buttons & Colors.BUTTON_CONTROL: - self.brush_map[event.keyval] = self.brush + self.brush_map[event.keyval] = Brush(self.easel.brush) + + else: + if self.brush_map.has_key(event.keyval): + self.set_brush(self.brush_map[event.keyval]) - return True + return True def on_mouse_button(self, widget, event): if self.overlay_active: @@ -1094,6 +1098,10 @@ class Colors(activity.Activity, ExportedGObject): def set_brush (self, brush): #log.debug("set_brush color=%d,%d,%d type=%d size=%d opacity=%d", brush.color.r, brush.color.g, brush.color.b, brush.type, brush.size, brush.opacity) + # End any current stroke. + if self.easel.stroke: + self.end_draw() + self.easel.play_command(DrawCommand.create_color_change(brush.color), True) self.easel.play_command(DrawCommand.create_size_change(brush.control, brush.type, brush.size/float(self.easel.width), brush.opacity), True) self.brushpreviewarea.queue_draw() diff --git a/src/colorsc_wrap.cxx b/src/colorsc_wrap.cxx index 96fd8d1..a0f7a72 100644 --- a/src/colorsc_wrap.cxx +++ b/src/colorsc_wrap.cxx @@ -6991,7 +6991,7 @@ fail: } -SWIGINTERN PyObject *_wrap_new_Brush(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_new_Brush__SWIG_0(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; Brush *result = 0 ; @@ -7004,6 +7004,59 @@ fail: } +SWIGINTERN PyObject *_wrap_new_Brush__SWIG_1(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + Brush *arg1 = 0 ; + Brush *result = 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject * obj0 = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"O:new_Brush",&obj0)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1, SWIGTYPE_p_Brush, 0 | 0); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_Brush" "', argument " "1"" of type '" "Brush const &""'"); + } + if (!argp1) { + SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "new_Brush" "', argument " "1"" of type '" "Brush const &""'"); + } + arg1 = reinterpret_cast< Brush * >(argp1); + result = (Brush *)new Brush((Brush const &)*arg1); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Brush, SWIG_POINTER_NEW | 0 ); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_new_Brush(PyObject *self, PyObject *args) { + int argc; + PyObject *argv[2]; + int ii; + + if (!PyTuple_Check(args)) SWIG_fail; + argc = (int)PyObject_Length(args); + for (ii = 0; (ii < argc) && (ii < 1); ii++) { + argv[ii] = PyTuple_GET_ITEM(args,ii); + } + if (argc == 0) { + return _wrap_new_Brush__SWIG_0(self, args); + } + if (argc == 1) { + int _v; + int res = SWIG_ConvertPtr(argv[0], 0, SWIGTYPE_p_Brush, 0); + _v = SWIG_CheckState(res); + if (_v) { + return _wrap_new_Brush__SWIG_1(self, args); + } + } + +fail: + SWIG_SetErrorMsg(PyExc_NotImplementedError,"Wrong number of arguments for overloaded function 'new_Brush'.\n Possible C/C++ prototypes are:\n"" Brush()\n"" Brush(Brush const &)\n"); + return NULL; +} + + SWIGINTERN PyObject *_wrap_delete_Brush(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; Brush *arg1 = (Brush *) 0 ; -- cgit v0.9.1