mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Merge from trunk
This commit is contained in:
commit
bdf28e378f
@ -73,6 +73,10 @@ class FB2MLizer(object):
|
|||||||
text = re.sub(r'(?miu)<p>\s*</p>', '', text)
|
text = re.sub(r'(?miu)<p>\s*</p>', '', text)
|
||||||
text = re.sub(r'(?miu)\s+</p>', '</p>', text)
|
text = re.sub(r'(?miu)\s+</p>', '</p>', text)
|
||||||
text = re.sub(r'(?miu)</p><p>', '</p>\n\n<p>', text)
|
text = re.sub(r'(?miu)</p><p>', '</p>\n\n<p>', text)
|
||||||
|
|
||||||
|
if self.opts.insert_blank_line:
|
||||||
|
text = re.sub(r'(?miu)</p>', '</p><empty-line />', text)
|
||||||
|
|
||||||
return text
|
return text
|
||||||
|
|
||||||
def fb2_header(self):
|
def fb2_header(self):
|
||||||
@ -293,6 +297,18 @@ class FB2MLizer(object):
|
|||||||
s_out, s_tags = self.handle_simple_tag('emphasis', tag_stack+tags)
|
s_out, s_tags = self.handle_simple_tag('emphasis', tag_stack+tags)
|
||||||
fb2_out += s_out
|
fb2_out += s_out
|
||||||
tags += s_tags
|
tags += s_tags
|
||||||
|
elif tag in ('del', 'strike'):
|
||||||
|
s_out, s_tags = self.handle_simple_tag('strikethrough', tag_stack+tags)
|
||||||
|
fb2_out += s_out
|
||||||
|
tags += s_tags
|
||||||
|
elif tag == 'sub':
|
||||||
|
s_out, s_tags = self.handle_simple_tag('sub', tag_stack+tags)
|
||||||
|
fb2_out += s_out
|
||||||
|
tags += s_tags
|
||||||
|
elif tag == 'sup':
|
||||||
|
s_out, s_tags = self.handle_simple_tag('sup', tag_stack+tags)
|
||||||
|
fb2_out += s_out
|
||||||
|
tags += s_tags
|
||||||
|
|
||||||
# Processes style information.
|
# Processes style information.
|
||||||
if style['font-style'] == 'italic':
|
if style['font-style'] == 'italic':
|
||||||
@ -303,6 +319,10 @@ class FB2MLizer(object):
|
|||||||
s_out, s_tags = self.handle_simple_tag('strong', tag_stack+tags)
|
s_out, s_tags = self.handle_simple_tag('strong', tag_stack+tags)
|
||||||
fb2_out += s_out
|
fb2_out += s_out
|
||||||
tags += s_tags
|
tags += s_tags
|
||||||
|
elif style['text-decoration'] == 'line-through':
|
||||||
|
s_out, s_tags = self.handle_simple_tag('strikethrough', tag_stack+tags)
|
||||||
|
fb2_out += s_out
|
||||||
|
tags += s_tags
|
||||||
|
|
||||||
# Process element text.
|
# Process element text.
|
||||||
if hasattr(elem_tree, 'text') and elem_tree.text:
|
if hasattr(elem_tree, 'text') and elem_tree.text:
|
||||||
|
@ -9,7 +9,7 @@ from PyQt4.Qt import QVariant, QFileInfo, QObject, SIGNAL, QBuffer, Qt, \
|
|||||||
QByteArray, QTranslator, QCoreApplication, QThread, \
|
QByteArray, QTranslator, QCoreApplication, QThread, \
|
||||||
QEvent, QTimer, pyqtSignal, QDate, QDesktopServices, \
|
QEvent, QTimer, pyqtSignal, QDate, QDesktopServices, \
|
||||||
QFileDialog, QMessageBox, QPixmap, QFileIconProvider, \
|
QFileDialog, QMessageBox, QPixmap, QFileIconProvider, \
|
||||||
QIcon, QApplication, QDialog, QPushButton, QUrl
|
QIcon, QApplication, QDialog, QPushButton, QUrl, QFont
|
||||||
|
|
||||||
ORG_NAME = 'KovidsBrain'
|
ORG_NAME = 'KovidsBrain'
|
||||||
APP_UID = 'libprs500'
|
APP_UID = 'libprs500'
|
||||||
@ -52,6 +52,7 @@ gprefs.defaults['show_splash_screen'] = True
|
|||||||
gprefs.defaults['toolbar_icon_size'] = 'medium'
|
gprefs.defaults['toolbar_icon_size'] = 'medium'
|
||||||
gprefs.defaults['toolbar_text'] = 'auto'
|
gprefs.defaults['toolbar_text'] = 'auto'
|
||||||
gprefs.defaults['show_child_bar'] = False
|
gprefs.defaults['show_child_bar'] = False
|
||||||
|
gprefs.defaults['font'] = None
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
@ -613,6 +614,10 @@ class Application(QApplication):
|
|||||||
qt_app = self
|
qt_app = self
|
||||||
self._file_open_paths = []
|
self._file_open_paths = []
|
||||||
self._file_open_lock = RLock()
|
self._file_open_lock = RLock()
|
||||||
|
self.original_font = QFont(QApplication.font())
|
||||||
|
fi = gprefs['font']
|
||||||
|
if fi is not None:
|
||||||
|
QApplication.setFont(QFont(*fi))
|
||||||
|
|
||||||
def _send_file_open_events(self):
|
def _send_file_open_events(self):
|
||||||
with self._file_open_lock:
|
with self._file_open_lock:
|
||||||
|
@ -154,15 +154,17 @@ class EditMetadataAction(InterfaceAction):
|
|||||||
d.view_format.connect(lambda
|
d.view_format.connect(lambda
|
||||||
fmt:self.gui.iactions['View'].view_format(row_list[current_row],
|
fmt:self.gui.iactions['View'].view_format(row_list[current_row],
|
||||||
fmt))
|
fmt))
|
||||||
if d.exec_() != d.Accepted:
|
ret = d.exec_()
|
||||||
d.view_format.disconnect()
|
d.break_cycles()
|
||||||
|
if ret != d.Accepted:
|
||||||
break
|
break
|
||||||
d.view_format.disconnect()
|
|
||||||
changed.add(d.id)
|
changed.add(d.id)
|
||||||
if d.row_delta == 0:
|
if d.row_delta == 0:
|
||||||
break
|
break
|
||||||
current_row += d.row_delta
|
current_row += d.row_delta
|
||||||
|
|
||||||
|
|
||||||
if changed:
|
if changed:
|
||||||
self.gui.library_view.model().refresh_ids(list(changed))
|
self.gui.library_view.model().refresh_ids(list(changed))
|
||||||
current = self.gui.library_view.currentIndex()
|
current = self.gui.library_view.currentIndex()
|
||||||
|
@ -293,7 +293,8 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
|
|||||||
finally:
|
finally:
|
||||||
self.fetch_cover_button.setEnabled(True)
|
self.fetch_cover_button.setEnabled(True)
|
||||||
self.unsetCursor()
|
self.unsetCursor()
|
||||||
self.pi.stop()
|
if self.pi is not None:
|
||||||
|
self.pi.stop()
|
||||||
|
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
@ -442,7 +443,6 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
|
|||||||
ResizableDialog.__init__(self, window)
|
ResizableDialog.__init__(self, window)
|
||||||
self.cover_fetcher = None
|
self.cover_fetcher = None
|
||||||
self.bc_box.layout().setAlignment(self.cover, Qt.AlignCenter|Qt.AlignHCenter)
|
self.bc_box.layout().setAlignment(self.cover, Qt.AlignCenter|Qt.AlignHCenter)
|
||||||
self.cancel_all = False
|
|
||||||
base = unicode(self.author_sort.toolTip())
|
base = unicode(self.author_sort.toolTip())
|
||||||
self.ok_aus_tooltip = '<p>' + textwrap.fill(base+'<br><br>'+
|
self.ok_aus_tooltip = '<p>' + textwrap.fill(base+'<br><br>'+
|
||||||
_(' The green color indicates that the current '
|
_(' The green color indicates that the current '
|
||||||
@ -573,7 +573,6 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
|
|||||||
QObject.connect(self.series, SIGNAL('editTextChanged(QString)'), self.enable_series_index)
|
QObject.connect(self.series, SIGNAL('editTextChanged(QString)'), self.enable_series_index)
|
||||||
self.series.lineEdit().editingFinished.connect(self.increment_series_index)
|
self.series.lineEdit().editingFinished.connect(self.increment_series_index)
|
||||||
|
|
||||||
self.show()
|
|
||||||
pm = QPixmap()
|
pm = QPixmap()
|
||||||
if cover:
|
if cover:
|
||||||
pm.loadFromData(cover)
|
pm.loadFromData(cover)
|
||||||
@ -593,6 +592,8 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
|
|||||||
self.original_author = unicode(self.authors.text()).strip()
|
self.original_author = unicode(self.authors.text()).strip()
|
||||||
self.original_title = unicode(self.title.text()).strip()
|
self.original_title = unicode(self.title.text()).strip()
|
||||||
|
|
||||||
|
self.show()
|
||||||
|
|
||||||
def create_custom_column_editors(self):
|
def create_custom_column_editors(self):
|
||||||
w = self.central_widget.widget(1)
|
w = self.central_widget.widget(1)
|
||||||
layout = w.layout()
|
layout = w.layout()
|
||||||
@ -907,3 +908,48 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
|
|||||||
dynamic.set('metasingle_window_geometry', bytes(self.saveGeometry()))
|
dynamic.set('metasingle_window_geometry', bytes(self.saveGeometry()))
|
||||||
dynamic.set('metasingle_splitter_state',
|
dynamic.set('metasingle_splitter_state',
|
||||||
bytes(self.splitter.saveState()))
|
bytes(self.splitter.saveState()))
|
||||||
|
|
||||||
|
def break_cycles(self):
|
||||||
|
# Break any reference cycles that could prevent python
|
||||||
|
# from garbage collecting this dialog
|
||||||
|
def disconnect(signal):
|
||||||
|
try:
|
||||||
|
signal.disconnect()
|
||||||
|
except:
|
||||||
|
pass # Fails if view format was never connected
|
||||||
|
disconnect(self.view_format)
|
||||||
|
for b in ('next_button', 'prev_button'):
|
||||||
|
x = getattr(self, b, None)
|
||||||
|
if x is not None:
|
||||||
|
disconnect(x.clicked)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
from calibre.library import db
|
||||||
|
from PyQt4.Qt import QApplication
|
||||||
|
from calibre.utils.mem import memory
|
||||||
|
import gc
|
||||||
|
|
||||||
|
|
||||||
|
app = QApplication([])
|
||||||
|
db = db()
|
||||||
|
|
||||||
|
# Initialize all Qt Objects once
|
||||||
|
d = MetadataSingleDialog(None, 4, db)
|
||||||
|
d.break_cycles()
|
||||||
|
d.reject()
|
||||||
|
del d
|
||||||
|
|
||||||
|
for i in range(5):
|
||||||
|
gc.collect()
|
||||||
|
before = memory()
|
||||||
|
|
||||||
|
d = MetadataSingleDialog(None, 4, db)
|
||||||
|
d.reject()
|
||||||
|
d.break_cycles()
|
||||||
|
del d
|
||||||
|
|
||||||
|
for i in range(5):
|
||||||
|
gc.collect()
|
||||||
|
print 'Used memory:', memory(before)/1024.**2, 'MB'
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,10 +5,11 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
|
from PyQt4.Qt import QApplication, QFont, QFontInfo, QFontDialog
|
||||||
|
|
||||||
from calibre.gui2.preferences import ConfigWidgetBase, test_widget
|
from calibre.gui2.preferences import ConfigWidgetBase, test_widget
|
||||||
from calibre.gui2.preferences.look_feel_ui import Ui_Form
|
from calibre.gui2.preferences.look_feel_ui import Ui_Form
|
||||||
from calibre.gui2 import config, gprefs
|
from calibre.gui2 import config, gprefs, qt_app
|
||||||
from calibre.utils.localization import available_translations, \
|
from calibre.utils.localization import available_translations, \
|
||||||
get_language, get_lang
|
get_language, get_lang
|
||||||
from calibre.utils.config import prefs
|
from calibre.utils.config import prefs
|
||||||
@ -56,12 +57,64 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
(_('Never'), 'never')]
|
(_('Never'), 'never')]
|
||||||
r('toolbar_text', gprefs, choices=choices)
|
r('toolbar_text', gprefs, choices=choices)
|
||||||
|
|
||||||
|
self.current_font = None
|
||||||
|
self.change_font_button.clicked.connect(self.change_font)
|
||||||
|
|
||||||
|
|
||||||
|
def initialize(self):
|
||||||
|
ConfigWidgetBase.initialize(self)
|
||||||
|
self.current_font = gprefs['font']
|
||||||
|
self.update_font_display()
|
||||||
|
|
||||||
|
def restore_defaults(self):
|
||||||
|
ConfigWidgetBase.restore_defaults(self)
|
||||||
|
ofont = self.current_font
|
||||||
|
self.current_font = None
|
||||||
|
if ofont is not None:
|
||||||
|
self.changed_signal.emit()
|
||||||
|
self.update_font_display()
|
||||||
|
|
||||||
|
def build_font_obj(self):
|
||||||
|
font_info = self.current_font
|
||||||
|
if font_info is not None:
|
||||||
|
font = QFont(*font_info)
|
||||||
|
else:
|
||||||
|
font = qt_app.original_font
|
||||||
|
return font
|
||||||
|
|
||||||
|
def update_font_display(self):
|
||||||
|
font = self.build_font_obj()
|
||||||
|
fi = QFontInfo(font)
|
||||||
|
name = unicode(fi.family())
|
||||||
|
|
||||||
|
self.font_display.setFont(font)
|
||||||
|
self.font_display.setText(_('Current font:') + ' ' + name +
|
||||||
|
' [%dpt]'%fi.pointSize())
|
||||||
|
|
||||||
|
def change_font(self, *args):
|
||||||
|
fd = QFontDialog(self.build_font_obj(), self)
|
||||||
|
if fd.exec_() == fd.Accepted:
|
||||||
|
font = fd.selectedFont()
|
||||||
|
fi = QFontInfo(font)
|
||||||
|
self.current_font = (unicode(fi.family()), fi.pointSize(),
|
||||||
|
fi.weight(), fi.italic())
|
||||||
|
self.update_font_display()
|
||||||
|
self.changed_signal.emit()
|
||||||
|
|
||||||
|
def commit(self, *args):
|
||||||
|
rr = ConfigWidgetBase.commit(self, *args)
|
||||||
|
if self.current_font != gprefs['font']:
|
||||||
|
gprefs['font'] = self.current_font
|
||||||
|
QApplication.setFont(self.font_display.font())
|
||||||
|
rr = True
|
||||||
|
return rr
|
||||||
|
|
||||||
|
|
||||||
def refresh_gui(self, gui):
|
def refresh_gui(self, gui):
|
||||||
gui.search.search_as_you_type(config['search_as_you_type'])
|
gui.search.search_as_you_type(config['search_as_you_type'])
|
||||||
|
self.update_font_display()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from PyQt4.Qt import QApplication
|
|
||||||
app = QApplication([])
|
app = QApplication([])
|
||||||
test_widget('Interface', 'Look & Feel')
|
test_widget('Interface', 'Look & Feel')
|
||||||
|
|
||||||
|
@ -183,7 +183,7 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="8" column="0" colspan="2">
|
<item row="9" column="0" colspan="2">
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
@ -196,6 +196,20 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="8" column="0">
|
||||||
|
<widget class="QLineEdit" name="font_display">
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="8" column="1">
|
||||||
|
<widget class="QPushButton" name="change_font_button">
|
||||||
|
<property name="text">
|
||||||
|
<string>Change &font (needs restart)</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
@ -19,12 +19,15 @@ def generate_test_db(library_path,
|
|||||||
max_tags=10
|
max_tags=10
|
||||||
):
|
):
|
||||||
import random, string, os, sys, time
|
import random, string, os, sys, time
|
||||||
|
from calibre.constants import preferred_encoding
|
||||||
|
|
||||||
if not os.path.exists(library_path):
|
if not os.path.exists(library_path):
|
||||||
os.makedirs(library_path)
|
os.makedirs(library_path)
|
||||||
|
|
||||||
|
letters = string.letters.decode(preferred_encoding)
|
||||||
|
|
||||||
def randstr(length):
|
def randstr(length):
|
||||||
return ''.join(random.choice(string.letters) for i in
|
return ''.join(random.choice(letters) for i in
|
||||||
xrange(length))
|
xrange(length))
|
||||||
|
|
||||||
all_tags = [randstr(tag_length) for j in xrange(num_of_tags)]
|
all_tags = [randstr(tag_length) for j in xrange(num_of_tags)]
|
||||||
|
55
src/calibre/utils/mem.py
Normal file
55
src/calibre/utils/mem.py
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||||
|
|
||||||
|
__license__ = 'GPL v3'
|
||||||
|
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
|
## {{{ http://code.activestate.com/recipes/286222/ (r1)
|
||||||
|
import os
|
||||||
|
|
||||||
|
_proc_status = '/proc/%d/status' % os.getpid()
|
||||||
|
|
||||||
|
_scale = {'kB': 1024.0, 'mB': 1024.0*1024.0,
|
||||||
|
'KB': 1024.0, 'MB': 1024.0*1024.0}
|
||||||
|
|
||||||
|
def _VmB(VmKey):
|
||||||
|
'''Private.
|
||||||
|
'''
|
||||||
|
global _proc_status, _scale
|
||||||
|
# get pseudo file /proc/<pid>/status
|
||||||
|
try:
|
||||||
|
t = open(_proc_status)
|
||||||
|
v = t.read()
|
||||||
|
t.close()
|
||||||
|
except:
|
||||||
|
return 0.0 # non-Linux?
|
||||||
|
# get VmKey line e.g. 'VmRSS: 9999 kB\n ...'
|
||||||
|
i = v.index(VmKey)
|
||||||
|
v = v[i:].split(None, 3) # whitespace
|
||||||
|
if len(v) < 3:
|
||||||
|
return 0.0 # invalid format?
|
||||||
|
# convert Vm value to bytes
|
||||||
|
return float(v[1]) * _scale[v[2]]
|
||||||
|
|
||||||
|
|
||||||
|
def memory(since=0.0):
|
||||||
|
'''Return memory usage in bytes.
|
||||||
|
'''
|
||||||
|
return _VmB('VmSize:') - since
|
||||||
|
|
||||||
|
|
||||||
|
def resident(since=0.0):
|
||||||
|
'''Return resident memory usage in bytes.
|
||||||
|
'''
|
||||||
|
return _VmB('VmRSS:') - since
|
||||||
|
|
||||||
|
|
||||||
|
def stacksize(since=0.0):
|
||||||
|
'''Return stack size in bytes.
|
||||||
|
'''
|
||||||
|
return _VmB('VmStk:') - since
|
||||||
|
## end of http://code.activestate.com/recipes/286222/ }}}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user