Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Newby pango problem

Reply
Thread Tools

Newby pango problem

 
 
Friedrich Dimmling
Guest
Posts: n/a
 
      08-30-2004
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
 
Reply With Quote
 
 
 
 
John Hunter
Guest
Posts: n/a
 
      08-30-2004
>>>>> "Friedrich" == Friedrich Dimmling <(E-Mail Removed)> writes:

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()

 
Reply With Quote
 
 
 
 
Friedrich Dimmling
Guest
Posts: n/a
 
      08-31-2004
John Hunter wrote:
>
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in Pango while using cairo/librsvg Hilmar Bunjes Python 1 06-30-2009 06:54 AM
Stupid Newby Question: VHDL/CPLD Shift Register Reset Problem dhudson01@gmail.com VHDL 6 06-30-2006 06:22 PM
wireless newby Crispy Sea Wireless Networking 3 01-18-2005 04:27 AM
[Newby] Problem with compilation. Python 3 12-09-2004 11:23 PM
Newby connect problem Sheldon Isaac Computer Support 2 10-16-2003 06:47 PM



Advertisments