[Pymoul-svn] SF.net SVN: pymoul: [34] pymoul/trunk/src/moul
Status: Alpha
Brought to you by:
tiran
|
From: <ti...@us...> - 2007-01-16 12:40:27
|
Revision: 34
http://pymoul.svn.sourceforge.net/pymoul/?rev=34&view=rev
Author: tiran
Date: 2007-01-16 04:40:27 -0800 (Tue, 16 Jan 2007)
Log Message:
-----------
* Time zone tab with time zone chooser partly working
Modified Paths:
--------------
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/time/cavern.py
Modified: pymoul/trunk/src/moul/qt/mainwindow.py
===================================================================
--- pymoul/trunk/src/moul/qt/mainwindow.py 2007-01-16 11:16:50 UTC (rev 33)
+++ pymoul/trunk/src/moul/qt/mainwindow.py 2007-01-16 12:40:27 UTC (rev 34)
@@ -1,10 +1,16 @@
import sys
-from PyQt4 import QtCore
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 moul.qt.ui.mainwindow import Ui_MainWindow
-from moul.time import cavern as caverntime
+from moul.time.cavern import CavernTime
+from moul.time.cavern import TIMEZONE_NAMES
class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
def __init__(self):
@@ -12,6 +18,46 @@
# Set up the user interface from Designer.
self.setupUi(self)
- # timezone
- self.cb_timezone_chooser.addItems(caverntime.TIMEZONE_NAMES)
+ self._timezone_init()
+
+ 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)
+
+ self._timezone_update()
+
+ def _timezone_update(self, ct=None):
+ """Update datetime widgets"""
+ if ct is None:
+ ct = self._caverntime()
+
+ self.dt_cavern.setDateTime(ct['cavern']['datetime'])
+ self.dt_local.setDateTime(ct['local']['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']
+ 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()
Modified: pymoul/trunk/src/moul/qt/ui/mainwindow.py
===================================================================
--- pymoul/trunk/src/moul/qt/ui/mainwindow.py 2007-01-16 11:16:50 UTC (rev 33)
+++ pymoul/trunk/src/moul/qt/ui/mainwindow.py 2007-01-16 12:40:27 UTC (rev 34)
@@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'src\moul\qt\ui\mainwindow.ui'
#
-# Created: Tue Jan 16 01:02:23 2007
+# Created: Tue Jan 16 12:47:17 2007
# by: PyQt4 UI code generator 4.1.1
#
# WARNING! All changes made in this file will be lost!
@@ -58,12 +58,6 @@
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.label = QtGui.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(15,10,430,58))
self.label.setFrameShape(QtGui.QFrame.StyledPanel)
@@ -290,6 +284,14 @@
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.setObjectName("gb_caverntime")
@@ -309,12 +311,13 @@
self.dt_cavern = QtGui.QDateTimeEdit(self.horizontalLayout_2)
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.label_3 = QtGui.QLabel(self.horizontalLayout_2)
- self.label_3.setObjectName("label_3")
- self.hboxlayout5.addWidget(self.label_3)
+ self.lb_cavern_utc = QtGui.QLabel(self.horizontalLayout_2)
+ self.lb_cavern_utc.setObjectName("lb_cavern_utc")
+ self.hboxlayout5.addWidget(self.lb_cavern_utc)
self.horizontalLayout_3 = QtGui.QWidget(self.gb_caverntime)
self.horizontalLayout_3.setGeometry(QtCore.QRect(20,70,261,31))
@@ -334,21 +337,13 @@
self.dt_local.setObjectName("dt_local")
self.hboxlayout6.addWidget(self.dt_local)
- self.label_11 = QtGui.QLabel(self.horizontalLayout_3)
- self.label_11.setObjectName("label_11")
- self.hboxlayout6.addWidget(self.label_11)
+ 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.gb_dnitime = QtGui.QGroupBox(self.tab_time)
self.gb_dnitime.setGeometry(QtCore.QRect(10,230,421,111))
self.gb_dnitime.setObjectName("gb_dnitime")
-
- 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.tabWidget.addTab(self.tab_time,"")
self.tab_4 = QtGui.QWidget()
@@ -359,6 +354,12 @@
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)
@@ -392,13 +393,13 @@
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.label_4.setText(QtGui.QApplication.translate("MainWindow", "Cavern time:", None, QtGui.QApplication.UnicodeUTF8))
- self.label_3.setText(QtGui.QApplication.translate("MainWindow", "UTC", 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.label_11.setText(QtGui.QApplication.translate("MainWindow", "UTC", None, QtGui.QApplication.UnicodeUTF8))
+ self.lb_local_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.gb_timezone.setTitle(QtGui.QApplication.translate("MainWindow", "Time Zone", 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))
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-16 11:16:50 UTC (rev 33)
+++ pymoul/trunk/src/moul/qt/ui/mainwindow.ui 2007-01-16 12:40:27 UTC (rev 34)
@@ -78,22 +78,6 @@
</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="QLabel" name="label" >
<property name="geometry" >
<rect>
@@ -564,6 +548,29 @@
<attribute name="title" >
<string>Time</string>
</attribute>
+ <widget class="QGroupBox" name="gb_timezone" >
+ <property name="geometry" >
+ <rect>
+ <x>10</x>
+ <y>10</y>
+ <width>421</width>
+ <height>81</height>
+ </rect>
+ </property>
+ <property name="title" >
+ <string>Time Zone</string>
+ </property>
+ <widget class="QComboBox" name="cb_timezone_chooser" >
+ <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>
@@ -604,10 +611,13 @@
<property name="readOnly" >
<bool>true</bool>
</property>
+ <property name="buttonSymbols" >
+ <enum>QAbstractSpinBox::UpDownArrows</enum>
+ </property>
</widget>
</item>
<item>
- <widget class="QLabel" name="label_3" >
+ <widget class="QLabel" name="lb_cavern_utc" >
<property name="text" >
<string>UTC</string>
</property>
@@ -646,7 +656,7 @@
</widget>
</item>
<item>
- <widget class="QLabel" name="label_11" >
+ <widget class="QLabel" name="lb_local_utc" >
<property name="text" >
<string>UTC</string>
</property>
@@ -668,29 +678,6 @@
<string>D'ni time</string>
</property>
</widget>
- <widget class="QGroupBox" name="gb_timezone" >
- <property name="geometry" >
- <rect>
- <x>10</x>
- <y>10</y>
- <width>421</width>
- <height>81</height>
- </rect>
- </property>
- <property name="title" >
- <string>Time Zone</string>
- </property>
- <widget class="QComboBox" name="cb_timezone_chooser" >
- <property name="geometry" >
- <rect>
- <x>10</x>
- <y>30</y>
- <width>271</width>
- <height>21</height>
- </rect>
- </property>
- </widget>
- </widget>
</widget>
<widget class="QWidget" name="tab_4" >
<attribute name="title" >
@@ -714,6 +701,22 @@
</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 11:16:50 UTC (rev 33)
+++ pymoul/trunk/src/moul/time/cavern.py 2007-01-16 12:40:27 UTC (rev 34)
@@ -17,10 +17,9 @@
#
"""pyMoul cavern time tool
"""
-__all__ = ['TIMEZONE_NAMES',]
+__all__ = ['TIMEZONE_NAMES', 'CavernTime']
from datetime import datetime
-from datetime import timedelta
#from pytz import common_timezones
from pytz import all_timezones
@@ -40,6 +39,9 @@
else:
unsupported.append(tz)
continue
+ split = tz.split('/')
+ if len(split) > 2:
+ continue
prefix, postfix = tz.split('/')[:2]
if prefix in SUPPORTED_TZ:
supported.append(tz)
@@ -57,8 +59,9 @@
CAVERN_TZ = timezone(CAVERN_TZ_NAME)
def diffTD(td1, td2):
- """Difference of two timedelta objects -> int
+ """Difference of two objects -> int
+ >>> from datetime import timedelta
>>> type(diffTD(timedelta(0, 3600), timedelta(0, -3600)))
<type 'int'>
>>> diffTD(timedelta(0, 3600), timedelta(0, -3600))
@@ -82,6 +85,8 @@
def td2int(td):
"""timedelta to int
+
+ >>> from datetime import timedelta
>>> td2int(timedelta(0, 3600))
3600
>>> td2int(timedelta(0, -3600))
@@ -100,41 +105,40 @@
cavern
datetime -- Current time in cavern TZ as <datetime> object
tz -- Cavern time zone object
- utcoffset -- (hours, fraction) offset from UTC
+ utcoffset -- (signum, hours, fraction) offset from UTC
cavern
datetime -- Current time in local TZ as <datetime> object
tz -- Local time zone object
- utcoffset -- (hours, fraction) offset from UTC
+ utcoffset -- (signum, hours, fraction) offset from UTC
>>> ct = CavernTime(local="Europe/Berlin")
>>> 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
+ >>> coff == ('-', -7, 0.0) or coff == ('-', -8, 0.0) or coff
True
>>> loff = result['local']['utcoffset']
- >>> loff == (1, 0.0) or loff == (2, 0.0) or loff
+ >>> loff == ('+', 1, 0.0) or loff == ('+', 2, 0.0) or loff
True
+
+ >>> 'UTC' in CavernTime.timezones
+ True
+ >>> 'UTC' in ct.timezones
+ True
"""
- _timezones = TIMEZONE_NAMES
+ timezones = TIMEZONE_NAMES
_cavern = CAVERN_TZ
_local = None
def __init__(self, local):
- self.setLocal(local)
+ self.setLocalTZ(local)
- def setLocal(self, local):
+ def setLocalTZ(self, local):
"""Set local time zone
"""
self._local = timezone(local)
- @property
- def timezones(self):
- """Available time zones as strings
- """
- return self._timezones
-
@staticmethod
def _utcnow():
"""Get current time in UTC
@@ -155,8 +159,9 @@
for id, tz in (('cavern', self._cavern), ('local', self._local)):
info = result.setdefault(id, {})
utcoffset = td2int(tz.utcoffset(now))
+ signum = utcoffset > 0 and '+' or '-'
info['tz'] = tz
- info['utcoffset'] = int(utcoffset/3600), float((utcoffset%3600)/3600.0)
+ info['utcoffset'] = signum,int(utcoffset/3600), float((utcoffset%3600)/3600.0)
info['datetime'] = self._normalize(tz, now)
result['utc'] = {'datetime' : now}
return result
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|