Exemple #1
0
    def _updateContentWithEmptyDays(self, ascendTime):
        stepDateSpan = wx.TimeSpan_Days(self.stepDays)

        # Collect data
        if ascendTime:
            currTime = self.fixedItemDay - wx.TimeSpan_Days(
                    self.fixedItemIndex)
        else:
            currTime = self.fixedItemDay - wx.TimeSpan_Days(
                    self.visibleItemCount - self.fixedItemIndex - 1)

        content = []
        maxWordCount = 0
        massWordCounts = self.wikiWordFilter.getMassWikiWordCountForDays(
                currTime, self.visibleItemCount)
        
        for i in xrange(self.visibleItemCount):
            wordCount = massWordCounts[i]
            content.append((currTime, wordCount))
            maxWordCount = max(maxWordCount, wordCount)
            currTime = currTime + stepDateSpan  # To ensure copying
        
        if not ascendTime:
            content.reverse()
           
        self.listMaxWordCount = maxWordCount
        self.listContent = content
Exemple #2
0
    def _HitTestInMonth(self, month, posX, posY):
        """
        Called by HitTest

        month -- wx.DateTime object repesenting the first day of
                the month to look at
        posX, posY -- Upper left position of month calendar
        """
        cellShiftX = self.cellWidth + self.cellDistHor
        cellShiftY = self.cellHeight + self.cellDistVert

        cellCol = posX // cellShiftX
        if cellCol >= 7:
            return (month, self.HITTEST_MONTH, None)

        # If cellRow is out of range will be decided later
        cellRow = posY // cellShiftY

        if cellRow == 0:
            # In title
            return (month, self.HITTEST_MONTH_TITLE,
                    wx.Rect(0, 0, self.cellWidth * 7 + self.cellDistHor * 6,
                            self.cellHeight))

        if cellRow == 1:
            # In weekday names
            return (month, self.HITTEST_MONTH, None)

        inCellX = posX % cellShiftX
        inCellY = posY % cellShiftY

        if inCellX >= self.cellWidth or inCellY >= self.cellHeight:
            # Somewhere between cells or a bit too far right/down
            return (month, self.HITTEST_MONTH, None)

        cellNumber = (cellRow - 2) * 7 + cellCol

        dayShift = cellNumber - self.getColForWeekDay(month.GetWeekDay())

        if dayShift < 0:
            # In a cell to the left of day 1
            return (month, self.HITTEST_MONTH, None)

        dayCount = wx.DateTime.GetNumberOfDaysInMonth(month.GetMonth(),
                                                      month.GetYear())

        if dayShift >= dayCount:
            # On an empty cell after the last day of month
            return (month, self.HITTEST_MONTH, None)

        date = month + wx.TimeSpan_Days(dayShift)

        return (date, self.HITTEST_DAY,
                wx.Rect(cellCol * cellShiftX, cellRow * cellShiftY,
                        self.cellWidth, self.cellHeight))
Exemple #3
0
    def OnKeyDown(self, event):
        if not self.hasFocus:
            event.Skip()
            return

        key_code = event.KeyCode()

        if key_code == wx.WXK_TAB:
            forward = not event.ShiftDown()
            ne = wx.NavigationKeyEvent()
            ne.SetDirection(forward)
            ne.SetCurrentFocus(self)
            ne.SetEventObject(self)
            self.GetParent().GetEventHandler().ProcessEvent(ne)
            event.Skip()
            return

        delta = None

        if key_code == wx.WXK_UP:
            delta = -7
        elif key_code == wx.WXK_DOWN:
            delta = 7
        elif key_code == wx.WXK_LEFT:
            delta = -1
        elif key_code == wx.WXK_RIGHT:
            delta = 1
        elif key_code == wx.WXK_HOME:
            curDate = wx.DateTimeFromDMY(int(self.cal_days[self.sel_key]),
                                         self.month - 1, self.year)
            newDate = wx.DateTime_Now()
            ts = newDate - curDate
            delta = ts.GetDays()

        if delta <> None:
            curDate = wx.DateTimeFromDMY(int(self.cal_days[self.sel_key]),
                                         self.month - 1, self.year)
            timeSpan = wx.TimeSpan_Days(delta)
            newDate = curDate + timeSpan

            if curDate.GetMonth() == newDate.GetMonth():
                self.set_day = newDate.GetDay()
                key = self.sel_key + delta
                self.SelectDay(key)
            else:
                self.month = newDate.GetMonth() + 1
                self.year = newDate.GetYear()
                self.set_day = newDate.GetDay()
                self.sel_key = None
                self.DoDrawing(wx.ClientDC(self))

        event.Skip()
    def getMassWikiWordCountForDays(self, startDay, count):
        """
        Returns a list dayWordCounts where dayWordCounts[i] is the same as
        len(self.getWikiWordsForDay(startDay + wx.TimeSpan_Days(self.dayResolution) * i))
        and len(dayWordCounts) == count.
        
        This base class contains a default implementation
        """
        day = startDay
        step = wx.TimeSpan_Days(self.dayResolution)

        dayWordCounts = []
        for i in xrange(count):
            dayWordCounts.append(len(self.getWikiWordsForDay(day)))
            day = day + step
        
        return dayWordCounts