Sync to trunk.

This commit is contained in:
John Schember 2009-06-07 11:57:27 -04:00
commit 0abc5a907a
3 changed files with 84 additions and 72 deletions

View File

@ -6,6 +6,7 @@ __license__ = 'GPL v3'
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>' __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
from PyQt4.Qt import Qt
from calibre.gui2.convert.lrf_output_ui import Ui_Form from calibre.gui2.convert.lrf_output_ui import Ui_Form
from calibre.gui2.convert import Widget from calibre.gui2.convert import Widget
@ -42,8 +43,10 @@ class PluginWidget(Widget, Ui_Form):
def set_value_handler(self, g, val): def set_value_handler(self, g, val):
if val is None and unicode(g.objectName()) in ('opt_serif_family', if unicode(g.objectName()) in ('opt_serif_family',
'opt_sans_family', 'opt_mono_family'): 'opt_sans_family', 'opt_mono_family'):
idx = g.findText(val, Qt.MatchFixedString)
if idx < 0:
idx = 0
g.setCurrentIndex(0) g.setCurrentIndex(0)
return True
return False return False

View File

@ -187,11 +187,11 @@ class Document(QWebPage):
return unicode(ans.toString()) return unicode(ans.toString())
return ans return ans
def scroll_by(self, x=0, y=0): def scroll_by(self, dx=0, dy=0):
self.javascript('window.scrollBy(%d, %d)'%(x, y)) self.mainFrame().scroll(dx, dy)
def scroll_to(self, x=0, y=0): def scroll_to(self, x=0, y=0):
self.javascript('window.scrollTo(%d, %d)'%(x, y)) self.mainFrame().setScrollPosition(QPoint(x, y))
def jump_to_anchor(self, anchor): def jump_to_anchor(self, anchor):
self.javascript('document.location.hash = "%s"'%anchor) self.javascript('document.location.hash = "%s"'%anchor)
@ -205,72 +205,54 @@ class Document(QWebPage):
def bookmark(self): def bookmark(self):
return self.javascript('calculate_bookmark(%d)'%(self.ypos+25), 'string') return self.javascript('calculate_bookmark(%d)'%(self.ypos+25), 'string')
@dynamic_property @property
def at_bottom(self): def at_bottom(self):
def fget(self):
return self.height - self.ypos <= self.window_height return self.height - self.ypos <= self.window_height
return property(fget=fget)
@dynamic_property @property
def at_top(self): def at_top(self):
def fget(self): return self.ypos <=0
return self.ypos <= 0
return property(fget=fget)
def test(self): def test(self):
pass pass
@dynamic_property @property
def ypos(self): def ypos(self):
def fget(self): return self.mainFrame().scrollPosition().y()
return self.javascript('window.pageYOffset', 'int')
return property(fget=fget)
@dynamic_property @property
def window_height(self): def window_height(self):
def fget(self):
return self.javascript('window.innerHeight', 'int') return self.javascript('window.innerHeight', 'int')
return property(fget=fget)
@dynamic_property @property
def window_width(self): def window_width(self):
def fget(self):
return self.javascript('window.innerWidth', 'int') return self.javascript('window.innerWidth', 'int')
return property(fget=fget)
@dynamic_property @property
def xpos(self): def xpos(self):
def fget(self): return self.mainFrame().scrollPosition().x()
return self.javascript('window.pageXOffset', 'int')
return property(fget=fget)
@dynamic_property @property
def scroll_fraction(self): def scroll_fraction(self):
def fget(self):
try: try:
return float(self.ypos)/(self.height-self.window_height) return float(self.ypos)/(self.height-self.window_height)
except ZeroDivisionError: except ZeroDivisionError:
return 0. return 0.
return property(fget=fget)
@dynamic_property @property
def hscroll_fraction(self): def hscroll_fraction(self):
def fget(self): try:
return float(self.xpos)/self.width return float(self.xpos)/self.width
return property(fget=fget) except ZeroDivisionError:
return 0.
@dynamic_property @property
def height(self): def height(self):
def fget(self):
return self.javascript('document.body.offsetHeight', 'int') # contentsSize gives inaccurate results return self.javascript('document.body.offsetHeight', 'int') # contentsSize gives inaccurate results
return property(fget=fget)
@dynamic_property @property
def width(self): def width(self):
def fget(self):
return self.mainFrame().contentsSize().width() # offsetWidth gives inaccurate results return self.mainFrame().contentsSize().width() # offsetWidth gives inaccurate results
return property(fget=fget)
class EntityDeclarationProcessor(object): class EntityDeclarationProcessor(object):
@ -346,23 +328,17 @@ class DocumentView(QWebView):
def sizeHint(self): def sizeHint(self):
return self._size_hint return self._size_hint
@dynamic_property @property
def scroll_fraction(self): def scroll_fraction(self):
def fget(self):
return self.document.scroll_fraction return self.document.scroll_fraction
return property(fget=fget)
@dynamic_property @property
def hscroll_fraction(self): def hscroll_fraction(self):
def fget(self):
return self.document.hscroll_fraction return self.document.hscroll_fraction
return property(fget=fget)
@dynamic_property @property
def content_size(self): def content_size(self):
def fget(self):
return self.document.width, self.document.height return self.document.width, self.document.height
return property(fget=fget)
def search(self, text): def search(self, text):
return self.findText(text) return self.findText(text)
@ -393,8 +369,6 @@ class DocumentView(QWebView):
self.scrollbar.setVisible(delta > 0) self.scrollbar.setVisible(delta > 0)
def load_finished(self, ok): def load_finished(self, ok):
self.document.mainFrame().setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff)
self.document.mainFrame().setScrollBarPolicy(Qt.Horizontal, Qt.ScrollBarAlwaysOff)
self._size_hint = self.document.mainFrame().contentsSize() self._size_hint = self.document.mainFrame().contentsSize()
scrolled = False scrolled = False
if self.to_bottom: if self.to_bottom:
@ -413,6 +387,8 @@ class DocumentView(QWebView):
self.document.set_reference_prefix('%d.'%(spine_index+1)) self.document.set_reference_prefix('%d.'%(spine_index+1))
if scrolled: if scrolled:
self.manager.scrolled(self.document.scroll_fraction) self.manager.scrolled(self.document.scroll_fraction)
self.document.mainFrame().setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff)
self.document.mainFrame().setScrollBarPolicy(Qt.Horizontal, Qt.ScrollBarAlwaysOff)
@classmethod @classmethod
@ -435,21 +411,18 @@ class DocumentView(QWebView):
self.scroll_by(y=overlap) self.scroll_by(y=overlap)
def previous_page(self): def previous_page(self):
delta_y = self.document.window_height - 25
if self.document.at_top: if self.document.at_top:
if self.manager is not None: if self.manager is not None:
self.manager.previous_document() self.manager.previous_document()
self.to_bottom = True self.to_bottom = True
else: else:
opos = self.document.ypos opos = self.document.ypos
while True: upper_limit = opos - delta_y
delta = abs(opos-self.document.ypos) if upper_limit < 0:
if delta > self.size().height(): upper_limit = 0
self.wheel_event(down=True) if upper_limit < opos:
break self.document.scroll_to(self.document.xpos, upper_limit)
pre = self.document.ypos
self.wheel_event(down=False)
if pre == self.document.ypos:
break
if self.manager is not None: if self.manager is not None:
self.manager.scrolled(self.scroll_fraction) self.manager.scrolled(self.scroll_fraction)
@ -477,7 +450,6 @@ class DocumentView(QWebView):
if self.manager is not None: if self.manager is not None:
self.manager.scrolled(self.scroll_fraction) self.manager.scrolled(self.scroll_fraction)
def scroll_by(self, x=0, y=0, notify=True): def scroll_by(self, x=0, y=0, notify=True):
old_pos = self.document.ypos old_pos = self.document.ypos
self.document.scroll_by(x, y) self.document.scroll_by(x, y)

