This module provides several functions to indicate the deprecation of a module, a method or a function.
This is a decorator which can be used to mark functions as deprecated. It will result in a warning being emitted when the function is used. The message in parameter will be displayed and should indicate how this function can be replaced. If the terminal can display colors, the warning messages will appear in blue.
This function can be used to mark a module as deprecated. It must be called explicitly at the beginning of the deprecated module. It will result in a warning being emitted. The message in parameter will be displayed and should indicate how this module can be replaced. If the terminal can display colors, the warning messages will appear in blue.
Determine if the calling code is ultimately called by sphinx to generate documentation. The result can be used to conditionally inhibit the decorators or some Salome-related imports that fail when called outside Salome.
This module provides utility functions to display colored text in the terminal. It is based on ISO 6429 standard that defines control codes to change characters representation in color-capable ASCII terminals.
In this module, colors are represented as lists of codes, so they can be added to obtain special effects (e.g. RED + GREEN_BG to display red text on green background). Several constants are defined for the most usual codes to facilitate the use of colors, but it is also possible to define colors directly from the corresponding code from ISO 6429 standard. In fact it is even necessary for less usual codes that don’t have an associated constant (e.g. PURPLE + [‘09’] can be used to display a crossed-out purple text).
Example:
import sys
from pal import termcolor
if termcolor.canDisplayColor(sys.stdout):
print termcolor.makeColoredMessage("Hello world!", termcolor.BLUE)
else:
print "Hello world!"
Black text (equivalent to BLACK_FG)
Black background
Black foreground
Blue text (equivalent to BOLD + BLUE_FG)
Blue background
Blue foreground
Bold text and brighter colors
Cyan text (equivalent to BOLD + CYAN_FG)
Cyan background
Cyan foreground
Default color for the terminal
Green text (equivalent to BOLD + GREEN_FG)
Green background
Green foreground
Purple text (equivalent to BOLD + PURPLE_FG)
Purple background
Purple foreground
Red text (equivalent to BOLD + RED_FG)
Red background
Red foreground
Underlined text
White text (equivalent to WHITE_FG)
White background
White foreground
Yellow text (equivalent to BOLD + YELLOW_FG)
Yellow background
Yellow foreground
Return True if the stream can display colored text, False otherwise.
Return the control sequence for the color in parameter, i.e. the string telling the terminal to display the following text in the given color.
Return a string that can be used to display the message in parameter with the given color.
This module defines a class which provides logging facility in Salome:
Bases: logging.Logger
This class formats and displays log messages in Salome environment. It inherits Logger class defined in logging module from Python library, so all methods from logging.Logger can be used here. The format of the traces is:
LEVEL [keyword] : Message
where LEVEL is the level of the message (DEBUG, INFO, etc.), keyword is the name of the logger, and Message is the message to log.
When creating a new Logger object, the parameter keyword defines the name of the logger, level defines the logging level (default is logging.DEBUG if KERNEL module is configured with –enable-debug option or logging.WARNING otherwise), and color defines the color of the log messages for this logger (log messages will appear in color only when displayed on color-capable ASCII terminals). See module salome.kernel.termcolor for the color constants.
By default, log messages will be displayed only on standard output. They can also be recorded in a file (see method setLogFile()). For now, the CORBA-based logging facility can not be used through this class.
A source filename sourceFileName can be defined. If this argument is specified, then the keyword is modified to the basename of the sourceFileName
Basic usage:
from salome.kernel.logger import Logger
log = Logger("Test")
log.debug("Debug message")
log.info("Information message")
log.warning("Warning message")
log.error("Error message")
log.critical("Fatal error message")
Close the log file.
Log a message with CRITICAL level. This method only exists for backward compatibility and is equivalent to critical(message).
Hide DEBUG level messages (equivalent to setLevel(logging.INFO)).
Set the color of log messages on color-capable terminals. If color is None, the default color will be used.
Define a log file to record the log messages (in addition to the standard output).
Log all messages, including DEBUG level messages (equivalent to setLevel(logging.DEBUG)).
Bases: salome.kernel.logger.Logger
This class extends Logger class and adds exception information when DEBUG messages are recorded. It exists mainly for backward compatibility, as the same thing can be done by calling Logger.debug(message, exc_info = True).
Log a DEBUG message with exception information (equivalent to Logger.debug(message, exc_info = True)).
This module provides a new class StudyEditor to complement Study and StudyBuilder classes.
This class provides utility methods to complement Study and StudyBuilder classes. Those methods may be moved in those classes in the future. The parameter studyId defines the ID of the study to edit. If it is None, the edited study will be the current study. The preferred way to get a StudyEditor object is through the method getStudyEditor() which allows to reuse existing instances.
This instance attribute contains the ID of the edited study. This attribute should not be modified.
This instance attribute contains the underlying Study object. It can be used to access the study but the attribute itself should not be modified.
This instance attribute contains the underlying StudyBuilder object. It can be used to edit the study but the attribute itself should not be modified.
Create a new object named name under fatherItem in the study, with the given attributes. If an object named name already exists under the father object, the new object is created with a new name name_X where X is the first available index.
| Parameters: | fatherItem (SObject) – item under which the new item will be added. |
|---|---|
| Returns: | new SObject created in the study |
See setItem() for the description of the other parameters.
Find an item with given attributes under fatherItem in the study. If none is found, return None. If several items correspond to the parameters, only the first one is returned. The search is made only on given parameters (i.e. not None). To look explicitly for an empty attribute, use an empty string in the corresponding parameter.
See setItem() for the description of the parameters.
Find a component corresponding to the Salome module moduleName in the study. If none is found, create a new component and associate it with the corresponding engine (i.e. the engine named moduleName). Note that in Salome 5, the module name and engine name must be identical (every module must provide an engine with the same name). In Salome 6 it will be possible to define a different name for the engine.
| Parameters: |
|
|---|---|
| Returns: | the SComponent found or created. |
Find an object under fatherItem in the study with the given attributes. Return the first one found if at least one exists, otherwise create a new one with the given attributes and return it.
See setItem() for the description of the parameters.
Return the value of the attribute named attributeName on the object sObject, or default if the attribute doesn’t exist.
Return the value of the attribute “AttributeExternalFileDef” of the object sObject, or an empty string if it is not set.
Return the value of the attribute “AttributeFileType” of the object sObject, or an empty string if it is not set.
Return the value of the attribute “AttributePixMap” of the object sObject, or an empty string if it is not set.
Get the CORBA object associated with the SObject item, eventually by first loading it with the corresponding engine.
Return the value of the attribute “AttributeLocalID” of the object sObject, or None if it is not set.
Load the engine corresponding to sComponent in the container containerName, associate the engine with the component and load the CORBA objects of this component in the study.
Remove the given item from the study. Note that the items are never really deleted. They just don’t appear in the study anymore.
| Parameters: |
|
|---|---|
| Returns: | True if the item was removed successfully, or False if an error happened. |
Set the value of the attribute named attributeName on the object sObject to the value attributeValue.
Set the attribute “AttributeExternalFileDef” of the object sObject to the value value.
Set the attribute “AttributeFileType” of the object sObject to the value value.
Set the attribute “AttributePixMap” of the object sObject to the value value.
Modify the attributes of an item in the study. Unspecified attributes (i.e. those set to None) are left unchanged.
| Parameters: |
|
|---|
Find an item tagged tag under fatherItem in the study tree or create it if there is none, then set its attributes.
| Parameters: |
|
|---|---|
| Returns: | the SObject at tag if found or created successfully, or None if an error happened. |
See setItem() for the description of the other parameters.
Set the attribute “AttributeLocalID” of the object sObject to the value value.
Return the ID of the active study. In GUI mode, this function is equivalent to salome.sg.getActiveStudyId(). Outside GUI, it returns salome.myStudyId variable.
Return a StudyEditor instance to edit the study with ID studyId. If studyId is None, return an editor for the current study.