class CellCache: def __init__(self): self.jdCells = {} ## a mapping from julan_day to Cell instance self.plugins = {} self.weekEvents = {} def clear(self): global cell, todayCell self.jdCells = {} self.weekEvents = {} cell = self.getCell(cell.jd) todayCell = self.getCell(todayCell.jd) def registerPlugin(self, name, setParamsCallable, getCellGroupCallable): """ setParamsCallable(cell): cell.attr1 = value1 .... getCellGroupCallable(cellCache, *args): return cell_group call cellCache.getCell(jd) inside getCellGroupFunc """ self.plugins[name] = ( setParamsCallable, getCellGroupCallable, ) for localCell in self.jdCells.values(): setParamsCallable(localCell) def getCell(self, jd): try: return self.jdCells[jd] except KeyError: return self.buildCell(jd) def getTmpCell(self, jd):## don't keep, no eventsData, no plugin params try: return self.jdCells[jd] except KeyError: return Cell(jd) getCellByDate = lambda self, y, m, d: self.getCell(core.primary_to_jd(y, m, d)) getTodayCell = lambda self: self.getCell(core.getCurrentJd()) def buildCell(self, jd): localCell = Cell(jd) for pluginData in self.plugins.values(): pluginData[0](localCell) self.jdCells[jd] = localCell cleanCacheDict(self.jdCells, maxDayCacheSize, jd) return localCell getCellGroup = lambda self, pluginName, *args:\ self.plugins[pluginName][1](self, *args) def getWeekData(self, absWeekNumber): cells = self.getCellGroup('WeekCal', absWeekNumber) try: wEventData = self.weekEvents[absWeekNumber] except KeyError: wEventData = event_lib.getWeekOccurrenceData(absWeekNumber, eventGroups) cleanCacheDict(self.weekEvents, maxWeekCacheSize, absWeekNumber) self.weekEvents[absWeekNumber] = wEventData return cells, wEventData
def getTodayCell(self): return self.getCell(core.getCurrentJd())
def __init__(self, showDesc=False): gtk.Window.__init__(self) self.maximize() self.initVars() ud.windowList.appendItem(self) ### self.set_title(_("Search Events")) self.connect("delete-event", self.closed) self.connect("key-press-event", self.keyPress) ### self.vbox = gtk.VBox() self.add(self.vbox) ###### frame = TextFrame() frame.set_label(_("Text")) frame.set_border_width(5) pack(self.vbox, frame) self.textInput = frame ## hbox = gtk.HBox() self.textCSensCheck = gtk.CheckButton(_("Case Sensitive")) self.textCSensCheck.set_active(False) ## FIXME pack(hbox, self.textCSensCheck) pack(self.vbox, hbox) ###### jd = core.getCurrentJd() year, month, day = jd_to_primary(jd) ###### hbox = gtk.HBox() frame = gtk.Frame() frame.set_label(_("Time")) frame.set_border_width(5) vboxIn = gtk.VBox() sgroup = gtk.SizeGroup(gtk.SizeGroupMode.HORIZONTAL) #### hboxIn = gtk.HBox() ## self.timeFromCheck = gtk.CheckButton(_("From")) sgroup.add_widget(self.timeFromCheck) pack(hboxIn, self.timeFromCheck) pack(hboxIn, gtk.Label(" ")) ## self.timeFromInput = DateTimeButton() self.timeFromInput.set_value(((year, 1, 1), (0, 0, 0))) pack(hboxIn, self.timeFromInput) ## pack(vboxIn, hboxIn) #### hboxIn = gtk.HBox() ## self.timeToCheck = gtk.CheckButton(_("To")) sgroup.add_widget(self.timeToCheck) pack(hboxIn, self.timeToCheck) pack(hboxIn, gtk.Label(" ")) ## self.timeToInput = DateTimeButton() self.timeToInput.set_value(( (year + 1, 1, 1), (0, 0, 0), )) pack(hboxIn, self.timeToInput) ## pack(vboxIn, hboxIn) ## self.timeFromCheck.connect("clicked", self.updateTimeFromSensitive) self.timeToCheck.connect("clicked", self.updateTimeToSensitive) self.updateTimeFromSensitive() self.updateTimeToSensitive() #### vboxIn.set_border_width(5) frame.add(vboxIn) pack(hbox, frame) pack(hbox, gtk.Label(""), 1, 1) pack(self.vbox, hbox) ###### hbox = gtk.HBox() hbox.set_border_width(5) self.modifiedFromCheck = gtk.CheckButton(_("Modified From")) pack(hbox, self.modifiedFromCheck) pack(hbox, gtk.Label(" ")) self.modifiedFromInput = DateTimeButton() self.modifiedFromInput.set_value(((year, 1, 1), (0, 0, 0))) pack(hbox, self.modifiedFromInput) ## self.modifiedFromCheck.connect("clicked", self.updateModifiedFromSensitive) self.updateModifiedFromSensitive() pack(self.vbox, hbox) ###### hbox = gtk.HBox() hbox.set_border_width(5) self.typeCheck = gtk.CheckButton(_("Event Type")) pack(hbox, self.typeCheck) pack(hbox, gtk.Label(" ")) ## combo = gtk.ComboBoxText() for cls in event_lib.classes.event: combo.append_text(cls.desc) combo.set_active(0) pack(hbox, combo) self.typeCombo = combo ## self.typeCheck.connect("clicked", self.updateTypeSensitive) self.updateTypeSensitive() pack(self.vbox, hbox) ###### hbox = gtk.HBox() hbox.set_border_width(5) self.groupCheck = gtk.CheckButton(_("Group")) pack(hbox, self.groupCheck) pack(hbox, gtk.Label(" ")) self.groupCombo = SingleGroupComboBox() pack(hbox, self.groupCombo) ## self.groupCheck.connect("clicked", self.updateGroupSensitive) self.updateGroupSensitive() pack(self.vbox, hbox) ###### bbox = gtk.HButtonBox() bbox.set_layout(gtk.ButtonBoxStyle.START) bbox.set_border_width(5) searchButton = gtk.Button() searchButton.set_label(_("_Search")) searchButton.set_image( gtk.Image.new_from_stock( gtk.STOCK_FIND, gtk.IconSize.BUTTON, )) searchButton.connect("clicked", self.searchClicked) bbox.add(searchButton) pack(self.vbox, bbox) ###### treev = gtk.TreeView() trees = gtk.TreeStore( int, # gid int, # eid str, # group_name GdkPixbuf.Pixbuf, # icon str, # summary str, # description ) ### treev.set_model(trees) treev.connect("button-press-event", self.treevButtonPress) treev.connect("row-activated", self.rowActivated) treev.connect("key-press-event", self.treevKeyPress) treev.set_headers_clickable(True) ### self.colGroup = gtk.TreeViewColumn( _("Group"), gtk.CellRendererText(), text=2, ) self.colGroup.set_resizable(True) self.colGroup.set_sort_column_id(2) self.colGroup.set_property("expand", False) treev.append_column(self.colGroup) ### self.colIcon = gtk.TreeViewColumn() cell = gtk.CellRendererPixbuf() pack(self.colIcon, cell) self.colIcon.add_attribute(cell, "pixbuf", 3) #self.colIcon.set_sort_column_id(3) # FIXME self.colIcon.set_property("expand", False) treev.append_column(self.colIcon) ### self.colSummary = gtk.TreeViewColumn( _("Summary"), gtk.CellRendererText(), text=4, ) self.colSummary.set_resizable(True) self.colSummary.set_sort_column_id(4) self.colSummary.set_property("expand", True) # FIXME treev.append_column(self.colSummary) ### self.colDesc = gtk.TreeViewColumn( _("Description"), gtk.CellRendererText(), text=5, ) self.colDesc.set_sort_column_id(5) self.colDesc.set_visible(showDesc) self.colDesc.set_property("expand", True) # FIXME treev.append_column(self.colDesc) ### trees.set_sort_func(2, self.sort_func_group) ###### swin = gtk.ScrolledWindow() swin.set_policy(gtk.PolicyType.AUTOMATIC, gtk.PolicyType.AUTOMATIC) swin.add(treev) #### vbox = gtk.VBox(spacing=5) vbox.set_border_width(5) ### topHbox = gtk.HBox() self.resultLabel = gtk.Label("") pack(topHbox, self.resultLabel) pack(topHbox, gtk.Label(""), 1, 1) pack(vbox, topHbox) #### columnBox = gtk.HBox(spacing=5) pack(columnBox, gtk.Label(_("Columns") + ": ")) ## check = gtk.CheckButton(_("Group")) check.set_active(True) check.connect( "clicked", lambda w: self.colGroup.set_visible(w.get_active()), ) pack(columnBox, check) ## check = gtk.CheckButton(_("Icon")) check.set_active(True) check.connect( "clicked", lambda w: self.colIcon.set_visible(w.get_active()), ) pack(columnBox, check) ## check = gtk.CheckButton(_("Summary")) check.set_active(True) check.connect( "clicked", lambda w: self.colSummary.set_visible(w.get_active()), ) pack(columnBox, check) ## check = gtk.CheckButton(_("Description")) check.set_active(showDesc) check.connect( "clicked", lambda w: self.colDesc.set_visible(w.get_active()), ) pack(columnBox, check) ## pack(vbox, columnBox) #### pack(vbox, swin, 1, 1) ## frame = gtk.Frame() frame.set_label(_("Search Results")) frame.set_border_width(10) frame.add(vbox) ## pack(self.vbox, frame, 1, 1) ### bbox2 = gtk.HButtonBox() bbox2.set_layout(gtk.ButtonBoxStyle.END) bbox2.set_border_width(10) closeButton = gtk.Button() closeButton.set_label(_("_Close")) closeButton.set_image( gtk.Image.new_from_stock( gtk.STOCK_CLOSE, gtk.IconSize.BUTTON, )) closeButton.connect("clicked", self.closed) bbox2.add(closeButton) pack(self.vbox, bbox2) ###### self.treev = treev self.trees = trees self.vbox.show_all()
class CalBase(CustomizableCalObj): signals = CustomizableCalObj.signals + [ ('popup-cell-menu', [int, int, int]), ('popup-main-menu', [int, int, int]), ('2button-press', []), ('pref-update-bg-color', []), ('day-info', []), ] myKeys = ( 'space', 'home', 't', 'menu', 'i', ) def initCal(self): self.initVars() listener.dateChange.add(self) #### self.defineDragAndDrop() self.connect('2button-press', ui.dayOpenEvolution) if ui.mainWin: self.connect('popup-cell-menu', ui.mainWin.menuCellPopup) self.connect('popup-main-menu', ui.mainWin.menuMainPopup) self.connect('pref-update-bg-color', ui.mainWin.prefUpdateBgColor) self.connect('day-info', ui.mainWin.dayInfoShow) def gotoJd(self, jd): ui.gotoJd(jd) self.onDateChange() goToday = lambda self, obj=None: self.gotoJd(core.getCurrentJd()) def jdPlus(self, p): ui.jdPlus(p) self.onDateChange() def changeDate(self, year, month, day, mode=None): ui.changeDate(year, month, day, mode) self.onDateChange() def onCurrentDateChange(self, gdate): self.queue_draw() def getCellPagePlus(self, jd, plus):## use for sliding raise NotImplementedError def gridCheckClicked(self, checkb): checkb.colorb.set_sensitive(checkb.get_active()) checkb.item.updateVar() self.queue_draw() def gridColorChanged(self, colorb): colorb.item.updateVar() self.queue_draw() def defineDragAndDrop(self): self.drag_source_set( gdk.ModifierType.MODIFIER_MASK, [], gdk.DragAction.MOVE,## FIXME ) self.drag_source_add_text_targets() ### self.connect('drag-data-get', self.dragDataGet) self.connect('drag-begin', self.dragBegin) self.connect('drag-data-received', self.dragDataRec) ### self.drag_dest_set( gtk.DestDefaults.ALL, [], gdk.DragAction.COPY,## FIXME ) self.drag_dest_add_text_targets() self.drag_dest_add_uri_targets() ## ACTION_MOVE ????????????????????? ## if source ACTION was ACTION_COPY, calendar recieves its own dragged day ## just like gnome-calendar-applet (but it seems not a logical behaviar) ''' #self.drag_source_add_uri_targets()#??????? ##self.connect('drag-end', self.dragCalEnd) ##self.connect('drag-drop', self.dragCalDrop) ##self.connect('drag-failed', self.dragCalFailed) #self.connect('drag-leave', self.dragLeave) ''' def dragDataGet(self, obj, context, selection, target_id, etime): ## context is instance of gi.repository.Gdk.DragContext text = '%.2d/%.2d/%.2d'%ui.cell.dates[ui.dragGetMode] selection.set_text(text, len(text)) #pbuf = newDndDatePixbuf(ui.cell.dates[ui.dragGetMode]) #selection.set_pixbuf(pbuf) return True def dragLeave(self, obj, context, etime): context.drop_reply(False, etime) return True def dragDataRec(self, obj, context, x, y, selection, target_id, etime): from scal3.ui_gtk.dnd import processDroppedDate try: dtype = selection.get_data_type() except AttributeError:## Old PyGTK dtype = selection.type text = selection.get_text() dateM = processDroppedDate(text, dtype) if dateM: self.changeDate(*dateM) elif dtype=='application/x-color': ## selection.get_text() == None text = selection.data ui.bgColor = ( ord(text[1]), ord(text[3]), ord(text[5]), ord(text[7]), ) self.emit('pref-update-bg-color') self.queue_draw() else: print('Unknown dropped data type "%s", text="%s", data="%s"'%(dtype, text, selection.data)) return True return False def dragBegin(self, obj, context): ## context is instance of gi.repository.Gdk.DragContext #win = context.get_source_window() #print('dragBegin', id(win), win.get_geometry()) pbuf = newDndDatePixbuf(ui.cell.dates[ui.dragGetMode]) w = pbuf.get_width() #print(dir(context)) gtk.drag_set_icon_pixbuf( context, pbuf, w/2,## y offset -10,## x offset FIXME - not to be hidden behind mouse cursor ) return True def getCellPos(self): raise NotImplementedError def keyPress(self, arg, gevent): CustomizableCalObj.keyPress(self, arg, gevent) kname = gdk.keyval_name(gevent.keyval).lower() if kname in ('space', 'home', 't'): self.goToday() elif kname=='menu': self.emit('popup-cell-menu', gevent.time, *self.getCellPos()) elif kname=='i': self.emit('day-info') else: return False return True
def goToday(self, obj=None): return self.gotoJd(core.getCurrentJd())
def __init__(self, showDesc=False): gtk.Window.__init__(self) self.maximize() self.initVars() ud.windowList.appendItem(self) ### self.set_title(_("Search Events")) self.connect("delete-event", self.closed) self.connect("key-press-event", self.keyPress) ### self.vbox = gtk.VBox() self.add(self.vbox) ###### frame = TextFrame() frame.set_label(_("Text")) frame.set_border_width(5) pack(self.vbox, frame) self.textInput = frame ## hbox = gtk.HBox() self.textCSensCheck = gtk.CheckButton(_("Case Sensitive")) self.textCSensCheck.set_active(False) ## FIXME pack(hbox, self.textCSensCheck) pack(self.vbox, hbox) ###### jd = core.getCurrentJd() year, month, day = jd_to_primary(jd) ###### hbox = gtk.HBox() frame = gtk.Frame() frame.set_label(_("Time")) frame.set_border_width(5) vboxIn = gtk.VBox() sgroup = gtk.SizeGroup(gtk.SizeGroupMode.HORIZONTAL) #### hboxIn = gtk.HBox() ## self.timeFromCheck = gtk.CheckButton(_("From")) sgroup.add_widget(self.timeFromCheck) pack(hboxIn, self.timeFromCheck) pack(hboxIn, gtk.Label(" ")) ## self.timeFromInput = DateTimeButton() self.timeFromInput.set_value(((year, 1, 1), (0, 0, 0))) pack(hboxIn, self.timeFromInput) ## pack(vboxIn, hboxIn) #### hboxIn = gtk.HBox() ## self.timeToCheck = gtk.CheckButton(_("To")) sgroup.add_widget(self.timeToCheck) pack(hboxIn, self.timeToCheck) pack(hboxIn, gtk.Label(" ")) ## self.timeToInput = DateTimeButton() self.timeToInput.set_value(( (year + 1, 1, 1), (0, 0, 0), )) pack(hboxIn, self.timeToInput) ## pack(vboxIn, hboxIn) ## self.timeFromCheck.connect("clicked", self.updateTimeFromSensitive) self.timeToCheck.connect("clicked", self.updateTimeToSensitive) self.updateTimeFromSensitive() self.updateTimeToSensitive() #### vboxIn.set_border_width(5) frame.add(vboxIn) pack(hbox, frame) pack(hbox, gtk.Label(""), 1, 1) pack(self.vbox, hbox) ###### hbox = gtk.HBox() hbox.set_border_width(5) self.modifiedFromCheck = gtk.CheckButton(_("Modified From")) pack(hbox, self.modifiedFromCheck) pack(hbox, gtk.Label(" ")) self.modifiedFromInput = DateTimeButton() self.modifiedFromInput.set_value(((year, 1, 1), (0, 0, 0))) pack(hbox, self.modifiedFromInput) ## self.modifiedFromCheck.connect("clicked", self.updateModifiedFromSensitive) self.updateModifiedFromSensitive() pack(self.vbox, hbox) ###### hbox = gtk.HBox() hbox.set_border_width(5) self.typeCheck = gtk.CheckButton(_("Event Type")) pack(hbox, self.typeCheck) pack(hbox, gtk.Label(" ")) ## combo = gtk.ComboBoxText() for cls in event_lib.classes.event: combo.append_text(cls.desc) combo.set_active(0) pack(hbox, combo) self.typeCombo = combo ## self.typeCheck.connect("clicked", self.updateTypeSensitive) self.updateTypeSensitive() pack(self.vbox, hbox) ###### hbox = gtk.HBox() hbox.set_border_width(5) self.groupCheck = gtk.CheckButton(_("Group")) pack(hbox, self.groupCheck) pack(hbox, gtk.Label(" ")) self.groupCombo = SingleGroupComboBox() pack(hbox, self.groupCombo) ## self.groupCheck.connect("clicked", self.updateGroupSensitive) self.updateGroupSensitive() pack(self.vbox, hbox) ###### bbox = gtk.HButtonBox() bbox.set_layout(gtk.ButtonBoxStyle.START) bbox.set_border_width(5) searchButton = gtk.Button() searchButton.set_label(_("_Search")) searchButton.set_image(gtk.Image.new_from_stock( gtk.STOCK_FIND, gtk.IconSize.BUTTON, )) searchButton.connect("clicked", self.searchClicked) bbox.add(searchButton) pack(self.vbox, bbox) ###### treev = gtk.TreeView() trees = gtk.TreeStore( int, # gid int, # eid str, # group_name GdkPixbuf.Pixbuf, # icon str, # summary str, # description ) ### treev.set_model(trees) treev.connect("button-press-event", self.treevButtonPress) treev.connect("row-activated", self.rowActivated) treev.connect("key-press-event", self.treevKeyPress) treev.set_headers_clickable(True) ### self.colGroup = gtk.TreeViewColumn( _("Group"), gtk.CellRendererText(), text=2, ) self.colGroup.set_resizable(True) self.colGroup.set_sort_column_id(2) self.colGroup.set_property("expand", False) treev.append_column(self.colGroup) ### self.colIcon = gtk.TreeViewColumn() cell = gtk.CellRendererPixbuf() pack(self.colIcon, cell) self.colIcon.add_attribute(cell, "pixbuf", 3) #self.colIcon.set_sort_column_id(3) # FIXME self.colIcon.set_property("expand", False) treev.append_column(self.colIcon) ### self.colSummary = gtk.TreeViewColumn( _("Summary"), gtk.CellRendererText(), text=4, ) self.colSummary.set_resizable(True) self.colSummary.set_sort_column_id(4) self.colSummary.set_property("expand", True) # FIXME treev.append_column(self.colSummary) ### self.colDesc = gtk.TreeViewColumn( _("Description"), gtk.CellRendererText(), text=5, ) self.colDesc.set_sort_column_id(5) self.colDesc.set_visible(showDesc) self.colDesc.set_property("expand", True) # FIXME treev.append_column(self.colDesc) ### trees.set_sort_func(2, self.sort_func_group) ###### swin = gtk.ScrolledWindow() swin.set_policy(gtk.PolicyType.AUTOMATIC, gtk.PolicyType.AUTOMATIC) swin.add(treev) #### vbox = gtk.VBox(spacing=5) vbox.set_border_width(5) ### topHbox = gtk.HBox() self.resultLabel = gtk.Label("") pack(topHbox, self.resultLabel) pack(topHbox, gtk.Label(""), 1, 1) pack(vbox, topHbox) #### columnBox = gtk.HBox(spacing=5) pack(columnBox, gtk.Label(_("Columns") + ": ")) ## check = gtk.CheckButton(_("Group")) check.set_active(True) check.connect( "clicked", lambda w: self.colGroup.set_visible(w.get_active()), ) pack(columnBox, check) ## check = gtk.CheckButton(_("Icon")) check.set_active(True) check.connect( "clicked", lambda w: self.colIcon.set_visible(w.get_active()), ) pack(columnBox, check) ## check = gtk.CheckButton(_("Summary")) check.set_active(True) check.connect( "clicked", lambda w: self.colSummary.set_visible(w.get_active()), ) pack(columnBox, check) ## check = gtk.CheckButton(_("Description")) check.set_active(showDesc) check.connect( "clicked", lambda w: self.colDesc.set_visible(w.get_active()), ) pack(columnBox, check) ## pack(vbox, columnBox) #### pack(vbox, swin, 1, 1) ## frame = gtk.Frame() frame.set_label(_("Search Results")) frame.set_border_width(10) frame.add(vbox) ## pack(self.vbox, frame, 1, 1) ### bbox2 = gtk.HButtonBox() bbox2.set_layout(gtk.ButtonBoxStyle.END) bbox2.set_border_width(10) closeButton = gtk.Button() closeButton.set_label(_("_Close")) closeButton.set_image(gtk.Image.new_from_stock( gtk.STOCK_CLOSE, gtk.IconSize.BUTTON, )) closeButton.connect("clicked", self.closed) bbox2.add(closeButton) pack(self.vbox, bbox2) ###### self.treev = treev self.trees = trees self.vbox.show_all()
def goToday(self, obj=None): ui.gotoJd(core.getCurrentJd()) self.onDateChange()