Merge lp:~mcg/pithos/disablescreensaver into lp:~kevin-mehall/pithos/trunk

Proposed by Matthew Gregg
Status: Needs review
Proposed branch: lp:~mcg/pithos/disablescreensaver
Merge into: lp:~kevin-mehall/pithos/trunk
Diff against target: 162 lines (+89/-5)
4 files modified
.bzrignore (+1/-0)
data/ui/PreferencesPithosDialog.ui (+21/-5)
pithos/PreferencesPithosDialog.py (+3/-0)
pithos/plugins/disable_screensaver.py (+64/-0)
To merge this branch: bzr merge lp:~mcg/pithos/disablescreensaver
Reviewer Review Type Date Requested Status
Kevin Mehall Needs Information
Review via email: mp+39418@code.launchpad.net

Description of the change

This is another plugin I used in Rhythmbox and wanted to have available in Pithos. It will inhibit the Gnome screensaver while Pithos is playing and uninhibit while paused.

To post a comment you must log in.
Revision history for this message
Kevin Mehall (kevin-mehall) wrote :

Thanks for your patch.

Can you give me an example of the use case? Since Pithos is audio-only, I don't think we need to keep the screen on as would a video app. The closest I can think of is if you wanted to keep the computer from going to sleep if you're listening to Pithos while doing non-computer work, but then it might be nice to allow the display to sleep and just inhibit power management in case you're on battery.

review: Needs Information
Revision history for this message
Matthew Gregg (mcg) wrote :

My personal use case is a combination of my previous plugin and this one. If Pithos is running and playing music I don't want my screensaver starting and if it does start(because I have locked my screen manually), to have the music pause. This is so I can have music while am working at the machine and not stopped if I walk away for a bit, but can still manually lock the screen and have the music pause. I would also use this plugin to implement a "party mode" when I want Pithos full screen and screensaver disabled. Now that you mention power management, true, you may not want to enable this on battery(I would since I would almost always manually lock screen or pause playback when I walk away from my laptop) and actually I am not sure this will stop the power manager from shutting down the display even with the screensaver disabled. Do they work independently with power manager trumping screensaver??

Unmerged revisions

143. By Matthew Gregg

Adding plugin to (un)inhibit gnome screensaver while pithos is playing

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2010-07-22 23:56:13 +0000
3+++ .bzrignore 2010-10-27 00:42:57 +0000
4@@ -1,2 +1,3 @@
5 pithos/libpiano/piano.py
6 pithos/libpiano/piano_wrap.c
7+debug_config
8
9=== modified file 'data/ui/PreferencesPithosDialog.ui'
10--- data/ui/PreferencesPithosDialog.ui 2010-10-13 15:43:55 +0000
11+++ data/ui/PreferencesPithosDialog.ui 2010-10-27 00:42:57 +0000
12@@ -18,7 +18,7 @@
13 <child>
14 <object class="GtkTable" id="table1">
15 <property name="visible">True</property>
16- <property name="n_rows">12</property>
17+ <property name="n_rows">13</property>
18 <property name="n_columns">3</property>
19 <property name="column_spacing">5</property>
20 <property name="row_spacing">5</property>
21@@ -151,6 +151,22 @@
22 </packing>
23 </child>
24 <child>
25+ <object class="GtkCheckButton" id="checkbutton_disablescreensaver">
26+ <property name="label" translatable="yes">Disable screensaver while playing</property>
27+ <property name="visible">True</property>
28+ <property name="can_focus">True</property>
29+ <property name="receives_default">False</property>
30+ <property name="active">True</property>
31+ <property name="draw_indicator">True</property>
32+ </object>
33+ <packing>
34+ <property name="left_attach">1</property>
35+ <property name="right_attach">4</property>
36+ <property name="top_attach">10</property>
37+ <property name="bottom_attach">11</property>
38+ </packing>
39+ </child>
40+ <child>
41 <object class="GtkLabel" id="label5">
42 <property name="visible">True</property>
43 <property name="label" translatable="yes">&lt;small&gt;&lt;a href='http://pandora.com'&gt;Create an account at pandora.com&lt;/a&gt;&lt;/small&gt;</property>
44@@ -215,8 +231,8 @@
45 </object>
46 <packing>
47 <property name="right_attach">3</property>
48- <property name="top_attach">10</property>
49- <property name="bottom_attach">11</property>
50+ <property name="top_attach">11</property>
51+ <property name="bottom_attach">12</property>
52 </packing>
53 </child>
54 <child>
55@@ -229,8 +245,8 @@
56 <packing>
57 <property name="left_attach">1</property>
58 <property name="right_attach">3</property>
59- <property name="top_attach">11</property>
60- <property name="bottom_attach">12</property>
61+ <property name="top_attach">12</property>
62+ <property name="bottom_attach">13</property>
63 </packing>
64 </child>
65 <child>
66
67=== modified file 'pithos/PreferencesPithosDialog.py'
68--- pithos/PreferencesPithosDialog.py 2010-10-16 22:15:11 +0000
69+++ pithos/PreferencesPithosDialog.py 2010-10-27 00:42:57 +0000
70@@ -76,6 +76,7 @@
71 "lastfm_key": False,
72 "enable_mediakeys":True,
73 "enable_screensaverpause":False,
74+ "enable_disablescreensaver":False,
75 "volume": 1.0,
76 }
77
78@@ -106,6 +107,7 @@
79 self.builder.get_object('prefs_proxy').set_text(self.__preferences["proxy"])
80 self.builder.get_object('checkbutton_notify').set_active(self.__preferences["notify"])
81 self.builder.get_object('checkbutton_screensaverpause').set_active(self.__preferences["enable_screensaverpause"])
82+ self.builder.get_object('checkbutton_disablescreensaver').set_active(self.__preferences["enable_disablescreensaver"])
83 self.builder.get_object('checkbutton_icon').set_active(self.__preferences["show_icon"])
84
85 self.lastfm_auth = LastFmAuth(self.__preferences, "lastfm_key", self.builder.get_object('lastfm_btn'))
86@@ -120,6 +122,7 @@
87 self.__preferences["proxy"] = self.builder.get_object('prefs_proxy').get_text()
88 self.__preferences["notify"] = self.builder.get_object('checkbutton_notify').get_active()
89 self.__preferences["enable_screensaverpause"] = self.builder.get_object('checkbutton_screensaverpause').get_active()
90+ self.__preferences["enable_disablescreensaver"] = self.builder.get_object('checkbutton_disablescreensaver').get_active()
91 self.__preferences["show_icon"] = self.builder.get_object('checkbutton_icon').get_active()
92
93 self.save()
94
95=== added file 'pithos/plugins/disable_screensaver.py'
96--- pithos/plugins/disable_screensaver.py 1970-01-01 00:00:00 +0000
97+++ pithos/plugins/disable_screensaver.py 2010-10-27 00:42:57 +0000
98@@ -0,0 +1,64 @@
99+# -*- coding: utf-8; tab-width: 4; indent-tabs-mode: nil; -*-
100+### BEGIN LICENSE
101+# Copyright (C) 2010 Kevin Mehall <km@kevinmehall.net>
102+#This program is free software: you can redistribute it and/or modify it
103+#under the terms of the GNU General Public License version 3, as published
104+#by the Free Software Foundation.
105+#
106+#This program is distributed in the hope that it will be useful, but
107+#WITHOUT ANY WARRANTY; without even the implied warranties of
108+#MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
109+#PURPOSE. See the GNU General Public License for more details.
110+#
111+#You should have received a copy of the GNU General Public License along
112+#with this program. If not, see <http://www.gnu.org/licenses/>.
113+### END LICENSE
114+
115+from pithos.plugin import PithosPlugin
116+import dbus
117+import logging
118+
119+
120+class DisableScreenSaverPlugin(PithosPlugin):
121+ preference = 'enable_disablescreensaver'
122+
123+ def bind_session_bus(self):
124+ try:
125+ self.session_bus = dbus.SessionBus()
126+ self.screensaver = self.session_bus.get_object("org.gnome.ScreenSaver","/org/gnome/ScreenSaver")
127+ logging.info("bus connected")
128+ return True
129+ except dbus.DBusException:
130+ return False
131+
132+ def on_enable(self):
133+ self.bind_session_bus() or logging.error("Could not bind session bus")
134+ self.state_callback_handle = self.window.connect("play-state-changed", self.play_state_changed)
135+
136+ def on_disable(self):
137+ self.uninhibit_screensaver() or logging.error("Could not unhibit screensaver")
138+ self.state_callback_handle = None
139+
140+ def inhibit_screensaver(self):
141+ try:
142+ self.cookie = self.screensaver.Inhibit('Pithos', 'Disabled by Pithos')
143+ logging.info("Inhibiting screensaver")
144+ return True
145+ except dbus.DBusException:
146+ return False
147+
148+ def uninhibit_screensaver(self):
149+ try:
150+ if hasattr(self, 'cookie'):
151+ logging.info("Uninhibiting screensaver")
152+ self.screensaver.UnInhibit(self.cookie)
153+ return True
154+ except dbus.DBusException:
155+ return False
156+
157+ def play_state_changed(self, window, playing):
158+ """ inhibit screensaver on play, uninhibit on pause """
159+ if playing:
160+ self.inhibit_screensaver() or logging.error("Could not connect events")
161+ if not playing:
162+ self.uninhibit_screensaver() or logging.error("Could not unhibit screensaver")