[PyKDE] KSystemTray and window closing

Sok Ann Yap ysa_arsenal at yahoo.com
Fri Aug 29 22:15:01 BST 2003


--- Jim Bublitz <jbublitz at nwinternet.com> wrote:
> On Thursday August 28 2003 17:16, Sok Ann Yap wrote:
> > Hi there,
> 
> > May I know how to keep my application from quitting when I
> > close the main window? The desired result is to let the
> > application to stay in the system tray and not taking any
> > space in the taskbar.
> 
> This seems to work too, using KMainWindow - it may require 
> PyKDE3.8 however for KApplication.quit and 
> KMainWindow.queryClose to work correctly (same casue for both 
> problems). 
> 
> Note that it doesn't close the main window but only hides it.
> The 
> extra memory used (as opposed to destroying the window) is 
> probably mininal, because the program remains running anyway.
> 
> If you want menus/toolbars/etc, or an XMLGUI constructed 
> interface, KMainWindow is a better choice than QWidget as in
> the 
> previous msg.
> 
> Jim
> 
> 
> 
> import sys
> 
> from qt import QLabel, QWidget, SIGNAL
> from kdecore import KApplication, KIconLoader
> from kdeui import KMainWindow, KSystemTray
> 
> class MainWin (KMainWindow):
>     def __init__ (self, *args):
>         apply (KMainWindow.__init__, (self,) + args)
> 
>         self.exitFlag = False
> 
>         icons = KIconLoader ()
> 
>         self.systray = KSystemTray (self)
>         self.systray.setPixmap (icons.loadIcon("stop", 0))
>         self.systray.connect (self.systray, 
>                                        
> SIGNAL("quitSelected()"),
>                                         self.slotQuitSelected)
>         self.systray.show ()
> 
>     def queryClose (self):
>         self.hide ()
>         return self.exitFlag
> 
>     def slotQuitSelected (self):
>         self.exitFlag = True
>         KApplication.kApplication ().quit ()
> 
> #-------------------- main 
> ------------------------------------------------
> 
> appName = "template"
> app = KApplication (sys.argv, appName)
> mainWindow = MainWin (None, "main window")
> 
> mainWindow.show()
> app.exec_loop()
> 

Thank you! It works perfectly on 3.7 here :)
In queryClose(), I just return False instead of using a flag,
and it works fine

Sok Ann

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com




More information about the PyQt mailing list