mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix rendering of custom delegates in item views to conform to GUI styles
This commit is contained in:
parent
65972716d4
commit
33c1401fd6
@ -99,7 +99,7 @@ _check_symlinks_prescript()
|
|||||||
includes=list(self.includes) + main_modules['console'],
|
includes=list(self.includes) + main_modules['console'],
|
||||||
packages=self.packages,
|
packages=self.packages,
|
||||||
excludes=self.excludes,
|
excludes=self.excludes,
|
||||||
debug=debug,
|
debug=debug
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -277,13 +277,7 @@ sys.frameworks_dir = os.path.join(os.path.dirname(os.environ['RESOURCEPATH']), '
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# auto = '--auto' in sys.argv
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
|
||||||
# if auto:
|
|
||||||
# sys.argv.remove('--auto')
|
|
||||||
# if auto and not os.path.exists('dist/auto'):
|
|
||||||
# print '%s does not exist'%os.path.abspath('dist/auto')
|
|
||||||
# return 1
|
|
||||||
#
|
|
||||||
sys.argv[1:2] = ['py2app']
|
sys.argv[1:2] = ['py2app']
|
||||||
setup(
|
setup(
|
||||||
name = APPNAME,
|
name = APPNAME,
|
||||||
|
@ -447,15 +447,14 @@ class Settings(QSettings):
|
|||||||
self.setValue(str(key), QVariant(QByteArray(val)))
|
self.setValue(str(key), QVariant(QByteArray(val)))
|
||||||
|
|
||||||
_settings = Settings()
|
_settings = Settings()
|
||||||
|
|
||||||
if not _settings.get('rationalized'):
|
if not _settings.get('rationalized'):
|
||||||
__settings = Settings(name='calibre')
|
__settings = Settings(name='calibre')
|
||||||
dbpath = os.path.join(os.path.expanduser('~'), 'library1.db').decode(sys.getfilesystemencoding())
|
dbpath = os.path.join(os.path.expanduser('~'), 'library1.db').decode(sys.getfilesystemencoding())
|
||||||
dbpath = unicode(__settings.value('database path',
|
dbpath = unicode(__settings.value('database path',
|
||||||
QVariant(QString.fromUtf8(dbpath.encode('utf-8')))).toString())
|
QVariant(QString.fromUtf8(dbpath.encode('utf-8')))).toString())
|
||||||
cmdline = __settings.value('LRF conversion defaults', QVariant(QByteArray(''))).toByteArray().data()
|
cmdline = __settings.value('LRF conversion defaults', QVariant(QByteArray(''))).toByteArray().data()
|
||||||
|
|
||||||
|
|
||||||
_settings.set('database path', dbpath)
|
|
||||||
if cmdline:
|
if cmdline:
|
||||||
cmdline = cPickle.loads(cmdline)
|
cmdline = cPickle.loads(cmdline)
|
||||||
_settings.set('LRF conversion defaults', cmdline)
|
_settings.set('LRF conversion defaults', cmdline)
|
||||||
@ -464,6 +463,7 @@ if not _settings.get('rationalized'):
|
|||||||
os.unlink(unicode(__settings.fileName()))
|
os.unlink(unicode(__settings.fileName()))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
_settings.set('database path', dbpath)
|
||||||
|
|
||||||
_spat = re.compile(r'^the\s+|^a\s+|^an\s+', re.IGNORECASE)
|
_spat = re.compile(r'^the\s+|^a\s+|^an\s+', re.IGNORECASE)
|
||||||
def english_sort(x, y):
|
def english_sort(x, y):
|
||||||
|
@ -9,7 +9,7 @@ from itertools import repeat
|
|||||||
from PyQt4.QtGui import QTableView, QProgressDialog, QAbstractItemView, QColor, \
|
from PyQt4.QtGui import QTableView, QProgressDialog, QAbstractItemView, QColor, \
|
||||||
QItemDelegate, QPainterPath, QLinearGradient, QBrush, \
|
QItemDelegate, QPainterPath, QLinearGradient, QBrush, \
|
||||||
QPen, QStyle, QPainter, QLineEdit, QApplication, \
|
QPen, QStyle, QPainter, QLineEdit, QApplication, \
|
||||||
QPalette, QImage
|
QPalette, QImage, QStyleOptionFocusRect, QApplication
|
||||||
from PyQt4.QtCore import QAbstractTableModel, QVariant, Qt, QString, \
|
from PyQt4.QtCore import QAbstractTableModel, QVariant, Qt, QString, \
|
||||||
QCoreApplication, SIGNAL, QObject, QSize, QModelIndex, \
|
QCoreApplication, SIGNAL, QObject, QSize, QModelIndex, \
|
||||||
QTimer
|
QTimer
|
||||||
@ -55,9 +55,8 @@ class LibraryDelegate(QItemDelegate):
|
|||||||
painter.restore()
|
painter.restore()
|
||||||
|
|
||||||
painter.save()
|
painter.save()
|
||||||
|
QApplication.style().drawControl(QStyle.CE_ItemViewItem, option, painter)
|
||||||
try:
|
try:
|
||||||
if option.state & QStyle.State_Selected:
|
|
||||||
painter.fillRect(option.rect, option.palette.highlight())
|
|
||||||
painter.setRenderHint(QPainter.Antialiasing)
|
painter.setRenderHint(QPainter.Antialiasing)
|
||||||
y = option.rect.center().y()-self.SIZE/2.
|
y = option.rect.center().y()-self.SIZE/2.
|
||||||
x = option.rect.right() - self.SIZE
|
x = option.rect.right() - self.SIZE
|
||||||
|
@ -4,7 +4,7 @@ import os, sys, textwrap, collections, traceback, shutil, time
|
|||||||
from xml.parsers.expat import ExpatError
|
from xml.parsers.expat import ExpatError
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from PyQt4.QtCore import Qt, SIGNAL, QObject, QCoreApplication, \
|
from PyQt4.QtCore import Qt, SIGNAL, QObject, QCoreApplication, \
|
||||||
QVariant, QThread, QSize, QUrl
|
QVariant, QThread, QUrl, QSize
|
||||||
from PyQt4.QtGui import QPixmap, QColor, QPainter, QMenu, QIcon, QMessageBox, \
|
from PyQt4.QtGui import QPixmap, QColor, QPainter, QMenu, QIcon, QMessageBox, \
|
||||||
QToolButton, QDialog, QDesktopServices
|
QToolButton, QDialog, QDesktopServices
|
||||||
from PyQt4.QtSvg import QSvgRenderer
|
from PyQt4.QtSvg import QSvgRenderer
|
||||||
@ -1190,4 +1190,14 @@ def main(args=sys.argv):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
sys.exit(main())
|
try:
|
||||||
|
sys.exit(main())
|
||||||
|
except:
|
||||||
|
if not iswindows: raise
|
||||||
|
from PyQt4.QtGui import QErrorMessage
|
||||||
|
logfile = os.path.expanduser('~/calibre.log')
|
||||||
|
if os.path.exists(logfile):
|
||||||
|
log = open(logfile).read()
|
||||||
|
if log.strip():
|
||||||
|
d = QErrorMessage()
|
||||||
|
d.showMessage(log)
|
||||||
|
@ -27,9 +27,9 @@
|
|||||||
<property name="geometry" >
|
<property name="geometry" >
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>86</y>
|
<y>79</y>
|
||||||
<width>865</width>
|
<width>865</width>
|
||||||
<height>712</height>
|
<height>716</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" >
|
<layout class="QGridLayout" >
|
||||||
@ -44,7 +44,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="LocationView" name="location_view" >
|
<widget class="LocationView" name="location_view" >
|
||||||
<property name="sizePolicy" >
|
<property name="sizePolicy" >
|
||||||
<sizepolicy vsizetype="Minimum" hsizetype="Expanding" >
|
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
@ -52,19 +52,25 @@
|
|||||||
<property name="maximumSize" >
|
<property name="maximumSize" >
|
||||||
<size>
|
<size>
|
||||||
<width>10000</width>
|
<width>10000</width>
|
||||||
<height>100</height>
|
<height>110</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="verticalScrollBarPolicy" >
|
<property name="verticalScrollBarPolicy" >
|
||||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="horizontalScrollBarPolicy" >
|
<property name="horizontalScrollBarPolicy" >
|
||||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
<enum>Qt::ScrollBarAsNeeded</enum>
|
||||||
|
</property>
|
||||||
|
<property name="tabKeyNavigation" >
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="showDropIndicator" stdset="0" >
|
||||||
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="iconSize" >
|
<property name="iconSize" >
|
||||||
<size>
|
<size>
|
||||||
<width>32</width>
|
<width>40</width>
|
||||||
<height>32</height>
|
<height>40</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="movement" >
|
<property name="movement" >
|
||||||
@ -77,14 +83,11 @@
|
|||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="spacing" >
|
<property name="spacing" >
|
||||||
<number>20</number>
|
<number>10</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="viewMode" >
|
<property name="viewMode" >
|
||||||
<enum>QListView::IconMode</enum>
|
<enum>QListView::IconMode</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="uniformItemSizes" >
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
@ -332,8 +335,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>847</width>
|
<width>857</width>
|
||||||
<height>553</height>
|
<height>552</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" >
|
<layout class="QGridLayout" >
|
||||||
@ -380,7 +383,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>865</width>
|
<width>865</width>
|
||||||
<height>86</height>
|
<height>79</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="minimumSize" >
|
<property name="minimumSize" >
|
||||||
@ -425,9 +428,9 @@
|
|||||||
<property name="geometry" >
|
<property name="geometry" >
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>798</y>
|
<y>795</y>
|
||||||
<width>865</width>
|
<width>865</width>
|
||||||
<height>24</height>
|
<height>27</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="mouseTracking" >
|
<property name="mouseTracking" >
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import os, sys, glob
|
import os, sys, glob, shutil
|
||||||
import sipconfig
|
import sipconfig
|
||||||
if os.environ.get('PYQT4PATH', None):
|
if os.environ.get('PYQT4PATH', None):
|
||||||
print os.environ['PYQT4PATH']
|
print os.environ['PYQT4PATH']
|
||||||
@ -37,7 +37,7 @@ makefile = pyqtconfig.QtGuiModuleMakefile (
|
|||||||
# ".dll" extension on Windows).
|
# ".dll" extension on Windows).
|
||||||
if 'linux' in sys.platform:
|
if 'linux' in sys.platform:
|
||||||
for f in glob.glob('../../.build/libpictureflow.a'):
|
for f in glob.glob('../../.build/libpictureflow.a'):
|
||||||
os.link(f, './'+os.path.basename(f))
|
shutil.copyfile(f, os.path.basename(f))
|
||||||
makefile.extra_lib_dirs = ['.']
|
makefile.extra_lib_dirs = ['.']
|
||||||
else:
|
else:
|
||||||
makefile.extra_lib_dirs = ['..\\..\\.build\\release', '../../.build', '.']
|
makefile.extra_lib_dirs = ['..\\..\\.build\\release', '../../.build', '.']
|
||||||
|
@ -7,9 +7,9 @@ import re, os
|
|||||||
from PyQt4.QtGui import QListView, QIcon, QFont, QLabel, QListWidget, \
|
from PyQt4.QtGui import QListView, QIcon, QFont, QLabel, QListWidget, \
|
||||||
QListWidgetItem, QTextCharFormat, QApplication, \
|
QListWidgetItem, QTextCharFormat, QApplication, \
|
||||||
QSyntaxHighlighter, QCursor, QColor, QWidget, \
|
QSyntaxHighlighter, QCursor, QColor, QWidget, \
|
||||||
QAbstractItemDelegate, QPixmap
|
QAbstractItemDelegate, QPixmap, QStyle
|
||||||
from PyQt4.QtCore import QAbstractListModel, QVariant, Qt, QRect, SIGNAL, \
|
from PyQt4.QtCore import QAbstractListModel, QVariant, Qt, QRect, SIGNAL, \
|
||||||
QObject, QRegExp, QRectF
|
QObject, QRegExp, QRectF, QString
|
||||||
|
|
||||||
from calibre.gui2.jobs import DetailView
|
from calibre.gui2.jobs import DetailView
|
||||||
from calibre.gui2 import human_readable, NONE, TableView, qstring_to_unicode, error_dialog
|
from calibre.gui2 import human_readable, NONE, TableView, qstring_to_unicode, error_dialog
|
||||||
@ -123,28 +123,42 @@ class LocationDelegate(QAbstractItemDelegate):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
QAbstractItemDelegate.__init__(self)
|
QAbstractItemDelegate.__init__(self)
|
||||||
self.icon_rect = QRect(0, 10, 150, 45)
|
self.pixmap = QPixmap(40, 40)
|
||||||
self.buffer = 5
|
self.text = QString('Reader\n999.9 MB Available202')
|
||||||
|
|
||||||
def get_rects(self, index, option):
|
def rects(self, option):
|
||||||
row = index.row()
|
style = QApplication.style()
|
||||||
irect = QRect(self.icon_rect)
|
irect = style.itemPixmapRect(option.rect, Qt.AlignHCenter|Qt.AlignTop, self.pixmap)
|
||||||
irect.translate(row*(irect.width()+self.buffer), 0)
|
trect = style.itemTextRect(option.fontMetrics, option.rect,
|
||||||
trect = irect.translated(0, irect.height())
|
Qt.AlignHCenter|Qt.AlignTop, True, self.text)
|
||||||
trect.adjust(0, 7, 0, 0)
|
trect.moveTop(irect.bottom())
|
||||||
return irect.adjusted(50, 0, -50, 0), trect
|
return irect, trect
|
||||||
|
|
||||||
def sizeHint(self, option, index):
|
def sizeHint(self, option, index):
|
||||||
irect, trect = self.get_rects(index, option)
|
irect, trect = self.rects(option)
|
||||||
return irect.united(trect).size()
|
return irect.united(trect).size()
|
||||||
|
|
||||||
def paint(self, painter, option, index):
|
def paint(self, painter, option, index):
|
||||||
font = QFont()
|
style = QApplication.style()
|
||||||
font.setPointSize(9)
|
|
||||||
icon = QIcon(index.model().data(index, Qt.DecorationRole))
|
|
||||||
highlight = getattr(index.model(), 'highlight_row', -1) == index.row()
|
|
||||||
text = index.model().data(index, Qt.DisplayRole).toString()
|
|
||||||
painter.save()
|
painter.save()
|
||||||
|
QApplication.style().drawControl(QStyle.CE_ItemViewItem, option, painter)
|
||||||
|
highlight = getattr(index.model(), 'highlight_row', -1) == index.row()
|
||||||
|
mode = QIcon.Active if highlight else QIcon.Normal
|
||||||
|
pixmap = QIcon(index.model().data(index, Qt.DecorationRole)).pixmap(self.pixmap.size())
|
||||||
|
pixmap = style.generatedIconPixmap(mode, pixmap, option)
|
||||||
|
text = index.model().data(index, Qt.DisplayRole).toString()
|
||||||
|
irect, trect = self.rects(option)
|
||||||
|
style.drawItemPixmap(painter, irect, Qt.AlignHCenter|Qt.AlignTop, pixmap)
|
||||||
|
painter.setFont(option.font)
|
||||||
|
style.drawItemText(painter, trect, Qt.AlignHCenter|Qt.AlignBottom,
|
||||||
|
option.palette, True, text)
|
||||||
|
painter.restore()
|
||||||
|
return
|
||||||
|
#font = QFont()
|
||||||
|
#font.setPointSize(9)
|
||||||
|
|
||||||
|
|
||||||
|
text = index.model().data(index, Qt.DisplayRole).toString()
|
||||||
irect, trect = self.get_rects(index, option)
|
irect, trect = self.get_rects(index, option)
|
||||||
|
|
||||||
mode = QIcon.Normal
|
mode = QIcon.Normal
|
||||||
|
@ -131,7 +131,7 @@ Why does |app| show only some of my fonts on OS X?
|
|||||||
|
|
||||||
The graphical user interface of |app| is not starting on Windows?
|
The graphical user interface of |app| is not starting on Windows?
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
If you've never used the graphical user interface before, try deleting the file library1.db (it will be somewhere under :file:`C:\\Documents and Settings` on Windows XP and :file:`C:\\Users` on Windows Vista. If that doesn't fix the problem, locate the file libprs500.log (in the same places as library1.db) and post its contents in a help message on the `Forums <http://calibre.kovidgoyal.net/discussion>`_.
|
If you've never used the graphical user interface before, try deleting the file library1.db (it will be somewhere under :file:`C:\\Documents and Settings` on Windows XP and :file:`C:\\Users` on Windows Vista. If that doesn't fix the problem, locate the file calibre.log (in the same places as library1.db) and post its contents in a help message on the `Forums <http://calibre.kovidgoyal.net/discussion>`_.
|
||||||
|
|
||||||
I want some feature added to |app|. What can I do?
|
I want some feature added to |app|. What can I do?
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
''' Create a windows installer '''
|
''' Create a windows installer '''
|
||||||
import sys, re, os, shutil, subprocess
|
import sys, re, os, shutil, subprocess, zipfile
|
||||||
from setup import VERSION, APPNAME, entry_points, scripts, basenames
|
from setup import VERSION, APPNAME, entry_points, scripts, basenames
|
||||||
from distutils.core import setup
|
from distutils.core import setup
|
||||||
from distutils.filelist import FileList
|
from distutils.filelist import FileList
|
||||||
@ -508,7 +508,11 @@ class BuildEXE(build_exe):
|
|||||||
shutil.rmtree(tg)
|
shutil.rmtree(tg)
|
||||||
shutil.copytree(imfd, tg)
|
shutil.copytree(imfd, tg)
|
||||||
|
|
||||||
|
print
|
||||||
|
print 'Adding GUI main.py'
|
||||||
|
f = zipfile.ZipFile(os.path.join('build', 'py2exe', 'library.zip'), 'a', zipfile.ZIP_DEFLATED)
|
||||||
|
f.write('src\\calibre\\gui2\\main.py', 'calibre\\gui2\\main.py')
|
||||||
|
f.close()
|
||||||
|
|
||||||
print
|
print
|
||||||
print
|
print
|
||||||
@ -525,18 +529,11 @@ class BuildEXE(build_exe):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
auto = '--auto' in sys.argv
|
|
||||||
if auto:
|
|
||||||
sys.argv.remove('--auto')
|
|
||||||
sys.argv[1:2] = ['py2exe']
|
sys.argv[1:2] = ['py2exe']
|
||||||
if '--verbose' not in sys.argv:
|
|
||||||
sys.argv.append('--quiet') #py2exe produces too much output by default
|
|
||||||
if auto and not os.path.exists('dist\\auto'):
|
|
||||||
print os.path.abspath('dist\\auto'), 'does not exist'
|
|
||||||
return 1
|
|
||||||
console = [dict(dest_base=basenames['console'][i], script=scripts['console'][i])
|
console = [dict(dest_base=basenames['console'][i], script=scripts['console'][i])
|
||||||
for i in range(len(scripts['console']))]
|
for i in range(len(scripts['console']))]
|
||||||
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
|
||||||
setup(
|
setup(
|
||||||
cmdclass = {'py2exe': BuildEXE},
|
cmdclass = {'py2exe': BuildEXE},
|
||||||
windows = [
|
windows = [
|
||||||
@ -572,8 +569,6 @@ def main():
|
|||||||
},
|
},
|
||||||
|
|
||||||
)
|
)
|
||||||
if auto:
|
|
||||||
subprocess.call(('shutdown', '-s', '-f', '-t', '01'))
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user