class MarkupButton(MultiStateButton): """ Just like MultiStateButton, except that it uses wx.GetApp().GetImage as the proviider of bitmaps. """ def __init__(self, parent, ID=-1, multibitmaps=(), bitmapProvider=wx.GetApp().GetImage, *args, **kwds): super(MarkupButton, self).__init__(parent, *args, **kwds)# DetailStampButton2 is at the bottom, and it has no __init()class CalendarStampBlock(DetailStampButton2): """ Calendar button in the Markup Bar """ def stampMixinClass(self): return Calendar.CalendarEventMixindef makeMarkupBar(parcel, oldVersion): """ Build the markup bar. """ # [[[ lots of code omitted here ]]] calendarStamp2 = \ CalendarStampBlock2.template('CalendarStamp', title=messages.STAMP_CALENDAR, multibitmaps=(isEvent, notEvent), helpString=messages.STAMP_CALENDAR_HELP, event=buttonPressed)class DetailStampButton2(DetailSynchronizer, MarkupButton): """ Common base class for the stamping buttons in the Markup Bar """ def stampMixinClass(self): # return the class of this stamp's Mixin Kind (bag of kind-specific attributes) raise NotImplementedError, "%s.stampMixinClass()" % (type(self)) def synchronizeItemDetail (self, item): # toggle this button to reflect the kind of the selected item mixinClass = self.stampMixinClass() mixinKind = mixinClass.getKind(self.itsView) shouldToggleBasedOnClass = isinstance(item, mixinClass) shouldToggleBasedOnKind = item.isItemOf(mixinKind) assert shouldToggleBasedOnClass == shouldToggleBasedOnKind, \ "Class/Kind mismatch! Item is class %s, kind %s; " \ "stamping with class %s, kind %s" % ( item.__class__.__name__, item.itsKind.itsName, mixinClass.__name__, mixinKind.itsName) if(shouldToggleBasedOnKind): self.parentBlock.widget.SetState("stamped") else: self.parentBlock.widget.SetState("unstamped") return False def onButtonPressedEvent (self, event): # Rekind the item by adding or removing the associated Mixin Kind Block.Block.finishEdits() item = self.item if not item or not self._isStampable(item): return mixinKind = self.stampMixinClass().getKind(self.itsView) if not item.itsKind.isKindOf(mixinKind): operation = 'add' else: operation = 'remove' # Now change the kind and class of this item #logger.debug("%s: stamping: %s %s to %s", debugName(self), operation, mixinKind, debugName(item)) item.StampKind(operation, mixinKind) #logger.debug("%s: done stamping: %s %s to %s", debugName(self), operation, mixinKind, debugName(item)) def onButtonPressedEventUpdateUI(self, event): item = self.item enable = item is not None and self._isStampable(item) and \ item.isAttributeModifiable('displayName') event.arguments ['Enable'] = enable def _isStampable(self, item): # for now, any ContentItem is stampable. This may change if Mixin rules/policy change return item.isItemOf(items.ContentItem.getKind(self.itsView))