From 100e40c0bfba047ea4135c6f06c5f5eb628d4c75 Mon Sep 17 00:00:00 2001 From: Kiooeht Date: Sat, 20 Aug 2011 02:01:11 -0700 Subject: [PATCH] Check if pynotify installed, don't break if not. Fixes #3 --- toast.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/toast.py b/toast.py index 98d739c..4a5e2a1 100644 --- a/toast.py +++ b/toast.py @@ -5,9 +5,8 @@ from PyQt4 import QtGui, QtCore try: import pynotify - pynote = True except: - pynote = False + pynotify = None class DefaultToast(object): def __init__(self, title, msg, icon): @@ -84,9 +83,12 @@ class ToastMachine(object): if self in self.parent.toasts: self.parent.toasts.remove(self) - def __init__(self, parent, name, type="default", types={'default' : DefaultToast, - 'libnotify': pynotify.Notification}, + def __init__(self, parent, name, type="default", types=({'default' : DefaultToast, + 'libnotify': pynotify.Notification} + if pynotify else + {'default' : DefaultToast}), extras={}): + print types self.mainwindow = parent self.name = name types.update(extras) @@ -96,7 +98,7 @@ class ToastMachine(object): if type == "libnotify": try: - if not pynote or not pynotify.init("ToastMachine"): + if not pynotify or not pynotify.init("ToastMachine"): raise Exception except: print "Problem initilizing pynotify" @@ -174,8 +176,10 @@ class PesterToast(QtGui.QFrame, DefaultToast): class PesterToastMachine(ToastMachine, QtCore.QObject): def __init__(self, parent, name, type="default", - types={'default' : DefaultToast, - 'libnotify': pynotify.Notification}, + types=({'default' : DefaultToast, + 'libnotify' : pynotify.Notification} + if pynotify else + {'default' : DefaultToast}), extras={}): ToastMachine.__init__(self, parent, name, type, types, extras) QtCore.QObject.__init__(self, parent)