Skip to content

Commit

Permalink
Various improvements
Browse files Browse the repository at this point in the history
This PR includes:
- Update to 0.9.0
- Settings includes better feedback to user
- Pop-ups include an icon and standad title
- Pop-ups remaing for 10 seconds
  • Loading branch information
dagwieers committed Apr 13, 2018
1 parent 6945ff7 commit c2025c1
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 30 deletions.
4 changes: 2 additions & 2 deletions addon.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="screensaver.turnoff" name="Turn Off" version="0.8.1" provider-name="Dag Wieers">
<addon id="screensaver.turnoff" name="Turn Off" version="0.9.0" provider-name="Dag Wieers">
<extension point="xbmc.addon.metadata">
<platform>all</platform>
<summary lang="en">Screensaver that turns your screen off to save power</summary>
<description lang="en">The Off screensaver turns your TV, projector or monitor off, so it can actually "save your screen".</description>
<description lang="en">The Turn Off screensaver turns your TV, projector or monitor off, like any old fashioned screensaver is intended to do.</description>
<source>http://github.com/dagwieers/plugin.screensaver.off</source>
<license>GPL3+</license>
<email>[email protected]</email>
Expand Down
23 changes: 16 additions & 7 deletions resources/language/English/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,26 @@

<!-- For the settings -->
<string id="30000">Display</string>
<string id="31001">Display method</string>
<string id="31002">Not all 'Display methods' work on every system. Carefully test.</string>
<string id="30001">Pick a method for turning off your display</string>
<string id="31000">Display method</string>
<string id="31001">Not all 'Display methods' work on every system. Carefully test.</string>
<string id="31002">- CEC methods require CEC device support. Check vendor manual.</string>
<string id="31003">- No Signal method disables video signal. Device may go to sleep or turn off.</string>
<string id="31004">- DPMS methods make use of VESA DPMS capabilities of your monitor.</string>
<string id="31005">Press HOME or BACK key on remote to return from screen saver.</string>
<string id="31006">NOTE: Not every device can be powered on automatically.</string>
<string id="31100">Do nothing</string>
<string id="31110">CEC Standby (built-in)</string>
<string id="31120">Raspberry Pi (using vcgencmd)</string>
<string id="31110">CEC (built-in)</string>
<string id="31120">No Signal on Raspberry Pi (using vcgencmd)</string>
<string id="31130">DPMS (built-in)</string>
<string id="31140">DPMS (using xset)</string>
<string id="31150">DPMS (using vbetool)</string>
<string id="31160">DPMS (using xrandr)</string>
<string id="31170">Android CEC (kernel)</string>
<string id="31170">CEC on Android (kernel)</string>
<string id="40000">Power</string>
<string id="41001">Power method</string>
<string id="41002">Don't change this unless you know exactly what you are doing.</string>
<string id="40001">Pick a method for turning off your system</string>
<string id="41000">Power method</string>
<string id="41001">Don't change this unless you know exactly what you are doing.</string>
<string id="41100">Do nothing</string>
<string id="41110">Suspend (built-in)</string>
<string id="41120">Hibernate (built-in)</string>
Expand All @@ -29,6 +36,8 @@
<string id="80000">Options</string>
<string id="80001">When activating screensaver...</string>
<string id="80500">Log off user</string>
<string id="80501">Useful in case you have parental controls enabled.</string>
<string id="80600">Mute audio</string>
<string id="80601">Ensure no audio is produced inadvertently, e.g. when using A/V receiver.</string>

</strings>
21 changes: 15 additions & 6 deletions resources/settings.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<settings>
<category id="display" label="30000">
<setting id="display_method" type="enum" label="31001" lvalues="31100|31110|31120|31130|31140|31150|31160|31170" default="1"/>
<setting id="display_label" type="text" label="31002" enable="false" />
<setting type="lsep" label="30001"/>
<setting id="display_method" type="select" label="31000" help="31001" lvalues="31100|31110|31120|31130|31140|31150|31160|31170" default="1"/>
<setting id="display_label" type="text" label="31001" enable="false" />
<setting id="cec_label" type="text" label="31002" enable="false" />
<setting id="rpi_label" type="text" label="31003" enable="false" />
<setting id="dpms_label" type="text" label="31004" enable="false" />
<setting id="deactivate_label" type="text" label="31005" enable="false" />
<setting id="deactivate_note" type="text" label="31006" enable="false" />
</category>
<category id="power" label="40000">
<setting id="power_method" type="enum" label="41001" lvalues="41100|41110|41120|41130|41140|41150|41160|41170" default="0"/>
<setting id="power_label" type="text" label="41002" enable="false" />
<setting type="lsep" label="40001"/>
<setting id="power_method" type="select" label="41000" help="41001" lvalues="41100|41110|41120|41130|41140|41150|41160|41170" default="0"/>
<setting id="power_label" type="text" label="41001" enable="false" />
</category>
<category id="options" label="80000">
<setting type="lsep" label="80001"/>
<setting id="logoff" type="bool" label="80500" default="false"/>
<setting id="mute" type="bool" label="80600" default="false"/>
<setting id="logoff" type="bool" label="80500" help="80501" default="false"/>
<setting id="logoff_label" type="text" label="80501" enable="false" />
<setting id="mute" type="bool" label="80600" help="80601" default="true"/>
<setting id="mute_label" type="text" label="80601" enable="false" />
</category>
</settings>
44 changes: 29 additions & 15 deletions screensaver.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,50 @@
import xbmcgui


