mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Cleanup signal connection in tag_view.py
This commit is contained in:
parent
a80094415a
commit
2988e48cf2
@ -10,17 +10,18 @@ Browsing book collection by tags.
|
|||||||
from itertools import izip
|
from itertools import izip
|
||||||
|
|
||||||
from PyQt4.Qt import Qt, QTreeView, QApplication, pyqtSignal, \
|
from PyQt4.Qt import Qt, QTreeView, QApplication, pyqtSignal, \
|
||||||
QFont, SIGNAL, QSize, QIcon, QPoint, \
|
QFont, QSize, QIcon, QPoint, \
|
||||||
QAbstractItemModel, QVariant, QModelIndex
|
QAbstractItemModel, QVariant, QModelIndex
|
||||||
from calibre.gui2 import config, NONE
|
from calibre.gui2 import config, NONE
|
||||||
from calibre.utils.config import prefs
|
from calibre.utils.config import prefs
|
||||||
from calibre.utils.search_query_parser import saved_searches
|
from calibre.utils.search_query_parser import saved_searches
|
||||||
from calibre.library.database2 import Tag
|
from calibre.library.database2 import Tag
|
||||||
|
|
||||||
class TagsView(QTreeView):
|
class TagsView(QTreeView): # {{{
|
||||||
|
|
||||||
need_refresh = pyqtSignal()
|
need_refresh = pyqtSignal()
|
||||||
restriction_set = pyqtSignal(object)
|
restriction_set = pyqtSignal(object)
|
||||||
|
tags_marked = pyqtSignal(object, object)
|
||||||
|
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
QTreeView.__init__(self, *args)
|
QTreeView.__init__(self, *args)
|
||||||
@ -36,10 +37,10 @@ class TagsView(QTreeView):
|
|||||||
self.tag_match = tag_match
|
self.tag_match = tag_match
|
||||||
self.db = db
|
self.db = db
|
||||||
self.setModel(self._model)
|
self.setModel(self._model)
|
||||||
self.connect(self, SIGNAL('clicked(QModelIndex)'), self.toggle)
|
self.clicked.connect(self.toggle)
|
||||||
self.popularity.setChecked(config['sort_by_popularity'])
|
self.popularity.setChecked(config['sort_by_popularity'])
|
||||||
self.connect(self.popularity, SIGNAL('stateChanged(int)'), self.sort_changed)
|
self.popularity.stateChanged.connect(self.sort_changed)
|
||||||
self.connect(self.restriction, SIGNAL('activated(const QString&)'), self.search_restriction_set)
|
self.restriction.activated[str].connect(self.search_restriction_set)
|
||||||
self.need_refresh.connect(self.recount, type=Qt.QueuedConnection)
|
self.need_refresh.connect(self.recount, type=Qt.QueuedConnection)
|
||||||
db.add_listener(self.database_changed)
|
db.add_listener(self.database_changed)
|
||||||
self.saved_searches_changed(recount=False)
|
self.saved_searches_changed(recount=False)
|
||||||
@ -69,15 +70,13 @@ class TagsView(QTreeView):
|
|||||||
self.model().set_search_restriction(self.search_restriction)
|
self.model().set_search_restriction(self.search_restriction)
|
||||||
self.restriction_set.emit(self.search_restriction)
|
self.restriction_set.emit(self.search_restriction)
|
||||||
self.recount() # Must happen after the emission of the restriction_set signal
|
self.recount() # Must happen after the emission of the restriction_set signal
|
||||||
self.emit(SIGNAL('tags_marked(PyQt_PyObject, PyQt_PyObject)'),
|
self.tags_marked.emit(self._model.tokens(), self.match_all)
|
||||||
self._model.tokens(), self.match_all)
|
|
||||||
|
|
||||||
def toggle(self, index):
|
def toggle(self, index):
|
||||||
modifiers = int(QApplication.keyboardModifiers())
|
modifiers = int(QApplication.keyboardModifiers())
|
||||||
exclusive = modifiers not in (Qt.CTRL, Qt.SHIFT)
|
exclusive = modifiers not in (Qt.CTRL, Qt.SHIFT)
|
||||||
if self._model.toggle(index, exclusive):
|
if self._model.toggle(index, exclusive):
|
||||||
self.emit(SIGNAL('tags_marked(PyQt_PyObject, PyQt_PyObject)'),
|
self.tags_marked.emit(self._model.tokens(), self.match_all)
|
||||||
self._model.tokens(), self.match_all)
|
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
self.model().clear_state()
|
self.model().clear_state()
|
||||||
@ -119,8 +118,9 @@ class TagsView(QTreeView):
|
|||||||
def set_new_model(self):
|
def set_new_model(self):
|
||||||
self._model = TagsModel(self.db, parent=self)
|
self._model = TagsModel(self.db, parent=self)
|
||||||
self.setModel(self._model)
|
self.setModel(self._model)
|
||||||
|
# }}}
|
||||||
|
|
||||||
class TagTreeItem(object):
|
class TagTreeItem(object): # {{{
|
||||||
|
|
||||||
CATEGORY = 0
|
CATEGORY = 0
|
||||||
TAG = 1
|
TAG = 1
|
||||||
@ -193,8 +193,10 @@ class TagTreeItem(object):
|
|||||||
if self.type == self.TAG:
|
if self.type == self.TAG:
|
||||||
self.tag.state = (self.tag.state + 1)%3
|
self.tag.state = (self.tag.state + 1)%3
|
||||||
|
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
class TagsModel(QAbstractItemModel): # {{{
|
||||||
|
|
||||||
class TagsModel(QAbstractItemModel):
|
|
||||||
categories_orig = [_('Authors'), _('Series'), _('Formats'), _('Publishers'),
|
categories_orig = [_('Authors'), _('Series'), _('Formats'), _('Publishers'),
|
||||||
_('Ratings'), _('News'), _('Tags')]
|
_('Ratings'), _('News'), _('Tags')]
|
||||||
row_map_orig = ['author', 'series', 'format', 'publisher', 'rating',
|
row_map_orig = ['author', 'series', 'format', 'publisher', 'rating',
|
||||||
@ -400,14 +402,12 @@ class TagsModel(QAbstractItemModel):
|
|||||||
tag_item = tag_index.internalPointer()
|
tag_item = tag_index.internalPointer()
|
||||||
tag = tag_item.tag
|
tag = tag_item.tag
|
||||||
if tag is except_:
|
if tag is except_:
|
||||||
self.emit(SIGNAL('dataChanged(QModelIndex,QModelIndex)'),
|
self.dataChanged.emit(tag_index, tag_index)
|
||||||
tag_index, tag_index)
|
|
||||||
continue
|
continue
|
||||||
if tag.state != 0 or tag in update_list:
|
if tag.state != 0 or tag in update_list:
|
||||||
tag.state = 0
|
tag.state = 0
|
||||||
update_list.append(tag)
|
update_list.append(tag)
|
||||||
self.emit(SIGNAL('dataChanged(QModelIndex,QModelIndex)'),
|
self.dataChanged.emit(tag_index, tag_index)
|
||||||
tag_index, tag_index)
|
|
||||||
|
|
||||||
def clear_state(self):
|
def clear_state(self):
|
||||||
self.reset_all_states()
|
self.reset_all_states()
|
||||||
@ -426,7 +426,7 @@ class TagsModel(QAbstractItemModel):
|
|||||||
if exclusive:
|
if exclusive:
|
||||||
self.reset_all_states(except_=item.tag)
|
self.reset_all_states(except_=item.tag)
|
||||||
self.ignore_next_search = 2
|
self.ignore_next_search = 2
|
||||||
self.emit(SIGNAL('dataChanged(QModelIndex,QModelIndex)'), index, index)
|
self.dataChanged.emit(index, index)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -451,3 +451,6 @@ class TagsModel(QAbstractItemModel):
|
|||||||
tags_seen.append(tag.name)
|
tags_seen.append(tag.name)
|
||||||
ans.append('%s%s:"=%s"'%(prefix, category, tag.name))
|
ans.append('%s%s:"=%s"'%(prefix, category, tag.name))
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
@ -538,14 +538,10 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
|||||||
self.library_view.model().cover_cache = self.cover_cache
|
self.library_view.model().cover_cache = self.cover_cache
|
||||||
self.connect(self.edit_categories, SIGNAL('clicked()'), self.do_edit_categories)
|
self.connect(self.edit_categories, SIGNAL('clicked()'), self.do_edit_categories)
|
||||||
self.tags_view.set_database(db, self.tag_match, self.popularity, self.search_restriction)
|
self.tags_view.set_database(db, self.tag_match, self.popularity, self.search_restriction)
|
||||||
self.connect(self.tags_view,
|
self.tags_view.tags_marked.connect(self.search.search_from_tags)
|
||||||
SIGNAL('tags_marked(PyQt_PyObject, PyQt_PyObject)'),
|
|
||||||
self.search.search_from_tags)
|
|
||||||
for x in (self.saved_search.clear_to_help, self.mark_restriction_set):
|
for x in (self.saved_search.clear_to_help, self.mark_restriction_set):
|
||||||
self.tags_view.restriction_set.connect(x)
|
self.tags_view.restriction_set.connect(x)
|
||||||
self.connect(self.tags_view,
|
self.tags_view.tags_marked.connect(self.saved_search.clear_to_help)
|
||||||
SIGNAL('tags_marked(PyQt_PyObject, PyQt_PyObject)'),
|
|
||||||
self.saved_search.clear_to_help)
|
|
||||||
self.search.search.connect(self.tags_view.model().reinit)
|
self.search.search.connect(self.tags_view.model().reinit)
|
||||||
for x in (self.location_view.count_changed, self.tags_view.recount,
|
for x in (self.location_view.count_changed, self.tags_view.recount,
|
||||||
self.restriction_count_changed):
|
self.restriction_count_changed):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user