def keyPressEvent(self, event): k = event.key() print time(), 'MonthCal.keyPressEvent', k, hex(k) if k==qc.Qt.Key_Up: self.jdPlus(-7) elif k==qc.Qt.Key_Down: self.jdPlus(7) elif k==qc.Qt.Key_Right: if rtl: self.jdPlus(-1) else: self.jdPlus(1) elif k==qc.Qt.Key_Left: if rtl: self.jdPlus(1) else: self.jdPlus(-1) elif k==qc.Qt.Key_Space or k==qc.Qt.Key_Home: self.goToday() elif k==qc.Qt.Key_End: self.changeDate(ui.cell.year, ui.cell.month, getMonthLen(ui.cell.year, ui.cell.month, core.primaryMode)) elif k==qc.Qt.Key_End: self.changeDate(ui.cell.year, ui.cell.month, getMonthLen(ui.cell.year, ui.cell.month, core.primaryMode)) elif k==qc.Qt.Key_PageUp: (year, month) = getPrevMonth(ui.cell.year, ui.cell.month) self.changeDate(year, month, ui.cell.day) elif k==qc.Qt.Key_PageDown: (year, month) = getNextMonth(ui.cell.year, ui.cell.month) self.changeDate(year, month, ui.cell.day) elif k==qc.Qt.Key_Menu:# Simulate right click (key beside Right-Ctrl) self.emit(qc.SIGNAL('popup-menu-cell'), *self.getCellPos()) elif k in (qc.Qt.Key_F10, qc.Qt.Key_M): #print 'keyPressEvent: menu', event.modifiers() if event.modifiers() & qc.Qt.ShiftModifier: ## Simulate right click (key beside Right-Ctrl) print 'popup-menu-cell' self.emit(qc.SIGNAL('popup-menu-cell'), *self.getCellPos()) else: print 'popup-menu-main' self.emit(qc.SIGNAL('popup-menu-main'), *self.getMainMenuPos()) else: event.ignore() ## I dont want the event. Propagate to the parent widget. #print time(), 'MonthCal.keyPressEvent', hex(k) return event.accept() ## I want the event. Do not propagate to the parent widget.
def comboMonthChanged(self, widget=None): monthIndex = self.comboMonth.get_active() if monthIndex == -1: return self.spinD.set_range( 1, getMonthLen( self.spinY.get_value(), monthIndex + 1, self.mode, ))
def monthPlus(plus=1): global cell if plus==1: (year, month) = getNextMonth(cell.year, cell.month) elif plus==-1: (year, month) = getPrevMonth(cell.year, cell.month) else: raise ValueError('monthPlus: bad argument %s'%plus) day = min(cell.day, getMonthLen(year, month, core.primaryMode)) cell = cellCache.getCellByDate(year, month, day)
def __init__(self, cellCache, year, month): self.year = year self.month = month self.monthLen = getMonthLen(year, month, calTypes.primary) self.offset = getWeekDay(year, month, 1) ## month start offset initJd = core.primary_to_jd(year, month, 1) self.weekNum = [getWeekNumberByJd(initJd + i * 7) for i in range(6)] ######### startJd, endJd = core.getJdRangeForMonth(year, month, calTypes.primary) tableStartJd = startJd - self.offset ##### list.__init__(self, [[ cellCache.getCell(tableStartJd + yPos * 7 + xPos) for xPos in range(7) ] for yPos in range(6)])
def __init__(self, cellCache, year, month): self.year = year self.month = month self.monthLen = getMonthLen(year, month, calTypes.primary) self.offset = getWeekDay(year, month, 1)## month start offset self.weekNum = [getWeekNumber(year, month, 1+7*i) for i in range(6)] ######### startJd, endJd = core.getJdRangeForMonth(year, month, calTypes.primary) tableStartJd = startJd - self.offset ##### list.__init__(self, [ [ cellCache.getCell( tableStartJd + yPos*7 + xPos ) for xPos in range(7) ] for yPos in range(6) ])
def keyPress(self, arg, event): t = time() #if t-self.kTime < ui.keyDelay: # return True kname = gdk.keyval_name(event.keyval).lower() #if kname.startswith('alt'): # return True ## How to disable Alt+Space of metacity ????????????????????? if kname=='up': self.jdPlus(-7) elif kname=='down': self.jdPlus(7) elif kname=='right': if rtl: self.jdPlus(-1) else: self.jdPlus(1) elif kname=='left': if rtl: self.jdPlus(1) else: self.jdPlus(-1) elif kname in ('space', 'home'): self.goToday() elif kname=='end': self.changeDate(ui.cell.year, ui.cell.month, getMonthLen(ui.cell.year, ui.cell.month, core.primaryMode)) elif kname=='page_up': ui.monthPlus(-1) self.onDateChange() elif kname=='page_down': ui.monthPlus(1) self.onDateChange() elif kname=='menu': self.emit('popup-menu-cell', event.time, *self.getCellPos()) elif kname in ('f10', 'm'): if event.state & gdk.SHIFT_MASK: # Simulate right click (key beside Right-Ctrl) self.emit('popup-menu-cell', event.time, *self.getCellPos()) else: self.emit('popup-menu-main', event.time, *self.getMainMenuPos()) else: return False return True
def keyPress(self, arg, event): if CalBase.keyPress(self, arg, event): return True kname = gdk.keyval_name(event.keyval).lower() #if kname.startswith('alt'): # return True ## How to disable Alt+Space of metacity ????????????????????? if kname=='up': self.jdPlus(-7) elif kname=='down': self.jdPlus(7) elif kname=='right': if rtl: self.jdPlus(-1) else: self.jdPlus(1) elif kname=='left': if rtl: self.jdPlus(1) else: self.jdPlus(-1) elif kname=='end': self.changeDate( ui.cell.year, ui.cell.month, getMonthLen(ui.cell.year, ui.cell.month, calTypes.primary), ) elif kname in ('page_up', 'k', 'p'): self.monthPlus(-1) elif kname in ('page_down', 'j', 'n'): self.monthPlus(1) elif kname in ('f10', 'm'): if event.state & gdk.SHIFT_MASK: # Simulate right click (key beside Right-Ctrl) self.emit('popup-menu-cell', event.time, *self.getCellPos()) else: self.emit('popup-menu-main', event.time, *self.getMainMenuPos()) else: return False return True
def keyPress(self, arg, gevent): if CalBase.keyPress(self, arg, gevent): return True kname = gdk.keyval_name(gevent.keyval).lower() #if kname.startswith('alt'): # return True ## How to disable Alt+Space of metacity ????????????????????? if kname=='up': self.jdPlus(-7) elif kname=='down': self.jdPlus(7) elif kname=='right': if rtl: self.jdPlus(-1) else: self.jdPlus(1) elif kname=='left': if rtl: self.jdPlus(1) else: self.jdPlus(-1) elif kname=='end': self.changeDate( ui.cell.year, ui.cell.month, core.getMonthLen(ui.cell.year, ui.cell.month, calTypes.primary), ) elif kname in ('page_up', 'k', 'p'): self.monthPlus(-1) elif kname in ('page_down', 'j', 'n'): self.monthPlus(1) elif kname in ('f10', 'm'): if gevent.state & gdk.SHIFT_MASK: # Simulate right click (key beside Right-Ctrl) self.emit('popup-cell-menu', gevent.time, *self.getCellPos()) else: self.emit('popup-main-menu', gevent.time, *self.getMainMenuPos()) else: return False return True
def comboMonthChanged(self, widget=None): self.spinD.set_range(1, getMonthLen( self.spinY.get_value(), self.comboMonth.get_active() + 1, self.mode, ))
def yearPlus(plus=1): global cell year = cell.year + plus month = cell.month day = min(cell.day, core.getMonthLen(year, month, calTypes.primary)) cell = cellCache.getCellByDate(year, month, day)
def yearPlus(plus=1): global cell year = cell.year + plus month = cell.month day = min(cell.day, getMonthLen(year, month, core.primaryMode)) cell = cellCache.getCellByDate(year, month, day)
def monthPlus(plus=1): global cell year, month = core.monthPlus(cell.year, cell.month, plus) day = min(cell.day, getMonthLen(year, month, core.primaryMode)) cell = cellCache.getCellByDate(year, month, day)
def comboMonthChanged(self, index=None): self.spinD.setRange(1, getMonthLen( int(self.spinY.value()), self.comboMonth.currentIndex() + 1, self.mode, ))
def buildStatus(self, year, month, addCache=True): #print 'Building cache (%s, %s)'%(year, month) s = MonthStatus()#s = [] s.year = year s.month = month pyear = year pmonth = month -1 if pmonth <= 0 : pmonth =12 pyear -=1 prevMonthLen = core.getMonthLen(pyear, pmonth, self.mode) currentMonthLen = core.getMonthLen(year, month, self.mode) s.monthLen = currentMonthLen ##################### s.weekNum = [self.weekNumber(year, month, 1+7*i) for i in xrange(6)] offset = core.getWeekDay(year, month, 1) if offset==0: ###### Which Method ???????????????????? #day = prevMonthLen - 6 ; s.weekNum = [self.weekNumber(year, month, 1+7*i)-1 for i in xrange(6)] day = 1 else: day = prevMonthLen - offset + 1 s.monthStartOffset = offset ###################### for i in xrange(6): s.append([]) for j in xrange(7): c = Cell() c.pos = (j, i) s[i].append(c) c.jd = core.to_jd(year, month, day, self.mode) if i<2 and day>15: c.gray = -1 c.date = (pyear, pmonth, day) #c.ym = (pyear, pmonth) elif i>=4 and day<20: c.gray = 1 nyear = year nmonth = month +1 if nmonth > 12 : nmonth =1 nyear += 1 c.date = (nyear, nmonth, day) else: c.gray = 0 c.date = (year, month, day) cyear, cmonth, cday = c.date if c.gray==0: wd = (core.firstWeekDay + j) % 7 ##?????????? if wd in self.holidayWeekDays: c.holiday = True day+=1 if i>3 and day>currentMonthLen: day =1 sday=1 if i<2 and day>prevMonthLen: day =1 if addCache: ## Clean Cache n = len(self.months) #print 'Cache size: %s'%n if n >= self.maxCache: keys = self.months.keys() keys.sort() if keys[n/2] < (year, month): rm = keys[0] if rm==self.today[:2]: rm = keys[1] else: rm = keys[-1] if rm==self.today[:2]: rm = keys[-2] #if rm != (year, month): #print 'Removing cache (%s, %s)'%(rm[0], rm[1]) self.months.pop(rm) try:#### for memory emhancement del self.months[(year, month)] except: pass self.months[(year, month)] = s return s