Title: [commits] (jeffrey) [15949] [APP] Add month, buttons, and column header to a panel with the calendar.
Revision
15949
Author
jeffrey
Date
2007-11-28 23:06:31 -0800 (Wed, 28 Nov 2007)

Log Message

[APP] Add month, buttons, and column header to a panel with the calendar.

Modified Paths

Added Paths

Diff

Added: branches/rearchitecture/Chandler-Platform/ocap/wxui/button.py (15948 => 15949)

--- branches/rearchitecture/Chandler-Platform/ocap/wxui/button.py	2007-11-29 03:09:25 UTC (rev 15948)
+++ branches/rearchitecture/Chandler-Platform/ocap/wxui/button.py	2007-11-29 07:06:31 UTC (rev 15949)
@@ -0,0 +1,47 @@
+import wx
+from wx.lib import buttons
+from image import get_raw_image
+
+# temporary hack because Mac/Linux force BitmapButtons to
+# have some specific borders
+if wx.Platform == '__WXMAC__':
+    PLATFORM_BORDER_PIXELS = 6
+elif wx.Platform == '__WXGTK__':
+    PLATFORM_BORDER_PIXELS =  10
+else:
+    PLATFORM_BORDER_PIXELS = 0
+
+class BitmapButton(buttons.GenBitmapButton):
+    """
+    Flat bitmap button, no border.
+
+    Currently, the wx.BitmapButton does not work well on MacOSX:
+    wxWidgets doesn't implement a button with no border.
+    Ideally, we would use a "proper" bitmap button that
+    actually generated a accurate masked area,
+    """
+
+    def __init__(self, parent, name):
+        """
+
+        @param parent: like all controls, requires a parent window
+        @type parent: wx.Window
+        @param name: unicode name of an image file
+        @type name: unicode
+        """
+
+        bitmap = wx.BitmapFromImage(get_raw_image(name + ".png"))
+        super(BitmapButton, self).__init__(parent, -1, bitmap, style=wx.NO_BORDER)
+        pressedBitmap = wx.BitmapFromImage(get_raw_image(name + "MouseDown.png"))
+        self.SetBitmapSelected(pressedBitmap)
+        self.SetBackgroundColour("white")
+        self.UpdateSize()
+
+    def UpdateSize(self):
+        """
+        Sizes the button to just fit the bitmap
+        """
+        bitmap = self.GetBitmapLabel()
+        width = bitmap.GetWidth() + PLATFORM_BORDER_PIXELS
+        height = bitmap.GetHeight() + PLATFORM_BORDER_PIXELS
+        self.SetMinSize(wx.Size(width, height))
Property changes on: branches/rearchitecture/Chandler-Platform/ocap/wxui/button.py
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: branches/rearchitecture/Chandler-Platform/ocap/wxui/calendar.py (15948 => 15949)

--- branches/rearchitecture/Chandler-Platform/ocap/wxui/calendar.py	2007-11-29 03:09:25 UTC (rev 15948)
+++ branches/rearchitecture/Chandler-Platform/ocap/wxui/calendar.py	2007-11-29 07:06:31 UTC (rev 15949)
@@ -17,7 +17,10 @@
 from math import radians
 from datetime import datetime, timedelta
 from colorsys import hsv_to_rgb
-from drawing import DrawWrappedText, DrawClippedText
+from drawing import DrawWrappedText, DrawClippedText, getFont
+from button import BitmapButton
+from wx.lib.stattext import GenStaticText
+from wx import colheader
 
 SWATCH_BUFFER = (2,2)
 TEXT_BUFFER = (2,2)
@@ -70,12 +73,7 @@
     gradient_right = wx.Color(0, 102, 204),
 )
 
-if wx.Platform == '__WXMSW__':
-    DEFAULT_FONT_SIZE = 8
-else:
-    DEFAULT_FONT_SIZE = 9
 
-
 class Event(InitializeSlots):
     __slots__ = ('id', 'title', 'start', 'duration', 'color', 'swatch_colors')
     def __cmp__(self, other):
@@ -207,14 +205,14 @@
         #measure = wx.GraphicsContext.CreateMeasuringContext()
         measure = wx.GraphicsContext.Create(self)
 
-        self.legend_font = wx.Font(DEFAULT_FONT_SIZE, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)
+        self.legend_font = getFont()
         self.legend_font_height = font_height(measure, self.legend_font)
         self.legend_strings = [str(i) for i in range(1,13)] * 2
 
-        self.time_font = wx.Font(DEFAULT_FONT_SIZE, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)
+        self.time_font = getFont(size=10, weight=wx.BOLD)
         self.time_font_height = font_height(measure, self.time_font)
 
-        self.title_font = self.legend_font
+        self.title_font = getFont()
         self.title_font_height = font_height(measure, self.title_font)
 
         self.range_start = None
@@ -703,16 +701,91 @@
 
 lorem = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt uty laboreq et dolore magna aliqua. Ut enimy qad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
 
