Example #1
0
class MonthNameObject(TextObject):
	def __init__(self, parent, mode, x=0, y=0, color=(0,0,0), font=None):
		TextObject.__init__(self, parent, x, y, color, font)
		self.mode = mode
	getText = lambda self: getMonthName(self.mode, self.parent.dates[self.mode][1])
Example #2
0
def calcTimeLineData(timeStart, timeWidth, pixelPerSec, borderTm):
    timeEnd = timeStart + timeWidth
    jd0 = getJdFromEpoch(timeStart)
    jd1 = getJdFromEpoch(timeEnd)
    widthDays = float(timeWidth) / dayLen
    dayPixel = dayLen * pixelPerSec  ## px
    #print('dayPixel = %s px'%dayPixel)
    getEPos = lambda epoch: (epoch - timeStart) * pixelPerSec
    getJPos = lambda jd: (getEpochFromJd(jd) - timeStart) * pixelPerSec
    ######################## Holidays
    holidays = []
    if changeHolidayBg and changeHolidayBgMinDays < widthDays < changeHolidayBgMaxDays:
        for jd in getHolidaysJdList(jd0, jd1 + 1):
            holidays.append(getJPos(jd))
    ######################## Ticks
    ticks = []
    tickEpochList = []
    minStep = minorStepMin / pixelPerSec  ## second
    #################
    year0, month0, day0 = jd_to_primary(jd0)
    year1, month1, day1 = jd_to_primary(jd1)
    ############ Year
    minStepYear = minStep // minYearLenSec  ## years ## int or iceil?
    yearPixel = minYearLenSec * pixelPerSec  ## pixels
    for (year, size) in getYearRangeTickValues(year0, year1 + 1, minStepYear):
        tmEpoch = getEpochFromDate(year, 1, 1, calTypes.primary)
        if tmEpoch in tickEpochList:
            continue
        unitSize = size * yearPixel
        label = formatYear(year) if unitSize >= majorStepMin else ''
        ticks.append(Tick(
            tmEpoch,
            getEPos(tmEpoch),
            unitSize,
            label,
        ))
        tickEpochList.append(tmEpoch)
    ############ Month
    monthPixel = avgMonthLen * pixelPerSec  ## px
    minMonthUnit = float(minStep) / avgMonthLen  ## month
    if minMonthUnit <= 3:
        for ym in range(year0 * 12 + month0 - 1,
                        year1 * 12 + month1 - 1 + 1):  ## +1 FIXME
            if ym % 3 == 0:
                monthUnit = 3
            else:
                monthUnit = 1
            if monthUnit < minMonthUnit:
                continue
            y, m = divmod(ym, 12)
            m += 1
            tmEpoch = getEpochFromDate(y, m, 1, calTypes.primary)
            if tmEpoch in tickEpochList:
                continue
            unitSize = monthPixel * monthUnit
            ticks.append(
                Tick(
                    tmEpoch,
                    getEPos(tmEpoch),
                    unitSize,
                    getMonthName(calTypes.primary, m)
                    if unitSize >= majorStepMin else '',
                ))
            tickEpochList.append(tmEpoch)
    ################
    if showWeekStart and showWeekStartMinDays < widthDays < showWeekStartMaxDays:
        wd0 = jwday(jd0)
        jdw0 = jd0 + (core.firstWeekDay - wd0) % 7
        unitSize = dayPixel * 7
        if unitSize < majorStepMin:
            label = ''
        else:
            label = core.weekDayNameAb[core.firstWeekDay]
        for jd in range(jdw0, jd1 + 1, 7):
            tmEpoch = getEpochFromJd(jd)
            ticks.append(
                Tick(
                    tmEpoch,
                    getEPos(tmEpoch),
                    unitSize,
                    label,
                    color=weekStartTickColor,
                ))
            #tickEpochList.append(tmEpoch)
    ############ Day of Month
    hasMonthName = timeWidth < 5 * dayLen
    minDayUnit = float(minStep) / dayLen  ## days
    if minDayUnit <= 15:
        for jd in range(jd0, jd1 + 1):
            tmEpoch = getEpochFromJd(jd)
            if tmEpoch in tickEpochList:
                continue
            year, month, day = jd_to_primary(jd)
            if day == 16:
                dayUnit = 15
            elif day in (6, 11, 21, 26):
                dayUnit = 5
            else:
                dayUnit = 1
            if dayUnit < minDayUnit:
                continue
            unitSize = dayPixel * dayUnit
            if unitSize < majorStepMin:
                label = ''
            elif hasMonthName:
                label = _(day) + ' ' + getMonthName(calTypes.primary, month)
            else:
                label = _(day)
            ticks.append(Tick(
                tmEpoch,
                getEPos(tmEpoch),
                unitSize,
                label,
            ))
            tickEpochList.append(tmEpoch)
    ############ Hour, Minute, Second
    for stepUnit, stepValue in unitSteps:
        stepSec = stepUnit * stepValue
        if stepSec < minStep:
            break
        unitSize = stepSec * pixelPerSec
        utcOffset = int(getUtcOffsetCurrent())
        firstEpoch = iceil(
            (timeStart + utcOffset) / stepSec) * stepSec - utcOffset
        for tmEpoch in range(firstEpoch, iceil(timeEnd), stepSec):
            if tmEpoch in tickEpochList:
                continue
            if unitSize < majorStepMin:
                label = ''
            else:
                jd, h, m, s = getJhmsFromEpoch(tmEpoch)
                if s == 0:
                    label = '%s:%s' % (
                        _(h),
                        _(m, fillZero=2),
                    )
                else:  # elif timeWidth < 60 or stepSec < 30:
                    label = addLRM('%s"' % _(s, fillZero=2))
                #else:
                #    label = '%s:%s:%s'%(
                #        _(h),
                #        _(m, fillZero=2),
                #        _(s, fillZero=2),
                #    )
            ticks.append(Tick(
                tmEpoch,
                getEPos(tmEpoch),
                unitSize,
                label,
            ))
            tickEpochList.append(tmEpoch)
    ######################## Event Boxes
    data = {
        'holidays': holidays,
        'ticks': ticks,
        'boxes': [],
    }
    ###
    data['boxes'] = calcEventBoxes(
        timeStart,
        timeEnd,
        pixelPerSec,
        borderTm,
    )
    ###
    return data
