Refactor for re-use

This commit is contained in:
Kovid Goyal 2015-01-24 08:54:50 +05:30
parent ef09e886b3
commit 36ed6c24a4

View File

@ -298,17 +298,9 @@ class FilesWidget(QWidget):
# }}}
class Jump(object): # {{{
# Jump {{{
def __init__(self):
self.pos_map = defaultdict(lambda : -1)
def clear(self):
self.pos_map.clear()
def __call__(self, key, locations):
self.pos_map[key] = (self.pos_map[key] + 1) % len(locations)
loc = locations[self.pos_map[key]]
def jump_to_location(loc):
from calibre.gui2.tweak_book.boss import get_boss
boss = get_boss()
if boss is None:
@ -328,6 +320,19 @@ class Jump(object): # {{{
if loc.text_on_line is not None:
editor.find(regex.compile(regex.escape(loc.text_on_line)))
class Jump(object):
def __init__(self):
self.pos_map = defaultdict(lambda : -1)
def clear(self):
self.pos_map.clear()
def __call__(self, key, locations):
self.pos_map[key] = (self.pos_map[key] + 1) % len(locations)
loc = locations[self.pos_map[key]]
jump_to_location(loc)
jump = Jump() # }}}
# Images {{{