Workaround for incompatibility between Qt 5.5+ and Ubuntu that caused the context menu for the book list to flicker. Fixes #1534936 [Context menu of the individual books on Ubuntu 15:10 flawed](https://bugs.launchpad.net/calibre/+bug/1534936)

This commit is contained in:
Kovid Goyal 2016-05-21 08:43:00 +05:30
parent 3636e380f3
commit 1c1d8c4f9e
3 changed files with 34 additions and 2 deletions

View File

@ -13,6 +13,7 @@ from PyQt5.Qt import (QImage, QSizePolicy, QTimer, QDialog, Qt, QSize, QAction,
QStackedLayout, QLabel, QByteArray, pyqtSignal, QKeySequence, QFont)
from calibre import plugins
from calibre.constants import islinux
from calibre.gui2 import (config, available_height, available_width, gprefs,
rating_font)
@ -170,8 +171,10 @@ if pictureflow is not None:
def contextMenuEvent(self, event):
if self.context_menu is not None:
from calibre.gui2.main_window import clone_menu
self.context_menu_requested.emit()
self.context_menu.popup(event.globalPos())
m = clone_menu(self.context_menu) if islinux else self.context_menu
m.popup(event.globalPos())
event.accept()
def sizeHint(self):

View File

@ -15,6 +15,7 @@ from PyQt5.Qt import (
QIcon, QItemSelection, QMimeData, QDrag, QStyle, QPoint, QUrl, QHeaderView,
QStyleOptionHeader, QItemSelectionModel, QSize, QFontMetrics)
from calibre.constants import islinux
from calibre.gui2.library.delegates import (RatingDelegate, PubDateDelegate,
TextDelegate, DateDelegate, CompleteDelegate, CcTextDelegate,
CcBoolDelegate, CcCommentsDelegate, CcDateDelegate, CcTemplateDelegate,
@ -818,11 +819,13 @@ class BooksView(QTableView): # {{{
self.edit_collections_action = edit_collections_action
def contextMenuEvent(self, event):
from calibre.gui2.main_window import clone_menu
sac = self.gui.iactions['Sort By']
sort_added = tuple(ac for ac in self.context_menu.actions() if ac is sac.qaction)
if sort_added:
sac.update_menu()
self.context_menu.popup(event.globalPos())
m = clone_menu(self.context_menu) if islinux else self.context_menu
m.popup(event.globalPos())
event.accept()
# }}}

View File

@ -162,3 +162,29 @@ class MainWindow(QMainWindow):
elif etype == ev.WindowUnblocked:
self.window_unblocked.emit()
return QMainWindow.event(self, ev)
def clone_menu(menu):
def clone_action(ac, parent):
if ac.isSeparator():
ans = QAction(parent)
ans.setSeparator(True)
return ans
sc = ac.shortcut()
sc = '' if sc.isEmpty() else sc.toString(sc.NativeText)
ans = QAction(ac.icon(), ac.text() + '\t' + sc, parent)
ans.triggered.connect(ac.trigger)
ans.setEnabled(ac.isEnabled())
ans.setStatusTip(ac.statusTip())
ans.setVisible(ac.isVisible())
return ans
def clone_one_menu(m):
ans = QMenu(m.parent())
for ac in m.actions():
cac = clone_action(ac, ans)
ans.addAction(cac)
m = ac.menu()
if m is not None:
cac.setMenu(clone_menu(m))
return ans
return clone_one_menu(menu)