Add an action ot the context menu for the book list headers to add custom columns

This commit is contained in:
Kovid Goyal 2010-09-07 14:02:09 -06:00
parent 2236678e4d
commit 6bfd24c278
2 changed files with 14 additions and 0 deletions

View File

@ -32,6 +32,9 @@ class LibraryViewMixin(object): # {{{
def __init__(self, db):
self.library_view.files_dropped.connect(self.iactions['Add Books'].files_dropped, type=Qt.QueuedConnection)
self.library_view.add_column_signal.connect(partial(self.iactions['Preferences'].do_config,
initial_plugin=('Interface', 'Custom Columns')),
type=Qt.QueuedConnection)
for func, args in [
('connect_to_search_box', (self.search,
self.search_done)),

View File

@ -23,6 +23,7 @@ from calibre.gui2.library import DEFAULT_SORT
class BooksView(QTableView): # {{{
files_dropped = pyqtSignal(object)
add_column_signal = pyqtSignal()
def __init__(self, parent, modelcls=BooksModel):
QTableView.__init__(self, parent)
@ -54,6 +55,7 @@ class BooksView(QTableView): # {{{
self.selectionModel().currentRowChanged.connect(self._model.current_changed)
# {{{ Column Header setup
self.can_add_columns = True
self.was_restored = False
self.column_header = self.horizontalHeader()
self.column_header.setMovable(True)
@ -93,6 +95,8 @@ class BooksView(QTableView): # {{{
self.sortByColumn(idx, Qt.DescendingOrder)
elif action == 'defaults':
self.apply_state(self.get_default_state())
elif action == 'addcustcol':
self.add_column_signal.emit()
elif action.startswith('align_'):
alignment = action.partition('_')[-1]
self._model.change_alignment(column, alignment)
@ -166,6 +170,12 @@ class BooksView(QTableView): # {{{
partial(self.column_header_context_handler,
action='defaults', column=col))
if self.can_add_columns:
self.column_header_context_menu.addAction(
_('Add your own columns'),
partial(self.column_header_context_handler,
action='addcustcol', column=col))
self.column_header_context_menu.popup(self.column_header.mapToGlobal(pos))
# }}}
@ -494,6 +504,7 @@ class DeviceBooksView(BooksView): # {{{
def __init__(self, parent):
BooksView.__init__(self, parent, DeviceBooksModel)
self.can_add_columns = False
self.columns_resized = False
self.resize_on_select = False
self.rating_delegate = None