Esempio n. 1
0
def getMonthMatrix(year, month):
    """Return matrix of dates in the month in the 7x6 format."""
    matrix = calendar.monthcalendar(year, month)
    blank_week = [0,0,0,0,0,0,0]
    last_month = goMonth(datetime.date(year, month, 1), -1)
    next_month = goMonth(datetime.date(year, month, 1), 1)
    last_month_day = calendar.monthrange(last_month.year, last_month.month)[1]
    next_month_day = 1
    first_week = matrix[0]
    for idx in range(6, -1, -1):
        if first_week[idx] == 0:
            first_week[idx] = datetime.date(last_month.year, last_month.month,
                                            last_month_day)
            last_month_day -= 1
    for week_idx in range(0, 6):
        try:
            week = matrix[week_idx]
        except IndexError:
            week = list(blank_week)
            matrix.append(week)
        for day_idx, day in enumerate(week):
            if isinstance(day, datetime.date):
                continue
            if day == 0:
                week[day_idx] = datetime.date(next_month.year,
                                              next_month.month, next_month_day)
                next_month_day += 1
                continue
            # current month and year
            week[day_idx] = datetime.date(year, month, day)
    return matrix
Esempio n. 2
0
def getMonthMatrix(year, month):
    """Return matrix of dates in the month in the 7x6 format."""
    matrix = calendar.monthcalendar(year, month)
    blank_week = [0, 0, 0, 0, 0, 0, 0]
    last_month = goMonth(datetime.date(year, month, 1), -1)
    next_month = goMonth(datetime.date(year, month, 1), 1)
    last_month_day = calendar.monthrange(last_month.year, last_month.month)[1]
    next_month_day = 1
    first_week = matrix[0]
    for idx in range(6, -1, -1):
        if first_week[idx] == 0:
            first_week[idx] = datetime.date(last_month.year, last_month.month,
                                            last_month_day)
            last_month_day -= 1
    for week_idx in range(0, 6):
        try:
            week = matrix[week_idx]
        except IndexError:
            week = list(blank_week)
            matrix.append(week)
        for day_idx, day in enumerate(week):
            if isinstance(day, datetime.date):
                continue
            if day == 0:
                week[day_idx] = datetime.date(next_month.year,
                                              next_month.month, next_month_day)
                next_month_day += 1
                continue
            # current month and year
            week[day_idx] = datetime.date(year, month, day)
    return matrix
Esempio n. 3
0
 def test_goMonth(self):
     self.assertEqual(dates.goMonth(datetime.date(2012, 8, 1), 10),
                      datetime.date(2013, 6, 1))
     self.assertEqual(dates.goMonth(datetime.date(2012, 8, 1), 10),
                      datetime.date(2013, 6, 1))
     self.assertEqual(dates.goMonth(datetime.date(2012, 3, 31), -1),
                      datetime.date(2012, 2, 29))
     self.assertEqual(dates.goMonth(datetime.date(2012, 3, 31), -13),
                      datetime.date(2011, 2, 28))
Esempio n. 4
0
 def processDayKeyDown(self, evt):
     """User is navigating the calendar; respond appropriately."""
     evtData = evt.EventData
     kc = evtData["keyCode"]
     ctrlDown = evtData["controlDown"]
     layout = self.Form.CalendarLayout
     for keys, func_args in self.key_actions.items():
         if kc in keys:
             func, args = func_args
             func(*args)
             evt.stop()
             return
     if kc not in [
             dKeys.key_Up, dKeys.key_Down, dKeys.key_Left, dKeys.key_Right
     ]:
         return
     evt.stop()
     if not ctrlDown:
         # move by day, wrapping around in the calendar
         x, y = self.Pos
         if kc == dKeys.key_Up and layout in ("month", ):
             y -= 1
             if y < 0:
                 y = 5
         elif kc == dKeys.key_Down and layout in ("month", ):
             y += 1
             if y > 5:
                 y = 0
         elif kc == dKeys.key_Left:
             x -= 1
             if x < 0:
                 x = 6
         elif kc == dKeys.key_Right:
             x += 1
             if x > 6:
                 x = 0
         new_ctrl = getattr(self.Parent, "day_%s_%s" % (x, y))
         new_ctrl.setFocus()
     else:
         year, month = self.Parent.Year, self.Parent.Month
         current_date = datetime.date(year, month, 1)
         if kc == dKeys.key_Left:
             new_date = goMonth(current_date, -1)
         elif kc == dKeys.key_Right:
             new_date = goMonth(current_date, 1)
         elif kc == dKeys.key_Up:
             new_date = goMonth(current_date, -12)
         elif kc == dKeys.key_Down:
             new_date = goMonth(current_date, 12)
         self.Parent.Year = new_date.year
         self.Parent.Month = new_date.month
