taurus taurus

Previous topic

TaurusAttributeControllerHelper

Next topic

TaurusBaseController

This Page

TaurusBaseComponent

Inheritance diagram of TaurusBaseComponent

class TaurusBaseComponent(name, parent=None, designMode=False)

Bases: taurus.core.tauruslistener.TaurusListener, taurus.qt.qtcore.configuration.configuration.BaseConfigurableClass

A generic Taurus component.

Note

Any class which inherits from TaurusBaseComponent is expected to also inherit from QObject (or from a QObject derived class) If this is not fullfilled, at least the class should reimplement the getSignaller() method to return a QObject to be used for emitting and connecting signals.

applyPendingOperations(ops=None)

Applies operations without caring about danger messages. Use TaurusBaseWidget.safeApplyOperation() if you want to warn the user before applying

Parameters:ops (:class:~`sequence` <:class:~`taurus.core.TaurusOperation`> or :class:~`None`) – list of operations to apply. If None is given (default) the component fetches the pending operations
contextMenuEvent(event)

Handle the popup menu event

Parameters:event – the popup menu event
deleteLater()

Reimplements the Qt.QObject deleteLater method to ensure that the this object stops listening its model.

displayValue(v)

Returns a string representation of the given value

Parameters:v (:class:~`object`) – the value to be translated to string
Return type::class:~`str`
Returns:a string representing the given value
eventReceived(evt_src, evt_type, evt_value)

The basic implementation of the event handling chain is as follows:

Note

in the earlier steps of the chain (i.e., in eventReceived()/fireEvent()), the code is executed in a Python thread, while from eventFilter ahead, the code is executed in a Qt thread. When writing widgets, one should normally work on the Qt thread (i.e. reimplementing handleEvent())

Parameters:
  • evt_src (:class:~`object`) – object that triggered the event
  • evt_type (:class:~`taurus.core.TaurusEventType`) – type of event
  • evt_value (:class:~`object`) – event value
filterEvent(evt_src=-1, evt_type=-1, evt_value=-1)

The event is processed by each and all filters in strict order unless one of them returns None (in which case the event is discarded)

Parameters:
  • evt_src (:class:~`object`) – object that triggered the event
  • evt_type (:class:~`taurus.core.TaurusEventType`) – type of event
  • evt_value (:class:~`object`) – event value
findModelClass()

Do a “best effort” to determine which model type corresponds to the given model name.

Return type::class:~`class TaurusModel` or :class:~`None`
Returns:The class object corresponding to the type of Taurus model this widget handles or None if no valid class is found.
fireEvent(evt_src=None, evt_type=None, evt_value=None)

Emits a “taurusEvent” signal. It is unlikely that you may need to reimplement this method in subclasses. Consider reimplementing eventReceived() or handleEvent() instead depending on whether you need to execute code in the python or Qt threads, respectively

Parameters:
  • evt_src (:class:~`object` or :class:~`None`) – object that triggered the event
  • evt_type (:class:~`taurus.core.TaurusEventType` or :class:~`None`) – type of event
  • evt_value (:class:~`object` or :class:~`None`) – event value
getDangerMessage()

Returns the current apply danger message or None if the apply operation is safe

Return type::class:~`str` or :class:~`None`
Returns:the apply danger message
getDisplayValue(cache=True)

Returns a string representation of the model value associated with this component.

Parameters:cache (:class:~`bool`) – if set to True (default) use the cache value. If set to False will force a connection to the server.
Return type::class:~`str`
Returns:a string representation of the model value.
getEventFilters()

Returns the list of event filters for this widget

Return type::class:~`sequence` <:class:~`callable`>
Returns:the event filters
getForceDangerousOperations()

Returns if apply dangerous operations is forced

Return type::class:~`bool`
Returns:wheter or not apply dangerous operations is forced
getFormatedToolTip(cache=True)

Returns a string with contents to be displayed in a tooltip.

Parameters:cache (:class:~`bool`) – if set to True (default) use the cache value. If set to False will force a connection to the server.
Return type::class:~`str`
Returns:a tooltip
getModel()

Returns the model name for this component.

Return type::class:~`str`
Returns:the model name.
getModelClass()

Return the class object for the widget. Default behavior is to do a ‘best effort’ to determine which model type corresponds to the current model name. Overwrite as necessary.

Return type::class:~`class TaurusModel` or :class:~`None`
Returns:The class object corresponding to the type of Taurus model this widget handles or None if no valid class is found.
getModelInConfig()
getModelName()

Returns the current model name.

Return type::class:~`str`
Returns:the model name
getModelObj()

Returns the taurus model obj associated with this component or None if no taurus model is associated.

Return type::class:~`taurus.core.TaurusModel` or :class:~`None`
Returns:the taurus model object
getModelType()

Returns the taurus model type associated with this component or taurus.core.TaurusElementType.Unknown if no taurus model is associated.

