mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Make activated() signal compatible with Qt. Allow setting app_id via the factory() function
This commit is contained in:
parent
d136c99cb4
commit
b679db73ed
@ -125,7 +125,7 @@ class MainWindow(QMainWindow):
|
|||||||
self.update_tray_toggle_action()
|
self.update_tray_toggle_action()
|
||||||
return QMainWindow.showEvent(self, ev)
|
return QMainWindow.showEvent(self, ev)
|
||||||
|
|
||||||
def tray_activated(self):
|
def tray_activated(self, reason):
|
||||||
self.setVisible(not self.isVisible())
|
self.setVisible(not self.isVisible())
|
||||||
|
|
||||||
def action_triggered(self, checked=False):
|
def action_triggered(self, checked=False):
|
||||||
|
@ -16,7 +16,7 @@ import os
|
|||||||
|
|
||||||
import dbus
|
import dbus
|
||||||
from PyQt5.Qt import (
|
from PyQt5.Qt import (
|
||||||
QApplication, QObject, pyqtSignal, Qt, QPoint, QRect, QMenu)
|
QApplication, QObject, pyqtSignal, Qt, QPoint, QRect, QMenu, QSystemTrayIcon)
|
||||||
|
|
||||||
from calibre.gui2.dbus_export.menu import DBusMenu
|
from calibre.gui2.dbus_export.menu import DBusMenu
|
||||||
from calibre.gui2.dbus_export.utils import icon_cache
|
from calibre.gui2.dbus_export.utils import icon_cache
|
||||||
@ -28,7 +28,7 @@ _sni_count = 0
|
|||||||
class StatusNotifierItem(QObject):
|
class StatusNotifierItem(QObject):
|
||||||
|
|
||||||
IFACE = 'org.kde.StatusNotifierItem'
|
IFACE = 'org.kde.StatusNotifierItem'
|
||||||
activated = pyqtSignal()
|
activated = pyqtSignal(object)
|
||||||
show_menu = pyqtSignal(int, int)
|
show_menu = pyqtSignal(int, int)
|
||||||
|
|
||||||
def __init__(self, **kw):
|
def __init__(self, **kw):
|
||||||
@ -93,6 +93,9 @@ class StatusNotifierItem(QObject):
|
|||||||
def supportsMessages(cls):
|
def supportsMessages(cls):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def emit_activated(self):
|
||||||
|
self.activated.emit(QSystemTrayIcon.Trigger)
|
||||||
|
|
||||||
_status_item_menu_count = 0
|
_status_item_menu_count = 0
|
||||||
|
|
||||||
class StatusNotifierItemAPI(Object):
|
class StatusNotifierItemAPI(Object):
|
||||||
@ -121,7 +124,7 @@ class StatusNotifierItemAPI(Object):
|
|||||||
if menu is None:
|
if menu is None:
|
||||||
menu = QMenu()
|
menu = QMenu()
|
||||||
if len(menu.actions()) == 0:
|
if len(menu.actions()) == 0:
|
||||||
menu.addAction(self.notifier.icon(), _('Show/hide %s') % self.title, self.notifier.activated.emit)
|
menu.addAction(self.notifier.icon(), _('Show/hide %s') % self.title, self.notifier.emit_activated)
|
||||||
# The menu must have at least one entry, namely the show/hide entry.
|
# The menu must have at least one entry, namely the show/hide entry.
|
||||||
# This is necessary as Canonical in their infinite wisdom decided to
|
# This is necessary as Canonical in their infinite wisdom decided to
|
||||||
# force all tray icons to show their popup menus when clicked.
|
# force all tray icons to show their popup menus when clicked.
|
||||||
@ -191,16 +194,16 @@ class StatusNotifierItemAPI(Object):
|
|||||||
|
|
||||||
@dbus_method(IFACE, in_signature='ii', out_signature='')
|
@dbus_method(IFACE, in_signature='ii', out_signature='')
|
||||||
def Activate(self, x, y):
|
def Activate(self, x, y):
|
||||||
self.notifier.activated.emit()
|
self.notifier.activated.emit(QSystemTrayIcon.Trigger)
|
||||||
|
|
||||||
@dbus_method(IFACE, in_signature='u', out_signature='')
|
@dbus_method(IFACE, in_signature='u', out_signature='')
|
||||||
def XAyatanaSecondaryActivate(self, timestamp):
|
def XAyatanaSecondaryActivate(self, timestamp):
|
||||||
# This is called when the user middle clicks the icon in Unity
|
# This is called when the user middle clicks the icon in Unity
|
||||||
self.notifier.activated.emit()
|
self.notifier.activated.emit(QSystemTrayIcon.MiddleClick)
|
||||||
|
|
||||||
@dbus_method(IFACE, in_signature='ii', out_signature='')
|
@dbus_method(IFACE, in_signature='ii', out_signature='')
|
||||||
def SecondaryActivate(self, x, y):
|
def SecondaryActivate(self, x, y):
|
||||||
self.notifier.activated.emit()
|
self.notifier.activated.emit(QSystemTrayIcon.MiddleClick)
|
||||||
|
|
||||||
@dbus_method(IFACE, in_signature='is', out_signature='')
|
@dbus_method(IFACE, in_signature='is', out_signature='')
|
||||||
def Scroll(self, delta, orientation):
|
def Scroll(self, delta, orientation):
|
||||||
|
@ -178,8 +178,8 @@ class Factory(QObject):
|
|||||||
# TODO: have the created widgets also handle bus disconnection
|
# TODO: have the created widgets also handle bus disconnection
|
||||||
|
|
||||||
_factory = None
|
_factory = None
|
||||||
def factory():
|
def factory(app_id=None):
|
||||||
global _factory
|
global _factory
|
||||||
if _factory is None:
|
if _factory is None:
|
||||||
_factory = Factory()
|
_factory = Factory(app_id=app_id)
|
||||||
return _factory
|
return _factory
|
||||||
|
Loading…
x
Reference in New Issue
Block a user