Add screen lock command for Gnome 3.8 and latest
This commit is contained in:
parent
24a0301847
commit
1286389658
|
@ -20,8 +20,7 @@ import gi
|
||||||
gi.require_version('Gdk', '3.0')
|
gi.require_version('Gdk', '3.0')
|
||||||
from gi.repository import Gdk, GLib
|
from gi.repository import Gdk, GLib
|
||||||
from html.parser import HTMLParser
|
from html.parser import HTMLParser
|
||||||
import babel.dates, os, errno, re, subprocess, threading, logging, locale, json
|
import babel.dates, os, errno, re, subprocess, threading, logging, locale, json, shutil, pyaudio, wave
|
||||||
import pyaudio, wave
|
|
||||||
|
|
||||||
bin_directory = os.path.dirname(os.path.realpath(__file__))
|
bin_directory = os.path.dirname(os.path.realpath(__file__))
|
||||||
home_directory = os.path.expanduser('~')
|
home_directory = os.path.expanduser('~')
|
||||||
|
@ -260,7 +259,11 @@ def lock_screen_command():
|
||||||
if desktop_session is not None:
|
if desktop_session is not None:
|
||||||
desktop_session = desktop_session.lower()
|
desktop_session = desktop_session.lower()
|
||||||
if desktop_session in ['gnome','unity', 'budgie-desktop'] or desktop_session.startswith('ubuntu'):
|
if desktop_session in ['gnome','unity', 'budgie-desktop'] or desktop_session.startswith('ubuntu'):
|
||||||
return ['gnome-screensaver-command', '--lock']
|
if command_exist('gnome-screensaver-command'):
|
||||||
|
return ['gnome-screensaver-command', '--lock']
|
||||||
|
else:
|
||||||
|
# From Gnome 3.8 no gnome-screensaver-command
|
||||||
|
return ['dbus-send', '--type=method_call', '--dest=org.gnome.ScreenSaver', '/org/gnome/ScreenSaver', 'org.gnome.ScreenSaver.Lock']
|
||||||
elif desktop_session == 'cinnamon':
|
elif desktop_session == 'cinnamon':
|
||||||
return ['cinnamon-screensaver-command', '--lock']
|
return ['cinnamon-screensaver-command', '--lock']
|
||||||
elif desktop_session == 'pantheon' or desktop_session.startswith('lubuntu'):
|
elif desktop_session == 'pantheon' or desktop_session.startswith('lubuntu'):
|
||||||
|
@ -289,7 +292,7 @@ def lock_desktop(user_defined_command):
|
||||||
try:
|
try:
|
||||||
subprocess.Popen(command)
|
subprocess.Popen(command)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error('Error in executing the commad' + str(command) + ' to lock screen', e)
|
logging.error('Error in executing the commad' + str(command) + ' to lock screen')
|
||||||
|
|
||||||
|
|
||||||
def html_to_text(html):
|
def html_to_text(html):
|
||||||
|
@ -301,6 +304,16 @@ def html_to_text(html):
|
||||||
return extractor.get_data()
|
return extractor.get_data()
|
||||||
|
|
||||||
|
|
||||||
|
def command_exist(command):
|
||||||
|
"""
|
||||||
|
Check whether the given command exist in the system or not.
|
||||||
|
"""
|
||||||
|
if shutil.which(command):
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class __HTMLTextExtractor(HTMLParser):
|
class __HTMLTextExtractor(HTMLParser):
|
||||||
"""
|
"""
|
||||||
Helper class to convert HTML to text
|
Helper class to convert HTML to text
|
||||||
|
|
Loading…
Reference in New Issue