Example #3
0
def getMonthDesc(status=None):
    if not status:
        status = getCurrentMonthStatus()
    first = None
    last = None
    for i in range(6):
        for j in range(7):
            c = status[i][j]
            if first:
                if c.month == status.month:
                    last = c
                else:
                    break
            else:
                if c.month == status.month:
                    first = c
                else:
                    continue
    text = ''
    for mode in calTypes.active:
        if text != '':
            text += '\n'
        if mode == calTypes.primary:
            y, m = first.dates[mode][:2]  ## = (status.year, status.month)
            text += '%s %s' % (getMonthName(mode, m), _(y))
        else:
            y1, m1 = first.dates[mode][:2]
            y2, m2 = last.dates[mode][:2]
            dy = y2 - y1
            if dy == 0:
                dm = m2 - m1
            elif dy == 1:
                dm = m2 + 12 - m1
            else:
                raise RuntimeError('y1=%d, m1=%d, y2=%d, m2=%d' %
                                   (y1, m1, y2, m2))
            if dm == 0:
                text += '%s %s' % (getMonthName(mode, m1), _(y1))
            elif dm == 1:
                if dy == 0:
                    text += '%s %s %s %s' % (
                        getMonthName(mode, m1),
                        _('and'),
                        getMonthName(mode, m2),
                        _(y1),
                    )
                else:
                    text += '%s %s %s %s %s' % (
                        getMonthName(mode, m1),
                        _(y1),
                        _('and'),
                        getMonthName(mode, m2),
                        _(y2),
                    )
            elif dm == 2:
                if dy == 0:
                    text += '%s%s %s %s %s %s' % (
                        getMonthName(mode, m1),
                        _(','),
                        getMonthName(mode, m1 + 1),
                        _('and'),
                        getMonthName(mode, m2),
                        _(y1),
                    )
                else:
                    if m1 == 11:
                        text += '%s %s %s %s %s %s %s' % (
                            getMonthName(mode, m1),
                            _('and'),
                            getMonthName(mode, m1 + 1),
                            _(y1),
                            _('and'),
                            getMonthName(mode, 1),
                            _(y2),
                        )
                    elif m1 == 12:
                        text += '%s %s %s %s %s %s %s' % (
                            getMonthName(mode, m1),
                            _(y1),
                            _('and'),
                            getMonthName(mode, 1),
                            _('and'),
                            getMonthName(mode, 2),
                            _(y2),
                        )
    return text
