Skip to content

Commit dd37217

Browse files
committed
qtplasmac: allow python scripts from user buttons
1 parent 259a180 commit dd37217

3 files changed

Lines changed: 29 additions & 4 deletions

File tree

docs/src/plasma/qtplasmac.adoc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3061,6 +3061,7 @@ n Name = PIERCE\&&CUT
30613061
Buttons can run the following:
30623062

30633063
. <<qt_button-cmds,External commands>>
3064+
. <<qt_button-py,External python scripts>>
30643065
. <<qt_button-code,G-code commands>>
30653066
. <<qt_button-toggle,Toggle a HAL pin>>
30663067
. <<qt_button-laser,Toggle the alignment laser HAL pin>>
@@ -3087,6 +3088,17 @@ To run an external command, the command is preceded by a % character.
30873088
n Code = %halshow
30883089
----
30893090

3091+
[[qt_button-py]]
3092+
[underline]*External Python Scripts*
3093+
3094+
To run an external python script, the script name is preceded by a % character and it also requires a .py extension.
3095+
It is valid to use the ~ character as a shortcut for the users home directory.
3096+
3097+
[source,{ini}]
3098+
----
3099+
n Code = %my_python_script.py
3100+
----
3101+
30903102
[[qt_button-code]]
30913103
[underline]*G-code*
30923104

share/qtvcp/screens/qtplasmac/qtplasmac_handler.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = '1.233.246'
1+
VERSION = '1.233.247'
22

33
'''
44
qtplasmac_handler.py
@@ -3482,7 +3482,10 @@ def user_button_setup(self):
34823482
self.idleHomedList.append('button_{}'.format(str(bNum)))
34833483
elif command and command[0] == '%':
34843484
cmd = command.lstrip('%').lstrip(' ').split(' ', 1)[0]
3485-
reply = Popen('which {}'.format(cmd), stdout=PIPE, stderr=PIPE, shell=True).communicate()[0]
3485+
if cmd[-3:] == '.py':
3486+
reply = os.path.exists(os.path.expanduser(cmd))
3487+
else:
3488+
reply = Popen('which {}'.format(cmd), stdout=PIPE, stderr=PIPE, shell=True).communicate()[0]
34863489
if not reply:
34873490
head = _translate('HandlerClass', 'External Code Error')
34883491
msg1 = _translate('HandlerClass', 'External command')
@@ -3640,8 +3643,13 @@ def user_button_command(self, bNum, command):
36403643
command = newCommand
36413644
ACTION.CALL_MDI(command)
36423645
elif command and command[0] == '%':
3643-
command = command.lstrip('%').lstrip() + '&'
3644-
Popen(command, stdout=PIPE, stderr=PIPE, shell=True)
3646+
command = command.lstrip('%').lstrip()
3647+
if command[-3:] == '.py':
3648+
cmd = 'python3 ' + command
3649+
Popen(cmd, stdin = None, stdout=PIPE, stderr=PIPE, shell=True)
3650+
else:
3651+
command += '&'
3652+
Popen(command, stdout=PIPE, stderr=PIPE, shell=True)
36453653
else:
36463654
head = _translate('HandlerClass', 'Code Error')
36473655
msg0 = _translate('HandlerClass', 'Invalid code for user button')

share/qtvcp/screens/qtplasmac/versions.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ <h2>QtPlasmaC Version History</h2>
3030
</table>
3131
<br>
3232
<!--- ****** ADD NEXT VERSION BELOW THIS LINE ****** --->
33+
<br><b><u>v1.233.247 2022 Oct 09</u></b>
34+
<ul style="margin:0;">
35+
<li>allow python scripts from user buttons</li>
36+
</ul>
37+
3338
<br><b><u>v1.233.246 2022 Sep 22</u></b>
3439
<ul style="margin:0;">
3540
<li>rework void sensing</li>

0 commit comments

Comments
 (0)