View File

@ -521,6 +521,43 @@ class LibraryDatabase2(LibraryDatabase):
FROM books; FROM books;
''') ''')
def upgrade_version_5(self):
'Update indexes/triggers for new books table'
self.conn.executescript('''
BEGIN TRANSACTION;
CREATE INDEX authors_idx ON books (author_sort COLLATE NOCASE);
CREATE INDEX books_idx ON books (sort COLLATE NOCASE);
CREATE TRIGGER books_delete_trg
AFTER DELETE ON books
BEGIN
DELETE FROM books_authors_link WHERE book=OLD.id;
DELETE FROM books_publishers_link WHERE book=OLD.id;
DELETE FROM books_ratings_link WHERE book=OLD.id;
DELETE FROM books_series_link WHERE book=OLD.id;
DELETE FROM books_tags_link WHERE book=OLD.id;
DELETE FROM data WHERE book=OLD.id;
DELETE FROM comments WHERE book=OLD.id;
DELETE FROM conversion_options WHERE book=OLD.id;
END;
CREATE TRIGGER books_insert_trg
AFTER INSERT ON books
BEGIN
UPDATE books SET sort=title_sort(NEW.title) WHERE id=NEW.id;
END;
CREATE TRIGGER books_update_trg
AFTER UPDATE ON books
BEGIN
UPDATE books SET sort=title_sort(NEW.title) WHERE id=NEW.id;
END;
UPDATE books SET sort=title_sort(title) WHERE sort IS NULL;
END TRANSACTION;
'''
)
def last_modified(self): def last_modified(self):
''' Return last modified time as a UTC datetime object''' ''' Return last modified time as a UTC datetime object'''
return datetime.utcfromtimestamp(os.stat(self.dbpath).st_mtime) return datetime.utcfromtimestamp(os.stat(self.dbpath).st_mtime)