Theoretical osx 10.8 notifier

This commit is contained in:
Kovid Goyal 2012-11-27 14:14:07 +05:30
parent 4289389a38
commit 8ab768f95f

View File

@ -7,7 +7,7 @@ __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
from calibre.constants import islinux, isosx from calibre.constants import islinux, isosx, get_osx_version, __appname__
class Notifier(object): class Notifier(object):
@ -101,32 +101,36 @@ class QtNotifier(Notifier):
except: except:
pass pass
class GrowlNotifier(Notifier): class AppleNotifier(Notifier):
notification_type = 'All notifications'
def __init__(self): def __init__(self):
self.ok = False
import os, sys
try: try:
import Growl self.exe = os.path.join(sys.console_binaries_path, 'notifier')
self.icon = Growl.Image.imageFromPath(I('notify.png')) self.ok = os.access(self.exe, os.X_OK)
self.growl = Growl.GrowlNotifier(applicationName='calibre', import subprocess
applicationIcon=self.icon, notifications=[self.notification_type]) self.call = subprocess.check_call
self.growl.register()
self.ok = True
except: except:
self.ok = False pass
def encode(self, msg): def notify(self, body, summary):
if isinstance(msg, unicode): def encode(x):
msg = msg.encode('utf-8') if isinstance(x, unicode):
return msg x = x.encode('utf-8')
return x
cmd = [self.exe, '-title', __appname__, '-activate',
'net.kovidgoyal.calibre', '-message', encode(body)]
if summary:
cmd += ['-subtitle', encode(summary)]
self.call(cmd)
def __call__(self, body, summary=None, replaces_id=None, timeout=0): def __call__(self, body, summary=None, replaces_id=None, timeout=0):
timeout, body, summary = self.get_msg_parms(timeout, body, summary) timeout, body, summary = self.get_msg_parms(timeout, body, summary)
if self.ok: if self.ok:
try: try:
self.growl.notify(self.notification_type, self.encode(summary), self.notify(body, summary)
self.encode(body))
except: except:
import traceback import traceback
traceback.print_exc() traceback.print_exc()
@ -140,10 +144,10 @@ def get_notifier(systray=None):
ans = FDONotifier() ans = FDONotifier()
if not ans.ok: if not ans.ok:
ans = None ans = None
#if isosx: elif False and isosx and get_osx_version() >= (10, 8, 0):
# ans = GrowlNotifier() ans = AppleNotifier()
# if not ans.ok: if not ans.ok:
# ans = None ans = None
if ans is None: if ans is None:
ans = QtNotifier(systray) ans = QtNotifier(systray)
if not ans.ok: if not ans.ok: