Merge lp:~jamiebennett/entertainer/bug-372452-disable-screensaver into lp:entertainer

Proposed by Jamie Bennett
Status: Needs review
Proposed branch: lp:~jamiebennett/entertainer/bug-372452-disable-screensaver
Merge into: lp:entertainer
Diff against target: 96 lines (+43/-0)
2 files modified
entertainerlib/client/client.py (+2/-0)
entertainerlib/client/media_player.py (+41/-0)
To merge this branch: bzr merge lp:~jamiebennett/entertainer/bug-372452-disable-screensaver
Reviewer Review Type Date Requested Status
Matt Layman Needs Fixing
Review via email: mp+25888@code.launchpad.net

Description of the change

Disable the screensaver whist video is being played.

Closes bug (LP:372452).

To post a comment you must log in.
Revision history for this message
Matt Layman (mblayman) wrote :
Download full text (4.0 KiB)

Jamie,

I really like the spirit of this branch because this is a much needed fix, but there are number of things that prevent me from merging this into the trunk. My comments follow:

general:
 * Adding a dependency of dbus means that you need to update the docs/DEPENDENCIES file to include python-dbus.

entertainerlib/client/client.py:
 * I think this really introduces a dependency in the client that shouldn't be there. I would suggest that the proper way to enable the screensaver before the client closes down is to use the instance variable you created in the media player. This could be done by adding a __del__ method to the media player that calls enable_screensaver. This would localize your dependency to the one place that needs it.

entertainerlib/client/media_player.py:
 * Import order is wrong. dbus would go after clutter.
 * There are tab characters strewn about in your file which is a no-no based on our style guidelines. Has this code been tested? I made a little test file that used a mix of spaces and tabs, and it flat out failed because of indentation errors. That makes me highly suspect of the code that is here.
 * Class names are typically nouns. You've provided a class name that seems more like a method. As a matter of fact, there are many handle_* methods in Entertainer. Could you select a more appropriate name? The first thing that popped into my head was ScreenSaverInhibitor, but that's just a suggestion.
 * On the subject of names, the instance name in the media player is not meaningful either. 'ss' tells me almost nothing if I know the context, and absolutely nothing if I don't know the context. Entertainer's code mostly tends towards verbosity at the cost of conciseness. If following my suggestion for a class name, `self.screen_saver_inhibitor` or `self.inhibitor` would be better.
 * The class should be a new style class (i.e. derive from `object`).
 * The class requires a docstring.
 * The existing docstrings require full stops at the end of each sentence.
 * Inconsistent use of single versus double quotes. Please stick with one or the other. Most of the code leans towards single quotes, but it's not universally true. But the code should at least have consistency in its code block.
 * The wrapping behavior is inconsistent with Entertainer conventions. If a line of code is meant to wrap, it should only be indented 4 spaces from the previous line that it is continuing. If that source line has multiple physical lines of wrap, then each line after the original should line up with each other.
 * Why is dbus_interface only assigned for the first time during a call to disable_screensaver? That would lead to a problem if the code ever called enable_screensaver first. Why can't it be moved to init?
 * Why is ss_cookie converting from string to an instance of Inhibit? In init, I think ss_cookie should be None.
 * Why does disable_screensaver need to be called in enable_screensaver if there is no cookie? I guess maybe that would be necessary if you had multiple instances of this class, but if you localized the instance to the media_player, then I think that logic becomes unnecessary. If no cookie is set, then it should be safe to a...

Read more...

review: Needs Fixing
Revision history for this message
Jamie Bennett (jamiebennett) wrote :
Download full text (4.6 KiB)

On Tue, 2010-05-25 at 00:34 +0000, Matt Layman wrote:
> Review: Needs Fixing
> Jamie,
>
> I really like the spirit of this branch because this is a much needed fix, but there are number of things that prevent me from merging this into the trunk. My comments follow:
>
> general:
> * Adding a dependency of dbus means that you need to update the docs/DEPENDENCIES file to include python-dbus.

Ah sorry, will fix.

> entertainerlib/client/client.py:
> * I think this really introduces a dependency in the client that shouldn't be there. I would suggest that the proper way to enable the screensaver before the client closes down is to use the instance variable you created in the media player. This could be done by adding a __del__ method to the media player that calls enable_screensaver. This would localize your dependency to the one place that needs it.

Yes, this is a much better way.

> entertainerlib/client/media_player.py:
> * Import order is wrong. dbus would go after clutter.

Due to alphabetic importing?

> * There are tab characters strewn about in your file which is a no-no based on our style guidelines. Has this code been tested? I made a little test file that used a mix of spaces and tabs, and it flat out failed because of indentation errors. That makes me highly suspect of the code that is here.

Yes, testing and working fine. Not sure where tab characters came from,
I'll check my editor settings.

> * Class names are typically nouns. You've provided a class name that seems more like a method. As a matter of fact, there are many handle_* methods in Entertainer. Could you select a more appropriate name? The first thing that popped into my head was ScreenSaverInhibitor, but that's just a suggestion.
> * On the subject of names, the instance name in the media player is not meaningful either. 'ss' tells me almost nothing if I know the context, and absolutely nothing if I don't know the context. Entertainer's code mostly tends towards verbosity at the cost of conciseness. If following my suggestion for a class name, `self.screen_saver_inhibitor` or `self.inhibitor` would be better.
> * The class should be a new style class (i.e. derive from `object`).
> * The class requires a docstring.
> * The existing docstrings require full stops at the end of each sentence.
> * Inconsistent use of single versus double quotes. Please stick with one or the other. Most of the code leans towards single quotes, but it's not universally true. But the code should at least have consistency in its code block.
> * The wrapping behavior is inconsistent with Entertainer conventions. If a line of code is meant to wrap, it should only be indented 4 spaces from the previous line that it is continuing. If that source line has multiple physical lines of wrap, then each line after the original should line up with each other.

