[Pymoul-svn] SF.net SVN: pymoul: [193] pymoul/trunk/src/moul
Status: Alpha
Brought to you by:
tiran
|
From: <ti...@us...> - 2007-02-26 15:16:26
|
Revision: 193
http://pymoul.svn.sourceforge.net/pymoul/?rev=193&view=rev
Author: tiran
Date: 2007-02-26 07:16:22 -0800 (Mon, 26 Feb 2007)
Log Message:
-----------
Changed the way a DniTime object is constructed. It now uses several class methods as constructor
Modified Paths:
--------------
pymoul/trunk/src/moul/qt/dninumbers.py
pymoul/trunk/src/moul/time/dni.py
Modified: pymoul/trunk/src/moul/qt/dninumbers.py
===================================================================
--- pymoul/trunk/src/moul/qt/dninumbers.py 2007-02-26 15:05:28 UTC (rev 192)
+++ pymoul/trunk/src/moul/qt/dninumbers.py 2007-02-26 15:16:22 UTC (rev 193)
@@ -63,7 +63,6 @@
# D'ni numbers
self.dninumbers = QDniNumbers()
self.caverntime = CavernTime()
- self.dnitime = DniTime()
self.setup_dninumbers()
# D'ni date and time
@@ -137,10 +136,10 @@
"""
SIGNAL: QTimer timeout
"""
- self.dnitime.fromUTC()
- self.clockscene.setClockFromDniTime(self.dnitime)
- self.setWidgetDniTime(self.dnitime)
- self.dte_earthtime.setDateTime(dt2qdt(self.dnitime.toUTC()))
+ dni = DniTime.fromUTC()
+ self.clockscene.setClockFromDniTime(dni)
+ self.setWidgetDniTime(dni)
+ self.dte_earthtime.setDateTime(dt2qdt(dni.toUTC()))
@pyqtSignature("bool")
def on_rb_curtime_clicked(self, value):
@@ -189,6 +188,7 @@
self.update_dniholidays()
@pyqtSignature("const QDateTime &")
+ @skipLogging
def on_dte_earthtime_dateTimeChanged(self, qdt):
if self.rb_earthtime.isChecked():
self.update_earthtime()
@@ -198,17 +198,17 @@
"""
if not self.rb_dnitime.isChecked():
return
- self.dnitime.set(*self.getWidgetDniTime())
- self.clockscene.setClockFromDniTime(self.dnitime)
- self.dte_earthtime.setDateTime(dt2qdt(self.dnitime.toUTC()))
+ dni = DniTime.fromDni(*self.getWidgetDniTime())
+ self.clockscene.setClockFromDniTime(dni)
+ self.dte_earthtime.setDateTime(dt2qdt(dni.toUTC()))
def update_earthtime(self):
"""Update view from earth time widget
"""
dt = qdt2dt(self.dte_earthtime.dateTime())
- self.dnitime.fromUTC(dt)
- self.clockscene.setClockFromDniTime(self.dnitime)
- self.setWidgetDniTime(self.dnitime)
+ dni = DniTime.fromUTC(dt)
+ self.clockscene.setClockFromDniTime(dni)
+ self.setWidgetDniTime(dni)
def update_dniholidays(self):
"""Update view from D'ni holiday widget
Modified: pymoul/trunk/src/moul/time/dni.py
===================================================================
--- pymoul/trunk/src/moul/time/dni.py 2007-02-26 15:05:28 UTC (rev 192)
+++ pymoul/trunk/src/moul/time/dni.py 2007-02-26 15:16:22 UTC (rev 193)
@@ -42,8 +42,7 @@
... else:
... return True
->>> dni = DniTime()
->>> dni.fromUTC(LEEFO_1_TABLE[1])
+>>> dni = DniTime.fromUTC(LEEFO_1_TABLE[1])
>>> dni.get()
(9655, 1, 1, 0, 0, 0, 0)
>>> str(dni)
@@ -52,7 +51,7 @@
True
>>> other = datetime(2007, 2, 12, 13, 55, 10, 0, tzinfo=UTC)
->>> dni.fromUTC(other)
+>>> dni = DniTime.fromUTC(other)
>>> dni.get()
(9662, 9, 4, 4, 21, 24, 22)
>>> str(dni)
@@ -69,13 +68,13 @@
80964
>>> CET = timezone('CET')
->>> dni.fromString("2007-02-12 14:55:10", tzinfo=CET)
+>>> dni = DniTime.fromString("2007-02-12 14:55:10", tzinfo=CET)
>>> str(dni)
'04:21:24:22, Leevotar 4, 9662'
->>> dni.fromString("2007-02-12 6:55:10", tzinfo='MST')
+>>> dni = DniTime.fromString("2007-02-12 6:55:10", tzinfo='MST')
>>> str(dni)
'04:21:24:22, Leevotar 4, 9662'
->>> dni.fromString("2007-02-12 13:55:10")
+>>> dni = DniTime.fromString("2007-02-12 13:55:10")
>>> str(dni)
'04:21:24:22, Leevotar 4, 9662'
@@ -199,46 +198,66 @@
prorahn second about 1.3929 seconds
"""
- def __init__(self, hahr=0, vailee=0, yahr=0, gahrtahvo=0, tahvo=0,
- gorahn=0, prorahn=0):
- self.set(hahr, vailee, yahr, gahrtahvo, tahvo, gorahn, prorahn)
-
- def set(self, hahr=0, vailee=0, yahr=0, gahrtahvo=0, tahvo=0,
- gorahn=0, prorahn=0):
+ def __init__(self, _initialize=False):
+ if not _initialize:
+ raise TypeError("You can't construct an instance this way!")
self._hahr = 0
self._prorahn = 0
- self.hahr = hahr
- self.vailee = vailee
- self.yahr = yahr
- self.gahrtahvo = gahrtahvo
- self.tahvo = tahvo
- self.gorahn = gorahn
- self._addProrahn(prorahn)
+ @classmethod
+ def fromDni(cls, hahr=0, vailee=0, yahr=0, gahrtahvo=0, tahvo=0,
+ gorahn=0, prorahn=0):
+ """Constructor from D'ni time
+ """
+ self = cls(_initialize=True)
+ self.set(hahr=0, vailee=0, yahr=0, gahrtahvo=0, tahvo=0,
+ gorahn=0, prorahn=0)
+ return self
- def get(self):
- return (self.hahr, self.vailee, self.yahr, self.gahrtahvo, self.tahvo,
- self.gorahn, self.prorahn)
+ @classmethod
+ def fromUTC(cls, utc_dt=None):
+ """Constructor from UTC date time object
- def fromUTC(self, utc_dt=None):
- """Convert from UTC datetime
+ Convert from UTC datetime
"""
+ self = cls(_initialize=True)
if utc_dt is None:
utc_dt = utcnow()
sec = td2sec(utc_dt - BASE_GREGORIAN)
prorahn = int(round(sec * FACTOR_PS))
self.set(hahr=BASE_HAHR, prorahn=prorahn)
+ return self
- def fromString(self, s, fmt="%Y-%m-%d %H:%M:%S", tzinfo=UTC):
- """Convert date from string to Dni Time
+ @classmethod
+ def fromString(cls, s, fmt="%Y-%m-%d %H:%M:%S", tzinfo=UTC):
+ """Constructor from date time string
+
+ Convert date from string to Dni Time
"""
if isinstance(tzinfo, basestring):
tzinfo = timezone(tzinfo)
dt = datetime.strptime(s, fmt)
dt = tzinfo.localize(dt)
utc_dt = UTC.normalize(dt.astimezone(UTC))
- return self.fromUTC(utc_dt)
+ return cls.fromUTC(utc_dt)
+ def set(self, hahr=0, vailee=0, yahr=0, gahrtahvo=0, tahvo=0,
+ gorahn=0, prorahn=0):
+ self._hahr = 0
+ self._prorahn = 0
+
+ self.hahr = hahr
+ self.vailee = vailee
+ self.yahr = yahr
+ self.gahrtahvo = gahrtahvo
+ self.tahvo = tahvo
+ self.gorahn = gorahn
+ self._addProrahn(prorahn)
+
+ def get(self):
+ return (self.hahr, self.vailee, self.yahr, self.gahrtahvo, self.tahvo,
+ self.gorahn, self.prorahn)
+
def toUTC(self):
"""Convert to UTC datetime value
"""
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|