PyFoam.ThirdParty.Gnuplot.termdefs module¶
Terminal definition file.
This module describes the options available to gnuplot’s various terminals. For the moment, it only supports a few terminals, but the infrastructure is here to add others as they are needed.
Part of the trick is that the ‘set terminal’ command takes myriad suboptions with various argument types, and order is sometimes significant. The other part of the trick is that there are over 50 terminal types, and each terminal has its own set of options.
The strategy here is to define a general mechanism for turning Python keyword parameters into fragments of gnuplot command strings. There are a number of classes derived from Arg that do this. Some take string args, some boolean, etc. Then the list of options that each terminal accepts is stored in the terminal_opts dictionary. Gnuplot.hardcopy(), in turn, uses this dictionary to interpret its keyword arguments and build the ‘set terminal’ command.
-
class
PyFoam.ThirdParty.Gnuplot.termdefs.
Arg
[source]¶ Bases:
object
Process terminal subargs and return a command fragment.
Pull one or more arguments from keyw and output a list of strings that will be appended to the ‘set terminal’ (separated by spaces). Delete any used args from keyw. If no relevant options are found, return None.
This is a base class for the actual argument-processing classes. Derived classes must define a __call__(self, keyw) method returning a list of strings or None.
-
class
PyFoam.ThirdParty.Gnuplot.termdefs.
ArgOneParam
(argname, default)[source]¶ Bases:
PyFoam.ThirdParty.Gnuplot.termdefs.Arg
Arg abstract base class specialized for exactly one parameter.
Members:
- ‘argname’ – The name of the keyword argument used to pass
- this argument to Python.
- ‘default’ – The default value of the argument, used if no
- keyword parameter is found. If this is None, then no default is assumed.
-
class
PyFoam.ThirdParty.Gnuplot.termdefs.
BareStringArg
(argname, fixedword=None, default=None)[source]¶ Bases:
PyFoam.ThirdParty.Gnuplot.termdefs.ArgOneParam
An arbitrary argument output without quotes.
The argument can be a string or anything with a str() representation, or a tuple of such things. Thus this can be used for strings (which will be output without quotation marks), integers, floating point arguments, or multiple arguments of the above types (which will be output separated by spaces). No checking is done that the argument is sensible.
-
class
PyFoam.ThirdParty.Gnuplot.termdefs.
BooleanArg
(argname, trueval, falseval, fixedword=None, default=None)[source]¶ Bases:
PyFoam.ThirdParty.Gnuplot.termdefs.ArgOneParam
An argument that takes a true/false value.
The argument should be 0 or 1. The option is output to gnuplot as ‘trueval’ if the argument is true or ‘falseval’ if the argument is false. Either one can be ‘None’, in which case nothing is output. ‘default’ should also be 0 or 1.
-
class
PyFoam.ThirdParty.Gnuplot.termdefs.
KeywordArg
(argname, options, fixedword=None, default=None)[source]¶ Bases:
PyFoam.ThirdParty.Gnuplot.termdefs.ArgOneParam
Represent an argument that must be passed as a keyword to gnuplot.
Some gnuplot options take the form of single unquoted keywords (possibly preceded by a fixed keyword). We allow those to be passed as strings ‘option=”keyword”’. Check that the option supplied is in the list of allowed options.
Members:
- ‘fixedword’ – the fixed keyword that must precede the
- variable keyword in the gnuplot command, or None if none is required.
- ‘options’ – a list of strings containing the legal
- alternatives for this argument.
-
class
PyFoam.ThirdParty.Gnuplot.termdefs.
KeywordOrBooleanArg
(options, argname=None, fixedword=None, default=None)[source]¶ Bases:
PyFoam.ThirdParty.Gnuplot.termdefs.Arg
Allow a keyword arg to be specified either as a keyword or a boolean.
This arg type is the most flexible way to allow keyword parameters to be specified. Say there is an option like ‘fontsize’ that can take the values ‘small’ or ‘large’. This could be represented as
‘KeywordOrBooleanArg(options=[“small”, “large”], argname=”fontsize”)’In that case, the fontsize could be specified in any of the following ways:
‘g.hardcopy(…, fontsize=”small”, …)’ ‘g.hardcopy(…, fontsize=”large”, …)’ ‘g.hardcopy(…, small=1, …)’ ‘g.hardcopy(…, large=1, …)’If ‘argname’ is set to be ‘None’, then the first two possibilities are omitted.
In the special case that there are exactly two alternatives, one can also use:
‘g.hardcopy(…, small=0, …) # implies fontsize=”large”’ ‘g.hardcopy(…, large=0, …) # implies fontsize=”small”’Obviously care must be taken to ensure that none of the implied keyword parameter names conflict with one another or with any of the other Args allowed by a function.
Members:
- ‘options’ – a list of strings representing allowed keyword
- values. These options can be used as boolean values in the style ‘option=1’.
- ‘argname’ – the name of the argname for the ‘arg=value’ style
- of setting the argument. If ‘None’, then this style is not allowed.
- ‘fixedword’ – a fixed keyword that must precede the option,
- or ‘None’.
- ‘default’ – the default option to set if nothing is set
- explicitly, or None to leave nothing set in that case.
-
class
PyFoam.ThirdParty.Gnuplot.termdefs.
MutuallyExclusiveArgs
(*subargs)[source]¶ Bases:
PyFoam.ThirdParty.Gnuplot.termdefs.Arg
A group of args, of which either zero or one may be set, but not more.
Members:
- subargs – a list [(‘argname’, arg), …] of Arg instances.
- ‘argname’ is used to identify the corresponding arg in error messages. (The name of the corresponding keyword args is determined internally by each arg.)
-
class
PyFoam.ThirdParty.Gnuplot.termdefs.
StringArg
(argname, fixedword=None, default=None)[source]¶ Bases:
PyFoam.ThirdParty.Gnuplot.termdefs.ArgOneParam
An option taking a quoted string argument.