GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed May 22, 2013 8:30 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: [PyGTK] gtk.Entry.paste_clipboard() sometimes breaks entry
PostPosted: Fri Dec 19, 2008 9:09 pm 
Offline
Familiar Face

Joined: Tue Jul 08, 2008 1:07 am
Posts: 10
Under some circumstances which I don't understand, gtk.Entry.paste_clipboard() breaks future operations on the Entry's contents. I wrote up a more detailed question here, which didn't get any responses. My question is, why does paste_clipboard break things so badly, and is there a way to prevent that breakage?

_________________
GTK experience: almost none.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 21, 2008 6:09 pm 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hello.

There are 2 problems with your code.

The first problem arises from the fact that paste_clipboard() method doesn't do any text manipulation but just emits "paste-clipboard" signal. It's the default handler for gtk.Entry's "paste-clipboard" signal that does the real work. But before that handler is called, gtk takes care of all pending events with higher priority. This is why you get empty txt when printing - since nothing has been added to the gtk.Entry yet.

The usual method to handle these kind of situations is to process all the events inside you function with this construct:
Code:
while gtk.events_pending() :
    gtk.main_iteration()

But here comes the second problem. This method resolves the problem when the application is written in C, but pygtk seems to be "immune" to that call (I'm no pygtk expert, so I cannot tell you why exactly this construct is not working here).

BTW, your last method that resolved your problem works as expected because no fiddling with events is done - the text is retrieved and inserted at the exact moment you call your functions.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 21, 2008 11:27 pm 
Offline
Familiar Face

Joined: Tue Jul 08, 2008 1:07 am
Posts: 10
Thanks for the explanation. I wonder why the DevHelp docs said absolutely nothing about the event part of your explanation.

Oh well, it's not important anymore. I'm now filtering the clipboard contents before inserting them into the GetEntry, so gtk.Clipboard.wait_for_text() is a better approach now.

_________________
GTK experience: almost none.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 22, 2008 12:42 am 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
mssever wrote:
I wonder why the DevHelp docs said absolutely nothing about the event part of your explanation.

These kind of things are usually undocumented and you need to dig through the gtk's source code to unearth them - the price we sometimes need to pay for getting top class GUI toolkit for free.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google Adsense [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group