+class CalendarPanel(wx.Panel):
+    def __init__(self, parent, name):
+        super(CalendarPanel, self).__init__(parent, -1, style=wx.NO_BORDER)
+        self.Bind(wx.EVT_SIZE, self.OnSize)
+        
+        self.SetBackgroundColour(wx.WHITE)
+
+        self.prevButton = BitmapButton(self, "CalBackArrow")
+        self.nextButton = BitmapButton(self, "CalForwardArrow")
+        self.monthText = GenStaticText(self, -1, 'November - December 2007')
+
+        self.monthText.SetFont(getFont(size=15, weight=wx.BOLD))
+        self.monthText.SetForegroundColour(wx.Color(64, 64, 64))
+        self.setupHeader()
+
+        splitterStyle = wx.SP_LIVE_UPDATE | wx.NO_BORDER | wx.SP_3DSASH
+        splitter = wx.SplitterWindow(self, style=splitterStyle)
+
+        self.calendar = Calendar(parent=splitter, time_formatter=None)
+        self.allday = AllDayCalendar(parent=splitter, time_formatter=None)
+
+        splitter.SplitHorizontally(self.allday, self.calendar)
+        splitter.SetMinimumPaneSize(20)
+        splitter.SashPosition = 20
+                
+        self.calendar.SetRange(datetime(2007,11,25))
+        self.allday.SetRange(datetime(2007,11,25))
+
+        sizer = wx.GridBagSizer(0, 0)
+        sizer.Add(self.prevButton, (0, 1), flag=wx.ALIGN_CENTER)
+        sizer.Add(self.nextButton, (0, 3), flag=wx.ALIGN_CENTER)
+        sizer.Add((10,30), (0, 4))
+        sizer.Add(self.monthText, (0, 5), flag=wx.ALIGN_CENTER)
+        sizer.Add(self.weekColumnHeader, (1, 0), (1,8), flag=wx.EXPAND)
+        sizer.Add(splitter, (2,0), (1,8), flag=wx.EXPAND)
+        sizer.AddGrowableRow(2)
+        sizer.AddGrowableCol(6)
+        sizer.SetEmptyCellSize((5,5))
+        
+        self.SetSizerAndFit(sizer)
+
+    def setupHeader(self):
+        weekColumnHeader = self.weekColumnHeader = colheader.ColumnHeader(self)
+
+        # turn this off for now, because our sizing needs to be exact
+        weekColumnHeader.SetAttribute(colheader.CH_ATTR_ProportionalResizing,False)
+
+        headerLabels = ["Week", "S", "M", "Tu", "W", "Th", "F", "S", '']
+        for header in headerLabels:
+            weekColumnHeader.AppendItem(header, wx.ALIGN_CENTER, 0, bSortEnabled=False)
+
+        # set up initial selection
+        weekColumnHeader.SetAttribute(colheader.CH_ATTR_VisibleSelection, True)
+        self.weekColumnHeader.SetSelectedItem(0)
+        self.margin_right = wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X)
+        self.ResizeHeader()
+
+    def ResizeHeader(self):
+        self.weekColumnHeader.Freeze()
+        widths = [MARGIN_LEFT + 1, self.margin_right]
+        inner_width = self.GetSize()[0] - sum(widths)
+        widths[1:1] = [inner_width/7] * 7
+        remainder = inner_width % 7
+        # evenly distribute remainder
+        for i in range(0, 3 * remainder, 3):
+            widths[(i % 7) + 1] += 1
+        for (i,width) in enumerate(widths):
+            extentPt = self.weekColumnHeader.GetItemSize(i)
+            extentPt.width = width
+            self.weekColumnHeader.SetItemSize(i, extentPt)
+        self.weekColumnHeader.Thaw()
+
+    def OnSize(self, event):
+        self.ResizeHeader()
+        event.Skip()
+
 def Demo():
     wxApp = wx.PySimpleApp()
     frame = wx.Frame(None, title="Calendar Mockup", size=wx.Size(600, 450))
+    frame.CenterOnParent()
     
-    splitterStyle = wx.SP_LIVE_UPDATE | wx.NO_BORDER | wx.SP_3DSASH
-    splitter = wx.SplitterWindow(frame, style=splitterStyle)
-
-    frame.CenterOnParent()
-    calendar = Calendar(parent=splitter, time_formatter=None)
-    calendar.SetRange(datetime(2007,11,25))
+    panel = CalendarPanel(frame, -1)
+    calendar = panel.calendar
+    allday = panel.allday
+    
     calendar.ChangeEvent(id="foo0", title=lorem,
                          start=datetime(2007,11,25,10), 
                          duration=timedelta(hours=1.095))
@@ -741,8 +814,6 @@
                          start=datetime(2007,11,25,23,45), 
                          duration=timedelta(hours=1))
     
-    allday = AllDayCalendar(parent=splitter, time_formatter=None)
-    allday.SetRange(datetime(2007,11,25))
     allday.ChangeEvent(id="bar0", title=lorem,
                        start=datetime(2007,11,24), 
                        duration=timedelta(3))
@@ -759,10 +830,6 @@
                        start=datetime(2007,11,28), 
                        duration=timedelta(5))
 
-    splitter.SplitHorizontally(allday, calendar)
-    splitter.SetMinimumPaneSize(20)
-    splitter.SashPosition = 20
-
     frame.Show()
     wxApp.MainLoop()
 

Modified: branches/rearchitecture/Chandler-Platform/ocap/wxui/image.py (15948 => 15949)

--- branches/rearchitecture/Chandler-Platform/ocap/wxui/image.py	2007-11-29 03:09:25 UTC (rev 15948)
+++ branches/rearchitecture/Chandler-Platform/ocap/wxui/image.py	2007-11-29 07:06:31 UTC (rev 15949)
@@ -12,7 +12,6 @@
     Also look first for platform specific images.
     """
     global imageCache
-    
     entry = imageCache.get(name)
     if entry is not None:
         image = entry[0]




_______________________________________________
Commits mailing list
[email protected]
http://lists.osafoundation.org/mailman/listinfo/commits

Reply via email to