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
1=== modified file 'entertainerlib/client/client.py'
2--- entertainerlib/client/client.py 2010-05-16 19:19:56 +0000
3+++ entertainerlib/client/client.py 2010-05-24 12:28:26 +0000
4@@ -17,6 +17,7 @@
5 from entertainerlib.gui.user_interface import UserInterface
6 from entertainerlib.gui.system_tray_icon import SystemTrayIcon
7 from entertainerlib.network.local.client import EntertainerLocalClientProtocol
8+from entertainerlib.client.media_player import HandleScreenSaver
9
10
11 class Client(object):
12@@ -53,6 +54,7 @@
13
14 def quit_client(self):
15 '''Close the client.'''
16+ HandleScreenSaver().enable_screensaver()
17 reactor.stop()
18 sys.exit(0)
19
20
21=== modified file 'entertainerlib/client/media_player.py'
22--- entertainerlib/client/media_player.py 2010-05-16 03:12:51 +0000
23+++ entertainerlib/client/media_player.py 2010-05-24 12:28:26 +0000
24@@ -8,6 +8,7 @@
25 import clutter
26 import gobject
27 import gst
28+import dbus
29
30 from entertainerlib.gui.widgets.motion_buffer import MotionBuffer
31 from entertainerlib.gui.widgets.texture import Texture
32@@ -85,6 +86,8 @@
33 self.video_texture.connect('button-release-event',
34 self._on_button_release_event)
35
36+ self.ss = HandleScreenSaver()
37+
38 def _on_gst_message(self, bus, message):
39 '''
40 Callback function that is called every time when message occurs on
41@@ -226,6 +229,7 @@
42 self.stage.set_color((0, 0, 0, 0))
43 self.video_texture.set_playing(True)
44 self.emit('play')
45+ self.ss.disable_screensaver()
46
47 if self._internal_callback_timeout_key is not None:
48 gobject.source_remove(self._internal_callback_timeout_key)
49@@ -244,6 +248,7 @@
50 if self.media.get_type() == Playable.VIDEO_STREAM:
51 self.stage.set_color(self.bgcolor)
52 self.stage.remove(self.video_texture)
53+ self.ss.enable_screensaver()
54 self.video_texture.set_playing(False)
55 # XXX: laymansterms - I don't know the implications of removing the
56 # position property.
57@@ -597,3 +602,39 @@
58 self.set_media_position(position)
59 self.emit('position-changed')
60
61+class HandleScreenSaver():
62+ def __init__(self):
63+ self.ss_cookie = ""
64+ self.dbus_interface = ""
65+
66+ def disable_screensaver(self, redisable=False):
67+ '''Disable the screensaver'''
68+ try:
69+ bus = dbus.Bus(dbus.Bus.TYPE_SESSION)
70+ dbus_obj = bus.get_object('org.gnome.ScreenSaver',
71+ '/org/gnome/ScreenSaver')
72+ self.dbus_interface = dbus.Interface(dbus_obj,
73+ "org.gnome.ScreenSaver")
74+ self.ss_cookie = self.dbus_interface.Inhibit("entertainer",
75+ 'Disabled by Entertainer')
76+ if (redisable == True):
77+ print "Entertainer: Getting new handle to screensaver"
78+ else:
79+ print "Entertainer: gnome screensaver stopped."
80+ except Exception, e:
81+ print "Entertainer: could not inhibit screensaver: %s" % e
82+
83+ def enable_screensaver(self):
84+ '''Enable the screensaver'''
85+
86+ # If we don't already have a handle to the screensaver cookie, get
87+ # a new one.
88+ if self.ss_cookie == "":
89+ self.disable_screensaver(True)
90+
91+ try:
92+ self.dbus_interface.UnInhibit(self.ss_cookie)
93+ print "Entertainer: gnome screensaver enabled."
94+ except Exception, e:
95+ print "Entertainer: could not UnInhibit signal: %s" % e
96+

Subscribers

People subscribed via source and target branches