Return type::class:~`taurus.core.TaurusElementType`
Returns:the taurus model type
getModelValueObj(cache=True)

Returns the tango obj value associated with this component or None if no taurus model is associated.

Parameters:cache (:class:~`bool`) – if set to True (default) use the cache value. If set to False will force a connection to the server.
Return type::class:~`PyTango.DeviceAttribute`
Returns:the tango value object.
getNoneValue()

Returns the current string representation when no valid model or model value exists.

Return type::class:~`str`
Returns:a string representation for an invalid value
getParentModelName()

Returns the parent model name or an empty string if the component has no parent

Return type::class:~`str`
Returns:the parent model name
getParentModelObj()

Returns the parent model object or None if the component has no parent or if the parent’s model is None

Return type::class:~`taurus.core.TaurusModel` or :class:~`None`
Returns:the parent taurus model object
getParentTaurusComponent()

Returns a parent Taurus component or None if no parent taurus.core.TaurusBaseComponent is found.

Raise :RuntimeError
getPendingOperations()

Returns the sequence of pending operations

Return type::class:~`sequence` <:class:~`taurus.core.TaurusOperation`>
Returns:a list of pending operations
getShowQuality()

Returns if showing the quality as a background color

Return type::class:~`bool`
Returns:True if showing the quality or False otherwise
getShowText()

Returns if showing the display value

Return type::class:~`bool`
Returns:True if showing the display value or False otherwise
getSignaller()

Reimplement this method if your derived class does not inherit from QObject. The return value should be a permanent object capable of emitting Qt signals. See TaurusImageItem as an example

getTaurusFactory(scheme=None)

Returns the the taurus factory singleton for the given scheme. This is just a helper method. It is the equivalent of doing:

import taurus
factory = taurus.Factory(scheme)
Parameters:scheme (:class:~`str` or :class:~`None`) – the scheme. None defaults to ‘tango’.
Return type::class:~`taurus.core.TaurusFactory`
Returns:the TaurusFactory
getTaurusManager()

Returns the the taurus manager singleton. This is just a helper method. It is the equivalent of doing:

import taurus
manager = taurus.Manager()
Return type::class:~`taurus.core.TaurusManager`
Returns:the TaurusManager
getTaurusPopupMenu()

Returns an xml string representing the current taurus popup menu

Return type::class:~`str`
Returns:an xml string representing the current taurus popup menu
getUseParentModel()

Returns whether this component is using the parent model

Return type::class:~`bool`
Returns:True if using parent model or False otherwise
handleEvent(evt_src, evt_type, evt_value)

Event handling. Default implementation does nothing. Reimplement as necessary

Parameters:
  • evt_src (:class:~`object` or :class:~`None`) – object that triggered the event
  • evt_type (:class:~`taurus.core.TaurusEventType` or :class:~`None`) – type of event
  • evt_value (:class:~`object` or :class:~`None`) – event value
hasPendingOperations()

Returns if the component has pending operations

Return type::class:~`bool`
Returns:True if there are pending operations or False otherwise
insertEventFilter(filter, index=-1)

insert a filter in a given position

Parameters:
  • filter (:class:~`callable(evt_src, evt_type, evt_value`) – ) a filter
  • index (:class:~`int`) – index to place the filter (default = -1 meaning place at the end)

See also: setEventFilters

isAttached()

Determines if this component is attached to the taurus model.

Return type::class:~`bool`
Returns:True if the component is attached or False otherwise.
isAutoProtectOperation()

Tells if this widget’s operations are protected against exceptions

Return type::class:~`bool`
Returns:True if operations are protected against exceptions or False otherwise
isChangeable()

Tells if this component value can be changed by the user. Default implementation will return True if and only if:

  • this component is attached to a valid taurus model and
  • the taurus model is writable and
  • this component is not read-only
Return type::class:~`bool`
Returns:True if this component value can be changed by the user or False otherwise
isDangerous()

Returns if the apply operation for this component is dangerous

Return type::class:~`bool`
Returns:wheter or not the apply operation for this component is dangerous
isModifiableByUser()

whether the user can change the contents of the widget

Return type::class:~`bool`
Returns:True if the user is allowed to modify the look&feel
isPaused()

Return the current pause state

Return type::class:~`bool`
Returns:wheater or not the widget is paused
isReadOnly()

Determines if this component is read-only or not in the sense that the user can interact with it. Default implementation returns True.

Override when necessary.

Return type::class:~`bool`
Returns:whether or not this component is read-only
postAttach()

Called inside self.attach() after actual attach is performed. Default implementation does not do anything.

Override when necessary.

postDetach()

Called inside self.detach() after actual deattach is performed. Default implementation does not do anything.

Override when necessary.

preAttach()

Called inside self.attach() before actual attach is performed. Default implementation just emits a signal.

