def formatDateTime(view, dt): syncDay = calendar.DateTimeUtil.shortDateFormat.format(view, dt) syncTime = calendar.formatTime(view, dt) text = "%s at %s" % (syncDay, syncTime) return text
def DrawDayEvents(self, gc, dayBounds, dateToRender, fontColor, day): # draw events eventTop = dayBounds.top + self.stringHeight block = self.blockItem view = block.itsView primaryCollection = block.contentsCollection maxTimeStr = "23" gc.SetFont(self._timeFont) maxHourWidth = gc.GetTextExtent(maxTimeStr)[0] gc.SetFont(self._superscriptFont) maxMinuteWidth = gc.GetTextExtent(maxTimeStr)[0] noonStrokeWidth = maxMinuteWidth + maxHourWidth noonStrokeDrawn = False drawNoonStroke = False oneDay = timedelta(1) gc.Clip(*dayBounds) for event in self.dayToEvents[dateToRender.date()]: eventTitle = event.itsItem.displayName if event.allDay: eventTitle = event.itsItem.displayName extraWidth = 1 gc.SetPen(self._zeroPen) collection = block.getContainingCollection( event.itsItem, primaryCollection) colorInfo = ColorInfo(collection) # GradientLeft GradientRight Outline Text # ============ ============= ======= ==== ## defaultColors [(204, 0, 0), (255, 50, 50), (255, 50, 50), (255, 255, 255)] ## defaultFYIColors [(255, 226, 226), (255, 242, 242), (255, 50, 50), (204, 0, 0)] ## selectedColors [(127, 0, 0), (204, 0, 0), (204, 0, 0), (255, 255, 255)] ## selectedFYIColors [(255, 170, 170), (255, 216, 216), (255, 50, 50), (204, 0, 0)] ## visibleColors [(255, 170, 170), (255, 170, 170), (255, 170, 170), (204, 0, 0)] ## visibleFYIColors [(255, 242, 242), (255, 242, 242), (255, 216, 216), (204, 0, 0)] if dateToRender.month != self._month: gc.SetFont(self._font, self._otherMonthColour) bgColour = wx.Colour(*colorInfo.defaultFYIColors[0]) else: gc.SetFont(self._textFont, colorInfo.selectedColors[3]) bgColour = wx.Colour(*colorInfo.defaultColors[1]) #gc.SetBrush(wx.Brush(wx.Colour(colorInfo.defaultColors[1]))) # workaround - the line above always gives black bgColour.alpha = 128 gc.SetBrush(wx.Brush(bgColour)) gc.DrawRoundedRectangle(dayBounds.left, eventTop, dayBounds.width, self.stringHeight, self.stringHeight / 2) DrawClippedText( gc, eventTitle, dayBounds.left + extraWidth + self.stringHeight / 2, eventTop, dayBounds.width - extraWidth - 1 - self.stringHeight / 2) eventTop += self.stringHeight #if (event.startTime + event.duration).date() <= dateToRender.date(): # self._multiDayEvents.remove(event) continue elif event.anyTime: extraWidth = 1 else: drawNoonStroke = True gc.SetFont(self._timeFont, fontColor) timeStr = formatTime(view, event.startTime, justHour=True) timeWidth = gc.GetTextExtent(timeStr)[0] gc.DrawText(timeStr, dayBounds.left, eventTop) if event.startTime.minute != 0: minuteStr = "%02d" % event.startTime.minute gc.SetFont(self._superscriptFont, fontColor) gc.DrawText(minuteStr, dayBounds.left + timeWidth, eventTop) timeWidth += gc.GetTextExtent(minuteStr)[0] else: timeWidth += 2 extraWidth = timeWidth + TIME_PADDING if dateToRender.month != self._month: gc.SetFont(self._font, self._otherMonthColour) else: collection = block.getContainingCollection( event.itsItem, primaryCollection) colorInfo = ColorInfo(collection) gc.SetFont(self._textFont, colorInfo.selectedColors[0]) # gc.DrawClippedRect is occasionally off by a pixel, so give # extra margin. DrawClippedText(gc, eventTitle, dayBounds.left + extraWidth, eventTop, dayBounds.width - extraWidth - 1) if (drawNoonStroke and not noonStrokeDrawn and event.startTime.hour >= 12): gc.SetPen(self._noonStrokePen) gc.StrokeLine(dayBounds.left, int(eventTop), dayBounds.left + noonStrokeWidth, int(eventTop)) noonStrokeDrawn = True eventTop += self.stringHeight if drawNoonStroke and not noonStrokeDrawn: gc.SetPen(self._noonStrokePen) gc.StrokeLine(dayBounds.left, int(eventTop), dayBounds.left + noonStrokeWidth, int(eventTop)) gc.ResetClip()
def DrawDayEvents(self, gc, dayBounds, dateToRender, fontColor, day): # draw events eventTop = dayBounds.top + self.stringHeight block = self.blockItem view = block.itsView primaryCollection = block.contentsCollection maxTimeStr = "23" gc.SetFont(self._timeFont) maxHourWidth = gc.GetTextExtent(maxTimeStr)[0] gc.SetFont(self._superscriptFont) maxMinuteWidth = gc.GetTextExtent(maxTimeStr)[0] noonStrokeWidth = maxMinuteWidth + maxHourWidth noonStrokeDrawn = False drawNoonStroke = False oneDay = timedelta(1) gc.Clip(*dayBounds) for event in self.dayToEvents[dateToRender.date()]: eventTitle = event.itsItem.displayName if event.allDay: eventTitle = event.itsItem.displayName extraWidth = 1 gc.SetPen(self._zeroPen) collection = block.getContainingCollection(event.itsItem, primaryCollection) colorInfo = ColorInfo(collection) # GradientLeft GradientRight Outline Text # ============ ============= ======= ==== ## defaultColors [(204, 0, 0), (255, 50, 50), (255, 50, 50), (255, 255, 255)] ## defaultFYIColors [(255, 226, 226), (255, 242, 242), (255, 50, 50), (204, 0, 0)] ## selectedColors [(127, 0, 0), (204, 0, 0), (204, 0, 0), (255, 255, 255)] ## selectedFYIColors [(255, 170, 170), (255, 216, 216), (255, 50, 50), (204, 0, 0)] ## visibleColors [(255, 170, 170), (255, 170, 170), (255, 170, 170), (204, 0, 0)] ## visibleFYIColors [(255, 242, 242), (255, 242, 242), (255, 216, 216), (204, 0, 0)] if dateToRender.month != self._month: gc.SetFont(self._font, self._otherMonthColour) bgColour = wx.Colour(*colorInfo.defaultFYIColors[0]) else: gc.SetFont(self._textFont, colorInfo.selectedColors[3]) bgColour = wx.Colour(*colorInfo.defaultColors[1]) #gc.SetBrush(wx.Brush(wx.Colour(colorInfo.defaultColors[1]))) # workaround - the line above always gives black bgColour.alpha = 128 gc.SetBrush(wx.Brush(bgColour)) gc.DrawRoundedRectangle(dayBounds.left, eventTop, dayBounds.width, self.stringHeight, self.stringHeight/2) DrawClippedText(gc, eventTitle, dayBounds.left + extraWidth + self.stringHeight/2, eventTop, dayBounds.width - extraWidth - 1 - self.stringHeight/2) eventTop += self.stringHeight #if (event.startTime + event.duration).date() <= dateToRender.date(): # self._multiDayEvents.remove(event) continue elif event.anyTime: extraWidth = 1 else: drawNoonStroke = True gc.SetFont(self._timeFont, fontColor) timeStr = formatTime(view, event.startTime, justHour=True) timeWidth = gc.GetTextExtent(timeStr)[0] gc.DrawText(timeStr, dayBounds.left, eventTop) if event.startTime.minute != 0: minuteStr = "%02d" % event.startTime.minute gc.SetFont(self._superscriptFont, fontColor) gc.DrawText(minuteStr, dayBounds.left + timeWidth, eventTop) timeWidth += gc.GetTextExtent(minuteStr)[0] else: timeWidth += 2 extraWidth = timeWidth + TIME_PADDING if dateToRender.month != self._month: gc.SetFont(self._font, self._otherMonthColour) else: collection = block.getContainingCollection(event.itsItem, primaryCollection) colorInfo = ColorInfo(collection) gc.SetFont(self._textFont, colorInfo.selectedColors[0]) # gc.DrawClippedRect is occasionally off by a pixel, so give # extra margin. DrawClippedText(gc, eventTitle, dayBounds.left + extraWidth, eventTop, dayBounds.width - extraWidth - 1) if (drawNoonStroke and not noonStrokeDrawn and event.startTime.hour >= 12): gc.SetPen(self._noonStrokePen) gc.StrokeLine(dayBounds.left, int(eventTop), dayBounds.left + noonStrokeWidth, int(eventTop)) noonStrokeDrawn = True eventTop += self.stringHeight if drawNoonStroke and not noonStrokeDrawn: gc.SetPen(self._noonStrokePen) gc.StrokeLine(dayBounds.left, int(eventTop), dayBounds.left + noonStrokeWidth, int(eventTop)) gc.ResetClip()