[PyQt] How can i capture activated signal of Tray Icon??
Jebagnana Das
jebagnanadas at gmail.com
Tue Nov 16 07:46:01 GMT 2010
Thanks a ton pete. Worked perfectly. Sorry for not making myself clear from
the first time itself..
On Wed, Nov 10, 2010 at 10:06 PM, <pyqt-request at riverbankcomputing.com>wrote:
> Date: Wed, 10 Nov 2010 17:36:32 +0100
> From: "Hans-Peter Jansen" <hpj at urpla.net>
> To: pyqt at riverbankcomputing.com
> Subject: Re: [PyQt] How can i capture activated signal of Tray Icon??
> Message-ID: <201011101736.32188.hpj at urpla.net>
> Content-Type: text/plain; charset="utf-8"
>
> On Wednesday 10 November 2010, 16:30:03 Jebagnana Das wrote:
> > Thanks pete for your reply.
> >
> > I think you've misunderstood the core of the problem. The problem
> > here is not the elif construct(Even changed the code, had no effect).
>
> Well, it might be a poor answer to a poorly formulated question then?
> Anyway..
>
> > If we double click on the tray icon, on completion of the first click
> > this function gets called, and once again it's called when you finish
> > your second click.. Any solutions...
>
> Ah, now I understand your problem. The Trigger event is always thrown,
> even in the DoubleClick case. Hmm, now you found out, why the Trolls
> didn't call the former event just LeftClick ;-), and fixing this would
> shift the issue into DoubleClick handling.
>
> Here's, how I would solve such an issue:
>
> import sys
> from PyQt4.QtCore import *
> from PyQt4.QtGui import *
>
> class MainWindow(QMainWindow):
>
> def __init__(self, parent=None):
> super(MainWindow, self).__init__(parent)
> self.trayIcon = QSystemTrayIcon(QIcon("some.png"), self)
> self.trayIcon.activated.connect(self.onTrayIconActivated)
> self.trayIcon.show()
> self.disambiguateTimer = QTimer(self)
> self.disambiguateTimer.setSingleShot(True)
> self.disambiguateTimer.timeout.connect(
> self.disambiguateTimerTimeout)
>
> def onTrayIconActivated(self, reason):
> print "onTrayIconActivated:", reason
> if reason == QSystemTrayIcon.Trigger:
> self.disambiguateTimer.start(qApp.doubleClickInterval())
> elif reason == QSystemTrayIcon.DoubleClick:
> self.disambiguateTimer.stop()
> print "Tray icon double clicked"
>
> def disambiguateTimerTimeout(self):
> print "Tray icon single clicked"
>
>
> if __name__ == "__main__":
> app = QApplication(sys.argv)
> w = MainWindow()
> w.show()
> sys.exit(app.exec_())
>
>
> Pete
>
> > Am Tuesday 09 November 2010 15:08:29 schrieb Jebagnana Das:
> > > > Thanks Zoltan.. It did help a lot.. But if i want to capture
> > > > single click and double click events of the mouse separately i'm
> > > > afraid this can't be used..
> > > >
> > > > def onTrayIconActivated(self, reason):
> > > > if reason == QSystemTrayIcon.DoubleClick:
> > > > print('tray icon double clicked')
> > > >
> > > > if reason == QSystemTrayIcon.Trigger:
> > > > print("Tray icon single clicked")
> > > >
> > > > If i double click the tray icon it executes both if conditions.
> > > > Any way
> > >
> > > of
> > >
> > > > resolving this?. Thanks again..
> > >
> > > elif instead of second if perhaps?
> > >
> > > Pete
> > >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20101116/a6ae79b0/attachment-0001.html>
More information about the PyQt
mailing list