Esempio n. 5
0
 def processDayKeyDown(self, evt):
     """User is navigating the calendar; respond appropriately."""
     evtData = evt.EventData
     kc = evtData["keyCode"]
     ctrlDown = evtData["controlDown"]
     layout = self.Form.CalendarLayout
     for keys, func_args in self.key_actions.items():
         if kc in keys:
             func, args = func_args
             func(*args)
             evt.stop()
             return
     if kc not in [dKeys.key_Up, dKeys.key_Down,
                   dKeys.key_Left, dKeys.key_Right]:
         return
     evt.stop()
     if not ctrlDown:
         # move by day, wrapping around in the calendar
         x,y = self.Pos
         if kc == dKeys.key_Up and layout in ("month",):
             y -= 1
             if y < 0:
                 y = 5
         elif kc == dKeys.key_Down and layout in ("month",):
             y += 1
             if y > 5:
                 y = 0
         elif kc == dKeys.key_Left:
             x -= 1
             if x < 0:
                 x = 6
         elif kc == dKeys.key_Right:
             x += 1
             if x > 6:
                 x = 0
         new_ctrl = getattr(self.Parent, "day_%s_%s" % (x,y))
         new_ctrl.setFocus()
     else:
         year, month = self.Parent.Year, self.Parent.Month
         current_date = datetime.date(year, month, 1)
         if kc == dKeys.key_Left:
             new_date = goMonth(current_date, -1)
         elif kc == dKeys.key_Right:
             new_date = goMonth(current_date, 1)
         elif kc == dKeys.key_Up:
             new_date = goMonth(current_date, -12)
         elif kc == dKeys.key_Down:
             new_date = goMonth(current_date, 12)
         self.Parent.Year = new_date.year
         self.Parent.Month = new_date.month
Esempio n. 6
0
 def onHit_but(self, evt):
     pnlLayout = self.Form.pnlLayout
     interval = {"butLeft": -1, "butRight": 1,}[evt.EventObject.Name]
     new_date = goMonth(datetime.date(pnlLayout.Year, pnlLayout.Month, 1),
                        interval)
     pnlLayout.Year = new_date.year
     pnlLayout.Month = new_date.month
     pnlLayout.setFocus()
Esempio n. 7
0
 def onHit_but(self, evt):
     pnlLayout = self.Form.pnlLayout
     interval = {
         "butLeft": -1,
         "butRight": 1,
     }[evt.EventObject.Name]
     new_date = goMonth(datetime.date(pnlLayout.Year, pnlLayout.Month, 1),
                        interval)
     pnlLayout.Year = new_date.year
     pnlLayout.Month = new_date.month
     pnlLayout.setFocus()
Esempio n. 8
0
	def test_goMonth(self):
		self.assertEqual(dates.goMonth(datetime.date(2012, 8, 1), 10), datetime.date(2013, 6, 1))
		self.assertEqual(dates.goMonth(datetime.date(2012, 8, 1), 10), datetime.date(2013, 6, 1))
		self.assertEqual(dates.goMonth(datetime.date(2012, 3, 31), -1), datetime.date(2012, 2, 29))
		self.assertEqual(dates.goMonth(datetime.date(2012, 3, 31), -13), datetime.date(2011, 2, 28))