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
## with this program; if not, write to the Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#!/usr/bin/env python2.5
#!/usr/bin/env python
import sys
import ez_setup
@ -33,8 +33,9 @@ except Exception, e:
"WARNING: Could not install the Python Imaging Library.", \
"Some functionality will be unavailable"
import sys
from setuptools import setup, find_packages
sys.path.append('src')
from libprs500 import __version__ as VERSION
if sys.hexversion < 0x2050000:
@ -45,7 +46,8 @@ if sys.hexversion < 0x2050000:
setup(
name='libprs500',
packages = find_packages(),
packages = find_packages('src'),
package_dir = { '' : 'src' },
version=VERSION,
author='Kovid Goyal',
author_email='kovid@kovidgoyal.net',
@ -63,7 +65,7 @@ setup(
'gui_scripts' : [ 'prs500-gui = libprs500.gui.main:main']
},
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",
"http://easynews.dl.sourceforge.net/sourceforge/pyusb/pyusb-0.3.5.tar.gz",
],
@ -111,7 +113,8 @@ setup(
try:
import PyQt4
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:
import PyQt4.Qt
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
else: mode += "rw"+x+"rw"+x+"rw"+x
return mode
return property(**locals())
return property(doc=doc, fget=fget)
@apply
def name_in_color():
@ -73,28 +73,28 @@ class FileFormatter(object):
ext = self.name[self.name.rfind("."):]
if ext in (".pdf", ".rtf", ".lrf", ".lrx", ".txt"): cname = green + self.name + normal
return cname
return property(**locals())
return property(doc=doc, fget=fget)
@apply
def human_readable_size():
doc=""" File size in human readable form """
def fget(self):
human_readable(self.size)
return property(**locals())
return property(doc=doc, fget=fget)
@apply
def modification_time():
doc=""" Last modified time in the Linux ls -l format """
def fget(self):
return time.strftime("%Y-%m-%d %H:%M", time.localtime(self.wtime))
return property(**locals())
return property(doc=doc, fget=fget)
@apply
def creation_time():
doc=""" Last modified time in the Linux ls -l format """
def fget(self):
return time.strftime("%Y-%m-%d %H:%M", time.localtime(self.ctime))
return property(**locals())
return property(doc=doc, fget=fget)
def info(dev):
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):
self.current_view.resizeColumnToContents(c)
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):
if not len(self.current_view.selectedIndexes()):
@ -240,13 +240,11 @@ class Main(QObject, Ui_MainWindow):
def edit(self, action):
if self.library_view.isVisible():
rows = self.library_view.selectionModel().selectedRows()
accepted = False
for row in rows:
_id = self.library_model.id_from_index(row)
dialog = QDialog(self.window)
ebd = EditBookDialog(dialog, _id, self.library_model.db)
if dialog.exec_() == QDialog.Accepted:
accepted = True
title = unicode(ebd.title.text().toUtf8(), 'utf-8').strip()
authors = unicode(ebd.authors.text().toUtf8(), 'utf-8').strip()
rating = ebd.rating.value()

View File

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

View File

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