def _save(self, path): comboItem = self.combo.get_active() months = [] module = calTypes.primaryModule() if comboItem == 0: s = getCurrentMonthStatus() months = [s] title = "%s %s" % ( locale_man.getMonthName( calTypes.primary, s.month, s.year, ), _(s.year), ) elif comboItem == 1: for i in range(1, 13): months.append(getMonthStatus(ui.cell.year, i)) title = "%s %s" % (_("Calendar"), _(ui.cell.year)) elif comboItem == 2: y0, m0 = self.ymBox0.get_value() y1, m1 = self.ymBox1.get_value() for ym in range(y0 * 12 + m0 - 1, y1 * 12 + m1): y, m = divmod(ym, 12) m += 1 months.append(getMonthStatus(y, m)) title = _("Calendar") exportToHtml(path, months, title) self.hide()
def save(self, widget=None): self.get_window().set_cursor(gdk.Cursor.new(gdk.CursorType.WATCH)) while gtk.events_pending(): gtk.main_iteration_do(False) path = self.fcw.get_filename() if path in (None, ''): return print('Exporting to html file "%s"'%path) i = self.combo.get_active() months = [] module = calTypes.primaryModule() if i==0: s = getCurrentMonthStatus() months = [s] title = '%s %s'%(locale_man.getMonthName(calTypes.primary, s.month, s.year), _(s.year)) elif i==1: for i in range(1, 13): months.append(getMonthStatus(ui.cell.year, i)) title = '%s %s'%(_('Calendar'), _(ui.cell.year)) elif i==2: y0, m0 = self.ymBox0.get_value() y1, m1 = self.ymBox1.get_value() for ym in range(y0*12+m0-1, y1*12+m1): y, m = divmod(ym, 12) m += 1 months.append(getMonthStatus(y, m)) title = _('Calendar') exportToHtml(path, months, title) self.get_window().set_cursor(gdk.Cursor.new(gdk.CursorType.LEFT_PTR)) self.hide()
def __init__(self, jd): self.eventsData = [] # self.eventsDataIsSet = False ## not used self.pluginsText = "" ### self.jd = jd date = core.jd_to_primary(jd) self.year, self.month, self.day = date self.weekDay = core.jwday(jd) self.weekNum = core.getWeekNumber(self.year, self.month, self.day) # self.weekNumNeg = self.weekNum + 1 - core.getYearWeeksCount(self.year) self.weekNumNeg = self.weekNum - int(calTypes.primaryModule().avgYearLen / 7) self.holiday = self.weekDay in core.holidayWeekDays ################### self.dates = [date if mode == calTypes.primary else jd_to(jd, mode) for mode in range(len(calTypes))] """ self.dates = dict([ ( mode, date if mode==calTypes.primary else jd_to(jd, mode) ) for mode in calTypes.active ]) """ ################### for k in core.plugIndex: plug = core.allPlugList[k] if plug: try: plug.update_cell(self) except: myRaiseTback() ################### # t0 = now() self.eventsData = event_lib.getDayOccurrenceData(jd, eventGroups) ## here? FIXME
def __init__(self, jd): self.eventsData = [] # self.eventsDataIsSet = False # not used self.pluginsText = "" ### self.jd = jd date = core.jd_to_primary(jd) self.year, self.month, self.day = date self.weekDay = core.jwday(jd) self.weekNum = core.getWeekNumber(self.year, self.month, self.day) # self.weekNumNeg = self.weekNum+1 - core.getYearWeeksCount(self.year) self.weekNumNeg = self.weekNum - int( calTypes.primaryModule().avgYearLen / 7 ) self.holiday = (self.weekDay in core.holidayWeekDays) ################### self.dates = [ date if mode == calTypes.primary else jd_to(jd, mode) for mode in range(len(calTypes)) ] """ self.dates = dict([ ( mode, date if mode==calTypes.primary else jd_to(jd, mode) ) for mode in calTypes.active ]) """ ################### for k in core.plugIndex: plug = core.allPlugList[k] if plug: try: plug.updateCell(self) except: myRaiseTback() ################### # t0 = now() self.eventsData = event_lib.getDayOccurrenceData( jd, eventGroups, ) # here? FIXME """
i = sys.exc_info() typ, value, tback = sys.exc_info() text = 'line %s: %s: %s\n'%(tback.tb_lineno, typ.__name__, value) if File: text = 'File "%s", '%File + text log.error(text) ################################################################################ ####################### class and function defenitions ######################### ################################################################################ popen_output = lambda cmd: Popen(cmd, stdout=subprocess.PIPE).communicate()[0] primary_to_jd = lambda y, m, d: calTypes.primaryModule().to_jd(y, m, d) jd_to_primary = lambda jd: calTypes.primaryModule().jd_to(jd) def getCurrentJd():## time.time() and mktime(localtime()) both return GMT, not local y, m, d = localtime()[:3] return calTypes[DATE_GREG].to_jd(y, m, d) def getWeekDateHmsFromEpoch(epoch): jd, hour, minute, sec = getJhmsFromEpoch(epoch) absWeekNumber, weekDay = getWeekDateFromJd(jd) return (absWeekNumber, weekDay, hour, minute, sec) def getMonthWeekNth(jd, mode): year, month, day = calTypes[mode].jd_to(jd) absWeekNumber, weekDay = getWeekDateFromJd(jd) ##
def jd_to_primary(jd): return calTypes.primaryModule().jd_to(jd)
def primary_to_jd(y, m, d): return calTypes.primaryModule().to_jd(y, m, d)
def onDraw(self, widget=None, event=None): cr = self.get_window().cairo_create() width = float(self.get_allocation().width) height = float(self.get_allocation().height) dia = min(width, height) maxR = float(dia) / 2.0 minR = self.innerCircleRatio * maxR x0 = (width - dia) / 2.0 y0 = (height - dia) / 2.0 cx = x0 + maxR cy = y0 + maxR #### #self.angleOffset #self.bgColor #self.wheelBgColor #self.lineColor #self.lineWidth #self.textColor #### cr.rectangle(0, 0, width, height) fillColor(cr, self.bgColor) #### calsN = len(calTypes.active) deltaR = (maxR - minR) / float(calsN) mode0 = calTypes.active[0] jd0 = to_jd(ui.todayCell.year, 1, 1, mode0) yearLen = calTypes.primaryModule().avgYearLen angle0 = self.angleOffset * pi / 180.0 - pi / 2.0 avgDeltaAngle = 2 * pi / 12 #### if self.todayIndicatorEnable: drawLineLengthAngle( cr, cx, cy, maxR, ## FIXME angle0 + 2.0 * pi * (ui.todayCell.jd - jd0) / yearLen, self.todayIndicatorWidth, ) fillColor(cr, self.todayIndicatorColor) #### drawCircle(cr, cx, cy, self.centerR) fillColor(cr, self.centerColor) #### drawCircleOutline(cr, cx, cy, maxR, maxR - minR) fillColor(cr, self.wheelBgColor) #### spinngJd = getSpringJdAfter(jd0) springAngle = angle0 + 2.0 * pi * (spinngJd - jd0) / yearLen ## radians for index, color in enumerate(( self.springColor, self.summerColor, self.autumnColor, self.winterColor, )): drawArcOutline( cr, cx, cy, maxR, maxR - minR, springAngle + index * pi / 2.0, springAngle + (index + 1) * pi / 2.0, ) fillColor(cr, color) #### for index, mode in enumerate(calTypes.active): dr = index * deltaR r = maxR - dr cx0 = x0 + dr cy0 = y0 + dr ### drawCircleOutline(cr, cx, cy, r, self.lineWidth) fillColor(cr, self.lineColor) #### year0, month0, day0 = jd_to(jd0, mode) ym0 = year0 * 12 + (month0 - 1) cr.set_line_width(self.lineWidth) for ym in range(ym0, ym0 + 12): year, month = divmod(ym, 12) month += 1 jd = to_jd(year, month, 1, mode) angle = angle0 + 2.0 * pi * (jd - jd0) / yearLen ## radians #angleD = angle * 180 / pi #print('mode=%s, year=%s, month=%s, angleD=%.1f'%(mode, year, month, angleD)) d = self.lineWidth sepX, sepY = goAngle( cx, cy, angle, r - d * 0.2, ## FIXME ) drawLineLengthAngle( cr, sepX, sepY, deltaR - d * 0.2, ## FIXME angle + pi, d, ) fillColor( cr, self.yearStartLineColor if month == 1 else self.lineColor, ) ### layoutMaxW = (r - deltaR) * 2.0 * pi / 12.0 layoutMaxH = deltaR layout = newTextLayout( self, text=getMonthName(mode, month, year), maxSize=(layoutMaxW, layoutMaxH), maximizeScale=0.6, truncate=False, ) layoutW, layoutH = layout.get_pixel_size() centerAngle = angle + avgDeltaAngle / 2.0 lx, ly = goAngle( cx, cy, centerAngle, (r - deltaR / 3.0), ) lx, ly = goAngle( lx, ly, angle - pi / 2.0, layoutW / 2.0, ) lx, ly = goAngle( lx, ly, angle, layoutH / 2.0, ) cr.move_to( lx, ly, ) #cr.save() rotateAngle = centerAngle + pi / 2.0 cr.rotate(rotateAngle) setColor(cr, self.textColor) show_layout(cr, layout) cr.rotate(-rotateAngle) #cr.restore() ##### drawCircleOutline(cr, cx, cy, minR, self.lineWidth) fillColor(cr, self.lineColor)
def onDraw(self, widget=None, event=None): cr = self.get_window().cairo_create() width = float(self.get_allocation().width) height = float(self.get_allocation().height) dia = min(width, height) maxR = float(dia) / 2.0 minR = self.innerCircleRatio * maxR x0 = (width - dia) / 2.0 y0 = (height - dia) / 2.0 cx = x0 + maxR cy = y0 + maxR #### #self.angleOffset #self.bgColor #self.wheelBgColor #self.lineColor #self.lineWidth #self.textColor #### cr.rectangle(0, 0, width, height) fillColor(cr, self.bgColor) #### calsN = len(calTypes.active) deltaR = (maxR - minR) / float(calsN) mode0 = calTypes.active[0] jd0 = to_jd(ui.todayCell.year, 1, 1, mode0) yearLen = calTypes.primaryModule().avgYearLen angle0 = self.angleOffset * pi / 180.0 - pi/2.0 avgDeltaAngle = 2*pi / 12 #### if self.todayIndicatorEnable: drawLineLengthAngle( cr, cx, cy, maxR,## FIXME angle0 + 2.0*pi*(ui.todayCell.jd - jd0)/yearLen, self.todayIndicatorWidth, ) fillColor(cr, self.todayIndicatorColor) #### drawCircle(cr, cx, cy, self.centerR) fillColor(cr, self.centerColor) #### drawCircleOutline(cr, cx, cy, maxR, maxR-minR) fillColor(cr, self.wheelBgColor) #### spinngJd = getSpringJdAfter(jd0) springAngle = angle0 + 2.0*pi*(spinngJd - jd0)/yearLen ## radians for index, color in enumerate(( self.springColor, self.summerColor, self.autumnColor, self.winterColor, )): drawArcOutline( cr, cx, cy, maxR, maxR-minR, springAngle + index * pi/2.0, springAngle + (index+1) * pi/2.0, ) fillColor(cr, color) #### for index, mode in enumerate(calTypes.active): dr = index * deltaR r = maxR - dr cx0 = x0 + dr cy0 = y0 + dr ### drawCircleOutline(cr, cx, cy, r, self.lineWidth) fillColor(cr, self.lineColor) #### year0, month0, day0 = jd_to(jd0, mode) ym0 = year0*12 + (month0-1) cr.set_line_width(self.lineWidth) for ym in range(ym0, ym0 + 12): year, month = divmod(ym, 12) ; month += 1 jd = to_jd(year, month, 1, mode) angle = angle0 + 2.0*pi*(jd - jd0)/yearLen ## radians #angleD = angle * 180 / pi #print('mode=%s, year=%s, month=%s, angleD=%.1f'%(mode, year, month, angleD)) d = self.lineWidth sepX, sepY = goAngle( cx, cy, angle, r - d*0.2,## FIXME ) drawLineLengthAngle( cr, sepX, sepY, deltaR - d*0.2,## FIXME angle + pi, d, ) fillColor( cr, self.yearStartLineColor if month==1 else self.lineColor, ) ### layoutMaxW = (r - deltaR) * 2.0 * pi / 12.0 layoutMaxH = deltaR layout = newTextLayout( self, text=getMonthName(mode, month, year), maxSize=(layoutMaxW, layoutMaxH), maximizeScale=0.6, truncate=False, ) layoutW, layoutH = layout.get_pixel_size() centerAngle = angle + avgDeltaAngle/2.0 lx, ly = goAngle( cx, cy, centerAngle, (r - deltaR/3.0), ) lx, ly = goAngle( lx, ly, angle - pi/2.0, layoutW / 2.0, ) lx, ly = goAngle( lx, ly, angle, layoutH / 2.0, ) cr.move_to( lx, ly, ) #cr.save() rotateAngle = centerAngle + pi/2.0 cr.rotate(rotateAngle) setColor(cr, self.textColor) ; show_layout(cr, layout) cr.rotate(-rotateAngle) #cr.restore() ##### drawCircleOutline(cr, cx, cy, minR, self.lineWidth) fillColor(cr, self.lineColor)
def myRaise(File=None): i = sys.exc_info() typ, value, tback = sys.exc_info() text = 'line %s: %s: %s\n' % (tback.tb_lineno, typ.__name__, value) if File: text = 'File "%s", ' % File + text log.error(text) ################################################################################ ####################### class and function defenitions ######################### ################################################################################ popen_output = lambda cmd: Popen(cmd, stdout=subprocess.PIPE).communicate()[0] primary_to_jd = lambda y, m, d: calTypes.primaryModule().to_jd(y, m, d) jd_to_primary = lambda jd: calTypes.primaryModule().jd_to(jd) def getCurrentJd( ): ## time.time() and mktime(localtime()) both return GMT, not local y, m, d = localtime()[:3] return calTypes[DATE_GREG].to_jd(y, m, d) def getWeekDateHmsFromEpoch(epoch): jd, hour, minute, sec = getJhmsFromEpoch(epoch) absWeekNumber, weekDay = getWeekDateFromJd(jd) return (absWeekNumber, weekDay, hour, minute, sec)