[pygtk] gnome-python question

2003-07-22 Thread Colin Fox
Hi, everyone.

I was using gnome-python pre2.0 for some time, with great success.
Unfortunately things seem to have changed for gnome-python 2.0 and now
my programs don't run.

I've already done the various conversions needed to support modules
moving around and being renamed. What I'm now stuck on is trying to add
a line to a gnome canvas object. I get an incomprehensible error, and
I've no way to determine what's wrong.

I've attached the program. The problem is in the call to 'build' within
the WorldObject. The first add() statement dies like this:

 
(tinydemo.py:5601): GnomeCanvas-CRITICAL **: file gnome-canvas.c: line
198 (gnome_canvas_item_new): assertion `g_type_is_a (type,
gnome_canvas_item_get_type ())' failed
Traceback (most recent call last):
  File ./tinydemo.py, line 106, in ?
st.populate()
  File ./tinydemo.py, line 89, in populate
self.element = WorldObject(self.canvas,200,200)
  File ./tinydemo.py, line 16, in __init__
self.build()
  File ./tinydemo.py, line 67, in build
fill_color='darkgrey')
RuntimeError: could not create canvas item object

Can anyone either shed some light, or point me to some documentation to
show how to add canvas objects in 2.0? I originally wrote this based on
the gnome-python example, but I can't find a 2.0 equivalent of that
example.

I've attached my program for reference.

Thanks in advance!

cf
#!/usr/bin/env python

import gtk, gtk.gdk, gnome.ui, gnome.canvas

class WorldObject:
def __init__(self,canvas,x,y):
	self.myobj = None
	self.myline = None
	self.mylinepoints = [x,y,x,y]
	self.canvas = canvas
	self.width = 20
	self.height = 20
	self.x = x
	self.y = y
	self.lmb_pressed = 0
	self.build()

def set_line_endpoint(self,x,y):
	self.mylinepoints[0] = x
	self.mylinepoints[1] = y
	self.myline.set(points=self.mylinepoints)

def item_event(self, widget, event=None):
	if event.type == gtk.gdk.BUTTON_RELEASE:
	if event.button == 1:
		self.lmb_pressed = 0
		self.myline.hide()
		return gtk.TRUE

elif event.type == gtk.gdk.BUTTON_PRESS:
if event.button == 1:
		self.lmb_pressed = 1
		self.set_line_endpoint(event.x,event.y)
		self.myline.show()
return gtk.TRUE

elif event.type == gtk.gdk.MOTION_NOTIFY:
if event.state  gtk.gdk.BUTTON1_MASK:
		self.set_line_endpoint(event.x, event.y)
		return gtk.TRUE
 
elif event.type == gtk.gdk.ENTER_NOTIFY:
# Make the outline wide, show the arrow
widget.set(width_units=3, fill_color=cyan)
	self.myline.show()
return gtk.TRUE

elif event.type == gtk.gdk.LEAVE_NOTIFY:
# Make the outline thin, hide the arrow
widget.set(width_units=1, fill_color=blue)
	if self.lmb_pressed == 0:
		self.myline.hide()
return gtk.TRUE

return gtk.FALSE

def build(self):
	self.myline = self.canvas.root().add('line',
	points=self.mylinepoints,
	width_units=1.0,
	line_style=gtk.gdk.LINE_ON_OFF_DASH,
	arrow_shape_a=10.0,
	arrow_shape_b=15.0,
	arrow_shape_c=5.0,
	first_arrowhead=gtk.TRUE,
	last_arrowhead=gtk.FALSE,
	fill_color='darkgrey')

	self.myobj = self.canvas.root().add('ellipse',
	x1=self.x-(self.width/2),
	y1=self.y-(self.height/2),
	x2=self.x+(self.width/2),
	y2=self.y+(self.height/2),
	fill_color='blue', outline_color='black',
	width_units=1.0)

	self.myline.hide()
	self.myobj.show()
	self.myobj.connect(event,self.item_event)


class SimpleTest:
def __init__(self):
	self.width = 400
	self.height = 400
	self.canvas = None

def populate(self):
	self.element = WorldObject(self.canvas,200,200)

def open_window(self):
	win = gtk.Window(gtk.WINDOW_TOPLEVEL)
	win.connect('destroy', gtk.mainquit)
	win.set_title('Simple Example')

	self.canvas = gnome.canvas.Canvas()
	self.canvas.set_size_request(self.width, self.height)
	self.canvas.set_scroll_region(0,0, self.width, self.height)
	win.add(self.canvas)
	self.canvas.show()
	win.show()

if __name__ == '__main__':
st = SimpleTest()
st.open_window()
st.populate()
gtk.mainloop()

___
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] python gtk/gnome editor

2003-07-22 Thread Xavier Ordoquy
On Thu, 2003-07-17 at 23:03, Martijn Brouwer wrote:
 Hi,
 For a program I am writing I need a text editor that is written in Python and has a 
 gtk2 or gnome2 interface. I searched freshmeat but found nothing. I contacted the 
 author of Moleskine quit some time ago and he said he would come up with at gtk2 
 version, but the developement seems quite dead.
 Is there somebody who knows a suitable program or is writing one? At this moment a 
 wealth of features is not important for me, but for the future I would like to have 
 syntax hightlighting.
 I considered writing one myself, but I am not even spending enough time on my own 
 application, so this hardly an option. Is gtk SourceWidget (being) ported? I guess 
 that when this is widget is available, writing a editor will be relatively easy.
 
 Martijn

Hi,

Glimmer might help you. Here's an example of glimmer editor within gnome
in python.
http://gael.sourceforge.net/misc/glimmer.py

Regards,
Xavier.

-- 

___
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] Caching list view/-model ?

2003-07-22 Thread Peter Schulte-Stracke
Hi,

I am in desparate need of a List/Tree widget that does *not* read the whole
database / model, but only a portion of it, essentially what is displayed.

This looks as an innocuous enough requirement, but I failed completely to
get anything to work, or even to find a model implementation.

The libgnomedb appears to contain something in this direction, however
a.t.m. I am still searching for it :-)

Anyway, it should not be that uncommon a requirement, because it is not
uncommon to have large databases, and expensive per item processing.  

A minimum would be to disconnect the scrollbar from the listview, so that
one could reflect the position in a data base of, say, 1 records in
the scrollbar, but only display the first twenty records, say, at the
beginning.  Has anyone ever tried this?

Regards,
Peter

___
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] Loading images

2003-07-22 Thread Colin Fox
Hi, all.

I'm trying to load some png images, and I used to use the GdkImLib
module, but now that seems to be passe.

What's the gnome2 way to load  use images?

Thanks,
  cf
-- 
Colin Fox [EMAIL PROTECTED]
CF Consulting Inc.

___
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] Loading images

2003-07-22 Thread Christian Reis
On Tue, Jul 22, 2003 at 07:10:35PM -0700, Colin Fox wrote:
 
 I'm trying to load some png images, and I used to use the GdkImLib
 module, but now that seems to be passe.
 
 What's the gnome2 way to load  use images?

GdkPixbuf is probably what you want 

(isn't that in the FAQ? It should be..)

Take care,
--
Christian Reis, Senior Engineer, Async Open Source, Brazil.
http://async.com.br/~kiko/ | [+55 16] 261 2331 | NMFL
___
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] Caching list view/-model ?

2003-07-22 Thread James Henstridge
Peter Schulte-Stracke wrote:

Hi,

I am in desparate need of a List/Tree widget that does *not* read the whole
database / model, but only a portion of it, essentially what is displayed.
This looks as an innocuous enough requirement, but I failed completely to
get anything to work, or even to find a model implementation.
The libgnomedb appears to contain something in this direction, however
a.t.m. I am still searching for it :-)
Anyway, it should not be that uncommon a requirement, because it is not
uncommon to have large databases, and expensive per item processing.  

A minimum would be to disconnect the scrollbar from the listview, so that
one could reflect the position in a data base of, say, 1 records in
the scrollbar, but only display the first twenty records, say, at the
beginning.  Has anyone ever tried this?
 

The reason why the text in every row is measured (which can take a while 
for a large model).

However, you can set a fixed height for the text cells using the 
gtk.CellRendererText.set_fixed_height_from_font() method.  It takes a 
single argument: the number of rows of text in the cell.  That way it 
won't bother measuring the text to find the row height.

James.

--
Email: [EMAIL PROTECTED]
WWW:   http://www.daa.com.au/~james/


___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/