[pygtk] textview & configure-event, Was: window.get_size() returns incorrect size?

Wiktor Grebla greblus at wp.pl
Thu Jan 12 03:00:32 WST 2006


Referring to my previous e-mail, I'd like to ask a few more questions,
let me quote it below:

On Mon, Dec 19, 2005 at 01:26:46AM +0100, Wiktor Grebla wrote:

> I'm trying to place an information window in the right upper corner of
> the screen, but after the textview buffer change, get_size() method
> returns incorrect (at least from what i'm expecting) window size:
> 
> http://metawire.org/~greblus/shots/1.png
> 
> Here it's waiting for data from a command in a subprocess,
> window size is (157, 24),
> 
> http://metawire.org/~greblus/shots/2.png
> 
> after setting new textview buffer text it does simply:
> 
> hintwin.show_all()
> screen = hintwin.get_screen()
> screenw = screen.get_width()
> hintw = hintwin.get_size()
> 
> hintwin.move(screenw - hintw[0], 30)
> 
> unfortunately the size stays the same until the next update:
> 
> http://metawire.org/~greblus/shots/3.png
> 
> and here, the correct size is returned, and everything looks 
> good (of course i guess that the window won't be placed in 
> the right place if there will be a bigger buffer change).
> 
> What should i do after buffer.set_text(info) to assure window 
> size recalculation? 
> 
> (pygtk-2.6.3)

After upgrading pygtk to pygtk-2.8.2 I returned to the documentation,
and according to gtk.Window.get_size() description (notes) I've been
trying to get window size and move it in a callback for configure-event. 
This way it should be done after wm notification and when the window 
state changes.

I attach sample code. As I understand the results, configure-event is 
emitted only after buffer text gets longer, otherwise textview size 
(and window size) stays unchanged. Is it possible to force/ensure 
size adjustment after textbuffer text gets shorter?

Regards,
W.

-- 
Subtlety is the art of saying what you think and getting out of the way
before it is understood.
-------------- next part --------------
#!/usr/bin/python
# coding: utf-8

import pygtk
pygtk.require('2.0')
import gtk
import gobject
import random

win = gtk.Window(gtk.WINDOW_POPUP)

textview = gtk.TextView()
textview.set_justification(gtk.JUSTIFY_LEFT)
buffer = textview.get_buffer()
win.add(textview)

win.show_all()

screen = win.get_screen()
screenw = screen.get_width()
screenh = screen.get_height()

n = 1
def change_text():
    global n
    text = "text"*n
    print "new text after set_text():", text
    buffer.set_text(text)
    n += random.choice([-1, 1])
    if n == 0: n = 1
    return True

def move(widget, event):
    win.width, win.height = win.get_size()
    print "configure-event size:", win.width, win.height
    win.move(screenw - win.width, 30)

win.connect('configure-event', move)

gobject.timeout_add(5000, change_text)

gtk.main()



More information about the pygtk mailing list