All pastes #51764 Raw Edit

markup-diff.txt

public text v1 · immutable
#51764 ·published 2006-04-27 14:59 UTC
rendered paste body
Index: chandler/parcels/osaf/framework/blocks/detail/detailblocks.py
===================================================================
--- chandler/parcels/osaf/framework/blocks/detail/detailblocks.py	(revision 10476)
+++ chandler/parcels/osaf/framework/blocks/detail/detailblocks.py	(working copy)
@@ -293,60 +293,54 @@
     mailMessageButton = \
         MailMessageButtonBlock.template('MailMessageButton',
                                         title=messages.STAMP_MAIL,
-                                        bitmap="MarkupBarMail.png",
-                                        toolbarItemKind='Button',
-                                        toggle=True,
+                                        buttonKind="Stamp",
+                                        icon="MarkupMail",
                                         helpString=messages.STAMP_MAIL_HELP,
                                         event=buttonPressed)
-    
+
     taskStamp = \
         TaskStampBlock.template('TaskStamp',
                                 title=messages.STAMP_TASK,
-                                bitmap="MarkupBarTask.png",
-                                toolbarItemKind='Button',
-                                toggle=True,
+                                buttonKind="Stamp",
+                                icon="MarkupTask",
                                 helpString=messages.STAMP_TASK_HELP,
                                 event=buttonPressed)
-                        
+
     calendarStamp = \
         CalendarStampBlock.template('CalendarStamp',
                                     title=messages.STAMP_CALENDAR,
-                                    bitmap="MarkupBarEvent.png",
-                                    toolbarItemKind='Button',
-                                    toggle=True,
+                                    buttonKind="Stamp",
+                                    icon="MarkupEvent",
                                     helpString=messages.STAMP_CALENDAR_HELP,
                                     event=buttonPressed)
 
     privateSwitchButton = \
         PrivateSwitchButtonBlock.template('PrivateSwitchButton',
                                     title=messages.PRIVATE,
-                                    bitmap="MarkupBarPrivate.png",
-                                    toolbarItemKind='Button',
-                                    toggle=True,
+                                    buttonKind="Stamp",
+                                    icon="MarkupPrivate",
                                     helpString=messages.PRIVATE,
                                     event=buttonPressed)
 
     readOnlyIcon = \
         ReadOnlyIconBlock.template('ReadOnlyIcon',
                                     title=messages.READONLY,
-                                    bitmap="MarkupBarReadOnly.png",
-                                    disabledBitmap="MarkupBarReadWrite.png",
-                                    toolbarItemKind='Status',
+                                    buttonKind="Stamp",
+                                    icon="MarkupReadOnly",
                                     helpString=messages.READONLY,
                                     event=buttonPressed)
 
-    # Finally, do the bar itself.
-    markupBar = MenusAndToolbars.Toolbar.template('MarkupBar',
+    markupBar = ControlBlocks.ContentItemDetail.template('MarkupBar',
                                     childrenBlocks=[mailMessageButton,
                                                     taskStamp,
                                                     calendarStamp,
                                                     privateSwitchButton,
                                                     readOnlyIcon],
                                     position=0.0,
-                                    toolSize=SizeType(20, 20),
+                                    toolSize=SizeType(30, 17),
                                     separatorWidth=16,
                                     stretchFactor=0.0).install(parcel)
-    
+
 def makeNoteSubtree(parcel, oldVersion):
     """ Build the subtree (and related stuff) for Note """
     blocks = schema.ns("osaf.framework.blocks", parcel.itsView)
Index: chandler/parcels/osaf/framework/blocks/detail/Detail.py
===================================================================
--- chandler/parcels/osaf/framework/blocks/detail/Detail.py	(revision 10476)
+++ chandler/parcels/osaf/framework/blocks/detail/Detail.py	(working copy)
@@ -36,6 +36,7 @@
 from datetime import datetime, time, timedelta
 from i18n import OSAFMessageFactory as _
 from osaf import messages
+from util import MultiStateButton
 
 """
 Detail.py
@@ -98,7 +99,7 @@
         # It's for us - tell our parent to resync.
         logger.debug("%s: Resyncing parent block due to kind change on %s", 
                      debugName(self), debugName(self.item))
-        self.parentBlock.synchronizeWidget()
+        self.parentBlock.synchronizeSoon()
         
     def unRender(self):
         # There's a wx bug on Mac (2857) that causes EVT_KILL_FOCUS events to happen
@@ -578,7 +579,7 @@
     def OnFinishChangesEvent (self, event):
         self.saveValue(validate=True)
 
-class DetailStampButton(DetailSynchronizer, MenusAndToolbars.ToolbarItem):
+class DetailStampButton(DetailSynchronizer, ControlBlocks.Button):
     """
       Common base class for the stamping buttons in the Markup Bar
     """
@@ -598,8 +599,11 @@
              item.__class__.__name__, 
              item.itsKind.itsName,
              mixinClass.__name__, 
-             mixinKind.itsName)            
-        self.parentBlock.widget.ToggleTool(self.toolID, shouldToggleBasedOnKind)
+             mixinKind.itsName)
+        if(shouldToggleBasedOnKind):
+            self.widget.SetState("stamped")
+        else:
+            self.widget.SetState("normal")
         return False
 
     def onButtonPressedEvent (self, event):
@@ -651,34 +655,44 @@
     def stampMixinClass(self):
         return TaskMixin
 
-class PrivateSwitchButtonBlock(DetailSynchronizer, MenusAndToolbars.ToolbarItem):
+class PrivateSwitchButtonBlock(DetailSynchronizer, ControlBlocks.Button):
     """
       "Never share" button in the Markup Bar
     """
     def synchronizeItemDetail (self, item):
         # toggle this button to reflect the privateness of the selected item        
-        self.parentBlock.widget.ToggleTool(self.toolID, item.private)
+        if item.private:
+            self.widget.SetState("stamped")
+        else:
+            self.widget.SetState("normal")
         return False
 
     def onButtonPressedEvent(self, event):
         item = self.item            
         self.postEventByName("FocusTogglePrivate", {'items': [item]})
         tool = event.arguments['sender']
-        self.parentBlock.widget.ToggleTool(tool.toolID, item.private) # in case the user canceled the dialog, reset markupbar buttons
+        # in case the user canceled the dialog, reset markupbar buttons
+        if item.private:
+            self.widget.SetState("stamped")
+        else:
+            self.widget.SetState("normal")
 
     def onButtonPressedEventUpdateUI(self, event):
         item = self.item            
         enable = item is not None and item.isAttributeModifiable('displayName')
         event.arguments ['Enable'] = enable
 
-class ReadOnlyIconBlock(DetailSynchronizer, MenusAndToolbars.ToolbarItem):
+class ReadOnlyIconBlock(DetailSynchronizer, ControlBlocks.Button):
     """
       "Read Only" icon in the Markup Bar
     """
     def synchronizeItemDetail (self, item):
         # toggle this icon to reflect the read only status of the selected item
         enable = ( item.getSharedState() == ContentItem.READONLY )
-        self.parentBlock.widget.EnableTool(self.toolID, enable)
+        if enable:
+            self.widget.SetState("stamped")
+        else:
+            self.widget.SetState("normal")
         return False
 
     def onButtonPressedEvent(self, event):
Index: chandler/parcels/osaf/framework/blocks/ControlBlocks.py
===================================================================
--- chandler/parcels/osaf/framework/blocks/ControlBlocks.py	(revision 10476)
+++ chandler/parcels/osaf/framework/blocks/ControlBlocks.py	(working copy)
@@ -18,6 +18,7 @@
 import wx.gizmos
 import webbrowser # for opening external links
 import PyICU
+from util import MultiStateButton
 
 import application.dialogs.ReminderDialog as ReminderDialog
 import Styles
@@ -32,7 +33,7 @@
     values = "Left", "Center", "Right"
 
 class buttonKindEnumType(schema.Enumeration):
-     values = "Text", "Image", "Toggle"
+     values = "Text", "Image", "Toggle", "Stamp"
 
 class Button(RectangularChild):
 
@@ -54,17 +55,49 @@
                                 (self.minimumSize.width, self.minimumSize.height))
         elif self.buttonKind == "Image":
             bitmap = wx.GetApp().GetImage (self.icon)
+#            # alternate way to get a bitmap button - use MultiStateButton
+#            button = wxChandlerMultiStateButton (parentWidget, 
+#                                id, 
+#                                wx.DefaultPosition,
+#                                (self.minimumSize.width, self.minimumSize.height),
+#                                multibitmaps=(bitmap,))
             button = wx.BitmapButton (parentWidget,
                                       id,
                                       bitmap,
                                       wx.DefaultPosition,
                                       (self.minimumSize.width, self.minimumSize.height))
         elif self.buttonKind == "Toggle":
-                button = wx.ToggleButton (parentWidget, 
-                                          id, 
-                                          self.title,
-                                          wx.DefaultPosition,
-                                          (self.minimumSize.width, self.minimumSize.height))
+            button = wx.ToggleButton (parentWidget, 
+                                      id, 
+                                      self.title,
+                                      wx.DefaultPosition,
+                                      (self.minimumSize.width, self.minimumSize.height))
+        elif self.buttonKind == "Stamp":
+            # for a stamp button, we use "self.icon" as the base name of all bitmaps and look for:
+            #
+            #   {icon}Normal, {icon}Stamped, {icon}Rollover, {icon}Pressed, {icon}Disabled
+            #
+            # From these we build two states named "normal" and "stamped", which can
+            # be used the toggle the appearance of the button.
+            #
+            assert len(self.icon) > 0
+            normal = MultiStateButton.BitmapInfo()
+            normal.normal   = "%sNormal" % self.icon
+            normal.rollover = "%sRollover" % self.icon
+            normal.disabled = "%sDisabled" % self.icon
+            normal.selected = "%sPressed" % self.icon
+            normal.stateName = "normal"
+            stamped = MultiStateButton.BitmapInfo()
+            stamped.normal   = "%sStamped" % self.icon
+            stamped.rollover = "%sRollover" % self.icon
+            stamped.disabled = "%sDisabled" % self.icon
+            stamped.selected = "%sPressed" % self.icon
+            stamped.stateName = "stamped"
+            button = wxChandlerMultiStateButton (parentWidget, 
+                                id, 
+                                wx.DefaultPosition,
+                                (self.minimumSize.width, self.minimumSize.height),
+                                multibitmaps=(normal, stamped))
         elif __debug__:
             assert False, "unknown buttonKind"
 
@@ -80,6 +113,22 @@
             self.post(event, {'item':self})
 
 
+class wxChandlerMultiStateButton(MultiStateButton.MultiStateButton):
+    """
+    Just like MultiStateButton, except that it uses wx.GetApp().GetImage as the
+    provider of bitmaps, and the button has no border.
+    """
+    def __init__(self, parent, ID, pos, size, multibitmaps, *args, **kwds):
+        super(wxChandlerMultiStateButton, self).__init__(parent,
+                                                        ID,
+                                                        pos,
+                                                        size,
+                                                        wx.BORDER_NONE,
+                                                        multibitmaps = multibitmaps,
+                                                        bitmapProvider = wx.GetApp().GetImage,
+                                                        *args, **kwds)
+
+
 class ContextMenu(RectangularChild):
     def displayContextMenu(self, parentWindow, position, data):
         menu = wx.Menu()
Index: chandler/util/MultiStateButton.py
===================================================================
--- chandler/util/MultiStateButton.py	(revision 10476)
+++ chandler/util/MultiStateButton.py	(working copy)
@@ -77,7 +77,7 @@
     Obviously this latter method is a lot more verbose
 
     """
-    def __init__(self, parent, ID=-1, multibitmaps=(),
+    def __init__(self, parent, ID, pos, size, style, multibitmaps=(),
                 bitmapProvider=wx.Image, *args, **kwds):
         """
         Initialize the button to the usual button states, plus a list of
@@ -104,7 +104,7 @@
         self.currentState = None
         self.bitmapProvider = bitmapProvider
 
-        super(MultiStateButton, self).__init__(parent, ID, None, *args, **kwds)
+        super(MultiStateButton, self).__init__(parent, ID, None, pos, size, style, *args, **kwds)
         firstStateName = self.AddStates(multibitmaps)
         assert firstStateName is not None
         self.SetState(firstStateName)
@@ -225,23 +225,31 @@
         Find the named bitmap, checking various file type extensions (are
         these available inside wx.Image somewhere?)
         
-        The design decision here is that the speicifc type of the image
+        The design decision here is that the specific type of the image
         is not as important as its name. Indeed, the type of the image can
         change over time to accomodate new technologies. By leaving the
         type unspecified, code does not have to change whenever the file
         format changes.
         """
         bitmap = None
+        ##rae
+        # is there a more robust list of image types? I made this list up myself..
         for ext in ("png", "gif", "jpg", "tiff", "psd"):
             try:
                 img = self.bitmapProvider("%s.%s" % (bitmapName, ext))
-                bitmap = img.ConvertToBitmap()
-                assert bitmap.GetWidth() > 0
-                break
+                convert = getattr(img, "ConvertToBitmap", None)
+                if convert is not None:
+                    bitmap = convert(img)
+                else:
+                    bitmap = img
+                if bitmap is not None:
+                    # stop when the bitmap is found
+                    break
             except IOError:
                 # file was not found
                 pass
-        assert bitmap is not None
+        if bitmap is not None:
+            assert bitmap.GetWidth() > 0
         return bitmap
  
 # execute with execfile("/Users/rae/work/osaf/rae-button/MultiStateButton.py", { "__name__" :"__main__" })