def currentTimeUpdate(self, restart=False, draw=True): if restart: try: source_remove(self.timeUpdateSourceId) except AttributeError: pass try: pixelPerSec = self.pixelPerSec except AttributeError: pixelPerSec = 1 seconds = iceil(0.4 / pixelPerSec) tm = now() #print('time=%.2f'%(tm%100), 'pixelPerSec=%.1f'%pixelPerSec, 'seconds=%d'%seconds) miliSeconds = int(1000 * (seconds + 0.01 - tm % 1)) miliSeconds = min(miliSeconds, 4294967295) # to avoid: OverflowError: %d not in range 0 to 4294967295 self.timeUpdateSourceId = timeout_add( miliSeconds, self.currentTimeUpdate, ) self.currentTime = int(tm) if draw and self.get_parent(): if self.get_parent().get_visible() and \ self.timeStart <= tm <= self.timeStart + self.timeWidth + 1: #print('%.2f'%(tm%100), 'currentTimeUpdate: DRAW') self.queue_draw()
def jd_to(jd): ## hijriAlg==0 if hijriUseDB: #jd = ifloor(jd) date = monthDb.getDateFromJd(jd) if date: return date year = ifloor(((30 * (jd - 1 - epoch)) + 10646) // 10631) month = min(12, iceil((jd - (29 + to_jd_c(year, 1, 1))) / 29.5) + 1) day = jd - to_jd_c(year, month, 1) + 1 return year, month, day
def jd_to(jd): ## hijriAlg==0 if hijriUseDB: #jd = ifloor(jd) date = monthDb.getDateFromJd(jd) if date: return date ##jd = ifloor(jd) + 0.5 year = ((30 * (jd - epoch)) + 10646) // 10631 month = min( 12, iceil( (jd - (29 + to_jd(year, 1, 1))) / 29.5 ) + 1 ) day = jd - to_jd(year, month, 1) + 1 return year, month, day
def currentTimeUpdate(self, restart=False, draw=True): if restart: try: source_remove(self.timeUpdateSourceId) except AttributeError: pass try: pixelPerSec = self.pixelPerSec except AttributeError: pixelPerSec = 1 seconds = iceil(0.4/pixelPerSec) tm = now() #print('time=%.2f'%(tm%100), 'pixelPerSec=%.1f'%pixelPerSec, 'seconds=%d'%seconds) self.timeUpdateSourceId = timeout_add( int(1000*(seconds + 0.01 - tm%1)), self.currentTimeUpdate, ) self.currentTime = int(tm) if draw and self.get_parent(): if self.get_parent().get_visible() and \ self.timeStart <= tm <= self.timeStart + self.timeWidth + 1: #print('%.2f'%(tm%100), 'currentTimeUpdate: DRAW') self.queue_draw()
return jd = monthDb.startJd for ymi in range(ym0, ym): jd += monthDb.monthLenByYm[ymi] return jd + day - 1 monthDb = MonthDbHolder() monthDb.load() ## monthDb.save() ################################################################################ is_leap = lambda year: (((year * 11) + 14) % 30) < 11 to_jd_c = lambda year, month, day:\ day + iceil(29.5 * (month - 1)) + \ (year - 1) * 354 + \ (11*year + 3) // 30 + \ epoch def to_jd(year, month, day): if hijriUseDB:## and hijriAlg==0 jd = monthDb.getJdFromDate(year, month, day) if jd is not None: return jd return to_jd_c(year, month, day) def jd_to(jd): ## hijriAlg==0 if hijriUseDB: #jd = ifloor(jd)
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 firstEpoch = iceil(timeStart/stepSec)*stepSec 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 = LRM + '%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
jd = monthDb.startJd for ymi in range(ym0, ym): jd += monthDb.monthLenByYm[ymi] return jd + day - 1 monthDb = MonthDbHolder() monthDb.load() ## monthDb.save() ################################################################################ isLeap = lambda year: (((year * 11) + 14) % 30) < 11 to_jd_c = lambda year, month, day:\ day + iceil(29.5 * (month - 1)) + \ (year - 1) * 354 + \ (11*year + 3) // 30 + \ epoch def to_jd(year, month, day): if hijriUseDB: ## and hijriAlg==0 jd = monthDb.getJdFromDate(year, month, day) if jd is not None: return jd return to_jd_c(year, month, day) def jd_to(jd): ## hijriAlg==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 = LRM + '%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