mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add support for Unity's global menubars to calibre
This commit is contained in:
parent
b368d2d38a
commit
6653d6978b
@ -25,17 +25,22 @@ from calibre.utils.filenames import expanduser
|
|||||||
gprefs = JSONConfig('gui')
|
gprefs = JSONConfig('gui')
|
||||||
defs = gprefs.defaults
|
defs = gprefs.defaults
|
||||||
|
|
||||||
if isosx:
|
native_menubar_defaults = {
|
||||||
defs['action-layout-menubar'] = (
|
'action-layout-menubar': (
|
||||||
'Add Books', 'Edit Metadata', 'Convert Books',
|
'Add Books', 'Edit Metadata', 'Convert Books',
|
||||||
'Choose Library', 'Save To Disk', 'Preferences',
|
'Choose Library', 'Save To Disk', 'Preferences',
|
||||||
'Help',
|
'Help',
|
||||||
)
|
),
|
||||||
defs['action-layout-menubar-device'] = (
|
'action-layout-menubar-device': (
|
||||||
'Add Books', 'Edit Metadata', 'Convert Books',
|
'Add Books', 'Edit Metadata', 'Convert Books',
|
||||||
'Location Manager', 'Send To Device',
|
'Location Manager', 'Send To Device',
|
||||||
'Save To Disk', 'Preferences', 'Help',
|
'Save To Disk', 'Preferences', 'Help',
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if isosx:
|
||||||
|
defs['action-layout-menubar'] = native_menubar_defaults['action-layout-menubar']
|
||||||
|
defs['action-layout-menubar-device'] = native_menubar_defaults['action-layout-menubar-device']
|
||||||
defs['action-layout-toolbar'] = (
|
defs['action-layout-toolbar'] = (
|
||||||
'Add Books', 'Edit Metadata', None, 'Convert Books', 'View', None,
|
'Add Books', 'Edit Metadata', None, 'Convert Books', 'View', None,
|
||||||
'Choose Library', 'Donate', None, 'Fetch News', 'Store', 'Save To Disk',
|
'Choose Library', 'Donate', None, 'Fetch News', 'Store', 'Save To Disk',
|
||||||
|
@ -10,12 +10,12 @@ __docformat__ = 'restructuredtext en'
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
import sip
|
import sip
|
||||||
from PyQt5.Qt import (Qt, QAction, QMenu, QMenuBar, QObject,
|
from PyQt5.Qt import (
|
||||||
QToolBar, QToolButton, QSize, pyqtSignal, QTimer)
|
Qt, QAction, QMenu, QObject, QToolBar, QToolButton, QSize, pyqtSignal, QTimer)
|
||||||
|
|
||||||
from calibre.constants import isosx
|
from calibre.constants import isosx
|
||||||
from calibre.gui2.throbber import create_donate_widget
|
from calibre.gui2.throbber import create_donate_widget
|
||||||
from calibre.gui2 import gprefs, workaround_broken_under_mouse
|
from calibre.gui2 import gprefs, workaround_broken_under_mouse, native_menubar_defaults
|
||||||
|
|
||||||
class ToolBar(QToolBar): # {{{
|
class ToolBar(QToolBar): # {{{
|
||||||
|
|
||||||
@ -273,6 +273,8 @@ if isosx:
|
|||||||
|
|
||||||
class MenuBar(QObject):
|
class MenuBar(QObject):
|
||||||
|
|
||||||
|
is_native_menubar = True
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_menubar(self):
|
def native_menubar(self):
|
||||||
return self.gui.native_menubar
|
return self.gui.native_menubar
|
||||||
@ -353,11 +355,17 @@ else:
|
|||||||
elif what in iactions:
|
elif what in iactions:
|
||||||
m.addAction(iactions[what].qaction)
|
m.addAction(iactions[what].qaction)
|
||||||
|
|
||||||
class MenuBar(QMenuBar):
|
from calibre.gui2.dbus_export.widgets import factory
|
||||||
|
|
||||||
|
class MenuBar(QObject):
|
||||||
|
|
||||||
|
is_native_menubar = False
|
||||||
|
|
||||||
def __init__(self, location_manager, parent):
|
def __init__(self, location_manager, parent):
|
||||||
QMenuBar.__init__(self, parent)
|
QObject.__init__(self, parent)
|
||||||
parent.setMenuBar(self)
|
f = factory(app_id='com.calibre-ebook.gui')
|
||||||
|
self.menu_bar = f.create_window_menubar(parent)
|
||||||
|
self.is_native_menubar = self.menu_bar.is_native_menubar
|
||||||
self.gui = parent
|
self.gui = parent
|
||||||
|
|
||||||
self.location_manager = location_manager
|
self.location_manager = location_manager
|
||||||
@ -368,6 +376,15 @@ else:
|
|||||||
self.donate_menu.addAction(self.gui.donate_action)
|
self.donate_menu.addAction(self.gui.donate_action)
|
||||||
self.donate_action.setMenu(self.donate_menu)
|
self.donate_action.setMenu(self.donate_menu)
|
||||||
|
|
||||||
|
def addAction(self, *args):
|
||||||
|
self.menu_bar.addAction(*args)
|
||||||
|
|
||||||
|
def setVisible(self, visible):
|
||||||
|
self.menu_bar.setVisible(visible)
|
||||||
|
|
||||||
|
def clear(self):
|
||||||
|
self.menu_bar.clear()
|
||||||
|
|
||||||
def init_bar(self, actions):
|
def init_bar(self, actions):
|
||||||
for ac in self.added_actions:
|
for ac in self.added_actions:
|
||||||
m = ac.menu()
|
m = ac.menu()
|
||||||
@ -424,6 +441,9 @@ class BarsManager(QObject):
|
|||||||
self.child_bars = tuple(bars[2:])
|
self.child_bars = tuple(bars[2:])
|
||||||
|
|
||||||
self.menu_bar = MenuBar(self.location_manager, self.parent())
|
self.menu_bar = MenuBar(self.location_manager, self.parent())
|
||||||
|
is_native_menubar = self.menu_bar.is_native_menubar
|
||||||
|
self.menubar_fallback = native_menubar_defaults['action-layout-menubar'] if is_native_menubar else ()
|
||||||
|
self.menubar_device_fallback = native_menubar_defaults['action-layout-menubar-device'] if is_native_menubar else ()
|
||||||
|
|
||||||
self.apply_settings()
|
self.apply_settings()
|
||||||
self.init_bars()
|
self.init_bars()
|
||||||
@ -447,8 +467,8 @@ class BarsManager(QObject):
|
|||||||
self.bar_actions = tuple(
|
self.bar_actions = tuple(
|
||||||
[gprefs['action-layout-toolbar'+x] for x in ('', '-device')] +
|
[gprefs['action-layout-toolbar'+x] for x in ('', '-device')] +
|
||||||
[gprefs['action-layout-toolbar-child']] +
|
[gprefs['action-layout-toolbar-child']] +
|
||||||
[gprefs['action-layout-menubar']] +
|
[gprefs['action-layout-menubar'] or self.menubar_fallback] +
|
||||||
[gprefs['action-layout-menubar-device']]
|
[gprefs['action-layout-menubar-device'] or self.menubar_device_fallback]
|
||||||
)
|
)
|
||||||
|
|
||||||
for bar, actions in zip(self.bars, self.bar_actions[:3]):
|
for bar, actions in zip(self.bars, self.bar_actions[:3]):
|
||||||
|
@ -33,6 +33,8 @@ menu_counter = 0
|
|||||||
|
|
||||||
class ExportedMenuBar(QMenuBar): # {{{
|
class ExportedMenuBar(QMenuBar): # {{{
|
||||||
|
|
||||||
|
is_native_menubar = True
|
||||||
|
|
||||||
def __init__(self, parent, menu_registrar, bus):
|
def __init__(self, parent, menu_registrar, bus):
|
||||||
global menu_counter
|
global menu_counter
|
||||||
if not parent.isWindow():
|
if not parent.isWindow():
|
||||||
@ -109,6 +111,7 @@ class ExportedMenuBar(QMenuBar): # {{{
|
|||||||
self.unregister()
|
self.unregister()
|
||||||
self.register()
|
self.register()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
class Factory(QObject):
|
class Factory(QObject):
|
||||||
@ -212,6 +215,7 @@ class Factory(QObject):
|
|||||||
return ans
|
return ans
|
||||||
ans = QMenuBar(parent)
|
ans = QMenuBar(parent)
|
||||||
parent.setMenuBar(ans)
|
parent.setMenuBar(ans)
|
||||||
|
ans.is_native_menubar = False
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
def register_status_notifier(self, item):
|
def register_status_notifier(self, item):
|
||||||
|
@ -712,7 +712,7 @@ class DeviceMenu(QMenu): # {{{
|
|||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
QMenu.__init__(self, parent)
|
QMenu.__init__(self, parent)
|
||||||
self.group = QActionGroup(self)
|
self.group = QActionGroup(self)
|
||||||
self.actions = []
|
self._actions = []
|
||||||
self._memory = []
|
self._memory = []
|
||||||
|
|
||||||
self.set_default_menu = QMenu(_('Set default send to device action'))
|
self.set_default_menu = QMenu(_('Set default send to device action'))
|
||||||
@ -771,7 +771,7 @@ class DeviceMenu(QMenu): # {{{
|
|||||||
self.group.addAction(action)
|
self.group.addAction(action)
|
||||||
else:
|
else:
|
||||||
action.a_s.connect(self.action_triggered)
|
action.a_s.connect(self.action_triggered)
|
||||||
self.actions.append(action)
|
self._actions.append(action)
|
||||||
mdest.addAction(action)
|
mdest.addAction(action)
|
||||||
if actions is basic_actions:
|
if actions is basic_actions:
|
||||||
menu.addSeparator()
|
menu.addSeparator()
|
||||||
@ -822,14 +822,14 @@ class DeviceMenu(QMenu): # {{{
|
|||||||
|
|
||||||
def trigger_default(self, *args):
|
def trigger_default(self, *args):
|
||||||
r = config['default_send_to_device_action']
|
r = config['default_send_to_device_action']
|
||||||
for action in self.actions:
|
for action in self._actions:
|
||||||
if repr(action) == r:
|
if repr(action) == r:
|
||||||
self.action_triggered(action)
|
self.action_triggered(action)
|
||||||
break
|
break
|
||||||
|
|
||||||
def enable_device_actions(self, enable, card_prefix=(None, None),
|
def enable_device_actions(self, enable, card_prefix=(None, None),
|
||||||
device=None):
|
device=None):
|
||||||
for action in self.actions:
|
for action in self._actions:
|
||||||
if action.dest in ('main:', 'carda:0', 'cardb:0'):
|
if action.dest in ('main:', 'carda:0', 'cardb:0'):
|
||||||
if not enable:
|
if not enable:
|
||||||
action.setEnabled(False)
|
action.setEnabled(False)
|
||||||
|
@ -333,7 +333,10 @@ def run_gui(opts, args, listener, app, gui_debug=None):
|
|||||||
wizard().exec_()
|
wizard().exec_()
|
||||||
dynamic.set('welcome_wizard_was_run', True)
|
dynamic.set('welcome_wizard_was_run', True)
|
||||||
from calibre.gui2.ui import Main
|
from calibre.gui2.ui import Main
|
||||||
actions = tuple(Main.create_application_menubar())
|
if isosx:
|
||||||
|
actions = tuple(Main.create_application_menubar())
|
||||||
|
else:
|
||||||
|
actions = tuple(Main.get_menubar_actions())
|
||||||
runner = GuiRunner(opts, args, actions, listener, app, gui_debug=gui_debug)
|
runner = GuiRunner(opts, args, actions, listener, app, gui_debug=gui_debug)
|
||||||
ret = app.exec_()
|
ret = app.exec_()
|
||||||
if getattr(runner.main, 'run_wizard_b4_shutdown', False):
|
if getattr(runner.main, 'run_wizard_b4_shutdown', False):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user