Implemented animated tab and device detection in separate thread

This commit is contained in:
Kovid Goyal 2007-06-07 07:38:26 +00:00
parent 226c037b61
commit 80b8992a97
10 changed files with 4264 additions and 110 deletions

View File

@ -1,8 +1,13 @@
all : main_ui.py images_rc.py
main_ui.py : main.ui main_ui.py : main.ui
pyuic4 main.ui | sed -s s/^.*Margin.*// | sed -e s/^.*boxlayout\.setObjectName.*// > main_ui.py pyuic4 main.ui | sed -s s/^.*Margin.*// | sed -e s/^.*boxlayout\.setObjectName.*// > main_ui.py
images_rc.py : images.qrc images_rc.py : images.qrc images
pyrcc4 images.qrc > images_rc.py pyrcc4 images.qrc > images_rc.py
clean : clean :
rm main_ui.py images_rc.py rm main_ui.py images_rc.py
test : all
python main.py

View File

@ -0,0 +1,39 @@
## Copyright (C) 2007 Kovid Goyal kovid@kovidgoyal.net
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## 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.Warning
from PyQt4.QtCore import QThread, SIGNAL
from libprs500.devices.prs500.driver import PRS500
class DeviceDetector(QThread):
def __init__(self, sleep_time=2000):
'''
@param sleep_time: Time to sleep between device probes in millisecs
@type sleep_time: integer
'''
self.devices = ([PRS500, False],)
self.sleep_time = sleep_time
QThread.__init__(self)
def run(self):
while True:
for device in self.devices:
connected = device[0].is_connected()
if connected and not device[1]:
self.emit(SIGNAL('connected(PyQt_PyObject, PyQt_PyObject)'), device[0], True)
device[1] ^= True
elif not connected and device[1]:
self.emit(SIGNAL('connected(PyQt_PyObject, PyQt_PyObject)'), device[0], False)
device[1] ^= True
self.msleep(self.sleep_time)

View File

@ -10,7 +10,8 @@
<file alias="card" >images/memory_stick_unmount.png</file> <file alias="card" >images/memory_stick_unmount.png</file>
<file>images/minus.png</file> <file>images/minus.png</file>
<file>images/plus.png</file> <file>images/plus.png</file>
<file>images/upload.png</file>
<file alias="reader" >images/reader.png</file> <file alias="reader" >images/reader.png</file>
<file>images/upload.png</file>
<file>images/jobs.svg</file>
</qresource> </qresource>
</RCC> </RCC>

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 43 KiB

File diff suppressed because it is too large Load Diff

View File

@ -30,9 +30,8 @@ class LibraryDelegate(QItemDelegate):
SIZE = 16 SIZE = 16
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):
QItemDelegate.__init__(self, parent) QItemDelegate.__init__(self, parent)
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)
for i in range(1, 5): for i in range(1, 5):
@ -47,14 +46,10 @@ class LibraryDelegate(QItemDelegate):
self.factor = self.SIZE/100. self.factor = self.SIZE/100.
def sizeHint(self, option, index): def sizeHint(self, option, index):
if index.column() != self.rating_column:
return QItemDelegate.sizeHint(self, option, index)
num = index.model().data(index, Qt.DisplayRole).toInt()[0] num = index.model().data(index, Qt.DisplayRole).toInt()[0]
return QSize(num*(self.SIZE), self.SIZE+4) return QSize(num*(self.SIZE), self.SIZE+4)
def paint(self, painter, option, index): def paint(self, painter, option, index):
if index.column() != self.rating_column:
return QItemDelegate.paint(self, painter, option, index)
num = index.model().data(index, Qt.DisplayRole).toInt()[0] num = index.model().data(index, Qt.DisplayRole).toInt()[0]
def draw_star(): def draw_star():
painter.save() painter.save()
@ -113,7 +108,7 @@ class BooksView(QTableView):
self.setModel(self.model) self.setModel(self.model)
self.setSelectionBehavior(QAbstractItemView.SelectRows) self.setSelectionBehavior(QAbstractItemView.SelectRows)
self.setSortingEnabled(True) self.setSortingEnabled(True)
self.setItemDelegate(LibraryDelegate(self, rating_column=4)) self.setItemDelegateForColumn(4, LibraryDelegate(self))
QObject.connect(self.model, SIGNAL('sorted()'), self.resizeRowsToContents) QObject.connect(self.model, SIGNAL('sorted()'), self.resizeRowsToContents)
QObject.connect(self.model, SIGNAL('searched()'), self.resizeRowsToContents) QObject.connect(self.model, SIGNAL('searched()'), self.resizeRowsToContents)
self.verticalHeader().setVisible(False) self.verticalHeader().setVisible(False)

