Newby pango problem

F

Friedrich Dimmling

Hi,

I would like to use pango.layout to display text in a pygtk2 project.
However I could not manage to get the pango.layout object incorporated
in my toplevel gtk.Window and have it displayed.

If anyone could help me either with a minimal example like 'Hello World'
displayed in italics in an pango.layout or the URL to a tutorial where I
can find the relevant infos (the PyGtk tutorial seems not to contain it,
unless I'm really blind)

Friedrich
 
J

John Hunter

Friedrich> Hi, I would like to use pango.layout to display text in
Friedrich> a pygtk2 project. However I could not manage to get the
Friedrich> pango.layout object incorporated in my toplevel
Friedrich> gtk.Window and have it displayed.

Friedrich> If anyone could help me either with a minimal example
Friedrich> like 'Hello World' displayed in italics in an
Friedrich> pango.layout or the URL to a tutorial where I can find
Friedrich> the relevant infos (the PyGtk tutorial seems not to
Friedrich> contain it, unless I'm really blind)

Here is pango_demo.py from my pygtk examples dir. I wrote this a long
time ago, so it may not be the best or most modern usage, but it may
help you along your way

from __future__ import division
import pygtk
pygtk.require('2.0')
import gtk
from gtk import gdk
import pango

win = gtk.Window()
win.show()
vbox = gtk.VBox()
vbox.show()
win.add(vbox)

figsize = 4,4
dpi = 72

def draw(widget):

gc = widget.window.new_gc()

context = widget.create_pango_context()
layout = widget.create_pango_layout('Some Text')
desc = pango.FontDescription('Times 14')


layout.set_font_description(desc)

widget.window.draw_layout(gc, x=100, y=200, layout=layout)
widget.window.draw_rectangle( gc, 1, 100,100,100,100)

def configure_event(widget, event):
global pixmap
pixmap = gtk.gdk.Pixmap(widget.window, 500, 500)
draw(widget)

return gtk.TRUE

def expose_event(widget, event):
draw(widget)
return gtk.TRUE

da = gtk.DrawingArea()
da.connect('configure_event', configure_event)
da.connect('expose_event', configure_event)

da.set_size_request(figsize[0]*dpi, figsize[1]*dpi)


da.show()
vbox.pack_start(da, gtk.TRUE, gtk.TRUE)

def byebye(button):
pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, 0, 8,
500,500)
pixbuf.get_from_drawable(pixmap, pixmap.get_colormap(),
0, 0, 0, 0, 500, 500)

pixbuf.save('somefile.png', 'png')
gtk.mainquit()

button = gtk.Button('Quit')
button.show()
vbox.pack_start(button, gtk.TRUE, gtk.TRUE)
button.connect('clicked', byebye)

gtk.mainloop()
 
F

Friedrich Dimmling

John said:
Here is pango_demo.py from my pygtk examples dir. I wrote this a long
time ago, so it may not be the best or most modern usage, but it may
help you along your way

Hi John,

it helped me along my way by pointing to the right section in the PyGtk
Tutorial. Thanks

Friedrich
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top