Example #4
0
def getMonthDesc(status=None):
	if not status:
		status = getCurrentMonthStatus()
	first = None
	last = None
	for i in range(6):
		for j in range(7):
			c = status[i][j]
			if first:
				if c.month == status.month:
					last = c
				else:
					break
			else:
				if c.month == status.month:
					first = c
				else:
					continue
	text = ''
	for mode in calTypes.active:
		if text != '':
			text += '\n'
		if mode==calTypes.primary:
			y, m = first.dates[mode][:2] ## = (status.year, status.month)
			text += '%s %s'%(getMonthName(mode, m), _(y))
		else:
			y1, m1 = first.dates[mode][:2]
			y2, m2 = last.dates[mode][:2]
			dy = y2 - y1
			if dy==0:
				dm = m2 - m1
			elif dy==1:
				dm = m2 + 12 - m1
			else:
				raise RuntimeError('y1=%d, m1=%d, y2=%d, m2=%d'%(y1, m1, y2, m2))
			if dm==0:
				text += '%s %s'%(getMonthName(mode, m1), _(y1))
			elif dm==1:
				if dy==0:
					text += '%s %s %s %s'%(
						getMonthName(mode, m1),
						_('and'),
						getMonthName(mode, m2),
						_(y1),
					)
				else:
					text += '%s %s %s %s %s'%(
						getMonthName(mode, m1),
						_(y1),
						_('and'),
						getMonthName(mode, m2),
						_(y2),
					)
			elif dm==2:
				if dy==0:
					text += '%s%s %s %s %s %s'%(
						getMonthName(mode, m1),
						_(','),
						getMonthName(mode, m1+1),
						_('and'),
						getMonthName(mode, m2),
						_(y1),
					)
				else:
					if m1==11:
						text += '%s %s %s %s %s %s %s'%(
							getMonthName(mode, m1),
							_('and'),
							getMonthName(mode, m1+1),
							_(y1),
							_('and'),
							getMonthName(mode, 1),
							_(y2),
						)
					elif m1==12:
						text += '%s %s %s %s %s %s %s'%(
							getMonthName(mode, m1),
							_(y1),
							_('and'),
							getMonthName(mode, 1),
							_('and'),
							getMonthName(mode, 2),
							_(y2),
						)
	return text
Example #5
0
	def getText(self):
		return getMonthName(self.mode, self.parent.dates[self.mode][1])
