On Wed, Jun 18, 2008 at 8:33 AM, Robert Boehne <[EMAIL PROTECTED]> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> I'm attempting to do what should be simple, and that is display currency
> symbols in a pango markup label widget.
> However, when attempting to display the Pound Sterling symbol for the UK
> currency,
> I can get it to runder in a python prompt easily:
>
> |>> print u'\u001E'
> <prints pound sterling symbol>
>
> but then if I put that in a gtk label it displays as a box with 00 across
> the top and 1E across the bottom.
>
> Question: What version of pyGTK supports unicode label strings?
It works on the version you have installed. I have success just
putting literal unicode into the pango layout. Where the 'X' in the
string below is actually and accented e that I am having trouble
making my browser accept but it is fine in emacs with utf coding
string (see attached for complete example)
# -*- coding: utf-8 -*-
gc = widget.window.new_gc()
context = widget.create_pango_context()
layout = widget.create_pango_layout(unicode('DXveloppXs et
fabriquXs', 'latin-1')
fontsize = 12 # points
scale = dpi/72.0
desc = pango.FontDescription('Bitstream Vera Sans, normal 12')
desc.set_size(int(scale*fontsize)*1024)
layout.set_font_description(desc)
inkRect, logicalRect = layout.get_pixel_extents()
l,b,w,h = inkRect
#l,b,w,h = logicalRect
x, y = 100, 100
widget.window.draw_rectangle( gc, 0, l+x, y+b, w, h)
widget.window.draw_layout(gc, x, y, layout=layout)
# -*- coding: utf-8 -*-
from __future__ import division
import pygtk
pygtk.require('2.6')
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 = 200
def draw(widget):
gc = widget.window.new_gc()
context = widget.create_pango_context()
layout = widget.create_pango_layout(u'\u001E')
fontsize = 12 # points
scale = dpi/72.0
desc = pango.FontDescription('Bitstream Vera Sans, normal 12')
desc.set_size(int(scale*fontsize)*1024)
layout.set_font_description(desc)
inkRect, logicalRect = layout.get_pixel_extents()
l,b,w,h = inkRect
#l,b,w,h = logicalRect
x, y = 100, 100
widget.window.draw_rectangle( gc, 0, l+x, y+b, w, h)
widget.window.draw_layout(gc, x, y, layout=layout)
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):
gtk.mainquit()
button = gtk.Button('Quit')
button.show()
vbox.pack_start(button, gtk.TRUE, gtk.TRUE)
button.connect('clicked', byebye)
gtk.main()
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/