From b4e467ea183b883c0f4f71c0c3d0d15602dbfc60 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 13 Mar 2019 18:30:31 +0530 Subject: [PATCH] Get rid of more xrange --- src/calibre/ebooks/docx/writer/fonts.py | 3 ++- src/calibre/ebooks/docx/writer/tables.py | 5 +++-- src/calibre/ebooks/lrf/html/table.py | 8 ++++---- src/calibre/ebooks/pdb/ereader/__init__.py | 4 ++-- src/calibre/ebooks/pdb/pdf/reader.py | 3 ++- src/calibre/ebooks/pdb/plucker/reader.py | 14 +++++++------- src/calibre/ebooks/pdf/render/gradients.py | 8 ++++---- src/calibre/ebooks/pdf/render/test.py | 3 ++- src/calibre/ebooks/pdf/render/toc.py | 3 ++- src/calibre/ebooks/unihandecode/pykakasi/h2a.py | 7 ++++--- src/calibre/ebooks/unihandecode/pykakasi/k2a.py | 4 ++-- src/calibre/gui2/actions/add.py | 4 ++-- src/calibre/gui2/actions/annotate.py | 5 ++--- src/calibre/gui2/actions/author_mapper.py | 3 ++- src/calibre/gui2/actions/choose_library.py | 4 ++-- src/calibre/gui2/actions/tag_mapper.py | 4 ++-- src/calibre/gui2/library/alternate_views.py | 12 ++++++------ src/calibre/gui2/library/models.py | 6 +++--- src/calibre/gui2/library/views.py | 16 ++++++++-------- src/calibre/gui2/preferences/ignored_devices.py | 7 ++++--- src/calibre/gui2/preferences/texture_chooser.py | 6 +++--- src/calibre/gui2/preferences/tweaks.py | 4 ++-- src/calibre/gui2/tag_browser/model.py | 11 ++++++----- src/calibre/gui2/tag_browser/view.py | 4 ++-- 24 files changed, 78 insertions(+), 70 deletions(-) diff --git a/src/calibre/ebooks/docx/writer/fonts.py b/src/calibre/ebooks/docx/writer/fonts.py index dccb8c22b7..a99ebbb7b6 100644 --- a/src/calibre/ebooks/docx/writer/fonts.py +++ b/src/calibre/ebooks/docx/writer/fonts.py @@ -11,12 +11,13 @@ from uuid import uuid4 from calibre.ebooks.oeb.base import OEB_STYLES from calibre.ebooks.oeb.transforms.subset import find_font_face_rules +from polyglot.builtins import range def obfuscate_font_data(data, key): prefix = bytearray(data[:32]) key = bytearray(reversed(key.bytes)) - prefix = bytes(bytearray(prefix[i]^key[i % len(key)] for i in xrange(len(prefix)))) + prefix = bytes(bytearray(prefix[i]^key[i % len(key)] for i in range(len(prefix)))) return prefix + data[32:] diff --git a/src/calibre/ebooks/docx/writer/tables.py b/src/calibre/ebooks/docx/writer/tables.py index 4094ccec01..b0ab81524a 100644 --- a/src/calibre/ebooks/docx/writer/tables.py +++ b/src/calibre/ebooks/docx/writer/tables.py @@ -10,6 +10,7 @@ from collections import namedtuple from calibre.ebooks.docx.writer.utils import convert_color from calibre.ebooks.docx.writer.styles import read_css_block_borders as rcbb, border_edges +from polyglot.builtins import range class Dummy(object): @@ -309,7 +310,7 @@ class Table(object): for cell in tuple(row.cells): idx = row.cells.index(cell) if cell.col_span > 1 and (cell is row.cells[-1] or not isinstance(row.cells[idx+1], SpannedCell)): - row.cells[idx:idx+1] = [cell] + [SpannedCell(cell, horizontal=True) for i in xrange(1, cell.col_span)] + row.cells[idx:idx+1] = [cell] + [SpannedCell(cell, horizontal=True) for i in range(1, cell.col_span)] # Expand vertically for r, row in enumerate(self.rows): @@ -322,7 +323,7 @@ class Table(object): except Exception: tcell = None if tcell is None: - nrow.cells.extend([SpannedCell(nrow.cells[-1], horizontal=True) for i in xrange(idx - len(nrow.cells))]) + nrow.cells.extend([SpannedCell(nrow.cells[-1], horizontal=True) for i in range(idx - len(nrow.cells))]) nrow.cells.append(sc) else: if isinstance(tcell, SpannedCell): diff --git a/src/calibre/ebooks/lrf/html/table.py b/src/calibre/ebooks/lrf/html/table.py index 6d0485d82f..cc62744954 100644 --- a/src/calibre/ebooks/lrf/html/table.py +++ b/src/calibre/ebooks/lrf/html/table.py @@ -7,7 +7,7 @@ from calibre.ebooks.lrf.fonts import get_font from calibre.ebooks.lrf.pylrs.pylrs import TextBlock, Text, CR, Span, \ CharButton, Plot, Paragraph, \ LrsTextTag -from polyglot.builtins import string_or_bytes +from polyglot.builtins import string_or_bytes, range def ceil(num): @@ -315,7 +315,7 @@ class Table(object): Return widths of columns + self.colpad ''' rows, cols = self.number_or_rows(), self.number_of_columns() - widths = range(cols) + widths = list(range(cols)) for c in range(cols): cellwidths = [0 for i in range(rows)] for r in range(rows): @@ -325,8 +325,8 @@ class Table(object): continue widths[c] = max(cellwidths) - min_widths = [self.minimum_width(i)+10 for i in xrange(cols)] - for i in xrange(len(widths)): + min_widths = [self.minimum_width(i)+10 for i in range(cols)] + for i in range(len(widths)): wp = self.width_percent(i) if wp >= 0.: widths[i] = max(min_widths[i], ceil((wp/100.) * (maxwidth - (cols-1)*self.colpad))) diff --git a/src/calibre/ebooks/pdb/ereader/__init__.py b/src/calibre/ebooks/pdb/ereader/__init__.py index f8c4f7b04b..757322a067 100644 --- a/src/calibre/ebooks/pdb/ereader/__init__.py +++ b/src/calibre/ebooks/pdb/ereader/__init__.py @@ -5,6 +5,7 @@ __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' import os +from polyglot.builtins import range class EreaderError(Exception): @@ -21,10 +22,9 @@ def image_name(name, taken_names=[]): name = '%s%s.png' % (names, namee) while name in taken_names: - for i in xrange(999999999999999999999999999): + for i in range(999999999999999999999999999): name = '%s%s.png' % (name[:-len('%s' % i)], i) name = name.ljust(32, '\x00')[:32] return name - diff --git a/src/calibre/ebooks/pdb/pdf/reader.py b/src/calibre/ebooks/pdb/pdf/reader.py index 71153add6f..4f166397c4 100644 --- a/src/calibre/ebooks/pdb/pdf/reader.py +++ b/src/calibre/ebooks/pdb/pdf/reader.py @@ -11,6 +11,7 @@ __docformat__ = 'restructuredtext en' from calibre.ebooks.pdb.formatreader import FormatReader from calibre.ptempfile import PersistentTemporaryFile +from polyglot.builtins import range class Reader(FormatReader): @@ -27,7 +28,7 @@ class Reader(FormatReader): pdf = PersistentTemporaryFile('.pdf') pdf.close() pdf = open(pdf, 'wb') - for x in xrange(self.header.section_count()): + for x in range(self.header.section_count()): pdf.write(self.header.section_data(x)) pdf.close() diff --git a/src/calibre/ebooks/pdb/plucker/reader.py b/src/calibre/ebooks/pdb/plucker/reader.py index 9a0d3a0180..82977b5f7b 100644 --- a/src/calibre/ebooks/pdb/plucker/reader.py +++ b/src/calibre/ebooks/pdb/plucker/reader.py @@ -17,7 +17,7 @@ from calibre.ebooks.pdb.formatreader import FormatReader from calibre.ebooks.compression.palmdoc import decompress_doc from calibre.utils.imghdr import identify from calibre.utils.img import save_cover_data_to, Canvas, image_from_data -from polyglot.builtins import codepoint_to_chr +from polyglot.builtins import codepoint_to_chr, range DATATYPE_PHTML = 0 DATATYPE_PHTML_COMPRESSED = 1 @@ -129,7 +129,7 @@ class HeaderRecord(object): self.home_html = None self.reserved = {} - for i in xrange(self.records): + for i in range(self.records): adv = 4*i name, = struct.unpack('>H', raw[6+adv:8+adv]) id, = struct.unpack('>H', raw[8+adv:10+adv]) @@ -166,7 +166,7 @@ class SectionHeaderText(object): # Paragraph attributes. self.attributes = [] - for i in xrange(section_header.paragraphs): + for i in range(section_header.paragraphs): adv = 4*i self.sizes.append(struct.unpack('>H', raw[adv:2+adv])[0]) self.attributes.append(struct.unpack('>H', raw[2+adv:4+adv])[0]) @@ -200,7 +200,7 @@ class SectionMetadata(object): record_count, = struct.unpack('>H', raw[0:2]) adv = 0 - for i in xrange(record_count): + for i in range(record_count): try: type, length = struct.unpack_from('>HH', raw, 2 + adv) except struct.error: @@ -213,7 +213,7 @@ class SectionMetadata(object): # ExceptionalCharSets elif type == 2: ii_adv = 0 - for ii in xrange(length / 2): + for ii in range(length / 2): uid, = struct.unpack('>H', raw[6+adv+ii_adv:8+adv+ii_adv]) mib, = struct.unpack('>H', raw[8+adv+ii_adv:10+adv+ii_adv]) self.exceptional_uid_encodings[uid] = MIBNUM_TO_NAME.get(mib, 'latin-1') @@ -270,9 +270,9 @@ class SectionCompositeImage(object): # to an image record. self.layout = [] offset = 4 - for i in xrange(self.rows): + for i in range(self.rows): col = [] - for j in xrange(self.columns): + for j in range(self.columns): col.append(struct.unpack('>H', raw[offset:offset+2])[0]) offset += 2 self.layout.append(col) diff --git a/src/calibre/ebooks/pdf/render/gradients.py b/src/calibre/ebooks/pdf/render/gradients.py index 6a51f5c111..f4baa5ab5b 100644 --- a/src/calibre/ebooks/pdf/render/gradients.py +++ b/src/calibre/ebooks/pdf/render/gradients.py @@ -8,7 +8,7 @@ __copyright__ = '2013, Kovid Goyal ' __docformat__ = 'restructuredtext en' import sys, copy -from polyglot.builtins import map +from polyglot.builtins import map, range from collections import namedtuple from PyQt5.Qt import QLinearGradient, QPointF @@ -111,7 +111,7 @@ class LinearGradientPattern(Dictionary): do_reflect = spread == gradient.ReflectSpread totl = abs(stops[-1][0] - stops[0][0]) intervals = [abs(stops[i+1][0] - stops[i][0])/totl - for i in xrange(len(stops)-1)] + for i in range(len(stops)-1)] while in_page(llimit): reflect ^= True @@ -139,14 +139,14 @@ class LinearGradientPattern(Dictionary): intervals = [i*rlen for i in intervals] rintervals = list(reversed(intervals)) - for i in xrange(num): + for i in range(num): reflect ^= True pos = i * len(base_stops) tvals = [t] for ival in (rintervals if reflect and do_reflect else intervals): tvals.append(tvals[-1] + ival) - for j in xrange(len(base_stops)): + for j in range(len(base_stops)): stops[pos+j][0] = tvals[j] t = tvals[-1] diff --git a/src/calibre/ebooks/pdf/render/test.py b/src/calibre/ebooks/pdf/render/test.py index da283f785c..829036b235 100644 --- a/src/calibre/ebooks/pdf/render/test.py +++ b/src/calibre/ebooks/pdf/render/test.py @@ -15,6 +15,7 @@ from PyQt5.Qt import (QBrush, QColor, QPoint, QPixmap, QPainterPath, QRectF, QBrush, QColor, QPoint, QPixmap, QPainterPath, QRectF, Qt, QPointF from calibre.ebooks.pdf.render.engine import PdfDevice +from polyglot.builtins import range def full(p, xmax, ymax): @@ -25,7 +26,7 @@ def full(p, xmax, ymax): pp.addRect(0, 0, xmax, ymax) p.drawPath(pp) p.save() - for i in xrange(3): + for i in range(3): col = [0, 0, 0, 200] col[i] = 255 p.setOpacity(0.3) diff --git a/src/calibre/ebooks/pdf/render/toc.py b/src/calibre/ebooks/pdf/render/toc.py index 51faf445db..6e275aaf69 100644 --- a/src/calibre/ebooks/pdf/render/toc.py +++ b/src/calibre/ebooks/pdf/render/toc.py @@ -10,6 +10,7 @@ import os from lxml.html import tostring from lxml.html.builder import (HTML, HEAD, BODY, TABLE, TR, TD, H2, STYLE) +from polyglot.builtins import range def calculate_page_number(num, map_expression, evaljs): @@ -49,7 +50,7 @@ def process_children(toc, table, level, pdf, pdf_page_number_map, evaljs): def toc_as_html(toc, pdf, opts, evaljs): pdf = pdf.engine.pdf indents = [] - for i in xrange(1, 7): + for i in range(1, 7): indents.extend((i, 1.4*i)) html = HTML( HEAD( diff --git a/src/calibre/ebooks/unihandecode/pykakasi/h2a.py b/src/calibre/ebooks/unihandecode/pykakasi/h2a.py index ad42edba39..409a110093 100644 --- a/src/calibre/ebooks/unihandecode/pykakasi/h2a.py +++ b/src/calibre/ebooks/unihandecode/pykakasi/h2a.py @@ -21,6 +21,8 @@ # * # */ +from polyglot.builtins import range + class H2a (object): @@ -79,7 +81,7 @@ class H2a (object): u"\u3063\u3058\u3085":"jju", u"\u3063\u3058\u3087":"jjo", u"\u3063\u3059":"ssu", u"\u3063\u305a":"zzu", u"\u3063\u305b":"sse", u"\u3063\u305e":"zze", - u"\u3063\u305d":"sso", u"\u3063\u305e":"zzo", + u"\u3063\u305d":"sso", u"\u3063\u305c":"zzo", u"\u3063\u305f":"tta", u"\u3063\u3060":"dda", u"\u3063\u3061":"tchi", u"\u3063\u3061\u3083":"tcha", u"\u3063\u3061\u3085":"tchu", u"\u3063\u3061\u3087":"tcho", @@ -173,10 +175,9 @@ class H2a (object): Hstr = "" max_len = -1 r = min(4, len(text)+1) - for x in xrange(r): + for x in range(r): if text[:x] in self.H2a_table: if max_len < x: max_len = x Hstr = self.H2a_table[text[:x]] return (Hstr, max_len) - diff --git a/src/calibre/ebooks/unihandecode/pykakasi/k2a.py b/src/calibre/ebooks/unihandecode/pykakasi/k2a.py index 63a564b9c8..7650199128 100644 --- a/src/calibre/ebooks/unihandecode/pykakasi/k2a.py +++ b/src/calibre/ebooks/unihandecode/pykakasi/k2a.py @@ -22,6 +22,7 @@ # */ from calibre.ebooks.unihandecode.pykakasi.jisyo import jisyo +from polyglot.builtins import range class K2a (object): @@ -38,10 +39,9 @@ class K2a (object): Hstr = "" max_len = -1 r = min(10, len(text)+1) - for x in xrange(r): + for x in range(r): if text[:x] in self.kanwa.kanadict: if max_len < x: max_len = x Hstr = self.kanwa.kanadict[text[:x]] return (Hstr, max_len) - diff --git a/src/calibre/gui2/actions/add.py b/src/calibre/gui2/actions/add.py index 28f45282f0..9b8575bd63 100644 --- a/src/calibre/gui2/actions/add.py +++ b/src/calibre/gui2/actions/add.py @@ -25,7 +25,7 @@ from calibre.gui2.actions import InterfaceAction from calibre.gui2 import question_dialog from calibre.ebooks.metadata import MetaInformation from calibre.ptempfile import PersistentTemporaryFile -from polyglot.builtins import string_or_bytes +from polyglot.builtins import string_or_bytes, range def get_filters(): @@ -311,7 +311,7 @@ class AddAction(InterfaceAction): book_id = db.id(index.row()) orig_fmts = tuple(db.new_api.format(book_id, fmt, as_path=True) for fmt in db.new_api.formats(book_id)) - for x in xrange(num): + for x in range(num): if dlg.duplicate_current_book: mi = origmi else: diff --git a/src/calibre/gui2/actions/annotate.py b/src/calibre/gui2/actions/annotate.py index 33103016df..b0d00e91c6 100644 --- a/src/calibre/gui2/actions/annotate.py +++ b/src/calibre/gui2/actions/annotate.py @@ -12,6 +12,7 @@ from calibre.gui2 import error_dialog from calibre.gui2.actions import InterfaceAction from calibre.devices.usbms.device import Device from calibre.gui2.dialogs.progress import ProgressDialog +from polyglot.builtins import range class Updater(QThread): # {{{ @@ -74,7 +75,7 @@ class FetchAnnotationsAction(InterfaceAction): def get_ids_from_selected_rows(): rows = self.gui.library_view.selectionModel().selectedRows() if not rows or len(rows) < 2: - rows = xrange(self.gui.library_view.model().rowCount(QModelIndex())) + rows = range(self.gui.library_view.model().rowCount(QModelIndex())) ids = map(self.gui.library_view.model().id, rows) return ids @@ -160,5 +161,3 @@ class FetchAnnotationsAction(InterfaceAction): _('Could not fetch annotations for some books. Click ' 'show details to see which ones.'), det_msg='\n'.join(entries), show=True) - - diff --git a/src/calibre/gui2/actions/author_mapper.py b/src/calibre/gui2/actions/author_mapper.py index f4134aa0d5..5bbd41cd47 100644 --- a/src/calibre/gui2/actions/author_mapper.py +++ b/src/calibre/gui2/actions/author_mapper.py @@ -8,6 +8,7 @@ from polyglot.builtins import map from calibre.gui2 import gprefs from calibre.gui2.actions import InterfaceAction +from polyglot.builtins import range class AuthorMapAction(InterfaceAction): @@ -24,7 +25,7 @@ class AuthorMapAction(InterfaceAction): selected = True if not rows or len(rows) < 2: selected = False - rows = xrange(self.gui.library_view.model().rowCount(None)) + rows = range(self.gui.library_view.model().rowCount(None)) ids = set(map(self.gui.library_view.model().id, rows)) self.do_map(ids, selected) diff --git a/src/calibre/gui2/actions/choose_library.py b/src/calibre/gui2/actions/choose_library.py index 67581a1077..cf757e17a6 100644 --- a/src/calibre/gui2/actions/choose_library.py +++ b/src/calibre/gui2/actions/choose_library.py @@ -20,7 +20,7 @@ from calibre.utils.icu import sort_key from calibre.gui2 import (gprefs, warning_dialog, Dispatcher, error_dialog, question_dialog, info_dialog, open_local_file, choose_dir) from calibre.gui2.actions import InterfaceAction -from polyglot.builtins import unicode_type +from polyglot.builtins import unicode_type, range def db_class(): @@ -593,7 +593,7 @@ class ChooseLibraryAction(InterfaceAction): import gc from calibre.utils.mem import memory ref = self.dbref - for i in xrange(3): + for i in range(3): gc.collect() if ref() is not None: print('DB object alive:', ref()) diff --git a/src/calibre/gui2/actions/tag_mapper.py b/src/calibre/gui2/actions/tag_mapper.py index b5cef2e748..9830903c09 100644 --- a/src/calibre/gui2/actions/tag_mapper.py +++ b/src/calibre/gui2/actions/tag_mapper.py @@ -4,7 +4,7 @@ from __future__ import (unicode_literals, division, absolute_import, print_function) -from polyglot.builtins import map +from polyglot.builtins import map, range from calibre.gui2 import gprefs from calibre.gui2.actions import InterfaceAction @@ -24,7 +24,7 @@ class TagMapAction(InterfaceAction): selected = True if not rows or len(rows) < 2: selected = False - rows = xrange(self.gui.library_view.model().rowCount(None)) + rows = range(self.gui.library_view.model().rowCount(None)) ids = set(map(self.gui.library_view.model().id, rows)) self.do_map(ids, selected) diff --git a/src/calibre/gui2/library/alternate_views.py b/src/calibre/gui2/library/alternate_views.py index fe7246068f..1f11a5d84c 100644 --- a/src/calibre/gui2/library/alternate_views.py +++ b/src/calibre/gui2/library/alternate_views.py @@ -30,7 +30,7 @@ from calibre.gui2 import gprefs, config, rating_font, empty_index from calibre.gui2.gestures import GestureManager from calibre.gui2.library.caches import CoverCache, ThumbnailCache from calibre.utils.config import prefs, tweaks -from polyglot.builtins import unicode_type +from polyglot.builtins import unicode_type, range CM_TO_INCH = 0.393701 CACHE_FORMAT = 'PPM' @@ -740,8 +740,8 @@ class GridView(QListView): @property def first_visible_row(self): geom = self.viewport().geometry() - for y in xrange(geom.top(), (self.spacing()*2) + geom.top(), 5): - for x in xrange(geom.left(), (self.spacing()*2) + geom.left(), 5): + for y in range(geom.top(), (self.spacing()*2) + geom.top(), 5): + for x in range(geom.left(), (self.spacing()*2) + geom.left(), 5): ans = self.indexAt(QPoint(x, y)).row() if ans > -1: return ans @@ -749,8 +749,8 @@ class GridView(QListView): @property def last_visible_row(self): geom = self.viewport().geometry() - for y in xrange(geom.bottom(), geom.bottom() - 2 * self.spacing(), -5): - for x in xrange(geom.left(), (self.spacing()*2) + geom.left(), 5): + for y in range(geom.bottom(), geom.bottom() - 2 * self.spacing(), -5): + for x in range(geom.left(), (self.spacing()*2) + geom.left(), 5): ans = self.indexAt(QPoint(x, y)).row() if ans > -1: item_width = self.delegate.item_size.width() + 2*self.spacing() @@ -760,7 +760,7 @@ class GridView(QListView): self.ignore_render_requests.clear() self.update_timer.stop() m = self.model() - for r in xrange(self.first_visible_row or 0, self.last_visible_row or (m.count() - 1)): + for r in range(self.first_visible_row or 0, self.last_visible_row or (m.count() - 1)): self.update(m.index(r, 0)) def start_view_animation(self, index): diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index 49c6df478e..9f5a37d84f 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -30,7 +30,7 @@ from calibre.constants import filesystem_encoding, DEBUG, config_dir from calibre.gui2.library import DEFAULT_SORT from calibre.utils.localization import calibre_langcode_to_name from calibre.library.coloring import color_row_key -from polyglot.builtins import unicode_type, string_or_bytes +from polyglot.builtins import unicode_type, string_or_bytes, range Counts = namedtuple('Counts', 'library_total total current') @@ -263,7 +263,7 @@ class BooksModel(QAbstractTableModel): # {{{ if alignment != 'left': self.alignment_map[colname] = alignment col = self.column_map.index(colname) - for row in xrange(self.rowCount(QModelIndex())): + for row in range(self.rowCount(QModelIndex())): self.dataChanged.emit(self.index(row, col), self.index(row, col)) @@ -278,7 +278,7 @@ class BooksModel(QAbstractTableModel): # {{{ old[colname] = font_type self.db.new_api.set_pref('styled_columns', old) col = self.column_map.index(colname) - for row in xrange(self.rowCount(QModelIndex())): + for row in range(self.rowCount(QModelIndex())): self.dataChanged.emit(self.index(row, col), self.index(row, col)) diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py index 484084094f..57c31b6c4d 100644 --- a/src/calibre/gui2/library/views.py +++ b/src/calibre/gui2/library/views.py @@ -8,7 +8,7 @@ __docformat__ = 'restructuredtext en' import itertools, operator from functools import partial -from polyglot.builtins import map, unicode_type +from polyglot.builtins import map, unicode_type, range from collections import OrderedDict from PyQt5.Qt import ( @@ -688,7 +688,7 @@ class BooksView(QTableView): # {{{ # Because of a bug in Qt 5 we have to ensure that the header is actually # relaid out by changing this value, without this sometimes ghost # columns remain visible when changing libraries - for i in xrange(h.count()): + for i in range(h.count()): val = h.isSectionHidden(i) h.setSectionHidden(i, not val) h.setSectionHidden(i, val) @@ -967,7 +967,7 @@ class BooksView(QTableView): # {{{ @property def visible_columns(self): h = self.horizontalHeader() - logical_indices = (x for x in xrange(h.count()) if not h.isSectionHidden(x)) + logical_indices = (x for x in range(h.count()) if not h.isSectionHidden(x)) rmap = {i:x for i, x in enumerate(self.column_map)} return (rmap[h.visualIndex(x)] for x in logical_indices if h.visualIndex(x) > -1) @@ -1108,7 +1108,7 @@ class BooksView(QTableView): # {{{ row_map = OrderedDict() ids = frozenset(ids) m = self.model() - for row in xrange(m.rowCount(QModelIndex())): + for row in range(m.rowCount(QModelIndex())): if len(row_map) >= len(ids): break c = m.id(row) @@ -1128,7 +1128,7 @@ class BooksView(QTableView): # {{{ rows = set([]) identifiers = set(identifiers) m = self.model() - for row in xrange(m.rowCount(QModelIndex())): + for row in range(m.rowCount(QModelIndex())): if m.id(row) in identifiers: rows.add(row) rows = list(sorted(rows)) @@ -1174,7 +1174,7 @@ class BooksView(QTableView): # {{{ if val is None: return m = self.model() - for row in xrange(m.rowCount(QModelIndex())): + for row in range(m.rowCount(QModelIndex())): if m.id(row) == val: self.set_current_row(row, select=False) break @@ -1193,7 +1193,7 @@ class BooksView(QTableView): # {{{ i.isValid()]) column = ci.column() - for i in xrange(ci.row()+1, self.row_count()): + for i in range(ci.row()+1, self.row_count()): if i in selected_rows: continue try: @@ -1202,7 +1202,7 @@ class BooksView(QTableView): # {{{ pass # No unselected rows after the current row, look before - for i in xrange(ci.row()-1, -1, -1): + for i in range(ci.row()-1, -1, -1): if i in selected_rows: continue try: diff --git a/src/calibre/gui2/preferences/ignored_devices.py b/src/calibre/gui2/preferences/ignored_devices.py index 5cb9820259..b0ecce5bcd 100644 --- a/src/calibre/gui2/preferences/ignored_devices.py +++ b/src/calibre/gui2/preferences/ignored_devices.py @@ -12,6 +12,7 @@ from PyQt5.Qt import (QLabel, QVBoxLayout, QListWidget, QListWidgetItem, Qt, from calibre.customize.ui import enable_plugin from calibre.gui2.preferences import ConfigWidgetBase, test_widget +from polyglot.builtins import range class ConfigWidget(ConfigWidgetBase): @@ -78,7 +79,7 @@ class ConfigWidget(ConfigWidgetBase): def commit(self): devs = {} - for i in xrange(0, self.devices.count()): + for i in range(0, self.devices.count()): e = self.devices.item(i) dev, uid = e.data(Qt.UserRole) if dev not in devs: @@ -89,7 +90,7 @@ class ConfigWidget(ConfigWidgetBase): for dev, bl in devs.iteritems(): dev.set_user_blacklisted_devices(bl) - for i in xrange(self.device_plugins.count()): + for i in range(self.device_plugins.count()): e = self.device_plugins.item(i) dev = e.data(Qt.UserRole) if e.checkState() == Qt.Unchecked: @@ -97,8 +98,8 @@ class ConfigWidget(ConfigWidgetBase): return True # Restart required + if __name__ == '__main__': from PyQt5.Qt import QApplication app = QApplication([]) test_widget('Sharing', 'Ignored Devices') - diff --git a/src/calibre/gui2/preferences/texture_chooser.py b/src/calibre/gui2/preferences/texture_chooser.py index fa45a7b94c..48b65323ce 100644 --- a/src/calibre/gui2/preferences/texture_chooser.py +++ b/src/calibre/gui2/preferences/texture_chooser.py @@ -15,7 +15,7 @@ from PyQt5.Qt import ( from calibre.constants import config_dir from calibre.gui2 import choose_files, error_dialog from calibre.utils.icu import sort_key -from polyglot.builtins import unicode_type +from polyglot.builtins import unicode_type, range def texture_dir(): @@ -85,7 +85,7 @@ class TextureChooser(QDialog): self.update_remove_state() if initial: - existing = {unicode_type(i.data(Qt.UserRole) or ''):i for i in (self.images.item(c) for c in xrange(self.images.count()))} + existing = {unicode_type(i.data(Qt.UserRole) or ''):i for i in (self.images.item(c) for c in range(self.images.count()))} item = existing.get(initial, None) if item is not None: item.setSelected(True) @@ -116,7 +116,7 @@ class TextureChooser(QDialog): path = path[0] fname = os.path.basename(path) name = fname.rpartition('.')[0] - existing = {unicode_type(i.data(Qt.UserRole) or ''):i for i in (self.images.item(c) for c in xrange(self.images.count()))} + existing = {unicode_type(i.data(Qt.UserRole) or ''):i for i in (self.images.item(c) for c in range(self.images.count()))} dest = os.path.join(self.tdir, fname) with open(path, 'rb') as s, open(dest, 'wb') as f: shutil.copyfileobj(s, f) diff --git a/src/calibre/gui2/preferences/tweaks.py b/src/calibre/gui2/preferences/tweaks.py index 61e1a2d7b4..ecff365aaa 100644 --- a/src/calibre/gui2/preferences/tweaks.py +++ b/src/calibre/gui2/preferences/tweaks.py @@ -19,7 +19,7 @@ from calibre import isbytestring from calibre.utils.icu import lower from calibre.utils.search_query_parser import (ParseException, SearchQueryParser) -from polyglot.builtins import unicode_type +from polyglot.builtins import unicode_type, range from PyQt5.Qt import ( QAbstractListModel, Qt, QStyledItemDelegate, QStyle, QStyleOptionViewItem, @@ -282,7 +282,7 @@ class Tweaks(QAbstractListModel, AdaptSQP): # {{{ self.plugin_tweaks = d def universal_set(self): - return set(xrange(self.rowCount())) + return set(range(self.rowCount())) def get_matches(self, location, query, candidates=None): if candidates is None: diff --git a/src/calibre/gui2/tag_browser/model.py b/src/calibre/gui2/tag_browser/model.py index a50dcfbed0..4415b372ea 100644 --- a/src/calibre/gui2/tag_browser/model.py +++ b/src/calibre/gui2/tag_browser/model.py @@ -23,6 +23,7 @@ from calibre.utils.icu import sort_key, lower, strcmp, collation_order, primary_ from calibre.library.field_metadata import category_icon_map from calibre.gui2.dialogs.confirm_delete import confirm from calibre.utils.formatter import EvalFormatter +from polyglot.builtins import range TAG_SEARCH_STATES = {'clear': 0, 'mark_plus': 1, 'mark_plusplus': 2, 'mark_minus': 3, 'mark_minusminus': 4} @@ -1492,7 +1493,7 @@ class TagsModel(QAbstractItemModel): # {{{ if path[depth] > start_path[depth]: start_path = path my_key = self.get_node(category_index).category_key - for j in xrange(self.rowCount(category_index)): + for j in range(self.rowCount(category_index)): tag_index = self.index(j, 0, category_index) tag_item = self.get_node(tag_index) if tag_item.type == TagTreeItem.CATEGORY: @@ -1503,7 +1504,7 @@ class TagsModel(QAbstractItemModel): # {{{ return True return False - for i in xrange(self.rowCount(QModelIndex())): + for i in range(self.rowCount(QModelIndex())): if process_level(0, self.index(i, 0, QModelIndex()), start_path): break return self.path_found @@ -1517,7 +1518,7 @@ class TagsModel(QAbstractItemModel): # {{{ if not key: return None - for i in xrange(self.rowCount(parent)): + for i in range(self.rowCount(parent)): idx = self.index(i, 0, parent) node = self.get_node(idx) if node.type == TagTreeItem.CATEGORY: @@ -1547,7 +1548,7 @@ class TagsModel(QAbstractItemModel): # {{{ process_tag(self.index(i, 0, tag_index), c) def process_level(category_index): - for j in xrange(self.rowCount(category_index)): + for j in range(self.rowCount(category_index)): tag_index = self.index(j, 0, category_index) tag_item = self.get_node(tag_index) if tag_item.boxed: @@ -1558,7 +1559,7 @@ class TagsModel(QAbstractItemModel): # {{{ else: process_tag(tag_index, tag_item) - for i in xrange(self.rowCount(QModelIndex())): + for i in range(self.rowCount(QModelIndex())): process_level(self.index(i, 0, QModelIndex())) # }}} diff --git a/src/calibre/gui2/tag_browser/view.py b/src/calibre/gui2/tag_browser/view.py index 9e74fc44d4..49a064257e 100644 --- a/src/calibre/gui2/tag_browser/view.py +++ b/src/calibre/gui2/tag_browser/view.py @@ -24,7 +24,7 @@ from calibre.gui2.tag_browser.model import (TagTreeItem, TAG_SEARCH_STATES, TagsModel, DRAG_IMAGE_ROLE, COUNT_ROLE) from calibre.gui2 import config, gprefs, choose_files, pixmap_to_data, rating_font, empty_index from calibre.utils.icu import sort_key -from polyglot.builtins import unicode_type +from polyglot.builtins import unicode_type, range class TagDelegate(QStyledItemDelegate): # {{{ @@ -723,7 +723,7 @@ class TagsView(QTreeView): # {{{ if not index.isValid(): return self.expand(index) - for r in xrange(self.model().rowCount(index)): + for r in range(self.model().rowCount(index)): self.expand_node_and_descendants(index.child(r, 0)) def collapse_menu_hovered(self, action):