Re: [pygtk] a widget like gimp's canvas
Johannes Zellner wrote: On Wed, Aug 04, 2004 at 10:41:52AM -0300, Christian Robottom Reis wrote: On Wed, Aug 04, 2004 at 03:38:08PM +0200, Johannes Zellner wrote: the rulers ARE the difficult part! w/o any rulers, it's easy. The painful thing is to size and scroll the rulers simulaneously with the drawingarea (which can be placed inside a scrolledwindow). Why not put rulers and canvas inside the scrolledwindow? because then the rulers will be scrolled away. I've attached an approach, which shows how it should look like (but which doesn't work correctly). There the drawingarea is about 600 x 400 pixels large, but the viewport is only about 280 x 280 pixels. Note that the rulers were scrolled correctly to match the visible part of the drawingarea (the rulers start at about 80 and not zero). As I've said, the pygtk code which produced the screenshot doesn't work quite correctly and I thought that there must be already some code which does the job. I hacked up the tut demo and got the attached that seems to work though somewhat jerkily. John #!/usr/bin/env python # example drawingarea.py import pygtk pygtk.require('2.0') import gtk import operator import time import string class DrawingAreaExample: def __init__(self): window = gtk.Window(gtk.WINDOW_TOPLEVEL) window.set_title(Drawing Area Example) window.connect(destroy, lambda w: gtk.main_quit()) self.area = gtk.DrawingArea() self.area.set_size_request(400, 300) self.pangolayout = self.area.create_pango_layout() self.sw = gtk.ScrolledWindow() self.sw.add_with_viewport(self.area) self.table = gtk.Table(2,2) self.hruler = gtk.HRuler() self.vruler = gtk.VRuler() self.hruler.set_range(0, 400, 0, 400) self.vruler.set_range(0, 300, 0, 300) self.table.attach(self.hruler, 1, 2, 0, 1, yoptions=0) self.table.attach(self.vruler, 0, 1, 1, 2, xoptions=0) self.table.attach(self.sw, 1, 2, 1, 2) window.add(self.table) self.area.set_events(gtk.gdk.POINTER_MOTION_MASK | gtk.gdk.POINTER_MOTION_HINT_MASK ) self.area.connect(expose-event, self.area_expose_cb) def motion_notify(ruler, event): return ruler.emit(motion_notify_event, event) self.area.connect_object(motion_notify_event, motion_notify, self.hruler) self.area.connect_object(motion_notify_event, motion_notify, self.vruler) self.hadj = self.sw.get_hadjustment() self.vadj = self.sw.get_vadjustment() def val_cb(adj, ruler, horiz): if horiz: span = self.sw.get_allocation()[3] else: span = self.sw.get_allocation()[2] l,u,p,m = ruler.get_range() v = adj.value ruler.set_range(v, v+span, p, m) while gtk.events_pending(): gtk.main_iteration() self.hadj.connect('value-changed', val_cb, self.hruler, True) self.vadj.connect('value-changed', val_cb, self.vruler, False) def size_allocate_cb(wid, allocation): x, y, w, h = allocation l,u,p,m = self.hruler.get_range() m = max(m, w) self.hruler.set_range(l, l+w, p, m) l,u,p,m = self.vruler.get_range() m = max(m, h) self.vruler.set_range(l, l+h, p, m) self.sw.connect('size-allocate', size_allocate_cb) self.area.show() self.hruler.show() self.vruler.show() self.sw.show() self.table.show() window.show() def area_expose_cb(self, area, event): self.style = self.area.get_style() self.gc = self.style.fg_gc[gtk.STATE_NORMAL] self.draw_point(10,10) self.draw_points(110, 10) self.draw_line(210, 10) self.draw_lines(310, 10) self.draw_segments(10, 100) self.draw_rectangles(110, 100) self.draw_arcs(210, 100) self.draw_pixmap(310, 100) self.draw_polygon(10, 200) self.draw_rgb_image(110, 200) return gtk.TRUE def draw_point(self, x, y): self.area.window.draw_point(self.gc, x+30, y+30) self.pangolayout.set_text(Point) self.area.window.draw_layout(self.gc, x+5, y+50, self.pangolayout) return def draw_points(self, x, y): points = [(x+10,y+10), (x+10,y), (x+40,y+30), (x+30,y+10), (x+50,y+10)] self.area.window.draw_points(self.gc, points) self.pangolayout.set_text(Points) self.area.window.draw_layout(self.gc, x+5, y+50, self.pangolayout) return def draw_line(self, x, y): self.area.window.draw_line(self.gc, x+10, y+10, x+20, y+30) self.pangolayout.set_text(Line) self.area.window.draw_layout(self.gc, x+5, y+50, self.pangolayout) return def
Re: [pygtk] a widget like gimp's canvas
On Wed, Aug 04, 2004 at 07:42:51AM +0200, Johannes Zellner wrote: is there something like gimp's canvas (scrollable drawingarea with rulers which scroll simulaneously with the drawingarea) for pygtk? -- maybe as code sample? There's a DrawingArea widget: http://www.pygtk.org/pygtk2tutorial/ch-DrawingArea.html I'm not sure about the rulers, though. You'll probably need to cook that up yourself. Take care, -- Christian Robottom Reis | http://async.com.br/~kiko/ | [+55 16] 3361 2331 ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] a widget like gimp's canvas
On Wed, Aug 04, 2004 at 09:48:15AM -0300, Christian Robottom Reis wrote: On Wed, Aug 04, 2004 at 07:42:51AM +0200, Johannes Zellner wrote: is there something like gimp's canvas (scrollable drawingarea with rulers which scroll simulaneously with the drawingarea) for pygtk? -- maybe as code sample? There's a DrawingArea widget: http://www.pygtk.org/pygtk2tutorial/ch-DrawingArea.html I'm not sure about the rulers, though. You'll probably need to cook that up yourself. the rulers ARE the difficult part! w/o any rulers, it's easy. The painful thing is to size and scroll the rulers simulaneously with the drawingarea (which can be placed inside a scrolledwindow). -- Johannes ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] a widget like gimp's canvas
On Wed, Aug 04, 2004 at 03:38:08PM +0200, Johannes Zellner wrote: the rulers ARE the difficult part! w/o any rulers, it's easy. The painful thing is to size and scroll the rulers simulaneously with the drawingarea (which can be placed inside a scrolledwindow). Why not put rulers and canvas inside the scrolledwindow? Take care, -- Christian Robottom Reis | http://async.com.br/~kiko/ | [+55 16] 3361 2331 ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] a widget like gimp's canvas
On Wed, Aug 04, 2004 at 10:41:52AM -0300, Christian Robottom Reis wrote: On Wed, Aug 04, 2004 at 03:38:08PM +0200, Johannes Zellner wrote: the rulers ARE the difficult part! w/o any rulers, it's easy. The painful thing is to size and scroll the rulers simulaneously with the drawingarea (which can be placed inside a scrolledwindow). Why not put rulers and canvas inside the scrolledwindow? because then the rulers will be scrolled away. I've attached an approach, which shows how it should look like (but which doesn't work correctly). There the drawingarea is about 600 x 400 pixels large, but the viewport is only about 280 x 280 pixels. Note that the rulers were scrolled correctly to match the visible part of the drawingarea (the rulers start at about 80 and not zero). As I've said, the pygtk code which produced the screenshot doesn't work quite correctly and I thought that there must be already some code which does the job. -- Johannes attachment: canvas.jpg___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] a widget like gimp's canvas
Hi, You should have a look at how Dia does this. It's C code alright, but it shows exactly what you want (don't know the class to look, probably lib/display.c). All I can remember is that it's pretty easy (in the end ;-). Regards, Arjan Johannes Zellner wrote: On Wed, Aug 04, 2004 at 10:41:52AM -0300, Christian Robottom Reis wrote: On Wed, Aug 04, 2004 at 03:38:08PM +0200, Johannes Zellner wrote: the rulers ARE the difficult part! w/o any rulers, it's easy. The painful thing is to size and scroll the rulers simulaneously with the drawingarea (which can be placed inside a scrolledwindow). Why not put rulers and canvas inside the scrolledwindow? because then the rulers will be scrolled away. I've attached an approach, which shows how it should look like (but which doesn't work correctly). There the drawingarea is about 600 x 400 pixels large, but the viewport is only about 280 x 280 pixels. Note that the rulers were scrolled correctly to match the visible part of the drawingarea (the rulers start at about 80 and not zero). As I've said, the pygtk code which produced the screenshot doesn't work quite correctly and I thought that there must be already some code which does the job. ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/ ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] a widget like gimp's canvas
I've written some code using rulers and scrollbars that maybe could be useful for you: http://inigo.katxi.org/cgi-bin/archzoom.cgi/[EMAIL PROTECTED]/gdesklets-editor--dev--0.1--patch-4/gdesklets-desktop.py btw, reading pygtk reference seems that rulers are deprecated... does anyone know the reasons? Iñigo El mié, 04-08-2004 a las 09:48 -0300, Christian Robottom Reis escribió: On Wed, Aug 04, 2004 at 07:42:51AM +0200, Johannes Zellner wrote: is there something like gimp's canvas (scrollable drawingarea with rulers which scroll simulaneously with the drawingarea) for pygtk? -- maybe as code sample? There's a DrawingArea widget: http://www.pygtk.org/pygtk2tutorial/ch-DrawingArea.html I'm not sure about the rulers, though. You'll probably need to cook that up yourself. Take care, -- Christian Robottom Reis | http://async.com.br/~kiko/ | [+55 16] 3361 2331 signature.asc Description: Esta parte del mensaje =?ISO-8859-1?Q?est=E1?= firmada digitalmente ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] a widget like gimp's canvas
Hi, is there something like gimp's canvas (scrollable drawingarea with rulers which scroll simulaneously with the drawingarea) for pygtk? -- maybe as code sample? -- Johannes ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/