Minor cleanups

This commit is contained in:
Kovid Goyal 2007-01-05 07:46:55 +00:00
parent 439860923c
commit 1a16e40b9e
7 changed files with 81 additions and 55 deletions

17
.project Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>libprs500</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>

9
.pydevproject Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse-pydev version="1.0"?>
<pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.5</pydev_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/libprs500/src</path>
</pydev_pathproperty>
</pydev_project>

View File

@ -12,7 +12,7 @@
## You should have received a copy of the GNU General Public License along ## You should have received a copy of the GNU General Public License along
## with this program; if not, write to the Free Software Foundation, Inc., ## with this program; if not, write to the Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#!/usr/bin/env python2.5 #!/usr/bin/env python
import sys import sys
import ez_setup import ez_setup
@ -33,8 +33,9 @@ except Exception, e:
"WARNING: Could not install the Python Imaging Library.", \ "WARNING: Could not install the Python Imaging Library.", \
"Some functionality will be unavailable" "Some functionality will be unavailable"
import sys
from setuptools import setup, find_packages from setuptools import setup, find_packages
sys.path.append('src')
from libprs500 import __version__ as VERSION from libprs500 import __version__ as VERSION
if sys.hexversion < 0x2050000: if sys.hexversion < 0x2050000:
@ -45,7 +46,8 @@ if sys.hexversion < 0x2050000:
setup( setup(
name='libprs500', name='libprs500',
packages = find_packages(), packages = find_packages('src'),
package_dir = { '' : 'src' },
version=VERSION, version=VERSION,
author='Kovid Goyal', author='Kovid Goyal',
author_email='kovid@kovidgoyal.net', author_email='kovid@kovidgoyal.net',
@ -63,7 +65,7 @@ setup(
'gui_scripts' : [ 'prs500-gui = libprs500.gui.main:main'] 'gui_scripts' : [ 'prs500-gui = libprs500.gui.main:main']
}, },
zip_safe = True, zip_safe = True,
install_requires=["pyusb>=0.3.5","pyxml>=0.8.4"], install_requires=["pyusb>=0.3.5", "pyxml>=0.8.4"],
dependency_links=["http://sourceforge.net/project/showfiles.php?group_id=6473", dependency_links=["http://sourceforge.net/project/showfiles.php?group_id=6473",
"http://easynews.dl.sourceforge.net/sourceforge/pyusb/pyusb-0.3.5.tar.gz", "http://easynews.dl.sourceforge.net/sourceforge/pyusb/pyusb-0.3.5.tar.gz",
], ],
@ -111,7 +113,8 @@ setup(
try: try:
import PyQt4 import PyQt4
except ImportError: except ImportError:
print "You do not have PyQt4 installed. The GUI will not work. You can obtain PyQt4 from http://www.riverbankcomputing.co.uk/pyqt/download.php" print "You do not have PyQt4 installed. The GUI will not work.", \
"You can obtain PyQt4 from http://www.riverbankcomputing.co.uk/pyqt/download.php"
else: else:
import PyQt4.Qt import PyQt4.Qt
if PyQt4.Qt.PYQT_VERSION < 0x40101: if PyQt4.Qt.PYQT_VERSION < 0x40101:

View File

@ -59,7 +59,7 @@ class FileFormatter(object):
if self.is_readonly: mode += "r-"+x+"r-"+x+"r-"+x if self.is_readonly: mode += "r-"+x+"r-"+x+"r-"+x
else: mode += "rw"+x+"rw"+x+"rw"+x else: mode += "rw"+x+"rw"+x+"rw"+x
return mode return mode
return property(**locals()) return property(doc=doc, fget=fget)
@apply @apply
def name_in_color(): def name_in_color():
@ -73,28 +73,28 @@ class FileFormatter(object):
ext = self.name[self.name.rfind("."):] ext = self.name[self.name.rfind("."):]
if ext in (".pdf", ".rtf", ".lrf", ".lrx", ".txt"): cname = green + self.name + normal if ext in (".pdf", ".rtf", ".lrf", ".lrx", ".txt"): cname = green + self.name + normal
return cname return cname
return property(**locals()) return property(doc=doc, fget=fget)
@apply @apply
def human_readable_size(): def human_readable_size():
doc=""" File size in human readable form """ doc=""" File size in human readable form """
def fget(self): def fget(self):
human_readable(self.size) human_readable(self.size)
return property(**locals()) return property(doc=doc, fget=fget)
@apply @apply
def modification_time(): def modification_time():
doc=""" Last modified time in the Linux ls -l format """ doc=""" Last modified time in the Linux ls -l format """
def fget(self): def fget(self):
return time.strftime("%Y-%m-%d %H:%M", time.localtime(self.wtime)) return time.strftime("%Y-%m-%d %H:%M", time.localtime(self.wtime))
return property(**locals()) return property(doc=doc, fget=fget)
@apply @apply
def creation_time(): def creation_time():
doc=""" Last modified time in the Linux ls -l format """ doc=""" Last modified time in the Linux ls -l format """
def fget(self): def fget(self):
return time.strftime("%Y-%m-%d %H:%M", time.localtime(self.ctime)) return time.strftime("%Y-%m-%d %H:%M", time.localtime(self.ctime))
return property(**locals()) return property(doc=doc, fget=fget)
def info(dev): def info(dev):
info = dev.get_device_information() info = dev.get_device_information()

View File

@ -122,7 +122,7 @@ class Main(QObject, Ui_MainWindow):
for c in range(topleft.column(), bottomright.column()+1): for c in range(topleft.column(), bottomright.column()+1):
self.current_view.resizeColumnToContents(c) self.current_view.resizeColumnToContents(c)
for r in range(topleft.row(), bottomright.row()+1): for r in range(topleft.row(), bottomright.row()+1):
self.current_view.resizeRowToContents(c) self.current_view.resizeRowToContents(r)
def show_book(self, current, previous): def show_book(self, current, previous):
if not len(self.current_view.selectedIndexes()): if not len(self.current_view.selectedIndexes()):
@ -240,13 +240,11 @@ class Main(QObject, Ui_MainWindow):
def edit(self, action): def edit(self, action):
if self.library_view.isVisible(): if self.library_view.isVisible():
rows = self.library_view.selectionModel().selectedRows() rows = self.library_view.selectionModel().selectedRows()
accepted = False
for row in rows: for row in rows:
_id = self.library_model.id_from_index(row) _id = self.library_model.id_from_index(row)
dialog = QDialog(self.window) dialog = QDialog(self.window)
ebd = EditBookDialog(dialog, _id, self.library_model.db) ebd = EditBookDialog(dialog, _id, self.library_model.db)
if dialog.exec_() == QDialog.Accepted: if dialog.exec_() == QDialog.Accepted:
accepted = True
title = unicode(ebd.title.text().toUtf8(), 'utf-8').strip() title = unicode(ebd.title.text().toUtf8(), 'utf-8').strip()
authors = unicode(ebd.authors.text().toUtf8(), 'utf-8').strip() authors = unicode(ebd.authors.text().toUtf8(), 'utf-8').strip()
rating = ebd.rating.value() rating = ebd.rating.value()

View File

@ -17,7 +17,6 @@ import os
import textwrap import textwrap
import time import time
import traceback import traceback
import sys
from operator import itemgetter, attrgetter from operator import itemgetter, attrgetter
from socket import gethostname from socket import gethostname
from urlparse import urlparse, urlunparse from urlparse import urlparse, urlunparse
@ -32,11 +31,9 @@ from PyQt4.QtCore import Qt, SIGNAL
from PyQt4.Qt import QApplication, QString, QFont, QAbstractListModel, \ from PyQt4.Qt import QApplication, QString, QFont, QAbstractListModel, \
QVariant, QAbstractTableModel, QTableView, QListView, \ QVariant, QAbstractTableModel, QTableView, QListView, \
QLabel, QAbstractItemView, QPixmap, QIcon, QSize, \ QLabel, QAbstractItemView, QPixmap, QIcon, QSize, \
QMessageBox, QSettings, QFileDialog, QErrorMessage, \ QSpinBox, QPoint, QPainterPath, QItemDelegate, QPainter, QPen, \
QSpinBox, QPoint, \ QColor, QLinearGradient, QBrush, QStyle, \
QIODevice, QPainterPath, QItemDelegate, QPainter, QPen, \ QByteArray, QBuffer, QMimeData, \
QColor, QLinearGradient, QBrush, QStyle, QStringList, \
QByteArray, QBuffer, QMimeData, QTextStream, QIODevice, \
QDrag, QRect QDrag, QRect
NONE = QVariant() #: Null value to return from the data function of item models NONE = QVariant() #: Null value to return from the data function of item models
@ -138,7 +135,7 @@ class FileDragAndDrop(object):
self._dragged_files, urls = [], [] self._dragged_files, urls = [], []
for _file in files: for _file in files:
urls.append(urlunparse(('file', quote(gethostname()), \ urls.append(urlunparse(('file', quote(gethostname()), \
quote(_file.name.encode('utf-8')), '','',''))) quote(_file.name.encode('utf-8')), '', '', '')))
self._dragged_files.append(_file) self._dragged_files.append(_file)
mime_data.setData("text/uri-list", QByteArray("\n".join(urls))) mime_data.setData("text/uri-list", QByteArray("\n".join(urls)))
user = os.getenv('USER') user = os.getenv('USER')
@ -301,7 +298,7 @@ class LibraryDelegate(QItemDelegate):
PEN = QPen(COLOR, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin) PEN = QPen(COLOR, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)
def __init__(self, parent, rating_column=-1): def __init__(self, parent, rating_column=-1):
QItemDelegate.__init__(self, parent ) QItemDelegate.__init__(self, parent)
self.rating_column = rating_column self.rating_column = rating_column
self.star_path = QPainterPath() self.star_path = QPainterPath()
self.star_path.moveTo(90, 50) self.star_path.moveTo(90, 50)
@ -585,7 +582,7 @@ class LibraryBooksModel(QAbstractTableModel):
if text == None: if text == None:
text = "Unknown" text = "Unknown"
return QVariant(text) return QVariant(text)
elif role == Qt.TextAlignmentRole and index.column() in [2,3,4]: elif role == Qt.TextAlignmentRole and index.column() in [2, 3, 4]:
return QVariant(Qt.AlignRight | Qt.AlignVCenter) return QVariant(Qt.AlignRight | Qt.AlignVCenter)
elif role == Qt.ToolTipRole and index.isValid(): elif role == Qt.ToolTipRole and index.isValid():
if index.column() in [0, 1, 4, 5]: if index.column() in [0, 1, 4, 5]:
@ -674,8 +671,11 @@ class DeviceBooksModel(QAbstractTableModel):
self._orig_data = book_list self._orig_data = book_list
self.reset() self.reset()
def rowCount(self, parent): return len(self._data) def rowCount(self, parent):
def columnCount(self, parent): return 4 return len(self._data)
def columnCount(self, parent):
return 4
def headerData(self, section, orientation, role): def headerData(self, section, orientation, role):
if role != Qt.DisplayRole: if role != Qt.DisplayRole:
@ -705,7 +705,7 @@ class DeviceBooksModel(QAbstractTableModel):
elif col == 3: elif col == 3:
text = time.strftime(TIME_WRITE_FMT, book.datetime) text = time.strftime(TIME_WRITE_FMT, book.datetime)
return QVariant(text) return QVariant(text)
elif role == Qt.TextAlignmentRole and index.column() in [2,3]: elif role == Qt.TextAlignmentRole and index.column() in [2, 3]:
return QVariant(Qt.AlignRight | Qt.AlignVCenter) return QVariant(Qt.AlignRight | Qt.AlignVCenter)
return NONE return NONE

View File

@ -25,7 +25,6 @@ to get and set meta information. For example:
""" """
import struct import struct
import array
import zlib import zlib
import xml.dom.minidom as dom import xml.dom.minidom as dom