def _popup(title='', msg='', delay=5000, image= ''):
def _log_error(msg='', level=xbmc.LOGERROR):
xbmc.log(msg='[%s] %s' % (addon_name, msg), level=level)


def _log_notice(msg='', level=xbmc.LOGNOTICE):
xbmc.log(msg='[%s] %s' % (addon_name, msg), level=level)


def _popup(title='', msg='', delay=10000, image=''):
if not title:
title = '%s screensaver failed' % addon_name
if not image:
image = addon_icon
xbmc.executebuiltin('XBMC.Notification("%s","%s",%d,"%s")' % (title, msg, delay, image))


def _run_builtin(builtin):
xbmc.log(msg="[%s] Executing builtin '%s'" % (addon_name, builtin), level=xbmc.LOGNOTICE)
_log_notice(msg="Executing builtin '%s'" % builtin)
try:
xbmc.executebuiltin(builtin)
except Exception as e:
xbmc.log(msg="[%s] Exception executing builtin '%s': %s" % (addon_name, builtin, e), level=xbmc.LOGERROR)
_popup(title='Screensaver failed', msg="[%s] Exception executing builtin '%s': %s" % (addon_name, builtin, e))
_log_error(msg="Exception executing builtin '%s': %s" % (builtin, e))
_popup(msg="Exception executing builtin '%s': %s" % (builtin, e))


def _run_command(command, shell=False):
# TODO: Add options for running using su or sudo
try:
cmd = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=shell)
(out, err) = cmd.communicate()
if cmd.returncode == 0:
xbmc.log(msg="[%s] Running command '%s' returned rc=%s" % (addon_name, ' '.join(command), cmd.returncode), level=xbmc.LOGNOTICE)
_log_notice(msg="Running command '%s' returned rc=%s" % (' '.join(command), cmd.returncode))
else:
xbmc.log(msg="[%s] Running command '%s' failed with rc=%s" % (addon_name, ' '.join(command), cmd.returncode), level=xbmc.LOGERROR)
_log_error(msg="Running command '%s' failed with rc=%s" % (' '.join(command), cmd.returncode))
if err:
xbmc.log(msg="[%s] Command '%s' returned on stderr: %s" % (addon_name, command[0], err), level=xbmc.LOGERROR)
_log_error(msg="Command '%s' returned on stderr: %s" % (command[0], err))
if out:
xbmc.log(msg="[%s] Command '%s' returned on stdout: %s " % (addon_name, command[0], out), level=xbmc.LOGERROR)
_popup(title='Screensaver failed', msg="%s\n%s" % (out, err))
_log_error(msg="Command '%s' returned on stdout: %s " % (command[0], out))
_popup(msg="%s\n%s" % (out, err))
sys.exit(1)
except Exception as e:
xbmc.log(msg="[%s] Exception running '%s': %s" % (addon_name, command[0], e), level=xbmc.LOGERROR)
_popup(title='Screensaver failed', msg="Exception running '%s': %s" % (command[0], e))
_log_error(msg="Exception running '%s': %s" % (command[0], e))
_popup(msg="Exception running '%s': %s" % (command[0], e))
sys.exit(2)
# TODO: Show pop-up on failure


class Screensaver(xbmcgui.WindowXMLDialog):
Expand All @@ -53,7 +66,7 @@ def onInit(self):
self._monitor = self.Monitor(self.exit)

# Power off system
xbmc.log(msg='[%s] Turn system off using method %s' % (addon_name, power_method), level=xbmc.LOGNOTICE)
_log_notice(msg='Turn system off using method %s' % power_method)
if power_method == '1': # Suspend (built-in)
_run_builtin('Suspend')
elif power_method == '2': # ShutDown action (built-in)
Expand All @@ -78,7 +91,7 @@ def exit(self):
_run_builtin('Mute')

# Turn on display
xbmc.log(msg='[%s] Turn display signal back on using method %s' % (addon_name, display_method), level=xbmc.LOGNOTICE)
_log_notice(msg='Turn display signal back on using method %s' % display_method)
if display_method == '1': # CEC Standby (built-in)
_run_builtin('CECActivateSource')
elif display_method == '2': # Raspberry Pi (using vcgencmd)
Expand All @@ -104,13 +117,14 @@ def exit(self):

addon_name = addon.getAddonInfo('name')
addon_path = addon.getAddonInfo('path')
addon_icon = addon.getAddonInfo('icon')
display_method = addon.getSetting('display_method')
power_method = addon.getSetting('power_method')
logoff = addon.getSetting('logoff')
mute = addon.getSetting('mute')

# Turn off display
xbmc.log(msg='[%s] Turn display signal off using method %s' % (addon_name, display_method), level=xbmc.LOGNOTICE)
_log_notice(msg='Turn display signal off using method %s' % display_method)
if display_method == '1': # CEC Standby (built-in)
_run_builtin('CECStandby')
elif display_method == '2': # Raspberry Pi (using vcgencmd)
Expand Down

0 comments on commit c2025c1

Please sign in to comment.