5555--------------
5656"""
5757
58+ import os
59+ import re
5860import sys
61+ import subprocess
62+ import functools
63+ from pathlib import Path
5964from PyQt5 import QtWidgets , QtCore , QtGui
6065from libinput_gestures_qt import main_window
6166from libinput_gestures_qt import edit_window
6267
63- import subprocess
64- from pathlib import Path
65- import os
66-
67- import re
68+ # NOTE `capture_output` was introduced in 3.7
69+ if sys . version_info < ( 3 , 7 ):
70+ run = functools . partial ( subprocess . run , stdout = subprocess . PIPE , stderr = subprocess . PIPE )
71+ else :
72+ run = functools . partial ( subprocess . run , capture_output = False )
6873
6974HOME = str (Path .home ())
7075CONFIG_LOCATION = HOME + '/.config/libinput-gestures.conf'
@@ -188,6 +193,7 @@ def write_config(new_conf):
188193 with open (CONFIG_LOCATION , 'w' ) as config :
189194 config .write ('' .join (new_conf ))
190195
196+
191197def write_defaults (defaults ):
192198 """Write default settings and backs old config up
193199
@@ -200,6 +206,7 @@ def write_defaults(defaults):
200206 config .write (defaults )
201207 return defaults
202208
209+
203210def fix_config ():
204211 """Fixes config
205212
@@ -231,6 +238,7 @@ def fix_config():
231238 fixed_conf .append (line )
232239 write_config ('' .join (fixed_conf ))
233240
241+
234242def resub_config ():
235243 """Delete multiple tabs and spaces"""
236244 conf = '' .join (read_config ())
@@ -255,13 +263,14 @@ def find_key_combo(qt_key_combo):
255263 xdotool_key_combo .append (lowered_key )
256264 return '+' .join (xdotool_key_combo )
257265
266+
258267def get_qdbus_name ():
259268 """It's either 'qdbus' or 'qdbus-qt5'"""
260269 try :
261- subprocess . run (['qdbus' ], capture_output = True )
270+ run (['qdbus' ])
262271 return 'qdbus'
263272 except FileNotFoundError :
264- subprocess . run (['qdbus-qt5' ], capture_output = True )
273+ run (['qdbus-qt5' ])
265274 return 'qdbus-qt5'
266275
267276
@@ -328,13 +337,12 @@ def __init__(self, parent=None):
328337 self .actionLicense .triggered .connect (self .show_copyleft )
329338 #-->
330339 try :
331- subprocess . run (['libinput-gestures-setup' , 'status' ], capture_output = True )
340+ run (['libinput-gestures-setup' , 'status' ])
332341 self .installed = True
333342 except FileNotFoundError :
334343 QtWidgets .QMessageBox .about (self , "Problem" , "Cannot find libinput-gestures. Are you sure it is installed correctly?" )
335344 self .installed = False
336-
337-
345+
338346 def start_adding (self ):
339347 """Shows EditGestures window"""
340348 self .adding = EditGestures (self )
@@ -393,26 +401,26 @@ def run_libinput_gestures(self):
393401 def kill_libinput_gestures (self ):
394402 """Fing libinput-gestures and kill it"""
395403 if self .installed :
396- p = subprocess . run (['ps' , 'axu' ], capture_output = True )
404+ p = run (['ps' , 'axu' ])
397405 s = p .stdout .decode ('utf-8' ).split ('\n ' )
398406 for proc in s :
399407 if 'python3' in proc and 'libinput-gestures' in proc and 'libinput-gestures-qt' not in proc :
400408 try :
401- subprocess . run (['kill' , proc .split ()[1 ]], capture_output = True )
409+ run (['kill' , proc .split ()[1 ]])
402410 except Exception :
403411 pass
404412 self .display_status ()
405413
406414 def set_to_autostart (self ):
407415 """Sets libinput-gestures to autostart"""
408416 if self .installed :
409- subprocess . run (['libinput-gestures-setup' , 'autostart' ], capture_output = True )
417+ run (['libinput-gestures-setup' , 'autostart' ])
410418 self .display_status ()
411419
412420 def disable_autostart (self ):
413421 """Set libinput-gestures to autostop"""
414422 if self .installed :
415- subprocess . run (['libinput-gestures-setup' , 'autostop' ], capture_output = True )
423+ run (['libinput-gestures-setup' , 'autostop' ])
416424 self .display_status ()
417425
418426 '''
@@ -422,7 +430,7 @@ def disable_autostart(self):
422430 def display_status (self ):
423431 """Check status of libinput-gestures and shows it in message box"""
424432 if self .installed :
425- status = subprocess . run (['libinput-gestures-setup' , 'status' ], capture_output = True )
433+ status = run (['libinput-gestures-setup' , 'status' ])
426434 status = status .stdout .decode ('utf-8' )
427435 installed = 'no'
428436 if 'is installed' in status :
@@ -439,21 +447,21 @@ def display_status(self):
439447 def restart_utility (self ):
440448 """Runs 'libinput-gestures-setup restart', displays output in message box"""
441449 if self .installed :
442- status = subprocess . run (['libinput-gestures-setup' , 'restart' ], capture_output = True )
450+ status = run (['libinput-gestures-setup' , 'restart' ])
443451 status = status .stdout .decode ('utf-8' )
444452 QtWidgets .QMessageBox .about (self , "Status" , status )
445453
446454 def stop_utility (self ):
447455 """Runs 'libinput-gestures-setup stop', displays output in message box"""
448456 if self .installed :
449- status = subprocess . run (['libinput-gestures-setup' , 'stop' ], capture_output = True )
457+ status = run (['libinput-gestures-setup' , 'stop' ])
450458 status = status .stdout .decode ('utf-8' )
451459 QtWidgets .QMessageBox .about (self , "Status" , status )
452460
453461 def start_utility (self ):
454462 """Runs 'libinput-gestures-setup start', displays output in message box"""
455463 if self .installed :
456- status = subprocess . run (['libinput-gestures-setup' , 'start' ], capture_output = True )
464+ status = run (['libinput-gestures-setup' , 'start' ])
457465 status = status .stdout .decode ('utf-8' )
458466 QtWidgets .QMessageBox .about (self , "Status" , status )
459467
@@ -709,12 +717,11 @@ def draw_plasma_actions(self):
709717
710718 self .actionType .setText ('Plasma action' )
711719 self .plasmaActions = QtWidgets .QComboBox ()
712- kwin_shortcuts = subprocess . run (
720+ kwin_shortcuts = run (
713721 [
714722 self .QDBUS_NAME , 'org.kde.kglobalaccel' , '/component/kwin' ,
715723 'org.kde.kglobalaccel.Component.shortcutNames'
716- ],
717- capture_output = True ,
724+ ]
718725 )
719726 kwin_shortcuts = kwin_shortcuts .stdout .decode ('utf-8' ).split ('\n ' )[:- 2 ]
720727 kwin_shortcuts .sort ()
@@ -786,5 +793,6 @@ def main():
786793 window .show ()
787794 app .exec_ ()
788795
796+
789797if __name__ == '__main__' :
790798 main ()
0 commit comments