- Revision
- 15952
- Author
- grant
- Date
- 2007-11-29 08:05:01 -0800 (Thu, 29 Nov 2007)
Log Message
[APP] Port CPIA's old Styles module, now sans schema API.
Modified Paths
Diff
Modified: branches/rearchitecture/Chandler-Platform/ocap/wxui/styles.py (15951 => 15952)
--- branches/rearchitecture/Chandler-Platform/ocap/wxui/styles.py 2007-11-29 16:01:07 UTC (rev 15951) +++ branches/rearchitecture/Chandler-Platform/ocap/wxui/styles.py 2007-11-29 16:05:01 UTC (rev 15952) @@ -13,57 +13,49 @@ # limitations under the License. -__parcel__ = "osaf.framework.blocks" - -from application import schema import wx -import logging -from osaf.pim.structs import ColorType -logger = logging.getLogger(__name__) +if __debug__: + import logging + logger = logging.getLogger(__name__) -class fontFamilyEnumType(schema.Enumeration): - values = "DefaultUIFont", "SerifFont", "SansSerifFont", "FixedPitchFont" +class ColorType(object): + # rgba values (0-255 scale) + + red = green = blue = alpha = 0 + def __init__(self, *args): + super(ColorType, self).__init__() + self.red, self.green, self.blue, self.alpha = args + +class CharacterStyle(object): + def __init__(self, **kw): + super(CharacterStyle, self).__init__() + for key, value in kw.iteritems(): + setattr(self, key, value) -class Style(schema.Item): - pass + # One of "DefaultUIFont", "SerifFont", "SansSerifFont", "FixedPitchFont" + fontFamily = 'DefaultUIFont' -class CharacterStyle(Style): - - fontFamily = schema.One( - fontFamilyEnumType, initialValue = 'DefaultUIFont', - ) - # we default to 11 points, which'll get scaled to the platform's # default GUI font - fontSize = schema.One(schema.Float, initialValue = 11.0) + fontSize = 11.0 # Currently, fontStyle is a string containing any of the following words: # bold light italic underline fakesuperscript # but others will be included in the future - fontStyle = schema.One(schema.Text, initialValue = '') + fontStyle = '' + fontName = '' - fontName = schema.One(schema.Text, initialValue = '') - -class ColorStyle(Style): +class ColorStyle(object): """ Class for Color Style Attributes for backgroundColor and foregroundColor """ - foregroundColor = schema.One( - ColorType, initialValue = ColorType(0, 0, 0, 255), - ) + foregroundColor = ColorType(0, 0, 0, 255), + backgroundColor = ColorType(255, 255, 255, 255) - backgroundColor = schema.One( - ColorType, initialValue = ColorType(255, 255, 255, 255), - ) - - schema.addClouds( - sharing = schema.Cloud(literal=[foregroundColor, backgroundColor]) - ) - fontCache = {} measurementsCache = {} @@ -183,7 +175,7 @@ class FontMeasurements(object): """ Measurements that we cache with each font """ def __init__(self, font): - aWidget = wx.GetApp().mainFrame + aWidget = wx.GetApp().TopWindow dc = wx.ClientDC(aWidget) oldWidgetFont = aWidget.GetFont() try: @@ -226,6 +218,25 @@ finally: aWidget.SetFont(oldWidgetFont) + + +# A few specific styles + +TextStyle = CharacterStyle() + +BigTextStyle = CharacterStyle(fontSize=15, fontStyle="bold") +LabelStyle = CharacterStyle() + +SummaryHeaderStyle = CharacterStyle(fontStyle="bold") + +SummaryRowStyle = CharacterStyle(fontSize=12) +SummaryPrefixStyle = CharacterStyle(fontSize=10) +SummarySectionLabelStyle = CharacterStyle(fontStyle="bold") +SummarySectionCountStyle = CharacterStyle(fontSize=10) + +SidebarRowStyle = CharacterStyle(fontSize=12) + +DetailConflictStyle = CharacterStyle(fontSize=10, fontStyle = "bold") def testFonts(): # To try to work out font differences between the platforms, I wrote the @@ -236,11 +247,16 @@ wx.SYS_ANSI_FIXED_FONT, wx.SYS_ANSI_VAR_FONT, wx.SYS_SYSTEM_FONT, \ wx.SYS_DEVICE_DEFAULT_FONT, wx.SYS_SYSTEM_FONT: f = wx.SystemSettings_GetFont(fam) - logger.debug("%d -> %s, %s %s (%s)" % (fam, f.GetFamily(), f.GetFaceName(), f.GetPointSize(), f.GetFamilyString())) + if __debug__: + logger.debug("%d -> %s, %s %s (%s)", fam, f.GetFamily(), + f.GetFaceName(), f.GetPointSize(), + f.GetFamilyString()) # Also see what a completely-default Font looks like f = wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False, "") - logger.debug("default -> %s, %s %s (%s)" % (f.GetFamily(), f.GetFaceName(), f.GetPointSize(), f.GetFamilyString())) + if __debug__: + logger.debug("default -> %s, %s %s (%s)", f.GetFamily(), + f.GetFaceName(), f.GetPointSize(), f.GetFamilyString()) # On Mac, where the grid uses Lucida Grande 13 when no font is specified, this says: #2005-05-09 13:53:43,536 styles DEBUG: 17 -> 70, Lucida Grande 11 (wxDEFAULT) #2005-05-09 13:53:43,548 styles DEBUG: 10 -> 70, Lucida Grande 13 (wxDEFAULT) @@ -278,7 +294,7 @@ # a scaling factor. -def testSuperscript(): +def testSuperscript(app): cs = CharacterStyle() @@ -329,19 +345,5 @@ ##dc.DrawRectangle(*iter(r)) - class TestApp(wx.App): - def OnInit(self): - frame = TestFrame(None, -1, "Test frame.") - frame.Show(True) - self.SetTopWindow(frame) - return True - - app = TestApp(0) - app.MainLoop() - - -if __name__ == '__main__': - # relative import weirdness, you may have to make a wrapper script - # RunPython -c 'from osaf.framework.blocks.Styles import testSuperscript; testSuperscript()' - - testSuperscript() + frame = TestFrame(None, -1, "Test frame.") + frame.Show(True)
_______________________________________________ Commits mailing list [email protected] http://lists.osafoundation.org/mailman/listinfo/commits
