def _doEndClickControl( self, point ): if self._scheduleDraggingState == 1: self._processEvt( wxEVT_COMMAND_SCHEDULE_ACTIVATED, point ) elif self._scheduleDraggingState == 2: _, dateTime = self._computeCoords( point, 0, 0 ) sched = self._scheduleDragged[2] self._drawDragging( None, self._computeAllCoords ) sched.Offset( dateTime.Subtract( self._scheduleDraggingOrigin[1] ) ) self._scheduleDraggingState = 0 elif self._scheduleDraggingState in [5, 6]: coords = {5: self._computeStartCoords, 6: self._computeEndCoords}[self._scheduleDraggingState] _, _, dateTime = coords( point ) sched = self._scheduleDragged[2] if self._scheduleDraggingState == 5: sched.SetStart( utils.copyDateTime( dateTime ) ) else: sched.SetEnd( utils.copyDateTime( dateTime ) ) self._scheduleDraggingState = 0 self._drawDragging( None, coords ) self.SetCursor( wx.STANDARD_CURSOR ) self._scheduleDraggingState = 0 self._scheduleDragged = None self._scheduleDraggingOrigin = None self._scheduleDraggingPrevious = None
def _getSchedInPeriod( schedules, start, end): """ Returns a list of copied schedules that intersect with the period defined by 'start' and 'end'. Schedule start and end are trimmed so as to lie between 'start' and 'end'. """ results = [] for schedule in schedules: schedule.bounds = None if schedule.start.IsLaterThan(end): continue if start.IsLaterThan(schedule.end): continue newSchedule = schedule.Clone() # This is used to find the original schedule object in _findSchedule. newSchedule.clientdata = schedule if start.IsLaterThan(schedule.start): newSchedule.start = utils.copyDateTime(start) if schedule.end.IsLaterThan(end): newSchedule.end = utils.copyDateTime(end) results.append(newSchedule) return results
def _getSchedInPeriod(schedules, start, end): """ Returns a list of copied schedules that intersect with the period defined by 'start' and 'end'. Schedule start and end are trimmed so as to lie between 'start' and 'end'. """ results = [] for schedule in schedules: schedule.bounds = None if schedule.start.IsLaterThan(end): continue if start.IsLaterThan(schedule.end): continue newSchedule = schedule.Clone() # This is used to find the original schedule object in _findSchedule. newSchedule.clientdata = schedule if start.IsLaterThan(schedule.start): newSchedule.start = utils.copyDateTime(start) if schedule.end.IsLaterThan(end): newSchedule.end = utils.copyDateTime(end) results.append(newSchedule) return results
def _doEndClickControl(self, point): if self._scheduleDraggingState == 1: self._processEvt(wxEVT_COMMAND_SCHEDULE_ACTIVATED, point) elif self._scheduleDraggingState == 2: _, dateTime = self._computeCoords(point, 0, 0) sched = self._scheduleDragged[2] self._drawDragging(None, self._computeAllCoords) sched.Offset(dateTime.Subtract(self._scheduleDraggingOrigin[1])) self._scheduleDraggingState = 0 elif self._scheduleDraggingState in [5, 6]: coords = { 5: self._computeStartCoords, 6: self._computeEndCoords }[self._scheduleDraggingState] _, _, dateTime = coords(point) sched = self._scheduleDragged[2] if self._scheduleDraggingState == 5: sched.SetStart(utils.copyDateTime(dateTime)) else: sched.SetEnd(utils.copyDateTime(dateTime)) self._scheduleDraggingState = 0 self._drawDragging(None, coords) self.SetCursor(wx.STANDARD_CURSOR) self._scheduleDraggingState = 0 self._scheduleDragged = None self._scheduleDraggingOrigin = None self._scheduleDraggingPrevious = None
def _paintMonthly( self, drawer, day, x, y, width, height): """ Draw month's calendar using calendar module functions """ if self._drawHeaders: w, h = self._paintMonthlyHeaders( drawer, day, x, y, width, height) else: w, h = width, 0 y += h height -= h if self._style == wxSCHEDULER_VERTICAL: month = calendar.monthcalendar( day.GetYear(), day.GetMonth() + 1 ) for w, monthWeek in enumerate( month ): for d, monthDay in enumerate( monthWeek ): cellW, cellH = 1.0 * width / 7, 1.0 * height / len(month) if monthDay == 0: theDay = None schedules = [] else: theDay = day theDay.SetDay(monthDay) theDay.SetHour(0) theDay.SetMinute(0) theDay.SetSecond(0) end = utils.copyDateTime(theDay) end.AddDS(wx.DateSpan(days=1)) schedules = self._getSchedInPeriod(self._schedules, theDay, end) self._datetimeCoords.append((utils.copyDateTime(theDay), wx.Point(d * cellW, w * cellH), wx.Point(d * cellW + cellW, w * cellH + cellH))) self._schedulesCoords.extend(drawer.DrawSchedulesCompact(theDay, schedules, d * cellW, w * cellH + y, cellW, cellH, self._highlightColor)) return (max(MONTH_CELL_SIZE_MIN.width * 7, width), max(MONTH_CELL_SIZE_MIN.height * (w + 1), height)) else: day.SetDay(1) day.SetHour(0) day.SetMinute(0) day.SetSecond(0) daysCount = wx.DateTime.GetNumberOfDaysInMonth(day.GetMonth()) minHeight = h w, h = self._paintPeriod(drawer, day, daysCount, x, y, width, height) minHeight += h return w, minHeight
def Clone(self): newSchedule = wxSchedule() for name, value in list(self.GetData().items()): setattr(newSchedule, name, value) # start and end should be copied as well newSchedule._start = copyDateTime(newSchedule._start) newSchedule._end = copyDateTime(newSchedule._end) return newSchedule
def Clone(self): newSchedule = wxSchedule() for name, value in self.GetData().items(): setattr(newSchedule, name, value) # start and end should be copied as well newSchedule._start = copyDateTime(newSchedule._start) newSchedule._end = copyDateTime(newSchedule._end) return newSchedule
def _paintWeekly( self, drawer, day, x, y, width, height ): """ Display weekly schedule """ firstDay = utils.setToWeekDayInSameWeek( day, 0, self._weekstart ) firstDay.SetHour(0) firstDay.SetMinute(0) firstDay.SetSecond(0) minWidth = minHeight = 0 if self._style == wxSCHEDULER_VERTICAL: x += LEFT_COLUMN_SIZE width -= LEFT_COLUMN_SIZE maxDY = 0 if self._drawHeaders: theDay = utils.copyDateTime(day) for idx in xrange(self._periodCount): maxDY = max(maxDY, self._paintWeeklyHeaders( drawer, theDay, x + 1.0 * width / self._periodCount * idx, y, 1.0 * width / self._periodCount, height )) theDay.AddDS(wx.DateSpan(weeks=1)) if self._style == wxSCHEDULER_VERTICAL: x -= LEFT_COLUMN_SIZE width += LEFT_COLUMN_SIZE minHeight += maxDY y += maxDY height -= maxDY if self._style == wxSCHEDULER_VERTICAL: w, h = drawer.DrawHours(x, y, width, height, self._style) minWidth += w x += w width -= w day = utils.copyDateTime(firstDay) for idx in xrange(self._periodCount): for weekday in xrange(7): theDay = utils.setToWeekDayInSameWeek(utils.copyDateTime(day), weekday, self._weekstart) self._paintDay(drawer, theDay, x + (weekday + 7 * idx) * 1.0 * width / 7 / self._periodCount, y, 1.0 * width / 7 / self._periodCount, height) day.AddDS(wx.DateSpan(weeks=1)) return max(WEEK_SIZE_MIN.width * self._periodCount + LEFT_COLUMN_SIZE, width), max(WEEK_SIZE_MIN.height, height) else: w, h = self._paintPeriod(drawer, firstDay, 7 * self._periodCount, x, y, width, height) minWidth += w minHeight += h return max(WEEK_SIZE_MIN.width * self._periodCount + LEFT_COLUMN_SIZE, minWidth), minHeight
def _paintMonthlyHeaders( self, drawer, day, x, y, width, height ): w, h = drawer.DrawMonthHeader(day, x, y, width, height) if self._style == wxSCHEDULER_HORIZONTAL: day.SetDay(1) day.SetHour(0) day.SetMinute(0) day.SetSecond(0) daysCount = wx.DateTime.GetNumberOfDaysInMonth(day.GetMonth()) maxDY = 0 for idx in xrange(daysCount): theDay = utils.copyDateTime(day) if 'phoenix' in wx.PlatformInfo: theDay.Add(wx.DateSpan(days=idx)) else : theDay.AddDS(wx.DateSpan(days=idx)) # Recherche la couleur par défaut pour le jour highlight = theDay.IsSameDate( wx.DateTime.Now() ) if self.joursSpeciaux != None and highlight == False : couleur = self.joursSpeciaux.GetCouleur(theDay) if couleur != None : highlight = couleur w, h = drawer.DrawSimpleDayHeader(theDay, x + 1.0 * idx * width / daysCount, y + h, 1.0 * width / daysCount, height, highlight) maxDY = max(maxDY, h) h += maxDY return w, h
def _paintWeeklyHeaders(self, drawer, day, x, y, width, height): firstDay = utils.setToWeekDayInSameWeek(day, 0, self._weekstart) firstDay.SetHour(0) firstDay.SetMinute(0) firstDay.SetSecond(0) maxDY = 0 for weekday in xrange(7): theDay = utils.setToWeekDayInSameWeek(utils.copyDateTime(firstDay), weekday, self._weekstart) if theDay.IsSameDate(wx.DateTime.Now()): color = self._highlightColor else: color = None w, h = drawer.DrawDayHeader(theDay, x + weekday * 1.0 * width / 7, y, 1.0 * width / 7, height, highlight=color) self._headerBounds.append( (int(x + (weekday + 1) * 1.0 * width / 7), y, height)) maxDY = max(maxDY, h) return maxDY
def _findSchedule(self, point): """ Check if the point is on a schedule and return the schedule """ sched = None for schedule, pointMin, pointMax in self._schedulesCoords: inX = (pointMin.x <= point.x) & (point.x <= pointMax.x) inY = (pointMin.y <= point.y) & (point.y <= pointMax.y) if inX & inY: sched = schedule.GetClientData() datet = None dateExacte = None for dt, pointMin, pointMax in self._datetimeCoords: inX = (pointMin.x <= point.x) & (point.x <= pointMax.x) inY = (pointMin.y <= point.y) & (point.y <= pointMax.y) if inX & inY: datet = utils.copyDateTime(dt) minutes = int(30.0 * (point.y - pointMin.y) / (pointMax.y - pointMin.y)) minutes = minutes - (minutes % 5) if 'phoenix' in wx.PlatformInfo: dateExacte = datet.Add(wx.TimeSpan(hours=0, min=minutes)) else: dateExacte = datet.AddTS(wx.TimeSpan(minutes=minutes)) return sched, datet, dateExacte
def _paintMonthlyHeaders( self, drawer, day, x, y, width, height ): if isinstance(self, wx.ScrolledWindow): _, h = drawer.DrawMonthHeader(day, 0, 0, self.GetSizeTuple()[0], height) w = width else: w, h = drawer.DrawMonthHeader(day, x, y, width, height) if self._style == wxSCHEDULER_HORIZONTAL: day.SetDay(1) day.SetHour(0) day.SetMinute(0) day.SetSecond(0) daysCount = wx.DateTime.GetNumberOfDaysInMonth(day.GetMonth()) maxDY = 0 for idx in xrange(daysCount): theDay = utils.copyDateTime(day) theDay.AddDS(wx.DateSpan(days=idx)) if theDay.IsSameDate( wx.DateTime.Now() ): color = self._highlightColor else: color = None w, h = drawer.DrawSimpleDayHeader(theDay, x + 1.0 * idx * width / daysCount, y + h, 1.0 * width / daysCount, height, highlight=color) self._headerBounds.append((x + 1.0 * (idx + 1) * width / daysCount, y + h, height)) maxDY = max(maxDY, h) h += maxDY return w, h
def _findSchedule( self, point ): """ Check if the point is on a schedule and return the schedule """ sched = None for schedule, pointMin, pointMax in self._schedulesCoords: inX = ( pointMin.x <= point.x ) & ( point.x <= pointMax.x ) inY = ( pointMin.y <= point.y ) & ( point.y <= pointMax.y ) if inX & inY: sched = schedule.GetClientData() datet = None dateExacte = None for dt, pointMin, pointMax in self._datetimeCoords: inX = ( pointMin.x <= point.x ) & ( point.x <= pointMax.x ) inY = ( pointMin.y <= point.y ) & ( point.y <= pointMax.y ) if inX & inY: datet = utils.copyDateTime(dt) minutes = int(30.0 * (point.y - pointMin.y) / (pointMax.y - pointMin.y)) minutes = minutes - (minutes % 5) if 'phoenix' in wx.PlatformInfo: dateExacte = datet.Add(wx.TimeSpan(hours=0, min=minutes)) else : dateExacte = datet.AddTS(wx.TimeSpan(minutes=minutes)) return sched, datet, dateExacte
def GetDate( self ): """ Return the current day view If my view type is different than wxSCHEDULER_DAILY, I'll return the first day of the period """ return utils.copyDateTime( self._currentDate )
def GetDate(self): """ Return the current day view If my view type is different than wxSCHEDULER_DAILY, I'll return the first day of the period """ return utils.copyDateTime(self._currentDate)
def _paintMonthlyHeaders(self, drawer, day, x, y, width, height): w, h = drawer.DrawMonthHeader(day, x, y, width, height) if self._style == wxSCHEDULER_HORIZONTAL: day.SetDay(1) day.SetHour(0) day.SetMinute(0) day.SetSecond(0) daysCount = wx.DateTime.GetNumberOfDaysInMonth(day.GetMonth()) maxDY = 0 for idx in xrange(daysCount): theDay = utils.copyDateTime(day) if 'phoenix' in wx.PlatformInfo: theDay.Add(wx.DateSpan(days=idx)) else: theDay.AddDS(wx.DateSpan(days=idx)) # Recherche la couleur par défaut pour le jour highlight = theDay.IsSameDate(wx.DateTime.Now()) if self.joursSpeciaux != None and highlight == False: couleur = self.joursSpeciaux.GetCouleur(theDay) if couleur != None: highlight = couleur w, h = drawer.DrawSimpleDayHeader( theDay, x + 1.0 * idx * width / daysCount, y + h, 1.0 * width / daysCount, height, highlight) maxDY = max(maxDY, h) h += maxDY return w, h
def _computeCoords( self, point, dx, dy ): pp = wx.Point(point.x + dx, point.y + dy) if pp.y < 0: pp.y = 0 if pp.y >= self._bitmap.GetHeight(): pp.y = self._bitmap.GetHeight() - 1 if pp.x < 0: pp.x = 0 if pp.x >= self._bitmap.GetWidth(): pp.x = self._bitmap.GetWidth() - 1 for idx, (dt, pointMin, pointMax) in enumerate(self._datetimeCoords): if pp.y >= pointMin.y and pp.y <= pointMax.y and pp.x >= pointMin.x and pp.x <= pointMax.x: break else: idx = -1 if idx >= 0: if self._scheduleDraggingStick: if self._style == wxSCHEDULER_VERTICAL: pp = wx.Point( pp.x, pointMin.y ) else: pp = wx.Point( pointMin.x, pp.y ) theTime = utils.copyDateTime( dt ) if self._style == wxSCHEDULER_VERTICAL: theTime.AddTS( wx.TimeSpan.Minutes( int(30.0 * (pp.y - pointMin.y) / (pointMax.y - pointMin.y)) ) ) else: theTime.AddTS( wx.TimeSpan.Minutes( int(30.0 * (pp.x - pointMin.x) / (pointMax.x - pointMin.x)) ) ) else: raise ValueError('Not found: %d %d' % (pp.x, pp.y)) return pp, theTime
def _paintWeeklyHeaders(self, drawer, day, x, y, width, height): firstDay = utils.setToWeekDayInSameWeek(day, 0, self._weekstart) firstDay.SetHour(0) firstDay.SetMinute(0) firstDay.SetSecond(0) maxDY = 0 for weekday in xrange(7): theDay = utils.setToWeekDayInSameWeek(utils.copyDateTime(firstDay), weekday, self._weekstart) # Recherche la couleur par défaut pour le jour highlight = theDay.IsSameDate(wx.DateTime.Now()) if self.joursSpeciaux != None and highlight == False: couleur = self.joursSpeciaux.GetCouleur(theDay) if couleur != None: highlight = couleur w, h = drawer.DrawDayHeader(theDay, x + weekday * 1.0 * width / 7, y, 1.0 * width / 7, height, highlight=highlight) maxDY = max(maxDY, h) return maxDY
def _paintDay( self, drawer, day, x, y, width, height ): """ Draw column schedules """ start = utils.copyDateTime(day) start.SetHour(0) start.SetMinute(0) start.SetSecond(0) return self._paintPeriod(drawer, start, 1, x, y, width, height)
def _paintDay(self, drawer, day, x, y, width, height): """ Draw column schedules """ start = utils.copyDateTime(day) start.SetHour(0) start.SetMinute(0) start.SetSecond(0) return self._paintPeriod(drawer, start, 1, x, y, width, height)
def GetWeekdayDate( self, weekday, day ): """ Return date of week day passed by Range values is 0 to 6 """ if weekday == 6: weekday = 0 else: weekday += 1 date = day.GetWeekDayInSameWeek( weekday, self._weekstart ) return utils.copyDateTime( date )
def GetWeekdayDate(self, weekday, day): """ Return date of week day passed by Range values is 0 to 6 """ if weekday == 6: weekday = 0 else: weekday += 1 date = day.GetWeekDayInSameWeek(weekday, self._weekstart) return utils.copyDateTime(date)
def _paintDay( self, drawer, day, x, y, width, height ): """ Draw column schedules """ start = utils.copyDateTime(day) start.SetHour(0) start.SetMinute(0) start.SetSecond(0) color = None if day.IsSameDate(wx.DateTime.Now()) and self._periodCount >= 2: color = self._highlightColor return self._paintPeriod(drawer, start, 1, x, y, width, height, highlight=color)
def _paintWeeklyHeaders( self, drawer, day, x, y, width, height ): firstDay = utils.setToWeekDayInSameWeek( day, 0, self._weekstart ) firstDay.SetHour(0) firstDay.SetMinute(0) firstDay.SetSecond(0) maxDY = 0 for weekday in xrange(7): theDay = utils.setToWeekDayInSameWeek(utils.copyDateTime(firstDay), weekday, self._weekstart) if theDay.IsSameDate( wx.DateTime.Now() ): color = self._highlightColor else: color = None w, h = drawer.DrawDayHeader(theDay, x + weekday * 1.0 * width / 7, y, 1.0 * width / 7, height, highlight=color) self._headerBounds.append((int(x + (weekday + 1) * 1.0 * width / 7), y, height)) maxDY = max(maxDY, h) return maxDY
def _paintWeeklyHeaders( self, drawer, day, x, y, width, height ): firstDay = utils.setToWeekDayInSameWeek( day, 0, self._weekstart ) firstDay.SetHour(0) firstDay.SetMinute(0) firstDay.SetSecond(0) maxDY = 0 for weekday in xrange(7): theDay = utils.setToWeekDayInSameWeek(utils.copyDateTime(firstDay), weekday, self._weekstart) # Recherche la couleur par défaut pour le jour highlight = theDay.IsSameDate( wx.DateTime.Now() ) if self.joursSpeciaux != None and highlight == False : couleur = self.joursSpeciaux.GetCouleur(theDay) if couleur != None : highlight = couleur w, h = drawer.DrawDayHeader(theDay, x + weekday * 1.0 * width / 7, y, 1.0 * width / 7, height, highlight=highlight) maxDY = max(maxDY, h) return maxDY
def _paintDay(self, drawer, day, x, y, width, height): """ Draw column schedules """ start = utils.copyDateTime(day) start.SetHour(0) start.SetMinute(0) start.SetSecond(0) color = None if day.IsSameDate(wx.DateTime.Now()) and self._periodCount >= 2: color = self._highlightColor return self._paintPeriod(drawer, start, 1, x, y, width, height, highlight=color)
def _computeCoords(self, point, dx, dy): pp = wx.Point(point.x + dx, point.y + dy) if pp.y < 0: pp.y = 0 if pp.y >= self._bitmap.GetHeight(): pp.y = self._bitmap.GetHeight() - 1 if pp.x < 0: pp.x = 0 if pp.x >= self._bitmap.GetWidth(): pp.x = self._bitmap.GetWidth() - 1 for idx, (dt, pointMin, pointMax) in enumerate(self._datetimeCoords): if pp.y >= pointMin.y and pp.y <= pointMax.y and pp.x >= pointMin.x and pp.x <= pointMax.x: break else: idx = -1 if idx >= 0: if self._scheduleDraggingStick: if self._style == wxSCHEDULER_VERTICAL: pp = wx.Point(pp.x, pointMin.y) else: pp = wx.Point(pointMin.x, pp.y) theTime = utils.copyDateTime(dt) if self._style == wxSCHEDULER_VERTICAL: theTime.AddTS( wx.TimeSpan.Minutes( int(30.0 * (pp.y - pointMin.y) / (pointMax.y - pointMin.y)))) else: theTime.AddTS( wx.TimeSpan.Minutes( int(30.0 * (pp.x - pointMin.x) / (pointMax.x - pointMin.x)))) else: raise ValueError('Not found: %d %d' % (pp.x, pp.y)) return pp, theTime
def _paintMonthlyHeaders(self, drawer, day, x, y, width, height): if isinstance(self, wx.ScrolledWindow): _, h = drawer.DrawMonthHeader(day, 0, 0, self.GetSizeTuple()[0], height) w = width else: w, h = drawer.DrawMonthHeader(day, x, y, width, height) if self._style == wxSCHEDULER_HORIZONTAL: day.SetDay(1) day.SetHour(0) day.SetMinute(0) day.SetSecond(0) daysCount = wx.DateTime.GetNumberOfDaysInMonth(day.GetMonth()) maxDY = 0 for idx in xrange(daysCount): theDay = utils.copyDateTime(day) theDay.AddDS(wx.DateSpan(days=idx)) if theDay.IsSameDate(wx.DateTime.Now()): color = self._highlightColor else: color = None w, h = drawer.DrawSimpleDayHeader( theDay, x + 1.0 * idx * width / daysCount, y + h, 1.0 * width / daysCount, height, highlight=color) self._headerBounds.append( (x + 1.0 * (idx + 1) * width / daysCount, y + h, height)) maxDY = max(maxDY, h) h += maxDY return w, h
def _paintMonthly(self, drawer, day, x, y, width, height): """ Draw month's calendar using calendar module functions """ if self._drawHeaders: w, h = self._paintMonthlyHeaders(drawer, day, x, y, width, height) else: w, h = width, 0 y += h height -= h if self._style == wxSCHEDULER_VERTICAL: month = calendar.monthcalendar(day.GetYear(), day.GetMonth() + 1) for w, monthWeek in enumerate(month): for d, monthDay in enumerate(monthWeek): cellW, cellH = 1.0 * width / 7, 1.0 * height / len(month) if monthDay == 0: theDay = None schedules = [] highlight = False else: theDay = day theDay.SetDay(monthDay) theDay.SetHour(0) theDay.SetMinute(0) theDay.SetSecond(0) end = utils.copyDateTime(theDay) if 'phoenix' in wx.PlatformInfo: end.Add(wx.DateSpan(days=1)) else: end.AddDS(wx.DateSpan(days=1)) schedules = self._getSchedInPeriod( self._schedules, theDay, end) # Recherche la couleur par défaut pour le jour highlight = theDay.IsSameDate(wx.DateTime.Now()) if self.joursSpeciaux != None and highlight == False: couleur = self.joursSpeciaux.GetCouleur(theDay) if couleur != None: highlight = couleur self._datetimeCoords.append( (utils.copyDateTime(theDay), wx.Point(d * cellW, w * cellH), wx.Point(d * cellW + cellW, w * cellH + cellH))) self._schedulesCoords.extend( drawer.DrawSchedulesCompact(theDay, schedules, d * cellW, w * cellH + y, cellW, cellH, highlight)) return (max(MONTH_CELL_SIZE_MIN.width * 7, width), max(MONTH_CELL_SIZE_MIN.height * (w + 1), height)) else: day.SetDay(1) day.SetHour(0) day.SetMinute(0) day.SetSecond(0) daysCount = wx.DateTime.GetNumberOfDaysInMonth(day.GetMonth()) minHeight = h w, h = self._paintPeriod(drawer, day, daysCount, x, y, width, height) minHeight += h return w, minHeight
def _paintMonthly(self, drawer, day, x, y, width, height): """ Draw month's calendar using calendar module functions """ if self._drawHeaders: w, h = self._paintMonthlyHeaders(drawer, day, x, y, width, height) else: w, h = width, 0 y += h height -= h if self._style == wxSCHEDULER_VERTICAL: month = calendar.monthcalendar(day.GetYear(), day.GetMonth() + 1) for w, monthWeek in enumerate(month): for d, monthDay in enumerate(monthWeek): cellW, cellH = 1.0 * width / 7, 1.0 * height / len(month) if monthDay == 0: theDay = None schedules = [] else: theDay = day theDay.SetDay(monthDay) theDay.SetHour(0) theDay.SetMinute(0) theDay.SetSecond(0) end = utils.copyDateTime(theDay) end.AddDS(wx.DateSpan(days=1)) schedules = self._getSchedInPeriod( self._schedules, theDay, end) if self._minSize is None or not self._resizable: self._datetimeCoords.append( (utils.copyDateTime(theDay), wx.Point(d * cellW, w * cellH), wx.Point(d * cellW + cellW, w * cellH + cellH))) displayed = drawer.DrawSchedulesCompact( theDay, schedules, d * cellW, w * cellH + y, cellW, cellH, self._highlightColor) self._schedulesCoords.extend(displayed) for schedule in set(schedules) - set( [sched for sched, _, _ in displayed]): schedule.Destroy() return (max(MONTH_CELL_SIZE_MIN.width * 7, width), max(MONTH_CELL_SIZE_MIN.height * (w + 1), height)) else: day.SetDay(1) day.SetHour(0) day.SetMinute(0) day.SetSecond(0) daysCount = wx.DateTime.GetNumberOfDaysInMonth(day.GetMonth()) minHeight = h w, h = self._paintPeriod(drawer, day, daysCount, x, y, width, height) minHeight += h return w, minHeight
def _paintWeekly(self, drawer, day, x, y, width, height): """ Display weekly schedule """ firstDay = utils.setToWeekDayInSameWeek(day, 0, self._weekstart) firstDay.SetHour(0) firstDay.SetMinute(0) firstDay.SetSecond(0) minWidth = minHeight = 0 if self._style == wxSCHEDULER_VERTICAL: x += LEFT_COLUMN_SIZE width -= LEFT_COLUMN_SIZE maxDY = 0 if self._drawHeaders: theDay = utils.copyDateTime(day) for idx in xrange(self._periodCount): maxDY = max( maxDY, self._paintWeeklyHeaders( drawer, theDay, x + 1.0 * width / self._periodCount * idx, y, 1.0 * width / self._periodCount, height)) if 'phoenix' in wx.PlatformInfo: theDay.Add(wx.DateSpan(weeks=1)) else: theDay.AddDS(wx.DateSpan(weeks=1)) if self._style == wxSCHEDULER_VERTICAL: x -= LEFT_COLUMN_SIZE width += LEFT_COLUMN_SIZE minHeight += maxDY y += maxDY height -= maxDY if self._style == wxSCHEDULER_VERTICAL: w, h = drawer.DrawHours(x, y, width, height, self._style) minWidth += w x += w width -= w day = utils.copyDateTime(firstDay) for idx in xrange(self._periodCount): for weekday in xrange(7): theDay = utils.setToWeekDayInSameWeek( utils.copyDateTime(day), weekday, self._weekstart) self._paintDay( drawer, theDay, x + (weekday + 7 * idx) * 1.0 * width / 7 / self._periodCount, y, 1.0 * width / 7 / self._periodCount, height) if 'phoenix' in wx.PlatformInfo: day.Add(wx.DateSpan(weeks=1)) else: day.AddDS(wx.DateSpan(weeks=1)) return max( WEEK_SIZE_MIN.width * self._periodCount + LEFT_COLUMN_SIZE, width), max(WEEK_SIZE_MIN.height, height) else: w, h = self._paintPeriod(drawer, firstDay, 7 * self._periodCount, x, y, width, height) minWidth += w minHeight += h return max( WEEK_SIZE_MIN.width * self._periodCount + LEFT_COLUMN_SIZE, minWidth), minHeight
def _paintPeriod(self, drawer, start, daysCount, x, y, width, height, highlight=None): end = utils.copyDateTime(start) end.AddDS(wx.DateSpan(days=daysCount)) blocks = self._splitSchedules(self._getSchedInPeriod(self._schedules, start, end)) offsetY = 0 if self._showOnlyWorkHour: workingHours = [(self._startingHour, self._startingPauseHour), (self._endingPauseHour, self._endingHour)] else: workingHours = [(self._startingHour, self._endingHour)] if not self.pageNumber: self.pageCount = 1 self.pageLimits = [0] pageHeight = self.GetSize().GetHeight() - 20 currentPageHeight = y for dayN in xrange(daysCount): theDay = utils.copyDateTime(start) theDay.AddDS(wx.DateSpan(days=dayN)) theDay.SetSecond(0) color = highlight if theDay.IsSameDate( wx.DateTime.Now() ): if self._viewType != wxSCHEDULER_DAILY or daysCount >= 2: color = self._highlightColor drawer.DrawDayBackground( x + 1.0 * width / daysCount * dayN, y, 1.0 * width / daysCount, height, highlight=color ) if blocks: dayWidth = width / len(blocks) for idx, block in enumerate(blocks): maxDY = 0 for schedule in block: show = True if self.pageNumber is not None: if self._schedulesPages.get(schedule.GetId(), None) != self.pageNumber: show = False if show: if self._style == wxSCHEDULER_VERTICAL: xx, yy, w, h = drawer.DrawScheduleVertical(schedule, start, workingHours, x + dayWidth * idx, y, dayWidth, height) elif self._style == wxSCHEDULER_HORIZONTAL: xx, yy, w, h = drawer.DrawScheduleHorizontal(schedule, start, daysCount, workingHours, x, y + offsetY, width, height) maxDY = max(maxDY, h) if self.pageNumber is None: if currentPageHeight + h >= pageHeight: pageNo = self.pageCount + 1 else: pageNo = self.pageCount self._schedulesPages[schedule.GetId()] = pageNo self._schedulesCoords.append((schedule, wx.Point(xx, yy), wx.Point(xx + w, yy + h))) else: schedule.Destroy() offsetY += maxDY if not self.pageNumber: currentPageHeight += maxDY if currentPageHeight >= pageHeight: self.pageLimits.append(currentPageHeight - maxDY) currentPageHeight = maxDY self.pageCount += 1 now = wx.DateTime.Now() for dayN in xrange(daysCount): theDay = utils.copyDateTime(start) theDay.AddDS(wx.DateSpan(days=dayN)) theDay.SetSecond(0) nbHours = len(self._lstDisplayedHours) for idx, hour in enumerate(self._lstDisplayedHours): theDay.SetHour(hour.GetHour()) theDay.SetMinute(hour.GetMinute()) if self._minSize is None or not self._resizable: if self._style == wxSCHEDULER_VERTICAL: self._datetimeCoords.append((utils.copyDateTime(theDay), wx.Point(x + 1.0 * width * dayN / daysCount, y + 1.0 * height * idx / nbHours), wx.Point(x + 1.0 * width * (dayN + 1) / daysCount, y + 1.0 * height * (idx + 1) / nbHours))) else: self._datetimeCoords.append((utils.copyDateTime(theDay), wx.Point(x + 1.0 * width * (nbHours * dayN + idx) / (nbHours * daysCount), y), wx.Point(x + 1.0 * width * (nbHours * dayN + idx + 1) / (nbHours * daysCount), y + height))) if isinstance(self, wx.ScrolledWindow) and self._showNow: now = wx.DateTime.Now() # This assumes self._lstDisplayedHours is sorted of course for dayN in xrange(daysCount): theDay = utils.copyDateTime(start) theDay.AddDS(wx.DateSpan(days=dayN)) if theDay.IsSameDate(now): theDay.SetSecond(0) previous = None for idx, hour in enumerate(self._lstDisplayedHours): theDay.SetHour(hour.GetHour()) theDay.SetMinute(hour.GetMinute()) if theDay.IsLaterThan(now): if idx != 0: if self._style == wxSCHEDULER_VERTICAL: yPrev = y + 1.0 * height * (idx - 1) / nbHours delta = 1.0 * height / nbHours * now.Subtract(previous).GetSeconds() \ / theDay.Subtract(previous).GetSeconds() drawer.DrawNowHorizontal(x, yPrev + delta, width) else: xPrev = x + 1.0 * width * (nbHours * dayN + idx - 1) / (nbHours * daysCount) delta = 1.0 * width / (nbHours * daysCount) * now.Subtract(previous).GetSeconds() \ / theDay.Subtract(previous).GetSeconds() drawer.DrawNowVertical(xPrev + delta, y, height) break previous = utils.copyDateTime( theDay ) break if self._style == wxSCHEDULER_VERTICAL: return max(width, DAY_SIZE_MIN.width), max(height, DAY_SIZE_MIN.height) else: return max(width, self._periodWidth), offsetY
def _paintDaily(self, drawer, day, x, y, width, height): """ Display day schedules """ minWidth = minHeight = 0 if self._style == wxSCHEDULER_VERTICAL: x += LEFT_COLUMN_SIZE width -= LEFT_COLUMN_SIZE theDay = utils.copyDateTime(day) if self._drawHeaders: maxDY = 0 for idx in xrange(self._periodCount): w, h = self._paintDailyHeaders( drawer, theDay, x + 1.0 * width / self._periodCount * idx, y, 1.0 * width / self._periodCount, height) maxDY = max(maxDY, h) if 'phoenix' in wx.PlatformInfo: theDay.Add(wx.DateSpan(days=1)) else: theDay.AddDS(wx.DateSpan(days=1)) minHeight += maxDY y += maxDY height -= maxDY else: for idx in xrange(self._periodCount): self._paintDailyHeaders(drawer, theDay, x + 1.0 * width / self._periodCount * idx, y, 1.0 * width / self._periodCount, height, includeText=False) if 'phoenix' in wx.PlatformInfo: theDay.Add(wx.DateSpan(days=1)) else: theDay.AddDS(wx.DateSpan(days=1)) if self._style == wxSCHEDULER_VERTICAL: x -= LEFT_COLUMN_SIZE width += LEFT_COLUMN_SIZE if self._style == wxSCHEDULER_VERTICAL or self._drawHeaders: if self._style == wxSCHEDULER_VERTICAL: w, h = drawer.DrawHours(x, y, width, height, self._style) else: maxDY = 0 for idx in xrange(self._periodCount): _, h = drawer.DrawHours( x + 1.0 * width / self._periodCount * idx, y, 1.0 * width / self._periodCount, height, self._style) maxDY = max(maxDY, h) w = 0 h = maxDY else: w, h = 0, 0 if self._style == wxSCHEDULER_VERTICAL: minWidth += w x += w width -= w else: minHeight += h y += h height -= h if self._style == wxSCHEDULER_HORIZONTAL: # Use directly paintPeriod or pagination fails w, h = self._paintPeriod(drawer, day, self._periodCount, x, y, width, height) else: w = 0 maxDY = 0 theDay = utils.copyDateTime(day) for idx in xrange(self._periodCount): dw, dh = self._paintDay( drawer, theDay, x + 1.0 * width / self._periodCount * idx, y, 1.0 * width / self._periodCount, height) w += dw maxDY = max(maxDY, dh) if 'phoenix' in wx.PlatformInfo: theDay.Add(wx.DateSpan(days=1)) else: theDay.AddDS(wx.DateSpan(days=1)) minWidth += w minHeight += h return minWidth, minHeight
def ScheduleSize(schedule, workingHours, firstDay, dayCount): """ This convenience static method computes the position and size size of the schedule in the direction that represent time, according to a set of working hours. The workingHours parameter is a list of 2-tuples of wx.DateTime objects defining intervals which are indeed worked. startPeriod and endPeriod delimit the period. """ totalSpan = 0 scheduleSpan = 0 position = 0 totalTime = 0 for startHour, endHour in workingHours: totalTime += copyDateTime(endHour).Subtract( startHour).GetMinutes() / 60.0 for dayNumber in xrange(dayCount): currentDay = copyDateTime(firstDay) currentDay.AddDS(wx.DateSpan(days=dayNumber)) for startHour, endHour in workingHours: startHourCopy = wx.DateTimeFromDMY(currentDay.GetDay(), currentDay.GetMonth(), currentDay.GetYear(), startHour.GetHour(), startHour.GetMinute(), 0) endHourCopy = wx.DateTimeFromDMY(currentDay.GetDay(), currentDay.GetMonth(), currentDay.GetYear(), endHour.GetHour(), endHour.GetMinute(), 0) totalSpan += endHourCopy.Subtract(startHourCopy).GetMinutes() localStart = copyDateTime(schedule.start) if localStart.IsLaterThan(endHourCopy): position += endHourCopy.Subtract( startHourCopy).GetMinutes() continue if startHourCopy.IsLaterThan(localStart): localStart = startHourCopy localEnd = copyDateTime(schedule.end) if startHourCopy.IsLaterThan(localEnd): continue position += localStart.Subtract(startHourCopy).GetMinutes() if localEnd.IsLaterThan(endHourCopy): localEnd = endHourCopy scheduleSpan += localEnd.Subtract(localStart).GetMinutes() return dayCount * totalTime * scheduleSpan / totalSpan, dayCount * totalTime * position / totalSpan, totalTime * dayCount
def _OnPaintHeaders(self, evt): dc = wx.PaintDC(self._headerPanel) if 'phoenix' not in wx.PlatformInfo: dc.BeginDrawing() try: dc.SetBackground(wx.Brush(SCHEDULER_BACKGROUND_BRUSH)) dc.SetPen(FOREGROUND_PEN) dc.Clear() dc.SetFont(wx.NORMAL_FONT) if self._drawerClass.use_gc: context = wx.GraphicsContext.Create(dc) else: context = dc drawer = self._drawerClass(context, self._lstDisplayedHours) if self._resizable: width, _ = self.GetVirtualSize() else: width, _ = self.CalcMinSize() day = utils.copyDate(self.GetDate()) x, y = 0, 0 # Take horizontal scrolling into account x0, _ = self.GetViewStart() xu, _ = self.GetScrollPixelsPerUnit() x0 *= xu x -= x0 if self._viewType == wxSCHEDULER_DAILY: if self._style == wxSCHEDULER_VERTICAL: x += LEFT_COLUMN_SIZE width -= LEFT_COLUMN_SIZE theDay = utils.copyDateTime(day) maxDY = 0 for idx in xrange(self._periodCount): _, h = self._paintDailyHeaders( drawer, theDay, x + 1.0 * width / self._periodCount * idx, y, 1.0 * width / self._periodCount, 36) maxDY = max(maxDY, h) theDay.AddDS(wx.DateSpan(days=1)) h = maxDY elif self._viewType == wxSCHEDULER_WEEKLY: if self._style == wxSCHEDULER_VERTICAL: x += LEFT_COLUMN_SIZE width -= LEFT_COLUMN_SIZE theDay = utils.copyDateTime(day) maxDY = 0 for idx in xrange(self._periodCount): h = self._paintWeeklyHeaders( drawer, theDay, x + 1.0 * width / self._periodCount * idx, y, 1.0 * width / self._periodCount, 36) maxDY = max(maxDY, h) theDay.AddDS(wx.DateSpan(weeks=1)) h = maxDY elif self._viewType == wxSCHEDULER_MONTHLY: _, h = self._paintMonthlyHeaders(drawer, day, x, y, width, 36) minW, minH = self._headerPanel.GetMinSize() if minH != h: self._headerPanel.SetMinSize(wx.Size(-1, h)) self._headerPanel.GetParent().Layout() finally: if 'phoenix' not in wx.PlatformInfo: dc.EndDrawing()
def _paintDaily( self, drawer, day, x, y, width, height ): """ Display day schedules """ minWidth = minHeight = 0 if self._style == wxSCHEDULER_VERTICAL: x += LEFT_COLUMN_SIZE width -= LEFT_COLUMN_SIZE theDay = utils.copyDateTime(day) if self._drawHeaders: maxDY = 0 for idx in xrange(self._periodCount): w, h = self._paintDailyHeaders( drawer, theDay, x + 1.0 * width / self._periodCount * idx, y, 1.0 * width / self._periodCount, height) maxDY = max(maxDY, h) if 'phoenix' in wx.PlatformInfo: theDay.Add(wx.DateSpan(days=1)) else : theDay.AddDS(wx.DateSpan(days=1)) minHeight += maxDY y += maxDY height -= maxDY else: for idx in xrange(self._periodCount): self._paintDailyHeaders( drawer, theDay, x + 1.0 * width / self._periodCount * idx, y, 1.0 * width / self._periodCount, height, includeText=False ) if 'phoenix' in wx.PlatformInfo: theDay.Add(wx.DateSpan(days=1)) else : theDay.AddDS(wx.DateSpan(days=1)) if self._style == wxSCHEDULER_VERTICAL: x -= LEFT_COLUMN_SIZE width += LEFT_COLUMN_SIZE if self._style == wxSCHEDULER_VERTICAL or self._drawHeaders: if self._style == wxSCHEDULER_VERTICAL: w, h = drawer.DrawHours(x, y, width, height, self._style) else: maxDY = 0 for idx in xrange(self._periodCount): _, h = drawer.DrawHours(x + 1.0 * width / self._periodCount * idx, y, 1.0 * width / self._periodCount, height, self._style) maxDY = max(maxDY, h) w = 0 h = maxDY else: w, h = 0, 0 if self._style == wxSCHEDULER_VERTICAL: minWidth += w x += w width -= w else: minHeight += h y += h height -= h if self._style == wxSCHEDULER_HORIZONTAL: # Use directly paintPeriod or pagination fails w, h = self._paintPeriod(drawer, day, self._periodCount, x, y, width, height) else: w = 0 maxDY = 0 theDay = utils.copyDateTime(day) for idx in xrange(self._periodCount): dw, dh = self._paintDay( drawer, theDay, x + 1.0 * width / self._periodCount * idx, y, 1.0 * width / self._periodCount, height ) w += dw maxDY = max(maxDY, dh) if 'phoenix' in wx.PlatformInfo: theDay.Add(wx.DateSpan(days=1)) else : theDay.AddDS(wx.DateSpan(days=1)) minWidth += w minHeight += h return minWidth, minHeight
def _OnPaintHeaders( self, evt ): dc = wx.PaintDC( self._headerPanel ) if 'phoenix' not in wx.PlatformInfo: dc.BeginDrawing() try: dc.SetBackground( wx.Brush( SCHEDULER_BACKGROUND_BRUSH ) ) dc.SetPen( FOREGROUND_PEN ) dc.Clear() dc.SetFont( wx.NORMAL_FONT ) if self._drawerClass.use_gc: context = wx.GraphicsContext.Create(dc) else: context = dc drawer = self._drawerClass(context, self._lstDisplayedHours) if self._resizable: width, _ = self.GetVirtualSize() else: width, _ = self.CalcMinSize() day = utils.copyDate(self.GetDate()) x, y = 0, 0 # Take horizontal scrolling into account x0, _ = self.GetViewStart() xu, _ = self.GetScrollPixelsPerUnit() x0 *= xu x -= x0 if self._viewType == wxSCHEDULER_DAILY: if self._style == wxSCHEDULER_VERTICAL: x += LEFT_COLUMN_SIZE width -= LEFT_COLUMN_SIZE theDay = utils.copyDateTime(day) maxDY = 0 for idx in xrange(self._periodCount): _, h = self._paintDailyHeaders(drawer, theDay, x + 1.0 * width / self._periodCount * idx, y, 1.0 * width / self._periodCount, 36) maxDY = max(maxDY, h) theDay.AddDS(wx.DateSpan(days=1)) h = maxDY elif self._viewType == wxSCHEDULER_WEEKLY: if self._style == wxSCHEDULER_VERTICAL: x += LEFT_COLUMN_SIZE width -= LEFT_COLUMN_SIZE theDay = utils.copyDateTime(day) maxDY = 0 for idx in xrange(self._periodCount): h = self._paintWeeklyHeaders(drawer, theDay, x + 1.0 * width / self._periodCount * idx, y, 1.0 * width / self._periodCount, 36) maxDY = max(maxDY, h) theDay.AddDS(wx.DateSpan(weeks=1)) h = maxDY elif self._viewType == wxSCHEDULER_MONTHLY: _, h = self._paintMonthlyHeaders(drawer, day, x, y, width, 36) minW, minH = self._headerPanel.GetMinSize() if minH != h: self._headerPanel.SetMinSize(wx.Size(-1, h)) self._headerPanel.GetParent().Layout() finally: if 'phoenix' not in wx.PlatformInfo: dc.EndDrawing()
def _paintPeriod(self, drawer, start, daysCount, x, y, width, height, highlight=None): end = utils.copyDateTime(start) end.AddDS(wx.DateSpan(days=daysCount)) blocks = self._splitSchedules( self._getSchedInPeriod(self._schedules, start, end)) offsetY = 0 if self._showOnlyWorkHour: workingHours = [(self._startingHour, self._startingPauseHour), (self._endingPauseHour, self._endingHour)] else: workingHours = [(self._startingHour, self._endingHour)] if not self.pageNumber: self.pageCount = 1 self.pageLimits = [0] pageHeight = self.GetSize().GetHeight() - 20 currentPageHeight = y for dayN in xrange(daysCount): theDay = utils.copyDateTime(start) theDay.AddDS(wx.DateSpan(days=dayN)) theDay.SetSecond(0) color = highlight if theDay.IsSameDate(wx.DateTime.Now()): if self._viewType != wxSCHEDULER_DAILY or daysCount >= 2: color = self._highlightColor drawer.DrawDayBackground(x + 1.0 * width / daysCount * dayN, y, 1.0 * width / daysCount, height, highlight=color) if blocks: dayWidth = width / len(blocks) for idx, block in enumerate(blocks): maxDY = 0 for schedule in block: show = True if self.pageNumber is not None: if self._schedulesPages.get(schedule.GetId(), None) != self.pageNumber: show = False if show: if self._style == wxSCHEDULER_VERTICAL: xx, yy, w, h = drawer.DrawScheduleVertical( schedule, start, workingHours, x + dayWidth * idx, y, dayWidth, height) elif self._style == wxSCHEDULER_HORIZONTAL: xx, yy, w, h = drawer.DrawScheduleHorizontal( schedule, start, daysCount, workingHours, x, y + offsetY, width, height) maxDY = max(maxDY, h) if self.pageNumber is None: if currentPageHeight + h >= pageHeight: pageNo = self.pageCount + 1 else: pageNo = self.pageCount self._schedulesPages[schedule.GetId()] = pageNo self._schedulesCoords.append( (schedule, wx.Point(xx, yy), wx.Point(xx + w, yy + h))) else: schedule.Destroy() offsetY += maxDY if not self.pageNumber: currentPageHeight += maxDY if currentPageHeight >= pageHeight: self.pageLimits.append(currentPageHeight - maxDY) currentPageHeight = maxDY self.pageCount += 1 now = wx.DateTime.Now() for dayN in xrange(daysCount): theDay = utils.copyDateTime(start) theDay.AddDS(wx.DateSpan(days=dayN)) theDay.SetSecond(0) nbHours = len(self._lstDisplayedHours) for idx, hour in enumerate(self._lstDisplayedHours): theDay.SetHour(hour.GetHour()) theDay.SetMinute(hour.GetMinute()) if self._minSize is None or not self._resizable: if self._style == wxSCHEDULER_VERTICAL: self._datetimeCoords.append( (utils.copyDateTime(theDay), wx.Point(x + 1.0 * width * dayN / daysCount, y + 1.0 * height * idx / nbHours), wx.Point(x + 1.0 * width * (dayN + 1) / daysCount, y + 1.0 * height * (idx + 1) / nbHours))) else: self._datetimeCoords.append( (utils.copyDateTime(theDay), wx.Point( x + 1.0 * width * (nbHours * dayN + idx) / (nbHours * daysCount), y), wx.Point( x + 1.0 * width * (nbHours * dayN + idx + 1) / (nbHours * daysCount), y + height))) if isinstance(self, wx.ScrolledWindow) and self._showNow: now = wx.DateTime.Now() # This assumes self._lstDisplayedHours is sorted of course for dayN in xrange(daysCount): theDay = utils.copyDateTime(start) theDay.AddDS(wx.DateSpan(days=dayN)) if theDay.IsSameDate(now): theDay.SetSecond(0) previous = None for idx, hour in enumerate(self._lstDisplayedHours): theDay.SetHour(hour.GetHour()) theDay.SetMinute(hour.GetMinute()) if theDay.IsLaterThan(now): if idx != 0: if self._style == wxSCHEDULER_VERTICAL: yPrev = y + 1.0 * height * (idx - 1) / nbHours delta = 1.0 * height / nbHours * now.Subtract(previous).GetSeconds() \ / theDay.Subtract(previous).GetSeconds() drawer.DrawNowHorizontal( x, yPrev + delta, width) else: xPrev = x + 1.0 * width * ( nbHours * dayN + idx - 1) / (nbHours * daysCount) delta = 1.0 * width / (nbHours * daysCount) * now.Subtract(previous).GetSeconds() \ / theDay.Subtract(previous).GetSeconds() drawer.DrawNowVertical( xPrev + delta, y, height) break previous = utils.copyDateTime(theDay) break if self._style == wxSCHEDULER_VERTICAL: return max(width, DAY_SIZE_MIN.width), max(height, DAY_SIZE_MIN.height) else: return max(width, self._periodWidth), offsetY
def _paintPeriod(self, drawer, start, daysCount, x, y, width, height): end = utils.copyDateTime(start) if 'phoenix' in wx.PlatformInfo: end.Add(wx.DateSpan(days=daysCount)) else: end.AddDS(wx.DateSpan(days=daysCount)) blocks = self._splitSchedules( self._getSchedInPeriod(self._schedules, start, end)) offsetY = 0 if self._showOnlyWorkHour: workingHours = [(self._startingHour, self._startingPauseHour), (self._endingPauseHour, self._endingHour)] else: workingHours = [(self._startingHour, self._endingHour)] if not self.pageNumber: self.pageCount = 1 self.pageLimits = [0] pageHeight = self.GetSize().GetHeight() - 20 currentPageHeight = y for dayN in xrange(daysCount): theDay = utils.copyDateTime(start) if 'phoenix' in wx.PlatformInfo: theDay.Add(wx.DateSpan(days=dayN)) else: theDay.AddDS(wx.DateSpan(days=dayN)) # Recherche la couleur par défaut pour le jour highlight = False if self._viewType != wxSCHEDULER_DAILY: highlight = theDay.IsSameDate(wx.DateTime.Now()) # Recherche si c'est un jour férié ou un jour de vacances if self.joursSpeciaux != None and self._viewType != wxSCHEDULER_DAILY and highlight == False: couleur = self.joursSpeciaux.GetCouleur(theDay) if couleur != None: highlight = couleur drawer.DrawDayBackground(x + 1.0 * width / daysCount * dayN, y, 1.0 * width / daysCount, height, highlight=highlight) if blocks: dayWidth = width / len(blocks) for idx, block in enumerate(blocks): maxDY = 0 for schedule in block: show = True if self.pageNumber is not None: if self._schedulesPages.get(schedule.GetId(), None) != self.pageNumber: show = False if show: if self._style == wxSCHEDULER_VERTICAL: xx, yy, w, h = drawer.DrawScheduleVertical( schedule, start, workingHours, x + dayWidth * idx, y, dayWidth, height) elif self._style == wxSCHEDULER_HORIZONTAL: xx, yy, w, h = drawer.DrawScheduleHorizontal( schedule, start, daysCount, workingHours, x, y + offsetY, width, height) maxDY = max(maxDY, h) if self.pageNumber is None: if currentPageHeight + h >= pageHeight: pageNo = self.pageCount + 1 else: pageNo = self.pageCount self._schedulesPages[schedule.GetId()] = pageNo self._schedulesCoords.append( (schedule, wx.Point(xx, yy), wx.Point(xx + w, yy + h))) offsetY += maxDY if not self.pageNumber: currentPageHeight += maxDY if currentPageHeight >= pageHeight: self.pageLimits.append(currentPageHeight - maxDY) currentPageHeight = maxDY self.pageCount += 1 for dayN in xrange(daysCount): theDay = utils.copyDateTime(start) if 'phoenix' in wx.PlatformInfo: theDay.Add(wx.DateSpan(days=dayN)) else: theDay.AddDS(wx.DateSpan(days=dayN)) theDay.SetSecond(0) nbHours = len(self._lstDisplayedHours) for idx, hour in enumerate(self._lstDisplayedHours): theDay.SetHour(hour.GetHour()) theDay.SetMinute(hour.GetMinute()) if self._style == wxSCHEDULER_VERTICAL: self._datetimeCoords.append( (utils.copyDateTime(theDay), wx.Point(x + 1.0 * width * dayN / daysCount, y + 1.0 * height * idx / nbHours), wx.Point(x + 1.0 * width * (dayN + 1) / daysCount, y + 1.0 * height * (idx + 1) / nbHours))) else: self._datetimeCoords.append( (utils.copyDateTime(theDay), wx.Point( x + 1.0 * width * (nbHours * dayN + idx) / (nbHours * daysCount), y), wx.Point( x + 1.0 * width * (nbHours * dayN + idx + 1) / (nbHours * daysCount), y + height))) if self._style == wxSCHEDULER_VERTICAL: return max(width, DAY_SIZE_MIN.width), max(height, DAY_SIZE_MIN.height) else: return max(width, DAY_SIZE_MIN.width), offsetY
def ScheduleSize(schedule, workingHours, firstDay, dayCount): """ This convenience static method computes the position and size size of the schedule in the direction that represent time, according to a set of working hours. The workingHours parameter is a list of 2-tuples of wx.DateTime objects defining intervals which are indeed worked. startPeriod and endPeriod delimit the period. """ totalSpan = 0 scheduleSpan = 0 position = 0 totalTime = 0 for startHour, endHour in workingHours: totalTime += copyDateTime(endHour).Subtract(startHour).GetMinutes() / 60.0 for dayNumber in xrange(dayCount): currentDay = copyDateTime(firstDay) currentDay.AddDS(wx.DateSpan(days=dayNumber)) for startHour, endHour in workingHours: startHourCopy = wx.DateTimeFromDMY(currentDay.GetDay(), currentDay.GetMonth(), currentDay.GetYear(), startHour.GetHour(), startHour.GetMinute(), 0) endHourCopy = wx.DateTimeFromDMY(currentDay.GetDay(), currentDay.GetMonth(), currentDay.GetYear(), endHour.GetHour(), endHour.GetMinute(), 0) totalSpan += endHourCopy.Subtract(startHourCopy).GetMinutes() localStart = copyDateTime(schedule.start) if localStart.IsLaterThan(endHourCopy): position += endHourCopy.Subtract(startHourCopy).GetMinutes() continue if startHourCopy.IsLaterThan(localStart): localStart = startHourCopy localEnd = copyDateTime(schedule.end) if startHourCopy.IsLaterThan(localEnd): continue position += localStart.Subtract(startHourCopy).GetMinutes() if localEnd.IsLaterThan(endHourCopy): localEnd = endHourCopy scheduleSpan += localEnd.Subtract(localStart).GetMinutes() return dayCount * totalTime * scheduleSpan / totalSpan, dayCount * totalTime * position / totalSpan, totalTime * dayCount
def _paintPeriod(self, drawer, start, daysCount, x, y, width, height): end = utils.copyDateTime(start) if 'phoenix' in wx.PlatformInfo: end.Add(wx.DateSpan(days=daysCount)) else : end.AddDS(wx.DateSpan(days=daysCount)) blocks = self._splitSchedules(self._getSchedInPeriod(self._schedules, start, end)) offsetY = 0 if self._showOnlyWorkHour: workingHours = [(self._startingHour, self._startingPauseHour), (self._endingPauseHour, self._endingHour)] else: workingHours = [(self._startingHour, self._endingHour)] if not self.pageNumber: self.pageCount = 1 self.pageLimits = [0] pageHeight = self.GetSize().GetHeight() - 20 currentPageHeight = y for dayN in xrange(daysCount): theDay = utils.copyDateTime(start) if 'phoenix' in wx.PlatformInfo: theDay.Add(wx.DateSpan(days=dayN)) else : theDay.AddDS(wx.DateSpan(days=dayN)) # Recherche la couleur par défaut pour le jour highlight = False if self._viewType != wxSCHEDULER_DAILY : highlight = theDay.IsSameDate( wx.DateTime.Now() ) # Recherche si c'est un jour férié ou un jour de vacances if self.joursSpeciaux != None and self._viewType != wxSCHEDULER_DAILY and highlight == False : couleur = self.joursSpeciaux.GetCouleur(theDay) if couleur != None : highlight = couleur drawer.DrawDayBackground( x + 1.0 * width / daysCount * dayN, y, 1.0 * width / daysCount, height, highlight=highlight) if blocks: dayWidth = width / len(blocks) for idx, block in enumerate(blocks): maxDY = 0 for schedule in block: show = True if self.pageNumber is not None: if self._schedulesPages.get(schedule.GetId(), None) != self.pageNumber: show = False if show: if self._style == wxSCHEDULER_VERTICAL: xx, yy, w, h = drawer.DrawScheduleVertical(schedule, start, workingHours, x + dayWidth * idx, y, dayWidth, height) elif self._style == wxSCHEDULER_HORIZONTAL: xx, yy, w, h = drawer.DrawScheduleHorizontal(schedule, start, daysCount, workingHours, x, y + offsetY, width, height) maxDY = max(maxDY, h) if self.pageNumber is None: if currentPageHeight + h >= pageHeight: pageNo = self.pageCount + 1 else: pageNo = self.pageCount self._schedulesPages[schedule.GetId()] = pageNo self._schedulesCoords.append((schedule, wx.Point(xx, yy), wx.Point(xx + w, yy + h))) offsetY += maxDY if not self.pageNumber: currentPageHeight += maxDY if currentPageHeight >= pageHeight: self.pageLimits.append(currentPageHeight - maxDY) currentPageHeight = maxDY self.pageCount += 1 for dayN in xrange(daysCount): theDay = utils.copyDateTime(start) if 'phoenix' in wx.PlatformInfo: theDay.Add(wx.DateSpan(days=dayN)) else : theDay.AddDS(wx.DateSpan(days=dayN)) theDay.SetSecond(0) nbHours = len(self._lstDisplayedHours) for idx, hour in enumerate(self._lstDisplayedHours): theDay.SetHour(hour.GetHour()) theDay.SetMinute(hour.GetMinute()) if self._style == wxSCHEDULER_VERTICAL: self._datetimeCoords.append((utils.copyDateTime(theDay), wx.Point(x + 1.0 * width * dayN / daysCount, y + 1.0 * height * idx / nbHours), wx.Point(x + 1.0 * width * (dayN + 1) / daysCount, y + 1.0 * height * (idx + 1) / nbHours))) else: self._datetimeCoords.append((utils.copyDateTime(theDay), wx.Point(x + 1.0 * width * (nbHours * dayN + idx) / (nbHours * daysCount), y), wx.Point(x + 1.0 * width * (nbHours * dayN + idx + 1) / (nbHours * daysCount), y + height))) if self._style == wxSCHEDULER_VERTICAL: return max(width, DAY_SIZE_MIN.width), max(height, DAY_SIZE_MIN.height) else: return max(width, DAY_SIZE_MIN.width), offsetY