[Pymoul-svn] SF.net SVN: pymoul: [43] pymoul/trunk/src/moul
Status: Alpha
Brought to you by:
tiran
From: <ti...@us...> - 2007-01-17 22:28:08
|
Revision: 43 http://pymoul.svn.sourceforge.net/pymoul/?rev=43&view=rev Author: tiran Date: 2007-01-17 14:28:07 -0800 (Wed, 17 Jan 2007) Log Message: ----------- * Auto change log level based on sys.frozen * Added some comments to time.dni * Finally the threaded server ping is working as expected Modified Paths: -------------- pymoul/trunk/src/moul/log.py pymoul/trunk/src/moul/qt/mainwindow.py pymoul/trunk/src/moul/qt/ui/mainwindow.py pymoul/trunk/src/moul/qt/ui/mainwindow.ui pymoul/trunk/src/moul/qt/ui/moulqt_rc.py pymoul/trunk/src/moul/time/dni.py Modified: pymoul/trunk/src/moul/log.py =================================================================== --- pymoul/trunk/src/moul/log.py 2007-01-17 13:37:52 UTC (rev 42) +++ pymoul/trunk/src/moul/log.py 2007-01-17 22:28:07 UTC (rev 43) @@ -22,8 +22,15 @@ __revision__ = "$Revision$" import logging +import sys -logging.basicConfig(level=logging.DEBUG, +# py2exe sets sys.frozen +if getattr(sys, 'frozen', False): + level = logging.ERROR +else: + level = logging.DEBUG + +logging.basicConfig(level=level, format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%a, %d %b %Y %H:%M:%S' ) Modified: pymoul/trunk/src/moul/qt/mainwindow.py =================================================================== --- pymoul/trunk/src/moul/qt/mainwindow.py 2007-01-17 13:37:52 UTC (rev 42) +++ pymoul/trunk/src/moul/qt/mainwindow.py 2007-01-17 22:28:07 UTC (rev 43) @@ -17,6 +17,8 @@ # """Moul QT GUI main windows """ +from __future__ import with_statement + __author__ = "Christian Heimes" __version__ = "$Id$" __revision__ = "$Revision$" @@ -24,18 +26,19 @@ import sys from PyQt4 import QtGui -from PyQt4.QtCore import QString -from PyQt4.QtCore import QStringList +from PyQt4 import QtCore from PyQt4.QtCore import pyqtSignature from PyQt4.QtCore import SIGNAL -from PyQt4.QtCore import QTimer from moul.qt.ui.mainwindow import Ui_MainWindow from moul.time.cavern import CavernTime from moul.file.wdysini import GraphicsIni from moul.server.ping import ServerList from moul.server.ping import isSocketError +from moul.log import getLogger +LOG = getLogger('moul.qt') + class MainWindow(QtGui.QMainWindow, Ui_MainWindow): def __init__(self): QtGui.QMainWindow.__init__(self) @@ -52,18 +55,19 @@ """init graphics tab """ self._graphicsini = GraphicsIni() - length = len(self._graphicsini._videomodes) -1 + length = len(self._graphicsini._videomodes) - 1 self.slid_screenres.setMaximum(length) self.connect(self.slid_screenres, SIGNAL("valueChanged(int)"), self.on_slid_screenres_changed) self.connect(self.slid_screenres, SIGNAL("sliderMoved(int)"), self.on_slid_screenres_changed) + @pyqtSignature("int") def on_slid_screenres_changed(self, idx): """SIGNAL: valueChanged (int) """ txt = self._graphicsini.getVidModeHuman(idx) - self.lb_screenres.setText(QString(txt)) + self.lb_screenres.setText(QtCore.QString(txt)) # ************************************************************************ # time zones @@ -75,7 +79,7 @@ self._timezone_update() # create a timer to update the display every second - self._timezone_timer = timer = QTimer(self) + self._timezone_timer = timer = QtCore.QTimer(self) timer.setInterval(1000) # 1 sec # TODO: needs optimization? run only when timer tab is active self.connect(timer, SIGNAL('timeout()'), self.on_timezone_timer_timeout) @@ -90,12 +94,13 @@ off = ct['cavern']['utcoffset'] txt = "UTC %s%i" % (off[0], abs(off[1])) - self.lb_cavern_utc.setText(QString(txt)) + self.lb_cavern_utc.setText(QtCore.QString(txt)) off = ct['pacific']['utcoffset'] txt = "UTC %s%i" % (off[0], abs(off[1])) - self.lb_pacific_utc.setText(QString(txt)) - + self.lb_pacific_utc.setText(QtCore.QString(txt)) + + @pyqtSignature("") def on_timezone_timer_timeout(self): """SIGNAL: QTimer timeout """ @@ -108,35 +113,83 @@ def _ping_init(self): """init ping tab """ - self.connect(self.button_ping, SIGNAL("clicked()"), self.on_button_ping_clicked) + self._ping_thread = thread = PingServerThread() + self.connect(self.button_ping, SIGNAL("clicked"), + self.on_button_ping_clicked) - def _ping_servers(self): - # TODO: Use a seperate thread! + self.connect(thread, SIGNAL("started"), + self.on_pingthread_started) + self.connect(thread, SIGNAL("done()"), + self.on_pingthread_done) + self.connect(thread, SIGNAL("server(const QString&)"), + self.on_pingthread_server) + self.connect(thread, SIGNAL("dnserror(const QString&, int, const QString&)"), + self.on_pingthread_error) + self.connect(thread, SIGNAL("dns(const QString&, float)"), + self.on_pingthread_dns) + self.connect(thread, SIGNAL("pingerror(const QString&, int, const QString&)"), + self.on_pingthread_error) + self.connect(thread, SIGNAL("ping(const QString&, float)"), + self.on_pingthread_ping) + + def on_pingthread_started(self): + LOG.debug('ping thread STARTED') + self.button_ping.setEnabled(False) self.text_ping.clear() - insertText = self.text_ping.insertPlainText + + def on_pingthread_done(self): + LOG.debug('ping thread DONE') + self.button_ping.setEnabled(True) - serverlist = ServerList() - # dns - for server in serverlist: - insertText("%s ... " % server.name) - result = server.dns() - if isSocketError(result): - insertText("DNS: FAILED\n") + def on_pingthread_server(self, name): + self.text_ping.insertPlainText("%s ... " % name) + + def on_pingthread_dns(self, name, time): + self.text_ping.insertPlainText("dns: %0.3f " % time) + + def on_pingthread_ping(self, name, time): + self.text_ping.insertPlainText("ping: %0.3f\n" % time) + + def on_pingthread_error(self, name, errcode, errmsg): + LOG.debug('error: %s, %i, %s' % (name, errcode, errmsg)) + self.text_ping.insertPlainText("error: %s\n" % errmsg) + + @pyqtSignature("bool") + def on_button_ping_clicked(self): + LOG.debug('ping thread CLICKED') + thread = self._ping_thread + if not thread.isRunning(): + servers = ServerList() + self._ping_thread.pingServers(servers) + +class PingServerThread(QtCore.QThread): + def __init__(self, parent=None): + QtCore.QThread.__init__(self, parent) + self._servers = None + + def pingServers(self, servers): + self.servers = servers + if not self.isRunning(): + self.start() + + def run(self): + self.emit(SIGNAL("started")) + + for server in self.servers: + name = server.name + self.emit(SIGNAL("server(const QString&)"), name) + dns = server.dns() + if isSocketError(dns): + self.emit(SIGNAL("dnserror(const QString&, int, const QString&)"), + name, dns[0], dns[1]) continue + self.emit(SIGNAL("dns(const QString&, float)"), name, dns) - insertText("dns: %0.3f " % result) - result = server.portping() - if isSocketError(result): - insertText("ping: FAILED\n") + ping = server.portping() + if isSocketError(ping): + self.emit(SIGNAL("pingerror(const QString&, int, const QString&)"), + name, ping[0], ping[1]) continue - insertText("pin: %0.3f\n" % result) + self.emit(SIGNAL("ping(const QString&, float)"), name, ping) - @pyqtSignature("") - def on_button_ping_clicked(self): - """SIGNAL: clicked() - """ - self.button_ping.setEnabled(False) - try: - self._ping_servers() - finally: - self.button_ping.setEnabled(True) + self.emit(SIGNAL("done()")) Modified: pymoul/trunk/src/moul/qt/ui/mainwindow.py =================================================================== --- pymoul/trunk/src/moul/qt/ui/mainwindow.py 2007-01-17 13:37:52 UTC (rev 42) +++ pymoul/trunk/src/moul/qt/ui/mainwindow.py 2007-01-17 22:28:07 UTC (rev 43) @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'src\moul\qt\ui\mainwindow.ui' # -# Created: Wed Jan 17 14:23:33 2007 +# Created: Wed Jan 17 23:18:34 2007 # by: PyQt4 UI code generator 4.1.1 # # WARNING! All changes made in this file will be lost! @@ -65,6 +65,12 @@ self.pushButton.setObjectName("pushButton") self.hboxlayout.addWidget(self.pushButton) + self.buttonbox_rresavcl = QtGui.QDialogButtonBox(self.centralwidget) + self.buttonbox_rresavcl.setGeometry(QtCore.QRect(10,480,441,32)) + self.buttonbox_rresavcl.setOrientation(QtCore.Qt.Horizontal) + self.buttonbox_rresavcl.setStandardButtons(QtGui.QDialogButtonBox.Close|QtGui.QDialogButtonBox.NoButton|QtGui.QDialogButtonBox.Reset|QtGui.QDialogButtonBox.Save) + self.buttonbox_rresavcl.setObjectName("buttonbox_rresavcl") + self.tabWidget = QtGui.QTabWidget(self.centralwidget) self.tabWidget.setGeometry(QtCore.QRect(5,100,450,375)) self.tabWidget.setTabPosition(QtGui.QTabWidget.North) @@ -283,6 +289,10 @@ self.tab_time = QtGui.QWidget() self.tab_time.setObjectName("tab_time") + self.gb_dnitime = QtGui.QGroupBox(self.tab_time) + self.gb_dnitime.setGeometry(QtCore.QRect(10,130,431,211)) + self.gb_dnitime.setObjectName("gb_dnitime") + self.gb_caverntime = QtGui.QGroupBox(self.tab_time) self.gb_caverntime.setGeometry(QtCore.QRect(10,10,431,111)) self.gb_caverntime.setObjectName("gb_caverntime") @@ -328,10 +338,6 @@ self.lb_pacific_utc = QtGui.QLabel(self.gridLayout) self.lb_pacific_utc.setObjectName("lb_pacific_utc") self.gridlayout.addWidget(self.lb_pacific_utc,1,2,1,1) - - self.gb_dnitime = QtGui.QGroupBox(self.tab_time) - self.gb_dnitime.setGeometry(QtCore.QRect(10,130,431,211)) - self.gb_dnitime.setObjectName("gb_dnitime") self.tabWidget.addTab(self.tab_time,"") self.tab = QtGui.QWidget() @@ -349,10 +355,6 @@ self.button_ping = QtGui.QPushButton(self.gb_servers) self.button_ping.setGeometry(QtCore.QRect(330,300,75,24)) self.button_ping.setObjectName("button_ping") - - self.label_3 = QtGui.QLabel(self.gb_servers) - self.label_3.setGeometry(QtCore.QRect(170,300,151,16)) - self.label_3.setObjectName("label_3") self.tabWidget.addTab(self.tab,"") self.tab_4 = QtGui.QWidget() @@ -363,12 +365,6 @@ self.label_6.setAlignment(QtCore.Qt.AlignCenter) self.label_6.setObjectName("label_6") self.tabWidget.addTab(self.tab_4,"") - - self.buttonbox_rresavcl = QtGui.QDialogButtonBox(self.centralwidget) - self.buttonbox_rresavcl.setGeometry(QtCore.QRect(10,480,441,32)) - self.buttonbox_rresavcl.setOrientation(QtCore.Qt.Horizontal) - self.buttonbox_rresavcl.setStandardButtons(QtGui.QDialogButtonBox.Close|QtGui.QDialogButtonBox.NoButton|QtGui.QDialogButtonBox.Reset|QtGui.QDialogButtonBox.Save) - self.buttonbox_rresavcl.setObjectName("buttonbox_rresavcl") MainWindow.setCentralWidget(self.centralwidget) self.statusbar = QtGui.QStatusBar(MainWindow) @@ -376,7 +372,7 @@ MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) - self.tabWidget.setCurrentIndex(3) + self.tabWidget.setCurrentIndex(0) QtCore.QObject.connect(self.buttonbox_rresavcl,QtCore.SIGNAL("rejected()"),MainWindow.close) QtCore.QMetaObject.connectSlotsByName(MainWindow) @@ -402,20 +398,19 @@ self.label_7.setText(QtGui.QApplication.translate("MainWindow", "Ultra", None, QtGui.QApplication.UnicodeUTF8)) self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_graphics), QtGui.QApplication.translate("MainWindow", "Graphis", None, QtGui.QApplication.UnicodeUTF8)) self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_audio), QtGui.QApplication.translate("MainWindow", "Audio", None, QtGui.QApplication.UnicodeUTF8)) + self.gb_dnitime.setTitle(QtGui.QApplication.translate("MainWindow", "D\'ni time", None, QtGui.QApplication.UnicodeUTF8)) self.gb_caverntime.setTitle(QtGui.QApplication.translate("MainWindow", "Time zones", None, QtGui.QApplication.UnicodeUTF8)) self.label_4.setText(QtGui.QApplication.translate("MainWindow", "Cavern time:", None, QtGui.QApplication.UnicodeUTF8)) self.lb_cavern_utc.setText(QtGui.QApplication.translate("MainWindow", "UTC", None, QtGui.QApplication.UnicodeUTF8)) self.label_5.setText(QtGui.QApplication.translate("MainWindow", "Pacific time:", None, QtGui.QApplication.UnicodeUTF8)) self.lb_pacific_utc.setText(QtGui.QApplication.translate("MainWindow", "UTC", None, QtGui.QApplication.UnicodeUTF8)) - self.gb_dnitime.setTitle(QtGui.QApplication.translate("MainWindow", "D\'ni time", None, QtGui.QApplication.UnicodeUTF8)) self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_time), QtGui.QApplication.translate("MainWindow", "Time", None, QtGui.QApplication.UnicodeUTF8)) self.gb_servers.setTitle(QtGui.QApplication.translate("MainWindow", "Ping servers", None, QtGui.QApplication.UnicodeUTF8)) self.text_ping.setHtml(QtGui.QApplication.translate("MainWindow", "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;\">\n" - "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"></p></body></html>", None, QtGui.QApplication.UnicodeUTF8)) + "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;\"></p></body></html>", None, QtGui.QApplication.UnicodeUTF8)) self.button_ping.setText(QtGui.QApplication.translate("MainWindow", "Ping", None, QtGui.QApplication.UnicodeUTF8)) - self.label_3.setText(QtGui.QApplication.translate("MainWindow", "TODO: Use a seperate thread", None, QtGui.QApplication.UnicodeUTF8)) self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), QtGui.QApplication.translate("MainWindow", "Servers", None, QtGui.QApplication.UnicodeUTF8)) self.label_6.setText(QtGui.QApplication.translate("MainWindow", "pyMoul tools", None, QtGui.QApplication.UnicodeUTF8)) self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_4), QtGui.QApplication.translate("MainWindow", "About", None, QtGui.QApplication.UnicodeUTF8)) Modified: pymoul/trunk/src/moul/qt/ui/mainwindow.ui =================================================================== --- pymoul/trunk/src/moul/qt/ui/mainwindow.ui 2007-01-17 13:37:52 UTC (rev 42) +++ pymoul/trunk/src/moul/qt/ui/mainwindow.ui 2007-01-17 22:28:07 UTC (rev 43) @@ -100,6 +100,22 @@ </item> </layout> </widget> + <widget class="QDialogButtonBox" name="buttonbox_rresavcl" > + <property name="geometry" > + <rect> + <x>10</x> + <y>480</y> + <width>441</width> + <height>32</height> + </rect> + </property> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons" > + <set>QDialogButtonBox::Close|QDialogButtonBox::NoButton|QDialogButtonBox::Reset|QDialogButtonBox::Save</set> + </property> + </widget> <widget class="QTabWidget" name="tabWidget" > <property name="geometry" > <rect> @@ -113,7 +129,7 @@ <enum>QTabWidget::North</enum> </property> <property name="currentIndex" > - <number>3</number> + <number>0</number> </property> <widget class="QWidget" name="tab_graphics" > <attribute name="title" > @@ -545,6 +561,19 @@ <attribute name="title" > <string>Time</string> </attribute> + <widget class="QGroupBox" name="gb_dnitime" > + <property name="geometry" > + <rect> + <x>10</x> + <y>130</y> + <width>431</width> + <height>211</height> + </rect> + </property> + <property name="title" > + <string>D'ni time</string> + </property> + </widget> <widget class="QGroupBox" name="gb_caverntime" > <property name="geometry" > <rect> @@ -639,19 +668,6 @@ </layout> </widget> </widget> - <widget class="QGroupBox" name="gb_dnitime" > - <property name="geometry" > - <rect> - <x>10</x> - <y>130</y> - <width>431</width> - <height>211</height> - </rect> - </property> - <property name="title" > - <string>D'ni time</string> - </property> - </widget> </widget> <widget class="QWidget" name="tab" > <attribute name="title" > @@ -685,7 +701,7 @@ <string><html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } </style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;"> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p></body></html></string> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;"></p></body></html></string> </property> </widget> <widget class="QPushButton" name="button_ping" > @@ -701,19 +717,6 @@ <string>Ping</string> </property> </widget> - <widget class="QLabel" name="label_3" > - <property name="geometry" > - <rect> - <x>170</x> - <y>300</y> - <width>151</width> - <height>16</height> - </rect> - </property> - <property name="text" > - <string>TODO: Use a seperate thread</string> - </property> - </widget> </widget> </widget> <widget class="QWidget" name="tab_4" > @@ -738,22 +741,6 @@ </widget> </widget> </widget> - <widget class="QDialogButtonBox" name="buttonbox_rresavcl" > - <property name="geometry" > - <rect> - <x>10</x> - <y>480</y> - <width>441</width> - <height>32</height> - </rect> - </property> - <property name="orientation" > - <enum>Qt::Horizontal</enum> - </property> - <property name="standardButtons" > - <set>QDialogButtonBox::Close|QDialogButtonBox::NoButton|QDialogButtonBox::Reset|QDialogButtonBox::Save</set> - </property> - </widget> </widget> <widget class="QStatusBar" name="statusbar" /> </widget> Modified: pymoul/trunk/src/moul/qt/ui/moulqt_rc.py =================================================================== --- pymoul/trunk/src/moul/qt/ui/moulqt_rc.py 2007-01-17 13:37:52 UTC (rev 42) +++ pymoul/trunk/src/moul/qt/ui/moulqt_rc.py 2007-01-17 22:28:07 UTC (rev 43) @@ -2,7 +2,7 @@ # Resource object code # -# Created: Di 16. Jan 01:02:23 2007 +# Created: Mi 17. Jan 17:01:45 2007 # by: The Resource Compiler for PyQt (Qt v4.2.2) # # WARNING! All changes made in this file will be lost! Modified: pymoul/trunk/src/moul/time/dni.py =================================================================== --- pymoul/trunk/src/moul/time/dni.py 2007-01-17 13:37:52 UTC (rev 42) +++ pymoul/trunk/src/moul/time/dni.py 2007-01-17 22:28:07 UTC (rev 43) @@ -54,7 +54,47 @@ # Official SI year 365.25 days = 31.557.600 seconds YEAR_SI = 31557600 # Sidereal year: 365.256 363 051 days (365 d 6 h 9 min 9 s) -YEAR_SIDEREAL = (((((365 * 24) + 6 ) * 60 ) + 9 ) * 60 ) + 9 -YEAR = float(YEAR_SIDEREAL) +# YEAR_SIDEREAL = (((((365 * 24) + 6 ) * 60 ) + 9 ) * 60 ) + 9 +YEAR = float(YEAR_SI) FACTOR = YEAR / PRORAHN_PER_HAHR + +class DniTime(object): + """D'ni time handler + + The D'ni were using a complex calendar based on a pentovigesimal (25) + numbering system. + + The DniTime class assumes the following rules: + + * Hahrtee Farah 1 started on 21st of April 7656 B.C. + * Hahrtee Fahrah 15 started 1719 A.C. + * A new hahr starts on 21st of April. + * The reference time for the calculation is Mountain Standard Time (MST) + without (!) DST. The UTC offset is always UTC-7. + * To compensate leap years a new hahr starts on midnight (0:00am) in every + forth year (year % 4 == 0). + * To simplify the code special cases like year % 100 and year % 400 are + NOT taken into account. I'm assuming a year has 365,25 days (which is + wrong). A year according to the Gregorian Calendar has 365,2425 days. + + Overview + --------- + + fahrah millenium 625 years + hahr year 1 year + vailee month 10 per year + yahr day 29 per vailee, about 30h 14min + gahrtahvo section about 6h, 3min + tahvo quarter about 14,5min + gorahn minute 36 seconds + prorahn second about 1.3929 seconds + """ + _fahrah = None # millenium (625 years) + _hahr = None # year (1 year) + _vailee = None # month (10 per year) + _yahr = None # day (29 per vailee) + _gahrtahvo = None # section (about 6h, 3min) + _tahvo = None # quarter (about 14,5min) + _gorahn = None # minute (about 36 seconds) + _prorahn = None # second (1,4 seconds) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |