Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
r""" User-customizable options for words """ #***************************************************************************** # Copyright (C) 2009 Franco Saliola <saliola@gmail.com> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** import copy from sage.rings.integer import Integer
word_options = {\ 'identifier':'word: ', \ 'display':'string', \ 'truncate':True, \ 'truncate_length':40, \ 'letter_separator':',', \ 'cache':True, \ 'old_repr':False \ }
def WordOptions(**kwargs): """ Sets the global options for elements of the word class. The defaults are for words to be displayed in list notation.
INPUT:
- ``display`` - 'string' (default), or 'list', words are displayed in string or list notation. - ``truncate`` - boolean (default: True), whether to truncate the string output of long words (see truncate_length below). - ``truncate_length`` - integer (default: 40), if the length of the word is greater than this integer, then the word is truncated. - ``letter_separator`` - (string, default: ",") if the string representation of letters have length greater than 1, then the letters are separated by this string in the string representation of the word.
If no parameters are set, then the function returns a copy of the options dictionary.
EXAMPLES::
sage: w = Word([2,1,3,12]) sage: u = Word("abba") sage: WordOptions(display='list') sage: w word: [2, 1, 3, 12] sage: u word: ['a', 'b', 'b', 'a'] sage: WordOptions(display='string') sage: w word: 2,1,3,12 sage: u word: abba """ global word_options return copy.copy(word_options) raise ValueError("display must be either 'list' or 'string'") else: if not isinstance(kwargs['truncate'], bool): raise ValueError("truncate must be True or False") else: word_options['truncate'] = kwargs['truncate'] if not isinstance(kwargs['truncate_length'], (int,Integer)) or kwargs['truncate_length'] <= 0: raise ValueError("truncate_length must be a positive integer") else: word_options['truncate_length'] = kwargs['truncate_length'] raise ValueError("letter_separator must be a string") else: raise ValueError("identifier must be a string") else: elif 'cache' in kwargs: if not isinstance(kwargs['cache'], bool): raise ValueError("cache must be True or False") else: word_options['cache'] = kwargs['cache'] elif 'old_repr' in kwargs: if not isinstance(kwargs['old_repr'], bool): raise ValueError("old_repr must be True or False") else: word_options['old_repr'] = kwargs['old_repr'] |