[PyKDE] KSystemTray and window closing
Jim Bublitz
jbublitz at nwinternet.com
Fri Aug 29 21:15:00 BST 2003
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()
More information about the PyQt
mailing list