View File

@ -16,13 +16,14 @@ import os, tempfile, sys
from PyQt4.QtCore import Qt, SIGNAL, QObject, QCoreApplication, \ from PyQt4.QtCore import Qt, SIGNAL, QObject, QCoreApplication, \
QSettings, QVariant, QSize, QEventLoop, QString, \ QSettings, QVariant, QSize, QEventLoop, QString, \
QBuffer, QIODevice, QModelIndex QBuffer, QIODevice, QModelIndex, QThread
from PyQt4.QtGui import QPixmap, QErrorMessage, QLineEdit, \ from PyQt4.QtGui import QPixmap, QErrorMessage, QLineEdit, \
QMessageBox, QFileDialog, QIcon, QDialog, QInputDialog QMessageBox, QFileDialog, QIcon, QDialog, QInputDialog
from PyQt4.Qt import qDebug, qFatal, qWarning, qCritical from PyQt4.Qt import qDebug, qFatal, qWarning, qCritical
from libprs500.gui2 import APP_TITLE, installErrorHandler from libprs500.gui2 import APP_TITLE, installErrorHandler
from libprs500.gui2.main_ui import Ui_MainWindow from libprs500.gui2.main_ui import Ui_MainWindow
from libprs500.gui2.device import DeviceDetector
class Main(QObject, Ui_MainWindow): class Main(QObject, Ui_MainWindow):
@ -33,6 +34,11 @@ class Main(QObject, Ui_MainWindow):
self.setupUi(window) self.setupUi(window)
self.read_settings() self.read_settings()
####################### Tabs setup #####################
self.tabs.setup()
self.tabs.animate()
####################### Setup books view ######################## ####################### Setup books view ########################
self.library_view.set_database(self.database_path) self.library_view.set_database(self.database_path)
self.library_view.connect_to_search_box(self.search) self.library_view.connect_to_search_box(self.search)
@ -45,11 +51,21 @@ class Main(QObject, Ui_MainWindow):
self.library_view.resizeRowsToContents() self.library_view.resizeRowsToContents()
self.search.setFocus(Qt.OtherFocusReason) self.search.setFocus(Qt.OtherFocusReason)
####################### Setup device detection ########################
self.detector = DeviceDetector(sleep_time=2000)
QObject.connect(self.detector, SIGNAL('connected(PyQt_PyObject, PyQt_PyObject)'),
self.device_connected, Qt.QueuedConnection)
self.detector.start(QThread.InheritPriority)
def device_connected(self, cls, connected):
print cls, connected
def read_settings(self): def read_settings(self):
settings = QSettings() settings = QSettings()
settings.beginGroup("MainWindow") settings.beginGroup("MainWindow")
self.window.resize(settings.value("size", QVariant(QSize(1000, 700))).\ self.window.resize(settings.value("size", QVariant(QSize(1000, 700))).toSize())
toSize())
settings.endGroup() settings.endGroup()
self.database_path = settings.value("database path", QVariant(os.path\ self.database_path = settings.value("database path", QVariant(os.path\
.expanduser("~/library1.db"))).toString() .expanduser("~/library1.db"))).toString()

View File

