Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to append to an existing gnome canvas bpath in Python?

Tags:

python

gnome

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.

like image 924
KitB Avatar asked Jul 09 '12 14:07

KitB


1 Answers

There's good libgnomecavas 2.3 documentation on native C API, that contains description for all C functions to work with gnomecanvas.

Python bindings do not expose all the described API in general, and your desired functions in particular, and there's no documentation on Python bindings for gnome canvas, all forces were sent to develop Gnome3-related things (you can explore it at live.gnome.org).

Another thing is that gnomecavas is quite outdated and Python bindings too; and there's no plans to support them in future (e.g. last several versions of Ubuntu has this package just being copied from version to version without any changes).

But there's another canvas library called GooCanvas which uses Cairo to draw on screen and seems to be more up-to-date, having PyGooCanvas Python bindings and used by some widespread projects, like Pitivi.


like image 199
Rostyslav Dzinko Avatar answered Sep 18 '22 19:09

Rostyslav Dzinko