PyDMShellCommand

class pydm.widgets.shell_command.PyDMShellCommand(parent: Optional[QWidget] = None, command: Optional[Union[str, List[str]]] = None, title: Optional[Union[str, List[str]]] = None, init_channel: Optional[str] = None)[source]

Bases: QPushButton, PyDMWidget

A QPushButton capable of executing shell commands.

Parameters:
  • parent (QWidget, optional) – The parent widget for the shell command

  • command (str or list, optional) – A string for a single command to run, or a list of strings for multiple commands

  • title (str or list, optional) – Title of the command to run, shown in the display. If a list, number of elements must match that of command

  • init_channel (str, optional) – The channel to be used by the widget

Q_ENUM(a0: Union[type, enum.Enum])
class TermOutputMode

Bases: object

Enum to select the behavior of the stdout/stderr output from a subprocess.

check_enable_state() None[source]

override parent method, so this widget does not get disabled when the pv disconnects. This method adds a Tool Tip with the reason why it is disabled.

confirmDialog() bool[source]

Show the confirmation dialog with the proper message in case `showConfirmMessage` is True.

Returns:

True if the message was confirmed or if `showConfirmMessage` is False.

Return type:

bool

eventFilter(self, a0: Optional[QObject], a1: Optional[QEvent]) bool[source]
execute_command(command: str, action=None) None[source]

Execute the shell command given by `command`. The process is available through the `process` member.

Parameters:
  • command (str) – Shell command

  • action (QAction) – Drop-down menu item that was selected in order to run `command`. Will be `None` if a button without a drop-down (only has a single command) was selected.

generate_context_menu() None[source]

Generates the custom context menu, and populates it with any external tools that have been loaded. PyDMWidget subclasses should override this method (after calling superclass implementation) to add the menu.

Return type:

QMenu

hide_warning_icon() None[source]

Hide the warning icon. This is called on a timer after the warning icon is shown.

mousePressEvent(self, e: Optional[QMouseEvent])[source]
mouseReleaseEvent(mouse_event: QMouseEvent) None[source]

mouseReleaseEvent is called when a mouse button is released. This means that if the user presses the mouse inside your widget, then drags the mouse somewhere else before releasing the mouse button, your widget receives the release event.

Parameters:

mouse_event

readAllowMultipleExecutions() bool[source]

Whether or not we should allow the same command to be executed even if it is still running.

Return type:

bool

readCommand() str[source]

DEPRECATED: use the ‘commands’ property. This property simply returns the first command from the ‘commands’ property. The shell command to run.

Return type:

str

readConfirmMessage() str[source]

Message to be displayed at the Confirmation dialog.

Return type:

str

readEnvironmentVariables() str[source]

Return the environment variables which would be set along with the shell command.

Returns:

self.env_var

Return type:

str

readPassword() str[source]

Password to be encrypted using SHA256.

Warning

To avoid issues exposing the password this method always returns an empty string.

Return type:

str

readPasswordProtected() bool[source]

Whether or not this button is password protected.

Returns:

  • bool

  • ——-

readProtectedPassword() str[source]

The encrypted password.

Return type:

str

readPyDMIcon() str[source]

Name of icon to be set from Qt provided standard icons or from the fontawesome icon-set. See “enum QStyle::StandardPixmap” in Qt’s QStyle documentation for full list of usable standard icons. See https://fontawesome.com/icons?d=gallery for list of usable fontawesome icons.

Return type:

str

readPyDMIconColor() QColor[source]

The color of the icon (color is only applied if using icon from the “Font Awesome” set) :rtype: QColor

readRedirectCommandOutput() bool[source]

Whether or not we should redirect the output of command to the shell.

This is deprecated in favor of the stdout property. If stdout has already been set, this property will be ignored and will log a warning when changed.

If the stdout property has not been changed, setting and checking this property will still work as it always had for backwards compatibility.

readRunCommandsInFullShell() bool[source]

Whether or not to run cmds with Popen’s option for running them through a shell subprocess.

Return type:

bool

readShowConfirmDialog() bool[source]

Whether or not to display a confirmation dialog.

Return type:

bool

readShowCurrentlyRunningIndication() bool[source]

Whether or not to have a button’s visuals change to indicate when the command is running. It’s nice to enable this when you know your button’s command runs long.

Return type:

bool

readShowIcon() bool[source]

Whether or not we should show the selected Icon.

Return type:

bool

readStderr() TermOutputMode[source]

The behavior of the subprocess’s standard error stream.

The options are:

  • HIDE (default): hide the stderr

  • SHOW: print stderr to terminal

  • STORE: capture stderr for programmatic retrieval

readStdout() TermOutputMode[source]

The behavior of the subprocess’s standard output stream.

The options are:

  • HIDE (default): hide the stdout

  • SHOW: print stdout to terminal

  • STORE: capture stdout for programmatic retrieval

This is implicitly linked to the older, soft deprecated parameter redirectCommandOutput, which can still be set to False to HIDE the stdout or True to SHOW the stdout, provided that stdout itself has not yet been set.

setAllowMultipleExecutions(value: bool) None[source]

Whether or not we should allow the same command to be executed even if it is still running.

Parameters:

value (bool) –

setCommand(value: str) None[source]

DEPRECATED: Use the ‘commands’ property instead. This property only has an effect if the ‘commands’ property is empty. If ‘commands’ is empty, it will be set to a single item list containing the value of ‘command’.

Parameters:

value (str) –

setConfirmMessage(value: str) None[source]

Message to be displayed at the Confirmation dialog.

Parameters:

value (str) –

setEnvironmentVariables(new_dict: str) None[source]

Set environment variables which would be set along with the shell command.

Parameters:

new_dict (str) –

setPassword(value: str) None[source]

Password to be encrypted using SHA256.

Parameters:

value (str) – The password to be encrypted

setPasswordProtected(value: bool) None[source]

Whether or not this button is password protected.

Parameters:

value (bool) –

setProtectedPassword(value: str) None[source]

Setter for the encrypted password.

Parameters:

value (str) –

setPyDMIcon(value: str) None[source]

Name of icon to be set from Qt provided standard icons or from the “Font Awesome” icon-set. See “enum QStyle::StandardPixmap” in Qt’s QStyle documentation for full list of usable standard icons. See https://fontawesome.com/icons?d=gallery for list of usable “Font Awesome” icons.

Parameters:

value (str) –

setPyDMIconColor(state_color: QColor) None[source]

The color of the icon (color is only applied if using icon from the “Font Awesome” set) :param new_color: :type new_color: QColor

setRunCommandsInFullShell(value: bool) None[source]

Whether or not to run cmds with Popen’s option for running them through a shell subprocess.

Parameters:

value (bool) –

setShowConfirmDialog(value: bool) None[source]

Whether or not to display a confirmation dialog.

Parameters:

value (bool) –

setShowCurrentlyRunningIndication(value: bool) None[source]

Whether or not to have a button’s visuals change to indicate when the command is running. It’s nice to enable this when you know your button’s command runs long.

Parameters:

value (bool) –

setShowIcon(value: bool) None[source]

Whether or not we should show the selected Icon.

Parameters:

value (bool) –

set_object_font_italic(object, italic)[source]

Enable or disable the italic font of an object.

Parameters:
  • object (QWidget) – Object which will have it’s font set

  • italic (bool) – Whether to enable or disable the object’s italic font

set_object_icon(object, iconName)[source]

Set the icon of an object. If empty string is passed, set the object to have no visible icon.

Parameters:
  • object (QWidget) – Shell command

  • iconName (str) – Shell command

show_warning_icon() None[source]

Show the warning icon. This is called when a shell command fails (i.e. exits with nonzero status)

validate_password() bool[source]

If the widget is `passwordProtected`, this method will prompt the user for the correct password.

Returns:

True in case the password was correct of if the widget is not password protected.

Return type:

bool

Note

See QPushButton Documentation for all inherited properties and methods.