@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>728</width> <width>777</width>
<height>822</height> <height>822</height>
</rect> </rect>
</property> </property>
@ -17,29 +17,14 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="windowTitle" > <property name="windowTitle" >
<string/> <string>libprs500</string>
</property> </property>
<property name="windowIcon" > <property name="windowIcon" >
<iconset/> <iconset resource="images.qrc" >:/library</iconset>
</property> </property>
<widget class="QWidget" name="centralwidget" > <widget class="QWidget" name="centralwidget" >
<layout class="QVBoxLayout" > <layout class="QGridLayout" >
<property name="spacing" > <item row="0" column="0" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>9</number>
</property>
<property name="topMargin" >
<number>9</number>
</property>
<property name="rightMargin" >
<number>9</number>
</property>
<property name="bottomMargin" >
<number>9</number>
</property>
<item>
<layout class="QHBoxLayout" > <layout class="QHBoxLayout" >
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
@ -117,7 +102,7 @@
</item> </item>
</layout> </layout>
</item> </item>
<item> <item row="1" column="0" >
<layout class="QHBoxLayout" > <layout class="QHBoxLayout" >
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
@ -165,7 +150,7 @@
<string/> <string/>
</property> </property>
<property name="frame" > <property name="frame" >
<bool>false</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
@ -184,31 +169,43 @@
</item> </item>
</layout> </layout>
</item> </item>
<item> <item row="2" column="0" >
<widget class="AnimatedTabWidget" name="tabs" >
<property name="tabPosition" >
<enum>QTabWidget::West</enum>
</property>
<property name="currentIndex" >
<number>0</number>
</property>
<property name="usesScrollButtons" >
<bool>false</bool>
</property>
<widget class="QWidget" name="books_tab" >
<attribute name="title" >
<string>Books</string>
</attribute>
<attribute name="icon" >
<iconset resource="images.qrc" >:/library</iconset>
</attribute>
<layout class="QGridLayout" > <layout class="QGridLayout" >
<property name="leftMargin" > <item row="0" column="0" >
<widget class="QStackedWidget" name="stacks" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Preferred" hsizetype="Expanding" >
<horstretch>100</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="currentIndex" >
<number>0</number> <number>0</number>
</property> </property>
<property name="topMargin" > <widget class="QWidget" name="library" >
<number>0</number> <layout class="QGridLayout" >
</property> <item row="0" column="0" >
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<property name="horizontalSpacing" >
<number>6</number>
</property>
<property name="verticalSpacing" >
<number>6</number>
</property>
<item row="1" column="0" >
<widget class="BooksView" name="library_view" > <widget class="BooksView" name="library_view" >
<property name="sizePolicy" > <property name="sizePolicy" >
<sizepolicy vsizetype="Preferred" hsizetype="Preferred" > <sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
<horstretch>0</horstretch> <horstretch>100</horstretch>
<verstretch>10</verstretch> <verstretch>10</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
@ -236,8 +233,58 @@
</widget> </widget>
</item> </item>
</layout> </layout>
</widget>
<widget class="QWidget" name="main_memory" >
<layout class="QGridLayout" >
<item row="0" column="0" >
<widget class="BooksView" name="main_memory_view" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
<horstretch>100</horstretch>
<verstretch>10</verstretch>
</sizepolicy>
</property>
<property name="acceptDrops" >
<bool>true</bool>
</property>
<property name="dragEnabled" >
<bool>true</bool>
</property>
<property name="dragDropOverwriteMode" >
<bool>false</bool>
</property>
<property name="dragDropMode" >
<enum>QAbstractItemView::DragDrop</enum>
</property>
<property name="alternatingRowColors" >
<bool>true</bool>
</property>
<property name="selectionBehavior" >
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="showGrid" >
<bool>false</bool>
</property>
</widget>
</item> </item>
<item> </layout>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="jobs_tab" >
<attribute name="title" >
<string>Jobs</string>
</attribute>
<attribute name="toolTip" >
<string>Show jobs being currently processed</string>
</attribute>
<layout class="QGridLayout" />
</widget>
</widget>
</item>
<item row="3" column="0" >
<layout class="QHBoxLayout" > <layout class="QHBoxLayout" >
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
@ -380,6 +427,12 @@
<extends>QLineEdit</extends> <extends>QLineEdit</extends>
<header>library.h</header> <header>library.h</header>
</customwidget> </customwidget>
<customwidget>
<class>AnimatedTabWidget</class>
<extends>QTabWidget</extends>
<header>progress.h</header>
<container>1</container>
</customwidget>
</customwidgets> </customwidgets>
<resources> <resources>
<include location="images.qrc" /> <include location="images.qrc" />

