7 from pretty_time
import month_name
, str_time
9 def memo_from_node(node
):
10 assert node
.localName
== 'memo'
13 v
= node
.getAttribute(attr
)
14 if v
== 'True': return True
15 if v
== 'False': return False
21 state
= node
.getAttribute('state')
22 if state
is None or state
== "":
27 time
, = node
.getElementsByTagName('time')
28 message
, = node
.getElementsByTagName('message')
31 soundnode
= node
.getElementsByTagName('sound')
32 if len(soundnode
) == 1:
33 if len(soundnode
[0].childNodes
) == 1:
34 soundfile
= soundnode
[0].childNodes
[0].nodeValue
35 if soundnode
[0].hasAttribute('disabled'):
38 message
= ''.join([n
.nodeValue
for n
in message
.childNodes
])
40 return Memo(float(time
.childNodes
[0].nodeValue
),
41 message
, flag('at'), state
, flag('hidden'), soundfile
, nosound
)
43 class Memo(gobject
.GObject
):
45 # Constants for memo 'state' attribute:
50 # 'time' is seconds since epoch
51 # 'at' is TRUE if the time of day matters
52 def __init__(self
, time
, message
, at
, state
= READY
, hidden
= 0, \
53 soundfile
= None, nosound
= False):
54 self
.__gobject
_init
__()
56 assert at
== 0 or at
== 1
57 assert state
== Memo
.READY
or state
== Memo
.EARLY
or state
== Memo
.DONE
58 assert hidden
== 0 or hidden
== 1
61 self
.message
= message
.strip()
65 self
.brief
= self
.message
.split('\n', 1)[0]
66 self
.soundfile
= soundfile
67 self
.nosound
= nosound
70 now_y
, now_m
, now_d
= time
.localtime(time
.time() + 5 * 60)[:3]
73 year
, month
, day
, hour
, min = time
.localtime(self
.time
)[:5]
77 return '%s-%d' % (month_name
[month
][:3], year
)
79 if month
!= now_m
or day
!= now_d
:
80 return '%02d-%s' % (day
, month_name
[month
][:3])
83 return str_time(hour
, min)
87 def comes_after(self
, other
):
88 return self
.time
> other
.time
90 def save(self
, parent
):
91 doc
= parent
.ownerDocument
93 node
= doc
.createElement('memo')
94 node
.setAttribute('at', str(self
.at
))
95 node
.setAttribute('state', self
.state
)
96 node
.setAttribute('hidden', str(self
.hidden
))
97 parent
.appendChild(node
)
99 time
= doc
.createElement('time')
100 time
.appendChild(doc
.createTextNode(str(self
.time
)))
101 node
.appendChild(time
)
103 message
= doc
.createElement('message')
104 message
.appendChild(doc
.createTextNode(self
.message
))
105 node
.appendChild(message
)
107 if self
.nosound
or (self
.soundfile
is not None and self
.soundfile
!= ""):
108 sound
= doc
.createElement('sound')
110 sound
.setAttribute('disabled', "True")
112 sound
.appendChild(doc
.createTextNode(self
.soundfile
))
113 node
.appendChild(sound
)
115 def set_hidden(self
, hidden
):
116 assert hidden
== 0 or hidden
== 1