Override when necessary.

preDetach()

Called inside self.detach() before actual deattach is performed. Default implementation just disconnects a signal.

Override when necessary.

resetAutoProtectOperation()

Resets protecting operations

resetDangerMessage()

Clears the danger message. After this method is executed the apply operation for this component will be considered safe.

resetForceDangerousOperations()

Clears forcing apply dangerous operations

resetModel()

Sets the model name to the empty string

resetModelInConfig()
resetModifiableByUser()

Equivalent to setModifiableByUser(self.__class__._modifiableByUser)

resetPendingOperations()

Clears the list of pending operations

resetShowQuality()

Resets the show quality to self.__class__._showQuality

resetShowText()

Resets the showing of the display value to True

resetTaurusPopupMenu()

Resets the taurus popup menu to empty

resetUseParentModel()

Resets the usage of parent model to False

setAutoProtectOperation(protect)

Sets/unsets this widget’s operations are protected against exceptions

Parameters:protect (bool) – wheater or not to protect widget operations
setDangerMessage(dangerMessage='')

Sets the danger message when applying an operation. If dangerMessage is None, the apply operation is considered safe

Parameters:dangerMessage (:class:~`str` or :class:~`None`) – the danger message. If None is given (default) the apply operation is considered safe
setEventFilters(filters=None)

sets the taurus event filters list. The filters are run in order, using each output to feed the next filter. A filter must be a function that accepts 3 arguments (evt_src, evt_type, evt_value) If the event is to be ignored, the filter must return None. If the event is not to be ignored, filter must return a (evt_src, evt_type, evt_value) tuple which may (or not) differ from the input.

For a library of common filters, see taurus/core/util/eventfilters.py

Parameters:filters (:class:~`sequence`) – a sequence of filters

Note: If you are setting a filter that applies a transformation on the parameters, you may want to generate a fake event to force the last value to be filtered as well. This can be done as in this example:

TaurusBaseComponent.fireEvent( TaurusBaseComponent.getModelObj(),
                            taurus.core.TaurusEventType.Periodic,
                            TaurusBaseComponent.getModelObj().getValueObj())

See also: insertEventFilter

setForceDangerousOperations(yesno)

Forces/clears the dangerous operations

Parameters:yesno (:class:~`bool`) – force or not the dangerous operations
setModel(model)

Sets/unsets the model name for this component

Parameters:model (:class:~`str`) – the new model name
setModelCheck(model, check=True)

Sets the component taurus model. Setting the check argument to True (default) will check if the current model is equal to the given argument. If so then nothing is done. This should be the standard way to call this method since it will avoid recursion.

Parameters:
  • model (:class:~`str`) – the new model name
  • check (:class:~`bool`) – whether or not to check against the actual model name
setModelInConfig(yesno)

Sets whether the model-related properties should be stored for this widget when creating the config dict with createConfig() (and restored when calling applyConfig()). By default this is not enabled. The following properties are affected by this: - “model”

Parameters:yesno (:class:~`bool`) – If True, the model-related properties will be registered as config properties. If False, they will be unregistered.

See also

registerConfigProperty(), createConfig(), applyConfig()

setModelName(modelName, parent=None)

This method will detach from the previous taurus model (if any), it will set the new model to the given modelName and it will attach this component to the new taurus model.

Parameters:
  • modelName (:class:~`str`) – the new taurus model name (according to the taurus convention)
  • parent (:class:~`TaurusBaseComponent`) – the parent or None (default) if this component does not have a parent Taurus component
setModifiableByUser(modifiable)

sets whether the user is allowed to modify the look&feel

Parameters:modifiable (:class:~`bool`) –
setNoneValue(v)

Sets the new string representation when no model or no model value exists.

Parameters:v (:class:~`str`) – the string representation for an invalid value
setPaused(paused=True)

Toggles the pause mode.

Parameters:paused (:class:~`bool`) – whether or not to pause (default = True)
setShowQuality(showQuality)

Sets/unsets the show quality property

Parameters:showQuality (:class:~`bool`) – whether or not to show the quality
setShowText(showText)

Sets/unsets showing the display value of the model

Parameters:showText (:class:~`bool`) – whether or not to show the display value
setTaurusPopupMenu(menuData)

Sets/unsets the taurus popup menu

Parameters:menuData (:class:~`str`) – an xml representing the popup menu
setUseParentModel(yesno)

Sets/unsets using the parent model

Parameters:yesno (:class:~`bool`) – whether or not to use parent model
toolTipObjToStr(toolTipObj)

Converts a python dict to a tooltip string.

Parameters:toolTipObj (:class:~`dict`) – a python object
Return type::class:~`str`
Returns:a tooltip
updateStyle()

Method called when the component detects an event that triggers a change in the style. Default implementation doesn’t do anything. Overwrite when necessary