Make fuzzyclock code more concise.

Also use % formatting instead of string replace.
Translation files updated accordingly.
This commit is contained in:
Benjamin Richter 2009-09-07 20:23:35 +02:00
parent 378cdaeaf0
commit c3d5c8cca2
32 changed files with 67878 additions and 57538 deletions

4662
po/be.po

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

4627
po/bg.po

File diff suppressed because it is too large Load diff

4586
po/br.po

File diff suppressed because it is too large Load diff

2854
po/cs.po

File diff suppressed because it is too large Load diff

4638
po/da.po

File diff suppressed because it is too large Load diff

3434
po/de.po

File diff suppressed because it is too large Load diff

4667
po/el.po

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

4660
po/eo.po

File diff suppressed because it is too large Load diff

4477
po/es.po

File diff suppressed because it is too large Load diff

4674
po/eu.po

File diff suppressed because it is too large Load diff

4559
po/fr.po

File diff suppressed because it is too large Load diff

4664
po/gl.po

File diff suppressed because it is too large Load diff

4561
po/hr.po

File diff suppressed because it is too large Load diff

4672
po/it.po

File diff suppressed because it is too large Load diff

4753
po/lt.po

File diff suppressed because it is too large Load diff

4539
po/nb.po

File diff suppressed because it is too large Load diff

4638
po/nl.po

File diff suppressed because it is too large Load diff

4539
po/no.po

File diff suppressed because it is too large Load diff

2829
po/pl.po

File diff suppressed because it is too large Load diff

4680
po/pt.po

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

2167
po/ru.po

File diff suppressed because it is too large Load diff

3473
po/sk.po

File diff suppressed because it is too large Load diff

4637
po/sr.po

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

3491
po/sv.po

File diff suppressed because it is too large Load diff

