mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add systray tooltip to demo and honor the DontUseNativeToolbars application attribute
This commit is contained in:
parent
c0e585960a
commit
23dce4673d
@ -6,9 +6,11 @@ from __future__ import (unicode_literals, division, absolute_import,
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import time
|
||||
|
||||
from PyQt5.Qt import (
|
||||
QApplication, QMainWindow, QVBoxLayout, Qt, QKeySequence, QAction,
|
||||
QActionGroup, QMenu, QPushButton, QWidget)
|
||||
QActionGroup, QMenu, QPushButton, QWidget, QTimer)
|
||||
|
||||
from calibre.gui2.dbus_export.utils import setup_for_cli_run
|
||||
from calibre.gui2.dbus_export.widgets import factory
|
||||
@ -76,12 +78,17 @@ class MainWindow(QMainWindow):
|
||||
l.addWidget(b), b.clicked.connect(self.change_icon)
|
||||
self.hib = b = QPushButton('Show/Hide system tray icon')
|
||||
l.addWidget(b), b.clicked.connect(self.systray.toggle)
|
||||
self.update_tooltip_timer = t = QTimer(self)
|
||||
t.setInterval(1000), t.timeout.connect(self.update_tooltip), t.start()
|
||||
self.ab = b = QPushButton('Add a new menu')
|
||||
b.clicked.connect(self.add_menu), l.addWidget(b)
|
||||
self.rb = b = QPushButton('Remove a created menu')
|
||||
b.clicked.connect(self.remove_menu), l.addWidget(b)
|
||||
print ('DBUS connection unique name:', f.bus.get_unique_name())
|
||||
|
||||
def update_tooltip(self):
|
||||
self.systray.setToolTip(time.strftime('A dynamically updated tooltip [%H:%M:%S]'))
|
||||
|
||||
def add_menu(self):
|
||||
mb = self.menuBar()
|
||||
m = mb.addMenu('Created menu %d' % len(mb.actions()))
|
||||
@ -137,6 +144,7 @@ class MainWindow(QMainWindow):
|
||||
self.menu_two.addAction('Action added by about to show')
|
||||
|
||||
app=QApplication([])
|
||||
app.setAttribute(Qt.AA_DontUseNativeMenuBar, False)
|
||||
app.setApplicationName('com.calibre-ebook.DBusExportDemo')
|
||||
mw=MainWindow()
|
||||
mw.show()
|
||||
|
@ -89,6 +89,10 @@ class StatusNotifierItem(QObject):
|
||||
def icon(self):
|
||||
return self._icon
|
||||
|
||||
@classmethod
|
||||
def supportsMessages(cls):
|
||||
return False
|
||||
|
||||
_status_item_menu_count = 0
|
||||
|
||||
class StatusNotifierItemAPI(Object):
|
||||
@ -141,6 +145,8 @@ class StatusNotifierItemAPI(Object):
|
||||
|
||||
@dbus_property(IFACE, signature='(sa(iiay)ss)')
|
||||
def ToolTip(self):
|
||||
# This is ignored on Unity, Canonical believes in user interfaces
|
||||
# that are so functionality free that they dont need tooltips
|
||||
return self.IconName, self.IconPixmap, self.Title, self.notifier.toolTip()
|
||||
|
||||
@dbus_property(IFACE, signature='a(iiay)')
|
||||
|
@ -8,7 +8,8 @@ __copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import time, sys
|
||||
|
||||
from PyQt5.Qt import QObject, QMenuBar, QAction, QEvent, QSystemTrayIcon, QApplication
|
||||
from PyQt5.Qt import (
|
||||
QObject, QMenuBar, QAction, QEvent, QSystemTrayIcon, QApplication, Qt)
|
||||
|
||||
from calibre.constants import iswindows, isosx
|
||||
|
||||
@ -149,7 +150,7 @@ class Factory(QObject):
|
||||
self.status_notifier = bool(self.bus.call_blocking(*args, timeout=0.1))
|
||||
|
||||
def create_window_menubar(self, parent):
|
||||
if self.has_global_menu:
|
||||
if not QApplication.instance().testAttribute(Qt.AA_DontUseNativeMenuBar) and self.has_global_menu:
|
||||
return ExportedMenuBar(parent, self.menu_registrar, self.bus)
|
||||
return QMenuBar(parent)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user