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 __init__(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 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.MODIFIER_MASK, (('', 0, 0), ), gdk.ACTION_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( gdk.MODIFIER_MASK, ( ('', 0, 0), ('application/x-color', 0, 0), ), gdk.ACTION_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): selection.set_text('%.2d/%.2d/%.2d' % ui.cell.dates[ui.dragGetMode]) 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 scal2.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): colormap = self.get_screen().get_system_colormap() ############################################# text = '%.2d/%.2d/%.2d' % ui.cell.dates[ui.dragGetMode] textLay = newTextLayout(self, text) w, h = textLay.get_pixel_size() pmap = gdk.Pixmap(None, w, h, 24) #pmap.set_colormap(colormap) gc = pmap.new_gc() gc.set_foreground(rgbToGdkColor(*ui.bgColor)) pmap.draw_rectangle(gc, True, 0, 0, w, h) #gc.set_background(ui.bgColor) ##pmap.set_direction(gtk.DIR_LTR)## FIXME pmap.draw_layout( gc, 0, 0, textLay, rgbToGdkColor(*ui.textColor), rgbToGdkColor( *ui.bgColor ), ## rgbToGdkColor(ui.gdkColorInvert(*ui.textColor)) ) pbuf = gdk.Pixbuf(gdk.COLORSPACE_RGB, True, 8, w, h) pbuf.get_from_drawable( pmap, colormap, 0, 0, 0, 0, -1, -1, ) context.set_icon_pixbuf( 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
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 __init__(self, showDesc=False): gtk.Window.__init__(self) 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(_('Time')) frame.set_border_width(5) vboxIn = gtk.VBox() sgroup = gtk.SizeGroup(gtk.SIZE_GROUP_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.combo_box_new_text() 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.BUTTONBOX_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.ICON_SIZE_BUTTON)) searchButton.connect('clicked', self.searchClicked) bbox.add(searchButton) pack(self.vbox, bbox) ###### treev = gtk.TreeView() trees = gtk.TreeStore(int, int, str, gdk.Pixbuf, str, str) ## gid, eid, group_name, icon, summary, description treev.set_model(trees) treev.connect('row-activated', self.rowActivated) 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) 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 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) 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) treev.append_column(self.colDesc) ### trees.set_sort_func(2, self.sort_func_group) ###### swin = gtk.ScrolledWindow() swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_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(_('Search Results')) frame.set_border_width(10) frame.add(vbox) ## pack(self.vbox, frame, 1, 1) ### bbox2 = gtk.HButtonBox() bbox2.set_layout(gtk.BUTTONBOX_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.ICON_SIZE_BUTTON)) closeButton.connect('clicked', self.closed) bbox2.add(closeButton) pack(self.vbox, bbox2) ###### self.treev = treev self.trees = trees self.vbox.show_all()
def __init__(self, showDesc=False): gtk.Window.__init__(self) 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(_('Time')) frame.set_border_width(5) vboxIn = gtk.VBox() sgroup = gtk.SizeGroup(gtk.SIZE_GROUP_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.combo_box_new_text() 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.BUTTONBOX_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.ICON_SIZE_BUTTON)) searchButton.connect('clicked', self.searchClicked) bbox.add(searchButton) pack(self.vbox, bbox) ###### treev = gtk.TreeView() trees = gtk.TreeStore(int, int, str, gdk.Pixbuf, str, str) ## gid, eid, group_name, icon, summary, 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) 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 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) 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) treev.append_column(self.colDesc) ### trees.set_sort_func(2, self.sort_func_group) ###### swin = gtk.ScrolledWindow() swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_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(_('Search Results')) frame.set_border_width(10) frame.add(vbox) ## pack(self.vbox, frame, 1, 1) ### bbox2 = gtk.HButtonBox() bbox2.set_layout(gtk.BUTTONBOX_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.ICON_SIZE_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()