Package peppy :: Package editra :: Module ed_style :: Class StyleMgr
[frames] | no frames]

Class StyleMgr

object --+
         |
        StyleMgr
Known Subclasses:

Manages style definitions and provides them on request. Also provides functionality for loading custom style sheets and modifying styles during run time.

Instance Methods
 
__init__(self, custom=u'')
Initializes the Style Manager
 
DefaultStyleDictionary(self)
This is the default style values that are used for styling documents.
 
BlankStyleDictionary(self)
Returns a dictionary of unset style items based on the tags defined in the current dictionary.
 
GetFontDictionary(self, default=True)
Does a system lookup to build a default set of fonts using ten point fonts as the standards size.
wx.Font
GetDefaultFont(self)
Constructs and returns a wxFont object from the settings of the default_style object.
wx.Colour or string
GetDefaultForeColour(self, as_hex=False)
Gets the foreground color of the default style and returns a Colour object.
wx.Colour or string
GetDefaultBackColour(self, as_hex=False)
Gets the background color of the default style and returns a Colour object.
StyleItem
GetItemByName(self, name)
Gets and returns a style item using its name for the search
 
GetStyleFont(self, primary=True)
Returns the primary font facename by default
string
GetStyleByName(self, name)
Gets and returns a style string using its name for the search
dict
GetStyleSet(self)
Returns the current set of styles or the default set if there is no current set.
 
HasNamedStyle(self, name)
Checks if a style has been set/loaded or not
bool
LoadStyleSheet(self, style_sheet, force=False)
Loads a custom style sheet and returns True on success
 
MergeFonts(self, style_dict, font_dict)
Does any string substitution that the style dictionary may need to have fonts and their sizes set.
 
MergeStyles(self, styles1, styles2)
Merges the styles from styles2 into styles1 overwriting any duplicate values already set in styles1 with the new data from styles2.
 
PackStyleSet(self, style_set)
Checks the difference of each item in the style set as compared to the default_style tag and packs any unset value in the item to be equal to the default style.
 
ParseStyleData(self, style_data, strict=False)
Parses a string style definitions read from an Editra Style Sheet.
 
SetGlobalFont(self, font_tag, fontface, size=-1)
Sets one of the fonts in the global font set by tag and sets it to the named font.
 
SetStyleFont(self, wx_font, primary=True)
Sets the\primary or secondary font and their respective size values.
 
SetStyleTag(self, style_tag, value)
Sets the value of style tag by name
 
SetStyles(self, style_dict, nomerge=False)
Sets the managers style data and returns True on success.

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Class Variables
  styles = {}
  FONT_PRIMARY = u'primary'
  FONT_SECONDARY = u'secondary'
  FONT_SIZE = u'size'
  FONT_SIZE2 = u'size2'
  FONT_SIZE3 = u'size3'
Properties

Inherited from object: __class__

Method Details

__init__(self, custom=u'')
(Constructor)

 

Initializes the Style Manager

Parameters:
  • custom - path to custom style sheet to use
Overrides: object.__init__

DefaultStyleDictionary(self)

 

This is the default style values that are used for styling documents. Its used as a fallback for undefined values in a style sheet.

Notes:
  • used as a fallback in case loading style sheet fails
  • incomplete style sheets are merged against this set to ensure a full set of definitions is avaiable

BlankStyleDictionary(self)

 

Returns a dictionary of unset style items based on the tags defined in the current dictionary.

Returns:
dictionary of unset style items using the current tag set as keys.

GetFontDictionary(self, default=True)

 

Does a system lookup to build a default set of fonts using ten point fonts as the standards size.

Parameters:
  • default (bool) - return default dictionary or custom
Returns:
font dictionary (primary, secondary) + (size, size2)

GetDefaultFont(self)

 

Constructs and returns a wxFont object from the settings of the default_style object.

Returns: wx.Font
font object of default style

GetDefaultForeColour(self, as_hex=False)

 

Gets the foreground color of the default style and returns a Colour object. Otherwise returns Black if the default style is not found.

Parameters:
  • as_hex (bool) - return a hex string or colour object
Returns: wx.Colour or string
wx.Colour of default style foreground or hex value

GetDefaultBackColour(self, as_hex=False)

 

Gets the background color of the default style and returns a Colour object. Otherwise returns white if the default style is not found.

Parameters:
  • hex (bool) - return a hex string or colour object
Returns: wx.Colour or string
wx.Colour of default style background or hex value

GetItemByName(self, name)

 

Gets and returns a style item using its name for the search

Parameters:
  • name - tag name of style item to get
Returns: StyleItem
style item (may be empty/null style item)

GetStyleFont(self, primary=True)

 

Returns the primary font facename by default

Parameters:
  • primary - Get Primary(default) or Secondary Font @return face name of current font in use

GetStyleByName(self, name)

 

Gets and returns a style string using its name for the search

Parameters:
  • name (string) - tag name of style to get
Returns: string
style item in string form

GetStyleSet(self)

 

Returns the current set of styles or the default set if there is no current set.

Returns: dict
current style set dictionary

HasNamedStyle(self, name)

 

Checks if a style has been set/loaded or not

Parameters:
  • name - tag name of style to look for
Returns:
whether item is in style set or not

LoadStyleSheet(self, style_sheet, force=False)

 

Loads a custom style sheet and returns True on success

Parameters:
  • style_sheet - path to style sheet to load
  • force - Force reparse of style sheet, default is to use cached data when available
Returns: bool
whether style sheet was loaded or not

MergeFonts(self, style_dict, font_dict)

 

Does any string substitution that the style dictionary may need to have fonts and their sizes set.

Parameters:
  • style_dict - dictionary of StyleItems
  • font_dict - dictionary of font data
Returns:
style dictionary with all font format strings substituded in

MergeStyles(self, styles1, styles2)

 

Merges the styles from styles2 into styles1 overwriting any duplicate values already set in styles1 with the new data from styles2.

Parameters:
  • styles1 - dictionary of StyleItems recieve merge
  • styles2 - dictionary of StyleItems to merge from
Returns:
style1 with all values from styles2 merged into it

PackStyleSet(self, style_set)

 

Checks the difference of each item in the style set as compared to the default_style tag and packs any unset value in the item to be equal to the default style.

Parameters:
  • style_set - style set to pack
Returns:
style_set with all unset attributes set to match default style

ParseStyleData(self, style_data, strict=False)

 

Parses a string style definitions read from an Editra Style Sheet. If the parameter 'strict' isnt set then any syntax errors are ignored and only good values are returned. If 'strict' is set the parser will raise errors and bailout.

Parameters:
  • style_data (string) - style sheet data string
  • strict - should the parser raise errors or ignore
Returns:
dictionary of StyleItems constructed from the style sheet data.

SetGlobalFont(self, font_tag, fontface, size=-1)

 

Sets one of the fonts in the global font set by tag and sets it to the named font. Returns true on success.

Parameters:
  • font_tag - fonttype identifier key
  • fontface - face name to set global font to

SetStyleFont(self, wx_font, primary=True)

 

Sets the\primary or secondary font and their respective size values.

Parameters:
  • wx_font - font object to set styles font info from
  • primary - Set primary(default) or secondary font

SetStyleTag(self, style_tag, value)

 

Sets the value of style tag by name

Parameters:
  • style_tag - desired tag name of style definition
  • value - style item to set tag to

SetStyles(self, style_dict, nomerge=False)

 

Sets the managers style data and returns True on success.

Parameters:
  • style_dict - dictionary of style items to use as managers style set.
  • nomerge (bool) - merge against default set or not