OK.

> * Why is dbus_interface only assigned for the first time during a call to disable_screensaver? That would lead to a problem if the code ever called enable_screensaver first. Why can't it be moved to init?

It can and will be moved.

> * Why is ss_cookie converting from string to an instance of Inhibit? In init, I think ss_cookie s...

Read more...

Unmerged revisions

413. By Jamie Bennett

Disable the screensaver whilst video is being played.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'entertainerlib/client/client.py'
--- entertainerlib/client/client.py 2010-05-16 19:19:56 +0000
+++ entertainerlib/client/client.py 2010-05-24 12:28:26 +0000
@@ -17,6 +17,7 @@
17from entertainerlib.gui.user_interface import UserInterface17from entertainerlib.gui.user_interface import UserInterface
18from entertainerlib.gui.system_tray_icon import SystemTrayIcon18from entertainerlib.gui.system_tray_icon import SystemTrayIcon
19from entertainerlib.network.local.client import EntertainerLocalClientProtocol19from entertainerlib.network.local.client import EntertainerLocalClientProtocol
20from entertainerlib.client.media_player import HandleScreenSaver
2021
2122
22class Client(object):23class Client(object):
@@ -53,6 +54,7 @@
5354
54 def quit_client(self):55 def quit_client(self):
55 '''Close the client.'''56 '''Close the client.'''
57 HandleScreenSaver().enable_screensaver()
56 reactor.stop()58 reactor.stop()
57 sys.exit(0)59 sys.exit(0)
5860
5961
=== modified file 'entertainerlib/client/media_player.py'
--- entertainerlib/client/media_player.py 2010-05-16 03:12:51 +0000
+++ entertainerlib/client/media_player.py 2010-05-24 12:28:26 +0000
@@ -8,6 +8,7 @@
8import clutter8import clutter
9import gobject9import gobject
10import gst10import gst
11import dbus
1112
12from entertainerlib.gui.widgets.motion_buffer import MotionBuffer13from entertainerlib.gui.widgets.motion_buffer import MotionBuffer
13from entertainerlib.gui.widgets.texture import Texture14from entertainerlib.gui.widgets.texture import Texture
@@ -85,6 +86,8 @@
85 self.video_texture.connect('button-release-event',86 self.video_texture.connect('button-release-event',
86 self._on_button_release_event)87 self._on_button_release_event)
8788
89 self.ss = HandleScreenSaver()
90
88 def _on_gst_message(self, bus, message):91 def _on_gst_message(self, bus, message):
89 '''92 '''
90 Callback function that is called every time when message occurs on93 Callback function that is called every time when message occurs on
@@ -226,6 +229,7 @@
226 self.stage.set_color((0, 0, 0, 0))229 self.stage.set_color((0, 0, 0, 0))
227 self.video_texture.set_playing(True)230 self.video_texture.set_playing(True)
228 self.emit('play')231 self.emit('play')
232 self.ss.disable_screensaver()
229233
230 if self._internal_callback_timeout_key is not None:234 if self._internal_callback_timeout_key is not None:
231 gobject.source_remove(self._internal_callback_timeout_key)235 gobject.source_remove(self._internal_callback_timeout_key)
@@ -244,6 +248,7 @@
244 if self.media.get_type() == Playable.VIDEO_STREAM:248 if self.media.get_type() == Playable.VIDEO_STREAM:
245 self.stage.set_color(self.bgcolor)249 self.stage.set_color(self.bgcolor)
246 self.stage.remove(self.video_texture)250 self.stage.remove(self.video_texture)
251 self.ss.enable_screensaver()
247 self.video_texture.set_playing(False)252 self.video_texture.set_playing(False)
248 # XXX: laymansterms - I don't know the implications of removing the253 # XXX: laymansterms - I don't know the implications of removing the
249 # position property.254 # position property.
@@ -597,3 +602,39 @@
597 self.set_media_position(position)602 self.set_media_position(position)
598 self.emit('position-changed')603 self.emit('position-changed')
599604
605class HandleScreenSaver():
606 def __init__(self):
607 self.ss_cookie = ""
608 self.dbus_interface = ""
609
610 def disable_screensaver(self, redisable=False):
611 '''Disable the screensaver'''
612 try:
613 bus = dbus.Bus(dbus.Bus.TYPE_SESSION)
614 dbus_obj = bus.get_object('org.gnome.ScreenSaver',
615 '/org/gnome/ScreenSaver')
616 self.dbus_interface = dbus.Interface(dbus_obj,
617 "org.gnome.ScreenSaver")
618 self.ss_cookie = self.dbus_interface.Inhibit("entertainer",
619 'Disabled by Entertainer')
620 if (redisable == True):
621 print "Entertainer: Getting new handle to screensaver"
622 else:
623 print "Entertainer: gnome screensaver stopped."
624 except Exception, e:
625 print "Entertainer: could not inhibit screensaver: %s" % e
626
627 def enable_screensaver(self):
628 '''Enable the screensaver'''
629
630 # If we don't already have a handle to the screensaver cookie, get
631 # a new one.
632 if self.ss_cookie == "":
633 self.disable_screensaver(True)
634
635 try:
636 self.dbus_interface.UnInhibit(self.ss_cookie)
637 print "Entertainer: gnome screensaver enabled."
638 except Exception, e:
639 print "Entertainer: could not UnInhibit signal: %s" % e
640

Subscribers

People subscribed via source and target branches