View File

@ -2,8 +2,8 @@
# Form implementation generated from reading ui file 'main.ui' # Form implementation generated from reading ui file 'main.ui'
# #
# Created: Sun May 27 10:53:01 2007 # Created: Wed Jun 6 19:26:17 2007
# by: PyQt4 UI code generator 4-snapshot-20070525 # by: PyQt4 UI code generator 4-snapshot-20070530
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!
@ -12,24 +12,20 @@ from PyQt4 import QtCore, QtGui
class Ui_MainWindow(object): class Ui_MainWindow(object):
def setupUi(self, MainWindow): def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow") MainWindow.setObjectName("MainWindow")
MainWindow.resize(QtCore.QSize(QtCore.QRect(0,0,728,822).size()).expandedTo(MainWindow.minimumSizeHint())) MainWindow.resize(QtCore.QSize(QtCore.QRect(0,0,777,822).size()).expandedTo(MainWindow.minimumSizeHint()))
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred,QtGui.QSizePolicy.Preferred) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred,QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0) sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0) sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth()) sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
MainWindow.setSizePolicy(sizePolicy) MainWindow.setSizePolicy(sizePolicy)
MainWindow.setWindowIcon(QtGui.QIcon(":/library"))
self.centralwidget = QtGui.QWidget(MainWindow) self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget") self.centralwidget.setObjectName("centralwidget")
self.vboxlayout = QtGui.QVBoxLayout(self.centralwidget) self.gridlayout = QtGui.QGridLayout(self.centralwidget)
self.vboxlayout.setSpacing(6) self.gridlayout.setObjectName("gridlayout")
self.hboxlayout = QtGui.QHBoxLayout() self.hboxlayout = QtGui.QHBoxLayout()
self.hboxlayout.setSpacing(6) self.hboxlayout.setSpacing(6)
@ -68,7 +64,7 @@ class Ui_MainWindow(object):
self.df.setOpenExternalLinks(True) self.df.setOpenExternalLinks(True)
self.df.setObjectName("df") self.df.setObjectName("df")
self.hboxlayout.addWidget(self.df) self.hboxlayout.addWidget(self.df)
self.vboxlayout.addLayout(self.hboxlayout) self.gridlayout.addLayout(self.hboxlayout,0,0,1,1)
self.hboxlayout1 = QtGui.QHBoxLayout() self.hboxlayout1 = QtGui.QHBoxLayout()
self.hboxlayout1.setSpacing(6) self.hboxlayout1.setSpacing(6)
@ -94,21 +90,38 @@ class Ui_MainWindow(object):
self.clear_button.setIcon(QtGui.QIcon(":/images/clear.png")) self.clear_button.setIcon(QtGui.QIcon(":/images/clear.png"))
self.clear_button.setObjectName("clear_button") self.clear_button.setObjectName("clear_button")
self.hboxlayout1.addWidget(self.clear_button) self.hboxlayout1.addWidget(self.clear_button)
self.vboxlayout.addLayout(self.hboxlayout1) self.gridlayout.addLayout(self.hboxlayout1,1,0,1,1)
self.gridlayout = QtGui.QGridLayout() self.tabs = AnimatedTabWidget(self.centralwidget)
self.tabs.setTabPosition(QtGui.QTabWidget.West)
self.tabs.setUsesScrollButtons(False)
self.tabs.setObjectName("tabs")
self.books_tab = QtGui.QWidget()
self.books_tab.setObjectName("books_tab")
self.gridlayout1 = QtGui.QGridLayout(self.books_tab)
self.gridlayout1.setObjectName("gridlayout1")
self.stacks = QtGui.QStackedWidget(self.books_tab)
self.gridlayout.setHorizontalSpacing(6) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Preferred)
self.gridlayout.setVerticalSpacing(6) sizePolicy.setHorizontalStretch(100)
self.gridlayout.setObjectName("gridlayout") sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.stacks.sizePolicy().hasHeightForWidth())
self.stacks.setSizePolicy(sizePolicy)
self.stacks.setObjectName("stacks")
self.library_view = BooksView(self.centralwidget) self.library = QtGui.QWidget()
self.library.setObjectName("library")
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred,QtGui.QSizePolicy.Preferred) self.gridlayout2 = QtGui.QGridLayout(self.library)
sizePolicy.setHorizontalStretch(0) self.gridlayout2.setObjectName("gridlayout2")
self.library_view = BooksView(self.library)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(100)
sizePolicy.setVerticalStretch(10) sizePolicy.setVerticalStretch(10)
sizePolicy.setHeightForWidth(self.library_view.sizePolicy().hasHeightForWidth()) sizePolicy.setHeightForWidth(self.library_view.sizePolicy().hasHeightForWidth())
self.library_view.setSizePolicy(sizePolicy) self.library_view.setSizePolicy(sizePolicy)
@ -120,8 +133,42 @@ class Ui_MainWindow(object):
self.library_view.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows) self.library_view.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
self.library_view.setShowGrid(False) self.library_view.setShowGrid(False)
self.library_view.setObjectName("library_view") self.library_view.setObjectName("library_view")
self.gridlayout.addWidget(self.library_view,1,0,1,1) self.gridlayout2.addWidget(self.library_view,0,0,1,1)
self.vboxlayout.addLayout(self.gridlayout) self.stacks.addWidget(self.library)
self.main_memory = QtGui.QWidget()
self.main_memory.setObjectName("main_memory")
self.gridlayout3 = QtGui.QGridLayout(self.main_memory)
self.gridlayout3.setObjectName("gridlayout3")
self.main_memory_view = BooksView(self.main_memory)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(100)
sizePolicy.setVerticalStretch(10)
sizePolicy.setHeightForWidth(self.main_memory_view.sizePolicy().hasHeightForWidth())
self.main_memory_view.setSizePolicy(sizePolicy)
self.main_memory_view.setAcceptDrops(True)
self.main_memory_view.setDragEnabled(True)
self.main_memory_view.setDragDropOverwriteMode(False)
self.main_memory_view.setDragDropMode(QtGui.QAbstractItemView.DragDrop)
self.main_memory_view.setAlternatingRowColors(True)
self.main_memory_view.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
self.main_memory_view.setShowGrid(False)
self.main_memory_view.setObjectName("main_memory_view")
self.gridlayout3.addWidget(self.main_memory_view,0,0,1,1)
self.stacks.addWidget(self.main_memory)
self.gridlayout1.addWidget(self.stacks,0,0,1,1)
self.tabs.addTab(self.books_tab,QtGui.QIcon(":/library"),"")
self.jobs_tab = QtGui.QWidget()
self.jobs_tab.setObjectName("jobs_tab")
self.gridlayout4 = QtGui.QGridLayout(self.jobs_tab)
self.gridlayout4.setObjectName("gridlayout4")
self.tabs.addTab(self.jobs_tab,"")
self.gridlayout.addWidget(self.tabs,2,0,1,1)
self.hboxlayout2 = QtGui.QHBoxLayout() self.hboxlayout2 = QtGui.QHBoxLayout()
self.hboxlayout2.setSpacing(6) self.hboxlayout2.setSpacing(6)
@ -142,7 +189,7 @@ class Ui_MainWindow(object):
self.book_info.setTextFormat(QtCore.Qt.RichText) self.book_info.setTextFormat(QtCore.Qt.RichText)
self.book_info.setObjectName("book_info") self.book_info.setObjectName("book_info")
self.hboxlayout2.addWidget(self.book_info) self.hboxlayout2.addWidget(self.book_info)
self.vboxlayout.addLayout(self.hboxlayout2) self.gridlayout.addLayout(self.hboxlayout2,3,0,1,1)
MainWindow.setCentralWidget(self.centralwidget) MainWindow.setCentralWidget(self.centralwidget)
self.tool_bar = QtGui.QToolBar(MainWindow) self.tool_bar = QtGui.QToolBar(MainWindow)
@ -173,16 +220,22 @@ class Ui_MainWindow(object):
self.label.setBuddy(self.search) self.label.setBuddy(self.search)
self.retranslateUi(MainWindow) self.retranslateUi(MainWindow)
self.tabs.setCurrentIndex(0)
self.stacks.setCurrentIndex(0)
QtCore.QObject.connect(self.clear_button,QtCore.SIGNAL("clicked()"),self.search.clear) QtCore.QObject.connect(self.clear_button,QtCore.SIGNAL("clicked()"),self.search.clear)
QtCore.QMetaObject.connectSlotsByName(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow): def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "libprs500", None, QtGui.QApplication.UnicodeUTF8))
self.df.setText(QtGui.QApplication.translate("MainWindow", "For help visit <a href=\"https://libprs500.kovidgoyal.net/wiki/GuiUsage\">http://libprs500.kovidgoyal.net</a><br><br><b>libprs500</b>: %1 by <b>Kovid Goyal</b> &copy; 2006<br>%2 %3 %4", None, QtGui.QApplication.UnicodeUTF8)) self.df.setText(QtGui.QApplication.translate("MainWindow", "For help visit <a href=\"https://libprs500.kovidgoyal.net/wiki/GuiUsage\">http://libprs500.kovidgoyal.net</a><br><br><b>libprs500</b>: %1 by <b>Kovid Goyal</b> &copy; 2006<br>%2 %3 %4", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("MainWindow", "&Search:", None, QtGui.QApplication.UnicodeUTF8)) self.label.setText(QtGui.QApplication.translate("MainWindow", "&Search:", None, QtGui.QApplication.UnicodeUTF8))
self.search.setToolTip(QtGui.QApplication.translate("MainWindow", "Search the list of books by title or author<br><br>Words separated by spaces are ANDed", None, QtGui.QApplication.UnicodeUTF8)) self.search.setToolTip(QtGui.QApplication.translate("MainWindow", "Search the list of books by title or author<br><br>Words separated by spaces are ANDed", None, QtGui.QApplication.UnicodeUTF8))
self.search.setWhatsThis(QtGui.QApplication.translate("MainWindow", "Search the list of books by title or author<br><br>Words separated by spaces are ANDed", None, QtGui.QApplication.UnicodeUTF8)) self.search.setWhatsThis(QtGui.QApplication.translate("MainWindow", "Search the list of books by title, author, publisher, tags and comments<br><br>Words separated by spaces are ANDed", None, QtGui.QApplication.UnicodeUTF8))
self.clear_button.setToolTip(QtGui.QApplication.translate("MainWindow", "Reset Quick Search", None, QtGui.QApplication.UnicodeUTF8)) self.clear_button.setToolTip(QtGui.QApplication.translate("MainWindow", "Reset Quick Search", None, QtGui.QApplication.UnicodeUTF8))
self.clear_button.setText(QtGui.QApplication.translate("MainWindow", "...", None, QtGui.QApplication.UnicodeUTF8)) self.clear_button.setText(QtGui.QApplication.translate("MainWindow", "...", None, QtGui.QApplication.UnicodeUTF8))
self.tabs.setTabText(self.tabs.indexOf(self.books_tab), QtGui.QApplication.translate("MainWindow", "Books", None, QtGui.QApplication.UnicodeUTF8))
self.tabs.setTabText(self.tabs.indexOf(self.jobs_tab), QtGui.QApplication.translate("MainWindow", "Jobs", None, QtGui.QApplication.UnicodeUTF8))
self.tabs.setTabToolTip(self.tabs.indexOf(self.jobs_tab),QtGui.QApplication.translate("MainWindow", "Show jobs being currently processed", None, QtGui.QApplication.UnicodeUTF8))
self.book_info.setText(QtGui.QApplication.translate("MainWindow", "<table><tr><td><b>Title: </b>%1</td><td><b>&nbsp;Size:</b> %2</td></tr><tr><td><b>Author: </b>%3</td><td><b>&nbsp;Type: </b>%4</td></tr></table>", None, QtGui.QApplication.UnicodeUTF8)) self.book_info.setText(QtGui.QApplication.translate("MainWindow", "<table><tr><td><b>Title: </b>%1</td><td><b>&nbsp;Size:</b> %2</td></tr><tr><td><b>Author: </b>%3</td><td><b>&nbsp;Type: </b>%4</td></tr></table>", None, QtGui.QApplication.UnicodeUTF8))
self.action_add.setText(QtGui.QApplication.translate("MainWindow", "Add books to Library", None, QtGui.QApplication.UnicodeUTF8)) self.action_add.setText(QtGui.QApplication.translate("MainWindow", "Add books to Library", None, QtGui.QApplication.UnicodeUTF8))
self.action_add.setShortcut(QtGui.QApplication.translate("MainWindow", "A", None, QtGui.QApplication.UnicodeUTF8)) self.action_add.setShortcut(QtGui.QApplication.translate("MainWindow", "A", None, QtGui.QApplication.UnicodeUTF8))
@ -192,5 +245,6 @@ class Ui_MainWindow(object):
self.action_edit.setShortcut(QtGui.QApplication.translate("MainWindow", "E", None, QtGui.QApplication.UnicodeUTF8)) self.action_edit.setShortcut(QtGui.QApplication.translate("MainWindow", "E", None, QtGui.QApplication.UnicodeUTF8))
from widgets import DeviceView, CoverDisplay from widgets import DeviceView, CoverDisplay
from progress import AnimatedTabWidget
from library import BooksView, SearchBox from library import BooksView, SearchBox
import images_rc import images_rc

View File

@ -0,0 +1,87 @@
## Copyright (C) 2007 Kovid Goyal kovid@kovidgoyal.net
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## 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.
from PyQt4.QtGui import QIconEngine, QTabWidget, QPixmap, QIcon, QPainter, QColor
from PyQt4.QtCore import QTimeLine, QObject, SIGNAL
from PyQt4.QtSvg import QSvgRenderer
class RotatingIconEngine(QIconEngine):
@staticmethod
def create_pixmaps(path, size=16, delta=10):
r = QSvgRenderer(path)
if not r.isValid():
raise Exception(path + ' not valid svg')
pixmaps = []
for angle in range(0, 360, 10):
pm = QPixmap(size, size)
pm.fill(QColor(0,0,0,0))
p = QPainter(pm)
p.translate(size/2., size/2.)
p.rotate(angle)
p.translate(-size/2., -size/2.)
r.render(p)
p.end()
pixmaps.append(pm)
return pixmaps
def __init__(self, path, size=16):
self.pixmaps = self.__class__.create_pixmaps(path, size)
self.current = 0
QIconEngine.__init__(self)
def next(self):
self.current += 1
self.current %= len(self.pixmaps)
def reset(self):
self.current = 0
def pixmap(self, size, mode, state):
return self.pixmaps[self.current]
class AnimatedTabWidget(QTabWidget):
def __init__(self, parent):
self.animated_tab = 1
self.ri = RotatingIconEngine(':/images/jobs.svg')
QTabWidget.__init__(self, parent)
self.timeline = QTimeLine(4000, self)
self.timeline.setLoopCount(0)
self.timeline.setCurveShape(QTimeLine.LinearCurve)
self.timeline.setFrameRange(0, len(self.ri.pixmaps))
QObject.connect(self.timeline, SIGNAL('frameChanged(int)'), self.next)
def setup(self):
self.setTabIcon(self.animated_tab, QIcon(self.ri))
def animate(self):
self.timeline.start()
def update_animated_tab(self):
tb = self.tabBar()
rect = tb.tabRect(self.animated_tab)
tb.update(rect)
def stop(self):
self.timeline.stop()
self.ri.reset()
self.update_animated_tab()
def next(self, frame):
self.ri.next()
self.update_animated_tab()