2175
po/uk.po

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -4,6 +4,7 @@
## Copyright (C) 2006 Christoph Neuroth <delmonico AT gmx.net> ## Copyright (C) 2006 Christoph Neuroth <delmonico AT gmx.net>
## Copyright (C) 2006-2007 Yann Leboulanger <asterix AT lagaule.org> ## Copyright (C) 2006-2007 Yann Leboulanger <asterix AT lagaule.org>
## Copyright (C) 2007 Jean-Marie Traissard <jim AT lapin.org> ## Copyright (C) 2007 Jean-Marie Traissard <jim AT lapin.org>
## Copyright (C) 2009 Benjamin Richter <br AT waldteufel-online.net>
## ##
## This file is part of Gajim. ## This file is part of Gajim.
## ##
@ -22,10 +23,10 @@
''' '''
Python class to show a "fuzzy clock". Python class to show a "fuzzy clock".
Homepage: http://home.gna.org/fuzzyclock/ Homepage of the original: http://home.gna.org/fuzzyclock/
Project Page: http://gna.org/projects/fuzzyclock Project Page of the original: http://gna.org/projects/fuzzyclock
The class has been ported from PHP code by The class is based on a port from PHP code by
Henrique Recidive <henrique at recidive.com> which was Henrique Recidive <henrique at recidive.com> which was
in turn based on the Fuzzy Clock Applet of Frerich Raabe (KDE). in turn based on the Fuzzy Clock Applet of Frerich Raabe (KDE).
So most of the credit goes to this guys, thanks :-) So most of the credit goes to this guys, thanks :-)
@ -34,105 +35,39 @@ So most of the credit goes to this guys, thanks :-)
import time import time
class FuzzyClock: class FuzzyClock:
def __init__(self): HOUR_NAMES = [ _('twelve'), _('one'), _('two'), _('three'), _('four'),
self.__hour = 0 _('five'), _('six'), _('seven'), _('eight'), _('nine'), _('ten'),
self.__minute = 0 _('eleven') ]
self.__dayOfWeek = 0
self.__hourNames = [ _('one'), _('two'), _('three'), _('four'), _('five'), _('six'), #Strings to use for the output. %(0)s will be replaced with the preceding hour
_('seven'), _('eight'), _('nine'), _('ten'), _('eleven'), #(e.g. "x PAST %(0)s"), %(1)s with the coming hour (e.g. "x TO %(0)s"). '''
_('twelve')] FUZZY_TIME = [ _("%(0)s o'clock"), _('five past %(0)s'), _('ten past %(0)s'),
_('quarter past %(0)s'), _('twenty past %(0)s'), _('twenty five past %(0)s'),
_('half past %(0)s'), _('twenty five to %(1)s'), _('twenty to %(1)s'),
_('quarter to %(1)s'), _('ten to %(1)s'), _('five to %(1)s'), _("%(1)s o'clock") ]
#Strings to use for the output. $0 will be replaced with the preceding hour (e.g. "x PAST $0"), $1 with the coming hour (e.g. "x TO $1). ''' FUZZY_DAYTIME = [ _('Night'), _('Early morning'), _('Morning'),
self.__normalFuzzy = [ _("$0 o'clock"), _('five past $0'), _('Almost noon'), _('Noon'), _('Afternoon'), _('Evening'),
_('ten past $0'), _('quarter past $0'), _('Late evening'), _('Night') ]
_('twenty past $0'), _('twenty five past $0'),
_('half past $0'), _('twenty five to $1'),
_('twenty to $1'), _('quarter to $1'),
_('ten to $1'), _('five to $1'), _("$1 o'clock") ]
#A "singular-form". It is used when talking about hour 0 FUZZY_WEEK = [ _('Start of week'), _('Middle of week'), _('Middle of week'),
self.__normalFuzzyOne = [ _("$0 o'clock"), _('five past $0'), _('Middle of week'), _('End of week'), _('Weekend!'), _('Weekend!') ]
_('ten past $0'), _('quarter past $0'),
_('twenty past $0'), _('twenty five past $0'),
_('half past $0'), _('twenty five to $1'),
_('twenty to $1'), _('quarter to $1'),
_('ten to $1'), _('five to $1'),
_("$1 o'clock") ]
self.__dayTime = [ _('Night'), _('Early morning'), _('Morning'), _('Almost noon'),
_('Noon'), _('Afternoon'), _('Evening'), _('Late evening') ]
self.__fuzzyWeek = [ _('Start of week'), _('Middle of week'), _('End of week'),
_('Weekend!') ]
self.setCurrent()
def setHour(self,hour):
self.__hour = int(hour)
def setMinute(self,minute):
self.__minute=int(minute)
def setDayOfWeek(self,day):
self.__dayOfWeek=int(day)
def setTime(self,time):
timeArray = time.split(":")
self.setHour(timeArray[0])
self.setMinute(timeArray[1])
def setCurrent(self):
hour=time.strftime("%H")
minute=time.strftime("%M")
day=time.strftime("%w")
self.setTime(hour+":"+minute)
self.setDayOfWeek(day)
def getFuzzyTime(self, fuzzyness = 1):
sector = 0
realHour = 0
def fuzzy_time(self, fuzzyness, now):
if fuzzyness == 1 or fuzzyness == 2: if fuzzyness == 1 or fuzzyness == 2:
if fuzzyness == 1: if fuzzyness == 1:
if self.__minute >2: sector = int(round(now.tm_min / 5.0))
sector = (self.__minute - 3) / 5 +1
else: else:
if self.__minute > 6: sector = int(round(now.tm_min / 15.0)) * 3
sector = ((self.__minute - 7) / 15 + 1) * 3
newTimeStr = self.__normalFuzzy[sector]
#$0 or $1?
deltaHour = int(newTimeStr[newTimeStr.find("$")+1])
if (self.__hour + deltaHour) % 12 > 0:
realHour = (self.__hour + deltaHour) % 12 - 1
else:
realHour = 12 - ((self.__hour + deltaHour) % 12 + 1)
if realHour == 0:
newTimeStr = self.__normalFuzzyOne[sector]
newTimeStr = newTimeStr.replace("$"+str(deltaHour),
self.__hourNames[realHour])
return self.FUZZY_TIME[sector] % {
'0': self.HOUR_NAMES[now.tm_hour % 12],
'1': self.HOUR_NAMES[(now.tm_hour + 1) % 12]}
elif fuzzyness == 3: elif fuzzyness == 3:
newTimeStr = self.__dayTime[self.__hour / 3] return self.FUZZY_DAYTIME[int(round(now.tm_hour / 3.0))]
else: else:
dayOfWeek = self.__dayOfWeek return self.FUZZY_WEEK[now.tm_wday]
if dayOfWeek == 1:
newTimeStr = self.__fuzzyWeek[0]
elif dayOfWeek >= 2 and dayOfWeek <= 4:
newTimeStr = self.__fuzzyWeek[1]
elif dayOfWeek == 5:
newTimeStr = self.__fuzzyWeek[2]
else:
newTimeStr = self.__fuzzyWeek[3]
return newTimeStr
# vim: se ts=3: # vim: se ts=3:

View file

@ -179,6 +179,9 @@ class ConversationTextview(gobject.GObject):
gobject.GObject.__init__(self) gobject.GObject.__init__(self)
self.used_in_history_window = used_in_history_window self.used_in_history_window = used_in_history_window
self.fc = FuzzyClock()
# no need to inherit TextView, use it as atrribute is safer # no need to inherit TextView, use it as atrribute is safer
self.tv = HtmlTextView() self.tv = HtmlTextView()
self.tv.html_hyperlink_handler = self.html_hyperlink_handler self.tv.html_hyperlink_handler = self.html_hyperlink_handler
@ -1178,9 +1181,7 @@ class ConversationTextview(gobject.GObject):
self.last_time_printout = time.mktime(tim) self.last_time_printout = time.mktime(tim)
end_iter = buffer_.get_end_iter() end_iter = buffer_.get_end_iter()
if gajim.config.get('print_time_fuzzy') > 0: if gajim.config.get('print_time_fuzzy') > 0:
fc = FuzzyClock() ft = self.fc.fuzzy_time(gajim.config.get('print_time_fuzzy'), tim)
fc.setTime(time.strftime('%H:%M', tim))
ft = fc.getFuzzyTime(gajim.config.get('print_time_fuzzy'))
tim_format = ft.decode(locale.getpreferredencoding()) tim_format = ft.decode(locale.getpreferredencoding())
else: else:
tim_format = self.get_time_to_show(tim) tim_format = self.get_time_to_show(tim)