mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Add a sort button that shows up only when the Cover grid is displayed
This commit is contained in:
parent
2b3b26e24f
commit
cc0bc790a3
@ -38,13 +38,16 @@ class SortByAction(InterfaceAction):
|
||||
|
||||
def genesis(self):
|
||||
self.sorted_icon = QIcon(I('ok.png'))
|
||||
self.qaction.menu().aboutToShow.connect(self.update_menu)
|
||||
self.qaction.menu().aboutToShow.connect(self.about_to_show)
|
||||
|
||||
def location_selected(self, loc):
|
||||
self.qaction.setEnabled(loc == 'library')
|
||||
|
||||
def update_menu(self):
|
||||
menu = self.qaction.menu()
|
||||
def about_to_show(self):
|
||||
self.update_menu()
|
||||
|
||||
def update_menu(self, menu=None):
|
||||
menu = self.qaction.menu() if menu is None else menu
|
||||
for action in menu.actions():
|
||||
action.sort_requested.disconnect()
|
||||
menu.clear()
|
||||
@ -57,7 +60,6 @@ class SortByAction(InterfaceAction):
|
||||
sort_col, order = 'date', True
|
||||
fm = db.field_metadata
|
||||
name_map = {v:k for k, v in fm.ui_sortable_field_keys().iteritems()}
|
||||
self._sactions = []
|
||||
for name in sorted(name_map, key=sort_key):
|
||||
key = name_map[name]
|
||||
if key == 'ondevice' and self.gui.device_connected is None:
|
||||
|
@ -612,6 +612,8 @@ class LayoutMixin(object): # {{{
|
||||
|
||||
def toggle_grid_view(self, show):
|
||||
self.library_view.alternate_views.show_view('grid' if show else None)
|
||||
self.sort_sep.setVisible(show)
|
||||
self.sort_button.setVisible(show)
|
||||
|
||||
def toggle_search_bar(self, show):
|
||||
self.search_bar.setVisible(show)
|
||||
|
@ -270,6 +270,26 @@ class SearchBar(QFrame): # {{{
|
||||
l.addWidget(x)
|
||||
x.setVisible(not tweaks['show_saved_search_box'])
|
||||
|
||||
parent.sort_sep = QFrame(self)
|
||||
parent.sort_sep.setFrameStyle(QFrame.VLine | QFrame.Sunken)
|
||||
parent.sort_sep.setVisible(False)
|
||||
l.addWidget(parent.sort_sep)
|
||||
parent.sort_button = self.sort_button = sb = QToolButton(self)
|
||||
sb.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
|
||||
sb.setCursor(Qt.PointingHandCursor)
|
||||
sb.setPopupMode(QToolButton.InstantPopup)
|
||||
sb.setAutoRaise(True)
|
||||
sb.setText(_('Sort'))
|
||||
sb.setIcon(QIcon(I('sort.png')))
|
||||
sb.setMenu(QMenu())
|
||||
sb.menu().aboutToShow.connect(self.populate_sort_menu)
|
||||
sb.setVisible(False)
|
||||
l.addWidget(sb)
|
||||
|
||||
def populate_sort_menu(self):
|
||||
from calibre.gui2.ui import get_gui
|
||||
get_gui().iactions['Sort By'].update_menu(self.sort_button.menu())
|
||||
|
||||
# }}}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user