GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Mon Sep 01, 2014 9:04 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Catching Window Focus Loss Event/Signal
PostPosted: Sun Sep 30, 2012 2:04 pm 
Offline

Joined: Sun Sep 30, 2012 9:27 am
Posts: 2
Hello,

I'm a beginner with GTK and want to realize some projects with PyGTK.
I've done only one other GUI-project yet and this was with AutoHotkey for Windows. Additionally I have some experience with webdesign using PHP and HTML with a bit of JavaScript.

You'll guess that PyGTK is something really new for me, though I have some experience with Python itself.

For my current project which is just an idea so far I wanted to test the essential concepts to see if the whole project can be realized at all.

The one essential thing I could not get working yet is catching any signal when the toplevel window loses focus (because the user clicks somewhere outside the window).
I could not find any signal which is sent in this case. All I could find seems to be working for widgets like buttons but not for the "window widget".

Is there a way of calling a function when the window loses focus at all?
another thing I was thinking about: Is it possible to add code that's run during the main-loop? - Could be a workaround :D

Best regards,

Lucas


Top
 Profile  
 
 Post subject: Re: Catching Window Focus Loss Event/Signal
PostPosted: Sun Sep 30, 2012 5:50 pm 
Offline
GTK+ Guru

Joined: Fri Mar 25, 2011 5:16 pm
Posts: 177
Location: USA
You want the GtkWidget "notify::is-active" signal.
This is C not Python but here's an example:

http://www.gtkforums.com/viewtopic.php?t=4728


Top
 Profile  
 
 Post subject: Re: Catching Window Focus Loss Event/Signal
PostPosted: Mon Oct 01, 2012 7:37 pm 
Offline

Joined: Sun Sep 30, 2012 9:27 am
Posts: 2
Hello "zerohour",

I want to thank you very much. You've just hit the point and your linked posting showed me the "notify::is-active" signal which as I found out is called everytime the focus changes to or from (!) the window it is connected to.

I then wrote a callback function which determines whether the window is focused now after the signal was sent. If the window has focus the callback function does nothing - otherwise it closes my application. Exactly what I wanted to do.

So your hint gave me enough input to solve my problem and I learned using the notify signal which I think is really useful. Thanks for that! It's absolutely right that this signal seems to be rarely mentioned in any tutorials so your input was the better!

Thanks again for your reply in such a short time!

Best regards,

Lucas


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 2 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