[Pymoul-svn] SF.net SVN: pymoul: [37] pymoul/trunk/src/moul
Status: Alpha
Brought to you by:
tiran
From: <ti...@us...> - 2007-01-16 20:52:04
|
Revision: 37 http://pymoul.svn.sourceforge.net/pymoul/?rev=37&view=rev Author: tiran Date: 2007-01-16 12:43:19 -0800 (Tue, 16 Jan 2007) Log Message: ----------- * Added PST time zone because the support used PST instead of MST/cavern time * Updated UI to use a timer for the time zone display. Qt is cool :) Modified Paths: -------------- pymoul/trunk/src/moul/qt/mainwindow.py pymoul/trunk/src/moul/qt/moulqt.py pymoul/trunk/src/moul/qt/ui/mainwindow.py pymoul/trunk/src/moul/qt/ui/mainwindow.ui pymoul/trunk/src/moul/time/cavern.py Modified: pymoul/trunk/src/moul/qt/mainwindow.py =================================================================== --- pymoul/trunk/src/moul/qt/mainwindow.py 2007-01-16 13:11:23 UTC (rev 36) +++ pymoul/trunk/src/moul/qt/mainwindow.py 2007-01-16 20:43:19 UTC (rev 37) @@ -24,12 +24,11 @@ import sys from PyQt4 import QtGui -from PyQt4.QtCore import QDir from PyQt4.QtCore import QString from PyQt4.QtCore import QStringList from PyQt4.QtCore import pyqtSignature from PyQt4.QtCore import SIGNAL -from PyQt4.QtCore import QFileInfo +from PyQt4.QtCore import QTimer from moul.qt.ui.mainwindow import Ui_MainWindow from moul.time.cavern import CavernTime @@ -45,19 +44,16 @@ def _timezone_init(self): """Init time zone tab""" - tz = 'Europe/Berlin' - self._caverntime = CavernTime(tz) - - chooser = self.cb_timezone_chooser - curidx = TIMEZONE_NAMES.index(tz) - chooser.addItems(QStringList(TIMEZONE_NAMES)) - chooser.setCurrentIndex(curidx) - - self.connect(self.cb_timezone_chooser, - SIGNAL("currentIndexChanged (const QString&)"), - self.on_cb_timezone_chooser_changed) - + # create info object and update display the first time + self._caverntime = CavernTime() self._timezone_update() + + # create a timer to update the display every second + self._timezone_timer = timer = QTimer(self) + timer.setInterval(1000) # 1 sec + # TODO: needs optimization? run only when timer tab is active + self.connect(timer, SIGNAL('timeout()'), self._timezone_update) + timer.start() def _timezone_update(self, ct=None): """Update datetime widgets""" @@ -65,22 +61,12 @@ ct = self._caverntime() self.dt_cavern.setDateTime(ct['cavern']['datetime']) - self.dt_local.setDateTime(ct['local']['datetime']) + self.dt_pacific.setDateTime(ct['pacific']['datetime']) - # TODO: handle fractions off = ct['cavern']['utcoffset'] txt = "UTC %s%i" % (off[0], abs(off[1])) self.lb_cavern_utc.setText(QString(txt)) - off = ct['local']['utcoffset'] + off = ct['pacific']['utcoffset'] txt = "UTC %s%i" % (off[0], abs(off[1])) - self.lb_local_utc.setText(QString(txt)) - - def on_cb_timezone_chooser_changed(self, name): - """Change time zone event - - SIGNAL: currentIndexChanged (const QString&) - """ - name = str(name) - self._caverntime.setLocalTZ(name) - self._timezone_update() + self.lb_pacific_utc.setText(QString(txt)) Modified: pymoul/trunk/src/moul/qt/moulqt.py =================================================================== --- pymoul/trunk/src/moul/qt/moulqt.py 2007-01-16 13:11:23 UTC (rev 36) +++ pymoul/trunk/src/moul/qt/moulqt.py 2007-01-16 20:43:19 UTC (rev 37) @@ -30,7 +30,6 @@ from moul.file import plasmalog from moul.file import wdysini from moul.file import kiimage -from moul.time import cavern as caverntime from moul.time import dni as dnitime def main(*args): Modified: pymoul/trunk/src/moul/qt/ui/mainwindow.py =================================================================== --- pymoul/trunk/src/moul/qt/ui/mainwindow.py 2007-01-16 13:11:23 UTC (rev 36) +++ pymoul/trunk/src/moul/qt/ui/mainwindow.py 2007-01-16 20:43:19 UTC (rev 37) @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'src\moul\qt\ui\mainwindow.ui' # -# Created: Tue Jan 16 13:40:50 2007 +# Created: Tue Jan 16 21:38:16 2007 # by: PyQt4 UI code generator 4.1.1 # # WARNING! All changes made in this file will be lost! @@ -65,6 +65,12 @@ self.label.setPixmap(QtGui.QPixmap(":/resources/moul_logo.png")) self.label.setObjectName("label") + 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) @@ -284,65 +290,49 @@ self.tab_time = QtGui.QWidget() self.tab_time.setObjectName("tab_time") - self.gb_timezone = QtGui.QGroupBox(self.tab_time) - self.gb_timezone.setGeometry(QtCore.QRect(10,10,421,81)) - self.gb_timezone.setObjectName("gb_timezone") - - self.cb_timezone_chooser = QtGui.QComboBox(self.gb_timezone) - self.cb_timezone_chooser.setGeometry(QtCore.QRect(10,30,271,21)) - self.cb_timezone_chooser.setObjectName("cb_timezone_chooser") - self.gb_caverntime = QtGui.QGroupBox(self.tab_time) - self.gb_caverntime.setGeometry(QtCore.QRect(10,100,421,121)) + self.gb_caverntime.setGeometry(QtCore.QRect(10,10,431,111)) self.gb_caverntime.setObjectName("gb_caverntime") - self.horizontalLayout_2 = QtGui.QWidget(self.gb_caverntime) - self.horizontalLayout_2.setGeometry(QtCore.QRect(20,20,261,31)) - self.horizontalLayout_2.setObjectName("horizontalLayout_2") + self.gridLayout = QtGui.QWidget(self.gb_caverntime) + self.gridLayout.setGeometry(QtCore.QRect(10,20,281,80)) + self.gridLayout.setObjectName("gridLayout") - self.hboxlayout5 = QtGui.QHBoxLayout(self.horizontalLayout_2) - self.hboxlayout5.setMargin(0) - self.hboxlayout5.setSpacing(6) - self.hboxlayout5.setObjectName("hboxlayout5") + self.gridlayout = QtGui.QGridLayout(self.gridLayout) + self.gridlayout.setMargin(0) + self.gridlayout.setSpacing(6) + self.gridlayout.setObjectName("gridlayout") - self.label_4 = QtGui.QLabel(self.horizontalLayout_2) - self.label_4.setObjectName("label_4") - self.hboxlayout5.addWidget(self.label_4) - - self.dt_cavern = QtGui.QDateTimeEdit(self.horizontalLayout_2) + self.dt_cavern = QtGui.QDateTimeEdit(self.gridLayout) self.dt_cavern.setReadOnly(True) self.dt_cavern.setButtonSymbols(QtGui.QAbstractSpinBox.UpDownArrows) self.dt_cavern.setObjectName("dt_cavern") - self.hboxlayout5.addWidget(self.dt_cavern) + self.gridlayout.addWidget(self.dt_cavern,0,1,1,1) - self.lb_cavern_utc = QtGui.QLabel(self.horizontalLayout_2) + self.label_4 = QtGui.QLabel(self.gridLayout) + self.label_4.setObjectName("label_4") + self.gridlayout.addWidget(self.label_4,0,0,1,1) + + self.lb_cavern_utc = QtGui.QLabel(self.gridLayout) self.lb_cavern_utc.setObjectName("lb_cavern_utc") - self.hboxlayout5.addWidget(self.lb_cavern_utc) + self.gridlayout.addWidget(self.lb_cavern_utc,0,2,1,1) - self.horizontalLayout_3 = QtGui.QWidget(self.gb_caverntime) - self.horizontalLayout_3.setGeometry(QtCore.QRect(20,70,261,31)) - self.horizontalLayout_3.setObjectName("horizontalLayout_3") - - self.hboxlayout6 = QtGui.QHBoxLayout(self.horizontalLayout_3) - self.hboxlayout6.setMargin(0) - self.hboxlayout6.setSpacing(6) - self.hboxlayout6.setObjectName("hboxlayout6") - - self.label_5 = QtGui.QLabel(self.horizontalLayout_3) + self.label_5 = QtGui.QLabel(self.gridLayout) self.label_5.setObjectName("label_5") - self.hboxlayout6.addWidget(self.label_5) + self.gridlayout.addWidget(self.label_5,1,0,1,1) - self.dt_local = QtGui.QDateTimeEdit(self.horizontalLayout_3) - self.dt_local.setReadOnly(True) - self.dt_local.setObjectName("dt_local") - self.hboxlayout6.addWidget(self.dt_local) + self.dt_pacific = QtGui.QDateTimeEdit(self.gridLayout) + self.dt_pacific.setReadOnly(True) + self.dt_pacific.setButtonSymbols(QtGui.QAbstractSpinBox.UpDownArrows) + self.dt_pacific.setObjectName("dt_pacific") + self.gridlayout.addWidget(self.dt_pacific,1,1,1,1) - self.lb_local_utc = QtGui.QLabel(self.horizontalLayout_3) - self.lb_local_utc.setObjectName("lb_local_utc") - self.hboxlayout6.addWidget(self.lb_local_utc) + 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,230,421,111)) + self.gb_dnitime.setGeometry(QtCore.QRect(10,130,431,211)) self.gb_dnitime.setObjectName("gb_dnitime") self.tabWidget.addTab(self.tab_time,"") @@ -354,12 +344,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) @@ -367,7 +351,7 @@ MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) - self.tabWidget.setCurrentIndex(2) + self.tabWidget.setCurrentIndex(0) QtCore.QObject.connect(self.buttonbox_rresavcl,QtCore.SIGNAL("rejected()"),MainWindow.close) QtCore.QMetaObject.connectSlotsByName(MainWindow) @@ -393,12 +377,11 @@ 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_timezone.setTitle(QtGui.QApplication.translate("MainWindow", "Time Zone", None, QtGui.QApplication.UnicodeUTF8)) - self.gb_caverntime.setTitle(QtGui.QApplication.translate("MainWindow", "Cavern 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", "Local time:", None, QtGui.QApplication.UnicodeUTF8)) - self.lb_local_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.label_6.setText(QtGui.QApplication.translate("MainWindow", "pyMoul tools", None, QtGui.QApplication.UnicodeUTF8)) Modified: pymoul/trunk/src/moul/qt/ui/mainwindow.ui =================================================================== --- pymoul/trunk/src/moul/qt/ui/mainwindow.ui 2007-01-16 13:11:23 UTC (rev 36) +++ pymoul/trunk/src/moul/qt/ui/mainwindow.ui 2007-01-16 20:43:19 UTC (rev 37) @@ -100,6 +100,22 @@ <pixmap resource="moulqt.qrc" >:/resources/moul_logo.png</pixmap> </property> </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>2</number> + <number>0</number> </property> <widget class="QWidget" name="tab_graphics" > <attribute name="title" > @@ -548,65 +564,35 @@ <attribute name="title" > <string>Time</string> </attribute> - <widget class="QGroupBox" name="gb_timezone" > + <widget class="QGroupBox" name="gb_caverntime" > <property name="geometry" > <rect> <x>10</x> <y>10</y> - <width>421</width> - <height>81</height> + <width>431</width> + <height>111</height> </rect> </property> <property name="title" > - <string>Time Zone</string> + <string>Time zones</string> </property> - <widget class="QComboBox" name="cb_timezone_chooser" > + <widget class="QWidget" name="gridLayout" > <property name="geometry" > <rect> <x>10</x> - <y>30</y> - <width>271</width> - <height>21</height> - </rect> - </property> - </widget> - </widget> - <widget class="QGroupBox" name="gb_caverntime" > - <property name="geometry" > - <rect> - <x>10</x> - <y>100</y> - <width>421</width> - <height>121</height> - </rect> - </property> - <property name="title" > - <string>Cavern Time</string> - </property> - <widget class="QWidget" name="horizontalLayout_2" > - <property name="geometry" > - <rect> - <x>20</x> <y>20</y> - <width>261</width> - <height>31</height> + <width>281</width> + <height>80</height> </rect> </property> - <layout class="QHBoxLayout" > + <layout class="QGridLayout" > <property name="margin" > <number>0</number> </property> <property name="spacing" > <number>6</number> </property> - <item> - <widget class="QLabel" name="label_4" > - <property name="text" > - <string>Cavern time:</string> - </property> - </widget> - </item> - <item> + <item row="0" column="1" > <widget class="QDateTimeEdit" name="dt_cavern" > <property name="readOnly" > <bool>true</bool> @@ -616,47 +602,39 @@ </property> </widget> </item> - <item> + <item row="0" column="0" > + <widget class="QLabel" name="label_4" > + <property name="text" > + <string>Cavern time:</string> + </property> + </widget> + </item> + <item row="0" column="2" > <widget class="QLabel" name="lb_cavern_utc" > <property name="text" > <string>UTC</string> </property> </widget> </item> - </layout> - </widget> - <widget class="QWidget" name="horizontalLayout_3" > - <property name="geometry" > - <rect> - <x>20</x> - <y>70</y> - <width>261</width> - <height>31</height> - </rect> - </property> - <layout class="QHBoxLayout" > - <property name="margin" > - <number>0</number> - </property> - <property name="spacing" > - <number>6</number> - </property> - <item> + <item row="1" column="0" > <widget class="QLabel" name="label_5" > <property name="text" > - <string>Local time:</string> + <string>Pacific time:</string> </property> </widget> </item> - <item> - <widget class="QDateTimeEdit" name="dt_local" > + <item row="1" column="1" > + <widget class="QDateTimeEdit" name="dt_pacific" > <property name="readOnly" > <bool>true</bool> </property> + <property name="buttonSymbols" > + <enum>QAbstractSpinBox::UpDownArrows</enum> + </property> </widget> </item> - <item> - <widget class="QLabel" name="lb_local_utc" > + <item row="1" column="2" > + <widget class="QLabel" name="lb_pacific_utc" > <property name="text" > <string>UTC</string> </property> @@ -669,9 +647,9 @@ <property name="geometry" > <rect> <x>10</x> - <y>230</y> - <width>421</width> - <height>111</height> + <y>130</y> + <width>431</width> + <height>211</height> </rect> </property> <property name="title" > @@ -701,22 +679,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/time/cavern.py =================================================================== --- pymoul/trunk/src/moul/time/cavern.py 2007-01-16 13:11:23 UTC (rev 36) +++ pymoul/trunk/src/moul/time/cavern.py 2007-01-16 20:43:19 UTC (rev 37) @@ -59,11 +59,14 @@ # Cyan HQ is near Spokane / Washington # Cavern time is Mountain Time Zone (MDT) with daylight savings (MST) -CAVERN_TZ_NAME = 'US/Mountain' # MDT / MST +CAVERN_TZ_NAME = 'US/Mountain' # MST / MDT CAVERN_TZ = timezone(CAVERN_TZ_NAME) +PACIFIC_TZ_NAME = 'US/Pacific' # PST / PDT +PACIFIC_TZ = timezone(PACIFIC_TZ_NAME) + def diffTD(td1, td2): - """Difference of two objects -> int + """Difference of two objects -> int >>> from datetime import timedelta >>> type(diffTD(timedelta(0, 3600), timedelta(0, -3600))) @@ -101,31 +104,49 @@ class CavernTime(object): """Cavern time calculator - Calculates the cavern time and local time based on a given local time + Calculates the cavern time and other useful tz based on a given local time zone. Call a CavernTime object: utc datetime -- Current time in UTC as <datetime> object - cavern - datetime -- Current time in cavern TZ as <datetime> object - tz -- Cavern time zone object + cavern, pacific + datetime -- current time TZ as <datetime> object + tz -- time zone object + dst -- dst in seconds if dst utcoffset -- (signum, hours, fraction) offset from UTC - cavern - datetime -- Current time in local TZ as <datetime> object - tz -- Local time zone object - utcoffset -- (signum, hours, fraction) offset from UTC + name -- long time like US/Mountain + id -- short name like MST - >>> ct = CavernTime(local="Europe/Berlin") + >>> ct = CavernTime() >>> result = ct() - >>> 'utc' in result, 'local' in result, 'cavern' in result - (True, True, True) - >>> coff = result['cavern']['utcoffset'] - >>> coff == ('-', -7, 0.0) or coff == ('-', -8, 0.0) or coff + >>> 'utc' in result True - >>> loff = result['local']['utcoffset'] - >>> loff == ('+', 1, 0.0) or loff == ('+', 2, 0.0) or loff + + >>> cav = result['cavern'] + >>> off = cav['utcoffset'] + >>> dst = cav['dst'] + >>> (not dst and off == ('-', -7, 0.0)) or (dst and off == ('-', -8, 0.0)) or off True + >>> cav['id'] + 'MST' + >>> cav['name'] + 'US/Mountain' + >>> cav['dst'] in (0, 3600) + True + >>> del cav + >>> pst = result['pacific'] + >>> dst = pst['dst'] + >>> (not dst and off == ('-', -7, 0.0)) or (dst and off == ('-', -8, 0.0)) or off + True + >>> pst['id'] + 'PST' + >>> pst['name'] + 'US/Pacific' + >>> pst['dst'] in (0, 3600) + True + >>> del pst + >>> 'UTC' in CavernTime.timezones True >>> 'UTC' in ct.timezones @@ -133,15 +154,7 @@ """ timezones = TIMEZONE_NAMES _cavern = CAVERN_TZ - _local = None - - def __init__(self, local): - self.setLocalTZ(local) - - def setLocalTZ(self, local): - """Set local time zone - """ - self._local = timezone(local) + _pacific = PACIFIC_TZ @staticmethod def _utcnow(): @@ -160,12 +173,18 @@ def __call__(self): now = self._utcnow() result = {} - for id, tz in (('cavern', self._cavern), ('local', self._local)): + for id, tz in (('cavern', self._cavern), ('pacific', self._pacific)): info = result.setdefault(id, {}) utcoffset = td2int(tz.utcoffset(now)) signum = utcoffset < 0 and '-' or '+' info['tz'] = tz info['utcoffset'] = signum,int(utcoffset/3600), float((utcoffset%3600)/3600.0) info['datetime'] = self._normalize(tz, now) + info['name'] = str(tz) + info['id'] = tz._tzname + info['dst'] = td2int(tz.dst(now)) result['utc'] = {'datetime' : now} return result + + def __str__(self): + return str(self._cavern) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |