Fix rendering of custom delegates in item views to conform to GUI styles

This commit is contained in:
Kovid Goyal 2008-06-15 00:03:20 -07:00
parent 65972716d4
commit 33c1401fd6
9 changed files with 79 additions and 64 deletions

View File

@ -99,7 +99,7 @@ _check_symlinks_prescript()
includes=list(self.includes) + main_modules['console'],
packages=self.packages,
excludes=self.excludes,
debug=debug,
debug=debug
)
@classmethod
@ -277,13 +277,7 @@ sys.frameworks_dir = os.path.join(os.path.dirname(os.environ['RESOURCEPATH']), '
def main():
# auto = '--auto' in sys.argv
# 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.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
sys.argv[1:2] = ['py2app']
setup(
name = APPNAME,

View File

@ -447,15 +447,14 @@ class Settings(QSettings):
self.setValue(str(key), QVariant(QByteArray(val)))
_settings = Settings()
if not _settings.get('rationalized'):
__settings = Settings(name='calibre')
dbpath = os.path.join(os.path.expanduser('~'), 'library1.db').decode(sys.getfilesystemencoding())
dbpath = unicode(__settings.value('database path',
QVariant(QString.fromUtf8(dbpath.encode('utf-8')))).toString())
cmdline = __settings.value('LRF conversion defaults', QVariant(QByteArray(''))).toByteArray().data()
_settings.set('database path', dbpath)
if cmdline:
cmdline = cPickle.loads(cmdline)
_settings.set('LRF conversion defaults', cmdline)
@ -464,6 +463,7 @@ if not _settings.get('rationalized'):
os.unlink(unicode(__settings.fileName()))
except:
pass
_settings.set('database path', dbpath)
_spat = re.compile(r'^the\s+|^a\s+|^an\s+', re.IGNORECASE)
def english_sort(x, y):

View File

@ -9,7 +9,7 @@ from itertools import repeat
from PyQt4.QtGui import QTableView, QProgressDialog, QAbstractItemView, QColor, \
QItemDelegate, QPainterPath, QLinearGradient, QBrush, \
QPen, QStyle, QPainter, QLineEdit, QApplication, \
QPalette, QImage
QPalette, QImage, QStyleOptionFocusRect, QApplication
from PyQt4.QtCore import QAbstractTableModel, QVariant, Qt, QString, \
QCoreApplication, SIGNAL, QObject, QSize, QModelIndex, \
QTimer
@ -55,9 +55,8 @@ class LibraryDelegate(QItemDelegate):
painter.restore()
painter.save()
QApplication.style().drawControl(QStyle.CE_ItemViewItem, option, painter)
try:
if option.state & QStyle.State_Selected:
painter.fillRect(option.rect, option.palette.highlight())
painter.setRenderHint(QPainter.Antialiasing)
y = option.rect.center().y()-self.SIZE/2.
x = option.rect.right() - self.SIZE

View File

@ -4,7 +4,7 @@ import os, sys, textwrap, collections, traceback, shutil, time
from xml.parsers.expat import ExpatError
from functools import partial
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, \
QToolButton, QDialog, QDesktopServices
from PyQt4.QtSvg import QSvgRenderer
@ -1190,4 +1190,14 @@ def main(args=sys.argv):
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)

View File

@ -27,9 +27,9 @@
<property name="geometry" >
<rect>
<x>0</x>
<y>86</y>
<y>79</y>
<width>865</width>
<height>712</height>
<height>716</height>
</rect>
</property>
<layout class="QGridLayout" >
@ -44,7 +44,7 @@
<item>
<widget class="LocationView" name="location_view" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Minimum" hsizetype="Expanding" >
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -52,19 +52,25 @@
<property name="maximumSize" >
<size>
<width>10000</width>
<height>100</height>
<height>110</height>
</size>
</property>
<property name="verticalScrollBarPolicy" >
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<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 name="iconSize" >
<size>
<width>32</width>
<height>32</height>
<width>40</width>
<height>40</height>
</size>
</property>
<property name="movement" >
@ -77,14 +83,11 @@
<bool>false</bool>
</property>
<property name="spacing" >
<number>20</number>
<number>10</number>
</property>
<property name="viewMode" >
<enum>QListView::IconMode</enum>
</property>
<property name="uniformItemSizes" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
@ -332,8 +335,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>847</width>
<height>553</height>
<width>857</width>
<height>552</height>
</rect>
</property>
<layout class="QGridLayout" >
@ -380,7 +383,7 @@
<x>0</x>
<y>0</y>
<width>865</width>
<height>86</height>
<height>79</height>
</rect>
</property>
<property name="minimumSize" >
@ -425,9 +428,9 @@
<property name="geometry" >
<rect>
<x>0</x>
<y>798</y>
<y>795</y>
<width>865</width>
<height>24</height>
<height>27</height>
</rect>
</property>
<property name="mouseTracking" >

View File

@ -1,4 +1,4 @@
import os, sys, glob
import os, sys, glob, shutil
import sipconfig
if os.environ.get('PYQT4PATH', None):
print os.environ['PYQT4PATH']
@ -37,7 +37,7 @@ makefile = pyqtconfig.QtGuiModuleMakefile (
# ".dll" extension on Windows).
if 'linux' in sys.platform:
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 = ['.']
else:
makefile.extra_lib_dirs = ['..\\..\\.build\\release', '../../.build', '.']

View File

@ -7,9 +7,9 @@ import re, os
from PyQt4.QtGui import QListView, QIcon, QFont, QLabel, QListWidget, \
QListWidgetItem, QTextCharFormat, QApplication, \
QSyntaxHighlighter, QCursor, QColor, QWidget, \
QAbstractItemDelegate, QPixmap
QAbstractItemDelegate, QPixmap, QStyle
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 import human_readable, NONE, TableView, qstring_to_unicode, error_dialog
@ -123,28 +123,42 @@ class LocationDelegate(QAbstractItemDelegate):
def __init__(self):
QAbstractItemDelegate.__init__(self)
self.icon_rect = QRect(0, 10, 150, 45)
self.buffer = 5
self.pixmap = QPixmap(40, 40)
self.text = QString('Reader\n999.9 MB Available202')
def get_rects(self, index, option):
row = index.row()
irect = QRect(self.icon_rect)
irect.translate(row*(irect.width()+self.buffer), 0)
trect = irect.translated(0, irect.height())
trect.adjust(0, 7, 0, 0)
return irect.adjusted(50, 0, -50, 0), trect
def rects(self, option):
style = QApplication.style()
irect = style.itemPixmapRect(option.rect, Qt.AlignHCenter|Qt.AlignTop, self.pixmap)
trect = style.itemTextRect(option.fontMetrics, option.rect,
Qt.AlignHCenter|Qt.AlignTop, True, self.text)
trect.moveTop(irect.bottom())
return irect, trect
def sizeHint(self, option, index):
irect, trect = self.get_rects(index, option)
irect, trect = self.rects(option)
return irect.united(trect).size()
def paint(self, painter, option, index):
font = QFont()
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()
style = QApplication.style()
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)
mode = QIcon.Normal

View File

@ -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?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -1,7 +1,7 @@
__license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
''' 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 distutils.core import setup
from distutils.filelist import FileList
@ -508,7 +508,11 @@ class BuildEXE(build_exe):
shutil.rmtree(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
@ -525,18 +529,11 @@ class BuildEXE(build_exe):
def main():
auto = '--auto' in sys.argv
if auto:
sys.argv.remove('--auto')
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])
for i in range(len(scripts['console']))]
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
setup(
cmdclass = {'py2exe': BuildEXE},
windows = [
@ -572,8 +569,6 @@ def main():
},
)
if auto:
subprocess.call(('shutdown', '-s', '-f', '-t', '01'))
return 0
if __name__ == '__main__':