mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-07 09:01:38 -04:00
More QVariant porting
This commit is contained in:
parent
fea5728d70
commit
ba7206a5ff
@ -29,7 +29,7 @@ class ItemDelegate(QStyledItemDelegate):
|
||||
return QStyledItemDelegate.sizeHint(self, *args) + QSize(0, 15)
|
||||
|
||||
def setEditorData(self, editor, index):
|
||||
name = unicode(index.data(Qt.DisplayRole).toString())
|
||||
name = unicode(index.data(Qt.DisplayRole) or '')
|
||||
editor.setText(name)
|
||||
editor.lineEdit().selectAll()
|
||||
|
||||
|
@ -9,7 +9,7 @@ __docformat__ = 'restructuredtext en'
|
||||
from PyQt5.Qt import (
|
||||
QCoreApplication, QModelIndex, QTimer, Qt, pyqtSignal, QWidget,
|
||||
QGridLayout, QDialog, QPixmap, QSize, QPalette, QShortcut, QKeySequence,
|
||||
QSplitter, QVBoxLayout, QCheckBox, QPushButton, QIcon, QBrush)
|
||||
QSplitter, QVBoxLayout, QCheckBox, QPushButton, QIcon, QBrush, QUrl)
|
||||
from PyQt5.QtWebKitWidgets import QWebView
|
||||
|
||||
from calibre.gui2 import gprefs
|
||||
@ -103,7 +103,7 @@ class BookInfo(QDialog):
|
||||
pass
|
||||
|
||||
def link_clicked(self, qurl):
|
||||
link = unicode(qurl.toString())
|
||||
link = unicode(qurl.toString(QUrl.None))
|
||||
self.link_delegate(link)
|
||||
|
||||
def done(self, r):
|
||||
|
@ -352,7 +352,7 @@ class CheckLibraryDialog(QDialog):
|
||||
child_count = tl.childCount()
|
||||
for i in range(0, child_count):
|
||||
item = tl.child(i)
|
||||
id = item.data(0, Qt.UserRole).toInt()[0]
|
||||
id = int(item.data(0, Qt.UserRole))
|
||||
all = self.db.formats(id, index_is_id=True, verify_formats=False)
|
||||
all = set([f.strip() for f in all.split(',')]) if all else set()
|
||||
valid = self.db.formats(id, index_is_id=True, verify_formats=True)
|
||||
@ -365,7 +365,7 @@ class CheckLibraryDialog(QDialog):
|
||||
child_count = tl.childCount()
|
||||
for i in range(0, child_count):
|
||||
item = tl.child(i)
|
||||
id = item.data(0, Qt.UserRole).toInt()[0]
|
||||
id = int(item.data(0, Qt.UserRole))
|
||||
self.db.set_has_cover(id, False)
|
||||
|
||||
def fix_extra_covers(self):
|
||||
@ -373,7 +373,7 @@ class CheckLibraryDialog(QDialog):
|
||||
child_count = tl.childCount()
|
||||
for i in range(0, child_count):
|
||||
item = tl.child(i)
|
||||
id = item.data(0, Qt.UserRole).toInt()[0]
|
||||
id = int(item.data(0, Qt.UserRole))
|
||||
self.db.set_has_cover(id, True)
|
||||
|
||||
def fix_items(self):
|
||||
|
@ -110,7 +110,7 @@ class DeleteMatchingFromDeviceDialog(QDialog, Ui_DeleteMatchingFromDeviceDialog)
|
||||
for row in range(self.table.rowCount()):
|
||||
if self.table.item(row, 0).checkState() == Qt.Unchecked:
|
||||
continue
|
||||
(model, id, path) = self.table.item(row, 0).data(Qt.UserRole).toPyObject()
|
||||
(model, id, path) = self.table.item(row, 0).data(Qt.UserRole)
|
||||
path = unicode(path)
|
||||
self.result.append((model, id, path))
|
||||
return
|
||||
|
@ -87,7 +87,7 @@ class DeviceCategoryEditor(QDialog, Ui_DeviceCategoryEditor):
|
||||
item.setText(item.previous_text())
|
||||
return
|
||||
if item.text() != item.initial_text():
|
||||
id_ = item.data(Qt.UserRole).toInt()[0]
|
||||
id_ = int(item.data(Qt.UserRole))
|
||||
self.to_rename[id_] = unicode(item.text())
|
||||
|
||||
def rename_tag(self):
|
||||
@ -113,7 +113,7 @@ class DeviceCategoryEditor(QDialog, Ui_DeviceCategoryEditor):
|
||||
return
|
||||
row = self.available_tags.row(deletes[0])
|
||||
for item in deletes:
|
||||
(id,ign) = item.data(Qt.UserRole).toInt()
|
||||
id = int(item.data(Qt.UserRole))
|
||||
self.to_delete.add(id)
|
||||
self.available_tags.takeItem(self.available_tags.row(item))
|
||||
|
||||
|
@ -135,7 +135,7 @@ class DuplicatesQuestion(QDialog):
|
||||
for i in xrange(self.dup_list.topLevelItemCount()):
|
||||
x = self.dup_list.topLevelItem(i)
|
||||
if x.checkState(0) == Qt.Checked:
|
||||
yield x.data(0, Qt.UserRole).toPyObject()
|
||||
yield x.data(0, Qt.UserRole)
|
||||
|
||||
@property
|
||||
def as_text(self):
|
||||
|
@ -274,7 +274,7 @@ class EditAuthorsDialog(QDialog, Ui_EditAuthorsDialog):
|
||||
self.save_state()
|
||||
self.result = []
|
||||
for row in range(0,self.table.rowCount()):
|
||||
id = self.table.item(row, 0).data(Qt.UserRole).toInt()[0]
|
||||
id = int(self.table.item(row, 0).data(Qt.UserRole))
|
||||
aut = unicode(self.table.item(row, 0).text()).strip()
|
||||
sort = unicode(self.table.item(row, 1).text()).strip()
|
||||
link = unicode(self.table.item(row, 2).text()).strip()
|
||||
|
@ -168,7 +168,7 @@ class MatchBooks(QDialog, Ui_MatchBooks):
|
||||
|
||||
def book_clicked(self, row, column):
|
||||
self.book_selected = True
|
||||
id_ = self.books_table.item(row, 0).data(Qt.UserRole).toInt()[0]
|
||||
id_ = int(self.books_table.item(row, 0).data(Qt.UserRole))
|
||||
self.current_library_book_id = id_
|
||||
|
||||
def book_doubleclicked(self, row, column):
|
||||
|
@ -569,12 +569,12 @@ class MetadataBulkDialog(ResizableDialog, Ui_MetadataBulkDialog):
|
||||
def s_r_sf_itemdata(self, idx):
|
||||
if idx is None:
|
||||
idx = self.search_field.currentIndex()
|
||||
return unicode(self.search_field.itemData(idx).toString())
|
||||
return unicode(self.search_field.itemData(idx) or '')
|
||||
|
||||
def s_r_df_itemdata(self, idx):
|
||||
if idx is None:
|
||||
idx = self.destination_field.currentIndex()
|
||||
return unicode(self.destination_field.itemData(idx).toString())
|
||||
return unicode(self.destination_field.itemData(idx) or '')
|
||||
|
||||
def s_r_get_field(self, mi, field):
|
||||
if field:
|
||||
|
@ -277,7 +277,7 @@ class Quickview(QDialog, Ui_Quickview):
|
||||
def book_doubleclicked(self, row, column):
|
||||
if self.no_valid_items:
|
||||
return
|
||||
book_id = self.books_table.item(row, self.title_column).data(Qt.UserRole).toInt()[0]
|
||||
book_id = int(self.books_table.item(row, self.title_column).data(Qt.UserRole))
|
||||
self.view.select_rows([book_id])
|
||||
modifiers = int(QApplication.keyboardModifiers())
|
||||
if modifiers in (Qt.CTRL, Qt.SHIFT):
|
||||
@ -315,4 +315,4 @@ class Quickview(QDialog, Ui_Quickview):
|
||||
# called by the close button
|
||||
def reject(self):
|
||||
self._close()
|
||||
QDialog.reject(self)
|
||||
QDialog.reject(self)
|
||||
|
@ -8,9 +8,9 @@ __docformat__ = 'restructuredtext en'
|
||||
|
||||
|
||||
from PyQt5.Qt import QVBoxLayout, QDialog, QLabel, QDialogButtonBox, Qt, \
|
||||
QAbstractListModel, QVariant, QListView, QSize
|
||||
QAbstractListModel, QListView, QSize
|
||||
|
||||
from calibre.gui2 import NONE, file_icon_provider
|
||||
from calibre.gui2 import file_icon_provider
|
||||
|
||||
class Formats(QAbstractListModel):
|
||||
|
||||
@ -28,16 +28,16 @@ class Formats(QAbstractListModel):
|
||||
if role == Qt.DisplayRole:
|
||||
fmt = self.fmts[row]
|
||||
count = self.counts[fmt]
|
||||
return QVariant('%s [%d]'%(fmt.upper(), count))
|
||||
return ('%s [%d]'%(fmt.upper(), count))
|
||||
if role == Qt.DecorationRole:
|
||||
return QVariant(self.fi.icon_from_ext(self.fmts[row].lower()))
|
||||
return (self.fi.icon_from_ext(self.fmts[row].lower()))
|
||||
if role == Qt.ToolTipRole:
|
||||
fmt = self.fmts[row]
|
||||
count = self.counts[fmt]
|
||||
return QVariant(
|
||||
return (
|
||||
_('There are %(count)d book(s) with the %(fmt)s format')%dict(
|
||||
count=count, fmt=fmt.upper()))
|
||||
return NONE
|
||||
return None
|
||||
|
||||
def flags(self, index):
|
||||
return Qt.ItemIsSelectable|Qt.ItemIsEnabled
|
||||
|
@ -165,7 +165,7 @@ class TagCategories(QDialog, Ui_TagCategories):
|
||||
return
|
||||
nodes = self.available_items_box.selectedItems() if node is None else [node]
|
||||
for node in nodes:
|
||||
index = self.all_items[node.data(Qt.UserRole).toPyObject()].index
|
||||
index = self.all_items[node.data(Qt.UserRole)].index
|
||||
if index not in self.applied_items:
|
||||
self.applied_items.append(index)
|
||||
self.applied_items.sort(key=lambda x:sort_key(self.all_items[x].name))
|
||||
@ -177,7 +177,7 @@ class TagCategories(QDialog, Ui_TagCategories):
|
||||
def unapply_tags(self, node=None):
|
||||
nodes = self.applied_items_box.selectedItems() if node is None else [node]
|
||||
for node in nodes:
|
||||
index = self.all_items[node.data(Qt.UserRole).toPyObject()].index
|
||||
index = self.all_items[node.data(Qt.UserRole)].index
|
||||
self.applied_items.remove(index)
|
||||
self.display_filtered_categories(None)
|
||||
|
||||
|
@ -210,7 +210,7 @@ class TagListEditor(QDialog, Ui_TagListEditor):
|
||||
item.setText(item.previous_text())
|
||||
return
|
||||
if item.text() != item.initial_text():
|
||||
id_ = item.data(Qt.UserRole).toInt()[0]
|
||||
id_ = int(item.data(Qt.UserRole))
|
||||
self.to_rename[id_] = unicode(item.text())
|
||||
orig = self.table.item(item.row(), 2)
|
||||
self.table.blockSignals(True)
|
||||
@ -240,7 +240,7 @@ class TagListEditor(QDialog, Ui_TagListEditor):
|
||||
return
|
||||
row = self.table.row(deletes[0])
|
||||
for item in deletes:
|
||||
(id,ign) = item.data(Qt.UserRole).toInt()
|
||||
id = int(item.data(Qt.UserRole))
|
||||
self.to_delete.add(id)
|
||||
self.table.removeRow(self.table.row(item))
|
||||
|
||||
|
@ -7,7 +7,7 @@ import json, os, traceback
|
||||
|
||||
from PyQt5.Qt import (Qt, QDialog, QDialogButtonBox, QSyntaxHighlighter, QFont,
|
||||
QRegExp, QApplication, QTextCharFormat, QColor, QCursor,
|
||||
QIcon, QSize, QVariant)
|
||||
QIcon, QSize)
|
||||
|
||||
from calibre import sanitize_file_name_unicode
|
||||
from calibre.constants import config_dir
|
||||
@ -248,7 +248,7 @@ class TemplateDialog(QDialog, Ui_TemplateDialog):
|
||||
from calibre.gui2.preferences.coloring import icon_rule_kinds
|
||||
for i,tup in enumerate(icon_rule_kinds):
|
||||
txt,val = tup
|
||||
self.icon_kind.addItem(txt, userData=QVariant(val))
|
||||
self.icon_kind.addItem(txt, userData=(val))
|
||||
if val == icon_rule_kind:
|
||||
dex = i
|
||||
self.icon_kind.setCurrentIndex(dex)
|
||||
@ -426,12 +426,12 @@ class TemplateDialog(QDialog, Ui_TemplateDialog):
|
||||
return
|
||||
|
||||
self.rule = (unicode(self.colored_field.itemData(
|
||||
self.colored_field.currentIndex()).toString()), txt)
|
||||
self.colored_field.currentIndex()) or ''), txt)
|
||||
elif self.iconing:
|
||||
rt = unicode(self.icon_kind.itemData(self.icon_kind.currentIndex()).toString())
|
||||
rt = unicode(self.icon_kind.itemData(self.icon_kind.currentIndex()) or '')
|
||||
self.rule = (rt,
|
||||
unicode(self.icon_field.itemData(
|
||||
self.icon_field.currentIndex()).toString()),
|
||||
self.icon_field.currentIndex()) or ''),
|
||||
txt)
|
||||
else:
|
||||
self.rule = ('', txt)
|
||||
|
@ -3,14 +3,14 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import time, os
|
||||
|
||||
from PyQt5.Qt import (QUrl, QAbstractListModel, Qt, QVariant, QFont)
|
||||
from PyQt5.Qt import (QUrl, QAbstractListModel, Qt, QFont)
|
||||
|
||||
from calibre.web.feeds.recipes import compile_recipe, custom_recipes
|
||||
from calibre.web.feeds.news import AutomaticNewsRecipe
|
||||
from calibre.gui2.dialogs.user_profiles_ui import Ui_Dialog
|
||||
from calibre.gui2 import (
|
||||
error_dialog, question_dialog, open_url, choose_files, ResizableDialog,
|
||||
NONE, open_local_file)
|
||||
open_local_file)
|
||||
from calibre.gui2.widgets import PythonHighlighter
|
||||
from calibre.ptempfile import PersistentTemporaryFile
|
||||
from calibre.utils.icu import sort_key
|
||||
@ -48,8 +48,8 @@ class CustomRecipeModel(QAbstractListModel):
|
||||
if role == Qt.DisplayRole:
|
||||
ans = self.title(index)
|
||||
if ans is not None:
|
||||
return QVariant(ans)
|
||||
return NONE
|
||||
return (ans)
|
||||
return None
|
||||
|
||||
def replace_by_title(self, title, script):
|
||||
urn = None
|
||||
@ -330,8 +330,8 @@ class %(classname)s(%(base_class)s):
|
||||
if not items:
|
||||
return
|
||||
item = items[-1]
|
||||
id_ = unicode(item.data(Qt.UserRole).toString())
|
||||
title = unicode(item.data(Qt.DisplayRole).toString()).rpartition(' [')[0]
|
||||
id_ = unicode(item.data(Qt.UserRole) or '')
|
||||
title = unicode(item.data(Qt.DisplayRole) or '').rpartition(' [')[0]
|
||||
profile = get_builtin_recipe_by_id(id_, download_recipe=True)
|
||||
if profile is None:
|
||||
raise Exception('Something weird happened')
|
||||
|
Loading…
x
Reference in New Issue
Block a user