15
15
# Lesser General Public License for more details.
17
17
# You should have received a copy of the GNU Lesser General Public
18
# License along with this program; if not, write to the
19
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
# Boston, MA 02111-1307, USA.
18
# License along with this program; if not, see <http://www.gnu.org/licenses/>.
22
import multiprocessing
26
from pitivi.check import NOTIFY_SOFT_DEPENDENCY
25
27
from pitivi.configure import APPNAME
26
28
from pitivi.utils.loggable import Loggable
27
29
from pitivi.utils.signal import Signallable
49
51
def _inhibit(self, list_, key):
50
if key is None or (not isinstance(key, str)):
52
assert key is not None
53
assert isinstance(key, str)
53
54
if not key in list_:
55
56
self.log("emitting 'update-power-inhibition'")
62
63
self.log("emitting 'update-power-inhibition'")
63
64
self.emit('update-power-inhibition')
65
if not isinstance(key, str):
66
assert isinstance(key, str)
70
69
self.log("emitting 'update-power-inhibition'")
71
70
self.emit('update-power-inhibition')
73
def _listToString(self, list_):
82
72
def _isInhibited(self, list_, key=None):
115
105
def getScreensaverInhibitors(self):
116
106
"""returns a comma seperated string of screensaver inhibitor keys"""
117
return self._listToString(self._screensaver_keys)
107
return ", ".join(self._screensaver_keys)
119
109
def screensaverIsBlockable(self):
146
136
def getSleepInhibitors(self):
147
137
"""returns a comma seperated string of sleep inhibitor keys"""
148
return self._listToString(self._sleep_keys)
138
return ", ".join(self._sleep_keys)
150
140
def sleepIsBlockable(self):
154
144
def uninhibitAll(self):
156
146
self.emit('update-power-inhibition')
159
def desktopMessage(self, title, message, icon=None):
148
def desktopMessage(self, title, message, unused_icon=None):
160
149
"""send a message to the desktop to be displayed to the user
161
150
@arg title: C{str} the title of the message
162
151
@arg message: C{str} the body of the message
163
@arg icon: C{GdkPixbuf.Pixbuf} icon to be shown with the message
152
@arg icon: C{str} icon to be shown with the message
165
self.debug("desktopMessage(): %s, %s" % title % message)
154
self.debug("desktopMessage(): %s, %s", title, message)
168
157
def getUniqueFilename(self, string):
169
158
"""Get a filename which can only be obtained from the specified string.
180
169
def __init__(self):
181
170
System.__init__(self)
182
# FIXME Notifications disabled for the time being
183
# Notify.init(APPNAME)
171
if NOTIFY_SOFT_DEPENDENCY:
172
from gi.repository import Notify
185
def desktopMessage(self, title, message, icon=None):
175
def desktopMessage(self, title, message, icon="pitivi"):
186
176
#call super method for consistent logging
187
System.desktopMessage(title, message, icon)
177
System.desktopMessage(self, title, message, icon)
189
# FIXME Notifications disabled for the time being
190
#notification = Notify.Notification(title, message)
191
#if icon is not None and isinstance(icon, GdkPixbuf.Pixbuf):
192
#notification.set_icon_from_pixbuf(icon)
179
if NOTIFY_SOFT_DEPENDENCY:
180
from gi.repository import Notify
181
notification = Notify.Notification.new(title, message, icon=icon)
184
except RuntimeError, e:
185
# This can happen if the system is not properly configured.
186
# See for example https://bugzilla.gnome.org/show_bug.cgi?id=719627.
187
self.error("desktopMessage: Failed displaying notification: %s", e.message)
196
193
#org.gnome.SessionManager flags
275
272
if os.name == 'posix':
276
273
if 'GNOME_DESKTOP_SESSION_ID' in os.environ:
278
# FIXME Disable notifications for the time being as it causes
279
# various errors and the implementation is not done yet
280
#from gi.repository import Notify
282
276
system_ = GnomeSystem
286
280
if system_ is None:
288
# FIXME Disable notifications for the time being as it causes
289
# various errors and the implementation is not done yet
290
# from gi.repository import Notify
291
system_ = FreedesktopOrgSystem
281
system_ = FreedesktopOrgSystem
294
282
elif os.name == 'nt':
296
284
elif os.name == 'mac':
306
294
system = System()
299
class CPUUsageTracker(object):
304
delta_time = (datetime.datetime.now() - self.last_moment).total_seconds()
305
delta_usage = resource.getrusage(resource.RUSAGE_SELF).ru_utime - self.last_usage.ru_utime
306
usage = float(delta_usage) / delta_time * 100
307
return usage / multiprocessing.cpu_count()
310
self.last_moment = datetime.datetime.now()
311
self.last_usage = resource.getrusage(resource.RUSAGE_SELF)