Beispiel #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])
Beispiel #2
0
 def save(self, widget=None):
     self.get_window().set_cursor(gdk.Cursor(gdk.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'%(core.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(gdk.LEFT_PTR))
     self.hide()
Beispiel #3
0
 def save(self, path):
     print 'save', path
     self.setCursor(qc.Qt.WaitCursor)
     #while gtk.events_pending():## FIXME
     #    gtk.main_iteration_do(False)
     if path in (None, ''):
         return
     print 'Exporting to html file "%s"'%path
     i = self.combo.currentIndex()
     months = []
     module = core.modules[core.primaryMode]
     if i==0:
         s = getCurrentMonthStatus()
         months = [s]
         title = '%s %s'%(core.getMonthName(core.primaryMode, s.month, s.year), _(s.year))
     elif i==1:
         for i in xrange(1, 13):
             months.append(getMonthStatus(ui.cell.year, i))
         title = '%s %s'%(_('Calendar'), _(ui.cell.year))
     elif i==2:
         y0, m0 = self.ymBox0.getYM()
         y1, m1 = self.ymBox1.getYM()
         for ym in xrange(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.setCursor(qc.Qt.ArrowCursor)
     self.hide()
Beispiel #4
0
 def build(self, mode):
     active = self.get_active()
     ls = self.get_model()
     ls.clear()
     for m in range(1, 13):
         ls.append([core.getMonthName(mode, m)])
     if active is not None:
         self.set_active(active)
Beispiel #5
0
 def __init__(self, rule):
     self.rule = rule
     ###
     gtk.HBox.__init__(self)
     ###
     self.buttons = []
     mode = self.rule.getMode()
     for i in range(12):
         b = gtk.ToggleButton(_(i+1))
         set_tooltip(b, core.getMonthName(mode, i+1))
         pack(self, b)
         self.buttons.append(b)
Beispiel #6
0
 def trayUpdate(self, gdate=None, checkDate=True):## FIXME
     if gdate==None:
         gdate = localtime()[:3]
     if self.lastGDate!=gdate or not checkDate:
         jd = core.modules[core.DATE_GREG].to_jd(*gdate)
         if core.primaryMode==core.DATE_GREG:
             ddate = gdate
         else:
             ddate = core.modules[core.primaryMode].jd_to(jd)
         self.lastGDate = gdate
         ui.todayCell = ui.cellCache.getTodayCell()
         imPath = ui.trayImageHoli if ui.todayCell.holiday else ui.trayImage
         self.pmap.load(imPath)
         try:
             self.painter.end()
         except:
             pass
         self.painter.begin(self.pmap)
         w = self.pmap.width()
         h = self.pmap.height()
         self.painter.drawText(qc.QPoint(0, h-2), _(ddate[2]))
         self.iconT.setPixmap(self.pmap)
         self.icon.setWidget(self.iconT)
         #self.icon.setGeometry(qc.QRectF(0, 0, w, h))
         #self.iconT.setGeometry(qc.QRect(0, 0, w, h))
         self.iconT.setFixedWidth(w)
         #self.iconT.setFixedHeight(h)
         ## position of left lower corner of text ^^
         ## trayTextColor, ui.trayFont, ui.fontUseDefault ??????
         ####################
         wd = core.getWeekDay(*ddate)
         tt = core.getWeekDayN(wd)
         #if ui.pluginsTextTray:##?????????
         #    sep = _(',')+' '
         #else:
         sep = u'<br>'
         for item in ui.shownCals:
             if item['enable']:
                 mode = item['mode']
                 (y, m, d) = ui.todayCell.dates[mode]
                 tt += u'%s%s %s %s'%(sep, _(d), core.getMonthName(mode, m), _(y))
         if ui.pluginsTextTray:
             text = ui.todayCell.pluginsText
             if text!='':
                 tt += u'%s%s'%(sep, text.replace(u'\t', sep)) #????????????
         if rtl:## tags: div, p, body
             tt = u'<p dir="rtl">%s</p>'%tt
         #else:
         #    tt = '<p dir="ltr">%s</p>'%tt
         self.tooltipContent.setMainText('') ## self.name
         self.tooltipContent.setSubText(tt)
         self.tooltipMgr.setContent(self.papplet.applet, self.tooltipContent)
     return True
Beispiel #7
0
 def getTrayTooltip(self):
     ##tt = core.weekDayName[core.getWeekDay(*ddate)]
     tt = core.weekDayName[core.jwday(ui.todayCell.jd)]
     #if ui.pluginsTextTray:##?????????
     #    sep = _(',')+' '
     #else:
     sep = '\n'
     for mode in calTypes.active:
         y, m, d = ui.todayCell.dates[mode]
         tt += '%s%s %s %s'%(sep, _(d), getMonthName(mode, m, y), _(y))
     if ui.pluginsTextTray:
         text = ui.todayCell.pluginsText
         if text!='':
             tt += '\n\n%s'%text ## .replace('\t', '\n') ## FIXME
     return tt
Beispiel #8
0
 def getTrayTooltip(self):
     ##tt = core.weekDayName[core.getWeekDay(*ddate)]
     tt = core.weekDayName[core.jwday(ui.todayCell.jd)]
     #if ui.pluginsTextTray:##?????????
     #    sep = _(',')+' '
     #else:
     sep = '\n'
     for mode in calTypes.active:
         y, m, d = ui.todayCell.dates[mode]
         tt += '%s%s %s %s'%(sep, _(d), getMonthName(mode, m, y), _(y))
     if ui.pluginsTextTray:
         text = ui.todayCell.pluginsText
         if text!='':
             tt += '\n\n%s'%text ## .replace('\t', '\n') ## FIXME
     for item in ui.todayCell.eventsData:
         if not item['showInTray']:
             continue
         itemS = ''
         if item['time']:
             itemS += item['time'] + ' - '
         itemS += item['text'][0]
         tt += '\n\n%s'%itemS
     return tt
Beispiel #9
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
        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
Beispiel #10
0
 def getText(self):
     return getMonthName(self.mode, self.parent.dates[self.mode][1])
Beispiel #11
0
 def changeMode(self, mode):
     if mode!=self.rule.getMode():
         for i in range(12):
             set_tooltip(self.buttons[i], core.getMonthName(mode, i+1))
Beispiel #12
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
Beispiel #13
0
 def _calPaintEvent(self, event):
   status = self.computeCurrentMonth()
   self.yearLabel.setText(qloc.toString(self.year))
   self.monthLabel.setText(core.getMonthName(self.mode, self.month, self.year))
   w = self.cal.width()
   h = self.cal.height()
   self.calW = w
   self.calH = h
   rtl = self._rtl()
   if rtl:
     self.cx = [ (w-self.leftMargin)*(13.0-2*i)/14.0\
                 for i in xrange(7) ] ## centers x
   else:
     self.cx = [self.leftMargin + (w-self.leftMargin)*(1.0+2*i)/14.0\
                for i in xrange(7) ] ## centers x
   self.cy = [self.topMargin + (h-self.topMargin)*(1.0+2*i)/12.0\
              for i in xrange(6) ] ## centers y
   self.dx = (w-self.leftMargin)/7.0 ## delta x
   self.dy = (h-self.topMargin)/6.0 ## delta y
   self.gx = [x + self._rtlSgn()*self.dx/2.0 for x in self.cx] ## grid x
   self.gy = [y - self.dy/2.0 for y in self.cy] ## grid y
   #######
   painter = qt.QPainter()
   painter.begin(self.cal)
   painter.setPen(self.bgColor)
   painter.setBrush(self.bgColor)
   painter.drawRect(0, 0, w, h)
   painter.setPen(self.normDayColor)
   painter.setBrush(self.normDayColor)#???
   for x in self.gx:
     painter.drawLine(x, 0, x, h)
   for y in self.gy:
     painter.drawLine(0, y, w, y)
   #######
   sx, sy = self.cell.pos
   if self.cursorBgColor!=None:
     painter.setBrush(self.cursorBgColor)
     painter.setPen(qt.QPen(qt.QBrush(self.cursorBgColor), 0, qc.Qt.SolidLine, qc.Qt.RoundCap))
     painter.drawRoundedRect(self.gx[sx]-rtl*self.dx, self.gy[sy],
       self.dx, self.dy, self.cursorR, self.cursorR)
   ###
   if self.cursorInColor!=None:
     painter.setBrush(self.cursorInColor)
     painter.setPen(qt.QPen(qt.QBrush(self.cursorInColor), 0, qc.Qt.SolidLine, qc.Qt.RoundCap))
     painter.drawRoundedRect(self.gx[sx]-rtl*self.dx+self.cursorD/2.0, self.gy[sy]+self.cursorD/2.0,
       self.dx-self.cursorD, self.dy-self.cursorD, self.cursorR, self.cursorR)
   #######
   painter.setPen(self.borderTextColor)
   for i in range(7):
     painter.drawText(qc.QRectF(self.gx[i]-rtl*self.dx, 0, self.dx, self.topMargin),
       qc.Qt.AlignCenter, self.getWeekDayName(i))
   for j in range(6):
     painter.drawText(qc.QRectF(self.gx[0]-(1-rtl)*self.leftMargin,
       self.gy[j], self.leftMargin, self.dy),
       qc.Qt.AlignCenter, qloc.toString(status.weekNum[j]))
   #######
   for i in range(7):
     for j in range(6):
       cell = status[j][i]
       if cell.gray:
         painter.setPen(self.inactiveDayColor)
       elif cell.holiday:
         painter.setPen(self.holidayColor)
       else:
         painter.setPen(self.normDayColor)
       painter.drawText(qc.QRectF(self.gx[i]-rtl*self.dx, self.gy[j], self.dx, self.dy),
         qc.Qt.AlignCenter, qloc.toString(cell.date[2]))
   #######
   painter.end()
Beispiel #14
0
 def __init__(self, parent=None, mode=None):
   qt.QWidget.__init__(self, parent)
   #super(self.__class__, self).__init__(parent)## if no class will be derived from this widget
   self.months = {}
   if mode is None:
       mode = core.primaryMode
   self.mode = mode
   y, m, d = core.getSysDate()
   self.year = y
   self.month = m
   self.day = d
   self.today = (y, m, d)
   self.computeCurrentMonth()
   ###########
   self.labelBox = qt.QWidget()
   self.cal = qt.QWidget()
   labelBoxL = qt.QHBoxLayout()
   labelBoxL.setContentsMargins(1, 1, 1, 1) ## left, top, right, bottom
   #####
   self.prevYearButton = qt.QPushButton('-')
   self.prevYearButton.setToolTip(_('Previous Year'))
   labelBoxL.addWidget(self.prevYearButton)
   #####
   self.yearLabel = qt.QLabel(qloc.toString(y))
   labelBoxL.addWidget(self.yearLabel)
   #####
   self.nextYearButton = qt.QPushButton('+')
   self.nextYearButton.setToolTip(_('Next Year'))
   labelBoxL.addWidget(self.nextYearButton)
   #####
   labelBoxL.addSpacing(30)
   #####
   self.prevMonthButton = qt.QPushButton('-')
   self.prevMonthButton.setToolTip(_('Previous Month'))
   labelBoxL.addWidget(self.prevMonthButton)
   #####
   self.monthLabel = qt.QLabel(core.getMonthName(self.mode, m, y))
   labelBoxL.addWidget(self.monthLabel)
   #####
   self.nextMonthButton = qt.QPushButton('+')
   self.nextMonthButton.setToolTip(_('Next Month'))
   labelBoxL.addWidget(self.nextMonthButton)
   #####
   self.labelBox.setLayout(labelBoxL)
   #####
   vbox = qt.QVBoxLayout()
   vbox.setContentsMargins(0, 0, 0, 0) ## left, top, right, bottom
   self.labelBox.setSizePolicy(qt.QSizePolicy(qt.QSizePolicy.Fixed, qt.QSizePolicy.Fixed))
   ## (Fixed,Fixed) or (Preferred,Fixed)
   vbox.addWidget(self.labelBox)
   vbox.addWidget(self.cal)
   self.setLayout(vbox)
   #####
   self.prevYearButton.connect(self.prevYearButton, qc.SIGNAL('clicked()'), self._prevYearClicked)
   self.nextYearButton.connect(self.nextYearButton, qc.SIGNAL('clicked()'), self._nextYearClicked)
   self.prevMonthButton.connect(self.prevMonthButton, qc.SIGNAL('clicked()'), self._prevMonthClicked)
   self.nextMonthButton.connect(self.nextMonthButton, qc.SIGNAL('clicked()'), self._nextMonthClicked)
   #####
   self.resize(self.calW, self.calH)
   self.cal.paintEvent = self._calPaintEvent
   self.cal.mousePressEvent = self.calMousePressEvent
   self.cal.keyPressEvent = self.keyPressEvent
Beispiel #15
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
Beispiel #16
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