Skip to content

Commit

Permalink
STY: for shellcmd widget, add comments on more features with shell, u…
Browse files Browse the repository at this point in the history
…pdate example labels to provide more info
  • Loading branch information
nstelter-slac committed Nov 3, 2023
1 parent eb5d68b commit 583af7e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>379</width>
<height>358</height>
<width>458</width>
<height>386</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -23,7 +23,7 @@
</sizepolicy>
</property>
<property name="text">
<string>The PyDMShellCommand button with run your command through a Bash shell if you enable the &quot;runCommandsInBash&quot; option. </string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The PyDMShellCommand button with run your command through a full shell if you enable the 'runCmdsInFullShell' option. This allows you to use some additional features such as shell syntax ('|', '&amp;amp;', ';', etc), environment variables ($VAR), glob expansion ('*', '?', etc), and some other features.&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
Expand Down Expand Up @@ -96,7 +96,7 @@
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>You also can run through Bash (without needing to enable the option) by specifying &quot;bash -c&quot; at the start of your command or by having the shell command call a script the runs multiple commands. </string>
<string>You can run through a Bash shell (without needing to enable any options) by specifying &quot;bash -c&quot; at the start of your command. </string>
</property>
<property name="wordWrap">
<bool>true</bool>
Expand Down Expand Up @@ -166,6 +166,16 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>You can also call a shell script. For this button to work correctly, run pydm from dir 'examples/shell_command' so it can find the script file.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="PyDMShellCommand" name="PyDMShellCommand_2">
<property name="toolTip">
Expand Down
11 changes: 6 additions & 5 deletions pydm/widgets/shell_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def __init__(
self.process = None
self._show_icon = True
self._redirect_output = False
# shell allows for more options such as command chaining ("cmd1;cmd2", "cmd1 && cmd2", etc ...)
# shell allows for more options such as command chaining ("cmd1;cmd2", "cmd1 && cmd2", etc ...),
# use of environment variables, glob expansion ('ls *.txt'), etc...
self._run_cmds_in_full_shell = False

self._password_protected = False
Expand Down Expand Up @@ -129,7 +130,7 @@ def showConfirmDialog(self, value: bool) -> None:
self._show_confirm_dialog = value

@Property(bool)
def runCommandsInFullShell(self) -> bool:
def runCmdsInFullShell(self) -> bool:
"""
Whether or not to run cmds with Popen's option for running them through a shell subprocess.
Expand All @@ -139,8 +140,8 @@ def runCommandsInFullShell(self) -> bool:
"""
return self._run_cmds_in_full_shell

@runCommandsInFullShell.setter
def runCommandsInFullShell(self, value: bool) -> None:
@runCmdsInFullShell.setter
def runCmdsInFullShell(self, value: bool) -> None:
"""
Whether or not to run cmds with Popen's option for running them through a shell subprocess.
Expand Down Expand Up @@ -551,7 +552,7 @@ def execute_command(self, command: str) -> None:
if (self.process is None or self.process.poll() is not None) or self._allow_multiple:
cmd = os.path.expanduser(os.path.expandvars(command))
args = shlex.split(cmd, posix="win" not in sys.platform)
# when Bash enabled, Popen takes the cmds as a single string (not list)
# when shell enabled, Popen should take the cmds as a single string (not list)
if self._run_cmds_in_full_shell:
args = cmd
try:
Expand Down

0 comments on commit 583af7e

Please sign in to comment.