[Pymoul-svn] SF.net SVN: pymoul: [119] pymoul/trunk
Status: Alpha
Brought to you by:
tiran
|
From: <ti...@us...> - 2007-02-02 14:38:56
|
Revision: 119
http://pymoul.svn.sourceforge.net/pymoul/?rev=119&view=rev
Author: tiran
Date: 2007-02-02 06:38:56 -0800 (Fri, 02 Feb 2007)
Log Message:
-----------
Added simple progress bar. Use it in the loc loader screen
Modified Paths:
--------------
pymoul/trunk/doc/TODO.txt
pymoul/trunk/src/moul/qt/errorhandler.py
pymoul/trunk/src/moul/qt/localization.py
pymoul/trunk/src/moul/qt/mainwindow.py
pymoul/trunk/src/moul/qt/threadlet.py
Added Paths:
-----------
pymoul/trunk/src/moul/qt/simpleprogressbar.py
pymoul/trunk/src/moul/qt/ui/simpleprogressbar.py
pymoul/trunk/src/moul/qt/ui/simpleprogressbar.ui
Modified: pymoul/trunk/doc/TODO.txt
===================================================================
--- pymoul/trunk/doc/TODO.txt 2007-02-02 12:35:40 UTC (rev 118)
+++ pymoul/trunk/doc/TODO.txt 2007-02-02 14:38:56 UTC (rev 119)
@@ -12,3 +12,7 @@
* complete chatlog viewer
* more checks and exceptions! Never fail silentely
* update readme.txt
+ * connect QThread.terminate() slots with its parents close/destroy signal
+ handler
+ * clean documents/journal/localization naming
+
Modified: pymoul/trunk/src/moul/qt/errorhandler.py
===================================================================
--- pymoul/trunk/src/moul/qt/errorhandler.py 2007-02-02 12:35:40 UTC (rev 118)
+++ pymoul/trunk/src/moul/qt/errorhandler.py 2007-02-02 14:38:56 UTC (rev 119)
@@ -38,8 +38,6 @@
LOG = getLogger('moul.qt.error')
-def trUtf8(s):
- return s
def qtexcepthook(typ, value, traceback):
"""
@@ -49,8 +47,10 @@
LOG.critical("UNHANDLED ERROR", exc_info=(typ, value, traceback))
return # XXX: remove
try:
- title = trUtf8("An unhandled error has occured")
- msg = (trUtf8("Please report the error:\n\n") +
+ title= QtGui.QApplication.translate("excepthook",
+ "An unhandled error has occured",
+ None, QtGui.QApplication.UnicodeUTF8)
+ msg = ("Please report the error:\n\n" +
'\n'.join([line.strip() for line in
format_exception(typ, value, traceback)])
)
@@ -111,7 +111,7 @@
"""
Info message box
"""
- mb = _mkMessageBox(context, icon='Info')
+ mb = _mkMessageBox(context, icon='Information')
mb.setStandardButtons(QtGui.QMessageBox.Ok)
mb.setWindowTitle(title)
mb.setText(text)
Modified: pymoul/trunk/src/moul/qt/localization.py
===================================================================
--- pymoul/trunk/src/moul/qt/localization.py 2007-02-02 12:35:40 UTC (rev 118)
+++ pymoul/trunk/src/moul/qt/localization.py 2007-02-02 14:38:56 UTC (rev 119)
@@ -37,6 +37,7 @@
from moul.log import getLogger
from moul.log import signalLogDecorator
from moul.qt.threadlet import Threadlet
+from moul.qt.simpleprogressbar import SimpleProgressbar
LOG = getLogger('moul.loc')
@@ -49,10 +50,43 @@
Mixin for documentation tab
"""
def _documents_init(self):
- installDir = lookupDir('install')
+ """
+ @qtsignal loadLocalization(): load loc data
+ """
+ self._journals_loaded = False
+ self.connect(self, SIGNAL('loadLocalization()'),
+ self.on_localization_doload)
+ self.cb_doc_language.addItems(insertDummyQ([]))
+ self.cb_doc_language_eventFilter = LocalizationLoadEventFilter(self)
+ self.cb_doc_language.installEventFilter(self.cb_doc_language_eventFilter)
+
+ @signalLogDecorator(LOG)
+ def on_localization_doload(self):
+ """
+ @qtslot loadLocalization(): Load localization
+ @qtsignal finished(): self._journal_threadlet
+ """
+ if self.cb_doc_language_eventFilter:
+ self.cb_doc_language.removeEventFilter(
+ self.cb_doc_language_eventFilter
+ )
+ self.cb_doc_language_eventFilter = None
+
+ if self._journals_loaded:
+ return
+
+ # TODO: other message box
+ self._journal_progressbar = SimpleProgressbar(self)
+ self._journal_progressbar.setWindowTitle(self.trUtf8("Loading journals"))
+ self._journal_progressbar.setProgressbar(0, 1, 0)
+ self._journal_progressbar.show()
+
+ installDir = lookupDir('install')
self._gamedir = UruGameDataDirectory(installDir)
if not self._gamedir.exists('loc'):
+ self.tab_sub_journals.setEnabled(False)
return
+
self._journal_threadlet = Threadlet()
self.connect(self._journal_threadlet, SIGNAL('finished()'),
self.on_localization_loaded)
@@ -60,8 +94,20 @@
@signalLogDecorator(LOG)
def on_localization_loaded(self):
- self.tab_sub_journals.setEnabled(True)
+ """
+ @qtslot finished(): self._journal_threadlet
+ """
+ # remove thread
+ self.disconnect(self._journal_threadlet, SIGNAL('finished()'),
+ self.on_localization_loaded)
+ del self._journal_threadlet
+ # close and remove info message box
+ self._journal_progressbar.setValue(1)
+ self._journal_progressbar.close()
+ del self._journal_progressbar
+ self._journals_loaded = True
+
self._documents_state = {}
self.connect(self.cb_doc_language, SIGNAL("currentIndexChanged(int)"),
@@ -72,9 +118,9 @@
self.on_cb_doc_set_currentIndexChanged)
#self.connect(self.cb_doc_element, SIGNAL("currentIndexChanged(int)"),
# self.on_cb_doc_element_currentIndexChanged)
-
languages = sorted(tr.languages())
self._documents_state['languages'] = languages
+ self.cb_doc_language.clear()
self.cb_doc_language.addItems(insertDummyQ(languages))
self.cb_doc_language.setCurrentIndex(0)
@@ -140,5 +186,17 @@
translation = tr[(lang, age, set, element)]
qstr = QtCore.QString(translation)
self.te_doc_view.setPlainText(qstr)
- self.te_doc_view.setEnabled(True)
-
+ self.te_doc_view.setEnabled(True)
+
+class LocalizationLoadEventFilter(QtCore.QObject):
+ """Event filter to load localization
+ """
+ def eventFilter(self, target, event):
+ """
+ Event filter
+ """
+ if event.type() in (QtCore.QEvent.MouseButtonPress,
+ QtCore.QEvent.FocusIn):
+ self.parent().emit(SIGNAL('loadLocalization()'))
+
+ return QtCore.QObject.eventFilter(self, target, event)
Modified: pymoul/trunk/src/moul/qt/mainwindow.py
===================================================================
--- pymoul/trunk/src/moul/qt/mainwindow.py 2007-02-02 12:35:40 UTC (rev 118)
+++ pymoul/trunk/src/moul/qt/mainwindow.py 2007-02-02 14:38:56 UTC (rev 119)
@@ -63,7 +63,6 @@
# dirty flag: unsaved changes
self._dirty = False
self.setDirty(False)
- self.tab_sub_journals.setEnabled(False)
# init handlers
self._timezone_init()
@@ -80,7 +79,7 @@
self.connect(self._moulrunning_thread, SIGNAL('moulIsRunning(bool)'),
self.on_moulIsRunning)
self._moulrunning_thread.startChecker(5.0) # check now and every 5 seconds
-
+
@signalLogDecorator(LOG)
def on_moulIsRunning(self, boolean):
"""
Added: pymoul/trunk/src/moul/qt/simpleprogressbar.py
===================================================================
--- pymoul/trunk/src/moul/qt/simpleprogressbar.py (rev 0)
+++ pymoul/trunk/src/moul/qt/simpleprogressbar.py 2007-02-02 14:38:56 UTC (rev 119)
@@ -0,0 +1,69 @@
+# pyMoul - Python interface to Myst Online URU Live
+# Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de>
+
+# 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., 59
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+"""Moul QT GUI main windows
+"""
+__author__ = "Christian Heimes"
+__version__ = "$Id: mainwindow.py 116 2007-02-02 03:32:28Z tiran $"
+__revision__ = "$Revision: 116 $"
+
+__all__ = ['SimpleProgressbar']
+
+from PyQt4 import QtGui
+from PyQt4.QtCore import pyqtSignature
+
+from moul.qt.ui.simpleprogressbar import Ui_SimpleProgressbar
+
+class SimpleProgressbar(QtGui.QDialog, Ui_SimpleProgressbar):
+ """A simple progress bar dialog
+
+ >>> bar = SimpleProgressbar()
+ >>> bar.setWindowTitle(bar.trUtf8('a bar'))
+ >>> bar.setProgressbar(0, 100, 20)
+ >>> bar.setValue(50)
+ """
+
+ def __init__(self, parent=None):
+ QtGui.QDialog.__init__(self, parent)
+ self.setupUi(self)
+
+ def setProgressbar(self, minval, maxval, value=None):
+ """Set progress bar min, max and initial value
+
+ @param minval: minimum value
+ @type minval: int
+ @param maxval: maximum value
+ @type maxval: int
+ @param value: initial value (set to minval if value is None)
+ @type value: int, None
+ """
+ if value is None:
+ value = minval
+ self.progressbar.setMinimum(minval)
+ self.progressbar.setMaximum(maxval)
+ self.progressbar.setValue(value)
+
+ @pyqtSignature("int")
+ def setValue(self, value):
+ """Set value of progress bar
+
+ @qtslot setValue(int): set value of progress bar
+ @param value: current value of the progress bar
+ @type value: int
+ """
+ return self.progressbar.setValue(value)
Modified: pymoul/trunk/src/moul/qt/threadlet.py
===================================================================
--- pymoul/trunk/src/moul/qt/threadlet.py 2007-02-02 12:35:40 UTC (rev 118)
+++ pymoul/trunk/src/moul/qt/threadlet.py 2007-02-02 14:38:56 UTC (rev 119)
@@ -36,34 +36,53 @@
Use this class to run a CPU or I/O bound function in a seperate thread.
- @signal started(): Signal is emitted when the thread starts executing.
- @signal finished(): Signal is emitted when the thread has finished.
- @signal terminated(): Signal is emitted when the thread is terminated.
- @signal done(result): Signal is emitted when the function has returned.
- The result argument contains the return value of the function.
-
+
>>> def pow(x, y): return x**y
>>> def printer(r): print r
- >>> example =Threadlet()
- >>> connect(example, SIGNAL('done(result)'), printer)
- >>> example.detach(pow, 2, 6)
-
- started()
- done(result)
- finished()
-
- @warning: The function and all applied arguments must be reentrant or
- thread safe!
+ >>> parent.example = Threadlet()
+ >>> parent.connect(parent.example, SIGNAL('done(result)'), printer)
+ >>> parent.example.detach(pow, 2, 6)
+
+ Signals emitted:
+ - started()
+ - done(result)
+ - finished()
+
+ You should disconnect all signals after the threadlet has finished
+ >>> parent.disconnect(parent.example, SIGNAL('done(result)'))
+ >>> del parent.example
+
+ @qtsignal started(): Signal is emitted when the thread starts executing.
+ @qtsignal finished(): Signal is emitted when the thread has finished.
+ @qtsignal terminated(): Signal is emitted when the thread is terminated.
+ @qtsignal done(result): Signal is emitted when the function has returned.
+
+ @warning: The function and all applied arguments must be thread safe!
"""
def __init__(self, parent=None):
+ """Constructor
+
+ @param parent: Qt parent object
+ @type parent: QObject instance or None
+ """
QtCore.QThread.__init__(self, parent)
self.mutex = QtCore.QMutex()
+ self.clear()
+
+ def clear(self):
+ """
+ Clear variables
+
+ Mutex must be locked before clear() is called from a method!
+ """
self._func = None
self._args = None
self._kwargs = None
def detach(self, func, *args, **kwargs):
"""
+ Detach a function call
+
@param func: a callable
@param *args: additional arguments for the function
@param **kwargs: additional keyword arguments for the function
@@ -77,7 +96,15 @@
self.start()
def run(self):
+ """
+ Payload - runs the script and emits done(result)
+
+ The function and its args/kwargs are cleared after the function has
+ run to avoid cyclic references.
+ """
self.mutex.lock()
result = self._func(*self._args, **self._kwargs)
self.emit(SIGNAL("done(result)"), result)
+ self.clear()
self.mutex.unlock()
+
Added: pymoul/trunk/src/moul/qt/ui/simpleprogressbar.py
===================================================================
--- pymoul/trunk/src/moul/qt/ui/simpleprogressbar.py (rev 0)
+++ pymoul/trunk/src/moul/qt/ui/simpleprogressbar.py 2007-02-02 14:38:56 UTC (rev 119)
@@ -0,0 +1,53 @@
+# -*- coding: utf-8 -*-
+
+# Form implementation generated from reading ui file 'src/moul/qt/ui/simpleprogressbar.ui'
+#
+# Created: Fri Feb 2 15:36:30 2007
+# by: PyQt4 UI code generator 4.1.1
+#
+# WARNING! All changes made in this file will be lost!
+
+import sys
+from PyQt4 import QtCore, QtGui
+
+class Ui_SimpleProgressbar(object):
+ def setupUi(self, SimpleProgressbar):
+ SimpleProgressbar.setObjectName("SimpleProgressbar")
+ SimpleProgressbar.resize(QtCore.QSize(QtCore.QRect(0,0,203,38).size()).expandedTo(SimpleProgressbar.minimumSizeHint()))
+ SimpleProgressbar.setMinimumSize(QtCore.QSize(203,38))
+ SimpleProgressbar.setMaximumSize(QtCore.QSize(203,38))
+ SimpleProgressbar.setWindowIcon(QtGui.QIcon(":/resources/uru_icon_32x32.png"))
+
+ self.verticalLayout = QtGui.QWidget(SimpleProgressbar)
+ self.verticalLayout.setGeometry(QtCore.QRect(0,0,201,41))
+ self.verticalLayout.setObjectName("verticalLayout")
+
+ self.vboxlayout = QtGui.QVBoxLayout(self.verticalLayout)
+ self.vboxlayout.setMargin(0)
+ self.vboxlayout.setSpacing(6)
+ self.vboxlayout.setObjectName("vboxlayout")
+
+ self.progressbar = QtGui.QProgressBar(self.verticalLayout)
+ self.progressbar.setMinimum(0)
+ self.progressbar.setMaximum(100)
+ self.progressbar.setProperty("value",QtCore.QVariant(0))
+ self.progressbar.setTextVisible(False)
+ self.progressbar.setOrientation(QtCore.Qt.Horizontal)
+ self.progressbar.setObjectName("progressbar")
+ self.vboxlayout.addWidget(self.progressbar)
+
+ self.retranslateUi(SimpleProgressbar)
+ QtCore.QMetaObject.connectSlotsByName(SimpleProgressbar)
+
+ def retranslateUi(self, SimpleProgressbar):
+ SimpleProgressbar.setWindowTitle(QtGui.QApplication.translate("SimpleProgressbar", "Title", None, QtGui.QApplication.UnicodeUTF8))
+
+from moul.qt.ui import moulqt_rc
+
+if __name__ == "__main__":
+ app = QtGui.QApplication(sys.argv)
+ SimpleProgressbar = QtGui.QDialog()
+ ui = Ui_SimpleProgressbar()
+ ui.setupUi(SimpleProgressbar)
+ SimpleProgressbar.show()
+ sys.exit(app.exec_())
Added: pymoul/trunk/src/moul/qt/ui/simpleprogressbar.ui
===================================================================
--- pymoul/trunk/src/moul/qt/ui/simpleprogressbar.ui (rev 0)
+++ pymoul/trunk/src/moul/qt/ui/simpleprogressbar.ui 2007-02-02 14:38:56 UTC (rev 119)
@@ -0,0 +1,72 @@
+<ui version="4.0" >
+ <class>SimpleProgressbar</class>
+ <widget class="QDialog" name="SimpleProgressbar" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>203</width>
+ <height>38</height>
+ </rect>
+ </property>
+ <property name="minimumSize" >
+ <size>
+ <width>203</width>
+ <height>38</height>
+ </size>
+ </property>
+ <property name="maximumSize" >
+ <size>
+ <width>203</width>
+ <height>38</height>
+ </size>
+ </property>
+ <property name="windowTitle" >
+ <string>Title</string>
+ </property>
+ <property name="windowIcon" >
+ <iconset resource="moulqt.qrc" >:/resources/uru_icon_32x32.png</iconset>
+ </property>
+ <widget class="QWidget" name="verticalLayout" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>201</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <layout class="QVBoxLayout" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QProgressBar" name="progressbar" >
+ <property name="minimum" >
+ <number>0</number>
+ </property>
+ <property name="maximum" >
+ <number>100</number>
+ </property>
+ <property name="value" >
+ <number>0</number>
+ </property>
+ <property name="textVisible" >
+ <bool>false</bool>
+ </property>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ <resources>
+ <include location="moulqt.qrc" />
+ </resources>
+ <connections/>
+</ui>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|