I am trying to make a simple drawing application using Python and gnomecanvas. Sadly, there appears to be no documentation for the Python bindings for gnomecanvas whatsoever. Thus, I am bumbling around using code samples and trying to guess from the C bindings.
As it is, I have the code working by keeping a list of current points in a stroke and generating a new path object from this list at each new item:
def get_pointer_coords(self, event):
return self.window_to_world(event.x, event.y)
def render_path(self):
path_def = gnomecanvas.path_def_new(self.cur_path)
self.current_item.set_bpath(path_def)
def button_press(self, event):
is_core = event.device is gdk.device_get_core_pointer()
if is_core:
return
self.drawing = True
(x, y) = self.get_pointer_coords(event)
self.cur_path = [(gnomecanvas.MOVETO_OPEN, x, y)]
self.current_item = self.root().add( gnomecanvas.CanvasBpath
, outline_color="#A6E22E"
, width_pixels=1
, cap_style=gdk.CAP_ROUND
)
def button_release(self, event):
self.drawing = False
def motion_notify(self, event):
is_core = event.device is gdk.device_get_core_pointer()
if not is_core and self.drawing:
(x, y) = self.get_pointer_coords(event)
self.cur_path.append((gnomecanvas.LINETO, x, y))
self.render_path()
This seems to me to be a rather inefficient method: generating a new object every time the pointer moves; and considering I'm getting subpixel precision from my tablet this is rather often.
My question is: is there a way by which I can simply append to the existing bpath on each pointer motion as I would in the C version of this library?
On a related note, is there any documentation for this API because I have done hours of Googling which have given me nothing in return.