View Single Post
Old 04-23-2008, 10:00 AM   #205
astrodad
Guru
astrodad ought to be getting tired of karma fortunes by now.astrodad ought to be getting tired of karma fortunes by now.astrodad ought to be getting tired of karma fortunes by now.astrodad ought to be getting tired of karma fortunes by now.astrodad ought to be getting tired of karma fortunes by now.astrodad ought to be getting tired of karma fortunes by now.astrodad ought to be getting tired of karma fortunes by now.astrodad ought to be getting tired of karma fortunes by now.astrodad ought to be getting tired of karma fortunes by now.astrodad ought to be getting tired of karma fortunes by now.astrodad ought to be getting tired of karma fortunes by now.
 
astrodad's Avatar
 
Posts: 962
Karma: 568242
Join Date: Dec 2007
Device: Kindle Oasis 3, Kindle Paperwhite 1, iPad, iPhone
One thing that's interesting. In trying to use my new DefaultTagEditor, I get an error when the accept runs. Here's what happens:

Quote:
Traceback (most recent call last):
File "/home/javier/workspace/libprs500/src/libprs500/gui2/dialogs/config.py", line 106, in edit_defaultTags
tag_string = ', '.join(d.tags)
TypeError: sequence item 0: expected string, QString found
Here's the code that invokes the default tag editor:

Quote:
def edit_defaultTags(self):
d = DefaultTagEditor(self, self.db,self.defaultTags.text())
d.exec_()
if d.result() == QDialog.Accepted:
tag_string = ', '.join(d.tags)
self.defaultTags.setText(tag_string)
I didn't change anything about the tag editor except that I changed the init to not look for the existing tags from a book, but from the Settings object. Any ideas?

Here's the new editor code:

Quote:
__license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
from PyQt4.QtCore import SIGNAL, Qt
from PyQt4.QtGui import QDialog, QMessageBox

from libprs500 import islinux, Settings
from libprs500.gui2.dialogs.tag_editor_ui import Ui_TagEditor
from libprs500.gui2 import qstring_to_unicode
from libprs500.gui2 import question_dialog, error_dialog
from libprs500.gui2.dialogs.tag_editor import TagEditor

class DefaultTagEditor(TagEditor):

def __init__(self, window, db, tagStrings):
QDialog.__init__(self, window)
Ui_TagEditor.__init__(self)
self.setupUi(self)

settings = Settings()

self.db = db
self.tags = tagStrings.split(',')

if self.tags:
for tag in self.tags:
self.applied_tags.addItem(tag)


all_tags = [tag.lower() for tag in self.db.all_tags()]
all_tags = list(set(all_tags))
all_tags.sort()
for tag in all_tags:
if tag not in tagStrings:
self.available_tags.addItem(tag)

self.connect(self.apply_button, SIGNAL('clicked()'), self.apply_tags)
self.connect(self.unapply_button, SIGNAL('clicked()'), self.unapply_tags)
self.connect(self.add_tag_button, SIGNAL('clicked()'), self.add_tag)
self.connect(self.delete_button, SIGNAL('clicked()'), self.delete_tags)
self.connect(self.add_tag_input, SIGNAL('returnPressed()'), self.add_tag)
self.connect(self.available_tags, SIGNAL('itemActivated(QListWidgetItem*)'), self.apply_tags)
self.connect(self.applied_tags, SIGNAL('itemActivated(QListWidgetItem*)'), self.unapply_tags)

def apply_tags(self, item=None):
items = self.available_tags.selectedItems() if item is None else [item]
for item in items:
tag = qstring_to_unicode(item.text())
self.tags.append(tag)
self.available_tags.takeItem(self.available_tags.r ow(item))

self.tags.sort()
self.applied_tags.clear()
for tag in self.tags:
self.applied_tags.addItem(tag)
astrodad is offline   Reply With Quote