Newby pango problem

Discussion in 'Python' started by Friedrich Dimmling, Aug 30, 2004.

  1. 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
     
    Friedrich Dimmling, Aug 30, 2004
    #1
    1. Advertising

  2. Friedrich Dimmling

    John Hunter Guest

    >>>>> "Friedrich" == Friedrich Dimmling <> 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()
     
    John Hunter, Aug 30, 2004
    #2
    1. Advertising

  3. 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
     
    Friedrich Dimmling, Aug 31, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul Guy
    Replies:
    3
    Views:
    617
    Paul Guy
    May 27, 2004
  2. Fred Nelson

    Base Windows Form Class (newby)

    Fred Nelson, Feb 10, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    695
    Fred Nelson
    Feb 10, 2004
  3. Replies:
    6
    Views:
    2,223
    Dave Higton
    Jun 30, 2006
  4. Guest
    Replies:
    3
    Views:
    381
    Fredrik Lundh
    Dec 9, 2004
  5. Hilmar Bunjes

    Error in Pango while using cairo/librsvg

    Hilmar Bunjes, Jun 15, 2009, in forum: Python
    Replies:
    1
    Views:
    752
Loading...

Share This Page