Example #6
0
def calcTimeLineData(timeStart, timeWidth, pixelPerSec, borderTm):
    timeEnd = timeStart + timeWidth
    jd0 = getJdFromEpoch(timeStart)
    jd1 = getJdFromEpoch(timeEnd)
    widthDays = float(timeWidth) / dayLen
    dayPixel = dayLen * pixelPerSec ## px
    #print('dayPixel = %s px'%dayPixel)
    getEPos = lambda epoch: (epoch-timeStart)*pixelPerSec
    getJPos = lambda jd: (getEpochFromJd(jd)-timeStart)*pixelPerSec
    ######################## Holidays
    holidays = []
    if changeHolidayBg and changeHolidayBgMinDays < widthDays < changeHolidayBgMaxDays:
        for jd in getHolidaysJdList(jd0, jd1+1):
            holidays.append(getJPos(jd))
    ######################## Ticks
    ticks = []
    tickEpochList = []
    minStep = minorStepMin / pixelPerSec ## second
    #################
    year0, month0, day0 = jd_to_primary(jd0)
    year1, month1, day1 = jd_to_primary(jd1)
    ############ Year
    minStepYear = minStep // minYearLenSec ## years ## int or iceil?
    yearPixel = minYearLenSec * pixelPerSec ## pixels
    for (year, size) in getYearRangeTickValues(year0, year1+1, minStepYear):
        tmEpoch = getEpochFromDate(year, 1, 1, calTypes.primary)
        if tmEpoch in tickEpochList:
            continue
        unitSize = size * yearPixel
        label = formatYear(year) if unitSize >= majorStepMin else ''
        ticks.append(Tick(
            tmEpoch,
            getEPos(tmEpoch),
            unitSize,
            label,
        ))
        tickEpochList.append(tmEpoch)
    ############ Month
    monthPixel = avgMonthLen * pixelPerSec ## px
    minMonthUnit = float(minStep) / avgMonthLen ## month
    if minMonthUnit <= 3:
        for ym in range(year0*12+month0-1, year1*12+month1-1+1):## +1 FIXME
            if ym%3==0:
                monthUnit = 3
            else:
                monthUnit = 1
            if monthUnit < minMonthUnit:
                continue
            y, m = divmod(ym, 12) ; m+=1
            tmEpoch = getEpochFromDate(y, m, 1, calTypes.primary)
            if tmEpoch in tickEpochList:
                continue
            unitSize = monthPixel * monthUnit
            ticks.append(Tick(
                tmEpoch,
                getEPos(tmEpoch),
                unitSize,
                getMonthName(calTypes.primary, m) if unitSize >= majorStepMin else '',
            ))
            tickEpochList.append(tmEpoch)
    ################
    if showWeekStart and showWeekStartMinDays < widthDays < showWeekStartMaxDays:
        wd0 = jwday(jd0)
        jdw0 = jd0 + (core.firstWeekDay - wd0) % 7
        unitSize = dayPixel * 7
        if unitSize < majorStepMin:
            label = ''
        else:
            label = core.weekDayNameAb[core.firstWeekDay]
        for jd in range(jdw0, jd1+1, 7):
            tmEpoch = getEpochFromJd(jd)
            ticks.append(Tick(
                tmEpoch,
                getEPos(tmEpoch),
                unitSize,
                label,
                color=weekStartTickColor,
            ))
            #tickEpochList.append(tmEpoch)
    ############ Day of Month
    hasMonthName = timeWidth < 5 * dayLen
    minDayUnit = float(minStep) / dayLen ## days
    if minDayUnit <= 15:
        for jd in range(jd0, jd1+1):
            tmEpoch = getEpochFromJd(jd)
            if tmEpoch in tickEpochList:
                continue
            year, month, day = jd_to_primary(jd)
            if day==16:
                dayUnit = 15
            elif day in (6, 11, 21, 26):
                dayUnit = 5
            else:
                dayUnit = 1
            if dayUnit < minDayUnit:
                continue
            unitSize = dayPixel*dayUnit
            if unitSize < majorStepMin:
                label = ''
            elif hasMonthName:
                label = _(day) + ' ' + getMonthName(calTypes.primary, month)
            else:
                label = _(day)
            ticks.append(Tick(
                tmEpoch,
                getEPos(tmEpoch),
                unitSize,
                label,
            ))
            tickEpochList.append(tmEpoch)
    ############ Hour, Minute, Second
    for stepUnit, stepValue in unitSteps:
        stepSec = stepUnit*stepValue
        if stepSec < minStep:
            break
        unitSize = stepSec*pixelPerSec
        utcOffset = int(getUtcOffsetCurrent())
        firstEpoch = iceil((timeStart+utcOffset) / stepSec) * stepSec - utcOffset
        for tmEpoch in range(firstEpoch, iceil(timeEnd), stepSec):
            if tmEpoch in tickEpochList:
                continue
            if unitSize < majorStepMin:
                label = ''
            else:
                jd, h, m, s = getJhmsFromEpoch(tmEpoch)
                if s==0:
                    label = '%s:%s'%(
                        _(h),
                        _(m, fillZero=2),
                    )
                else:# elif timeWidth < 60 or stepSec < 30:
                    label = addLRM('%s"'%_(s, fillZero=2))
                #else:
                #    label = '%s:%s:%s'%(
                #        _(h),
                #        _(m, fillZero=2),
                #        _(s, fillZero=2),
                #    )
            ticks.append(Tick(
                tmEpoch,
                getEPos(tmEpoch),
                unitSize,
                label,
            ))
            tickEpochList.append(tmEpoch)
    ######################## Event Boxes
    data = {
        'holidays': holidays,
        'ticks': ticks,
        'boxes': [],
    }
    ###
    data['boxes'] = calcEventBoxes(
        timeStart,
        timeEnd,
        pixelPerSec,
        borderTm,
    )
    ###
    return data
Example #7
0
 def getText(self):
     return getMonthName(self.mode, self.parent.dates[self.mode][1])