[work] Add notification pause reminder
This commit is contained in:
parent
feccebb1c9
commit
25242a0cc2
2 changed files with 146 additions and 1 deletions
136
bin/notify.py
Normal file
136
bin/notify.py
Normal file
|
@ -0,0 +1,136 @@
|
|||
# Copyright (C) 2009 www.stani.be
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see http://www.gnu.org/licenses/
|
||||
|
||||
# Follows PEP8
|
||||
|
||||
APP_NAME = 'notify.py'
|
||||
|
||||
from sys import stderr
|
||||
|
||||
# Notify (linux)
|
||||
try:
|
||||
# import Notify
|
||||
# import gobject
|
||||
# gobject.threads_init()
|
||||
import gi
|
||||
gi.require_version('Notify', '0.7')
|
||||
from gi.repository import Notify
|
||||
except (ImportError, ValueError):
|
||||
Notify = None
|
||||
|
||||
# Growl (Mac Os X)
|
||||
if Notify:
|
||||
Growl = None
|
||||
else:
|
||||
try:
|
||||
import Growl
|
||||
except ImportError:
|
||||
Growl = None
|
||||
|
||||
# Toasterbox (Windows)
|
||||
if Notify or Growl:
|
||||
TB = None
|
||||
else:
|
||||
try:
|
||||
import wx
|
||||
import other.pyWx.toasterbox as TB
|
||||
except ImportError:
|
||||
TB = None
|
||||
|
||||
|
||||
def register(app_name):
|
||||
global APP_NAME
|
||||
APP_NAME = app_name
|
||||
|
||||
|
||||
def init(app_name, icon=None):
|
||||
print("Warning: couldn't find any notification API", file=stderr)
|
||||
register(app_name)
|
||||
|
||||
if Notify:
|
||||
|
||||
def init(app_name, icon=None):
|
||||
register(app_name)
|
||||
Notify.init(app_name)
|
||||
|
||||
def send(title, message, icon='gtk-dialog-info', wxicon=None,
|
||||
urgent=False, timeout=None):
|
||||
n = Notify.Notification.new(title, message, icon)
|
||||
if urgent:
|
||||
n.set_urgency(2)
|
||||
if timeout:
|
||||
n.set_timeout(timeout)
|
||||
n.show()
|
||||
|
||||
elif Growl:
|
||||
|
||||
def init(app_name, icon=None):
|
||||
"""Create a growl notifier with appropriate icon if specified.
|
||||
The notification classes default to [APP_NAME]. The user can
|
||||
enable/disable notifications based on this class name."""
|
||||
global growl
|
||||
register(app_name)
|
||||
if icon is None:
|
||||
icon = {}
|
||||
else:
|
||||
icon = {'applicationIcon': Growl.Image.imageFromPath(icon)}
|
||||
growl = Growl.GrowlNotifier(APP_NAME, [APP_NAME], **icon)
|
||||
|
||||
def send(title, message, icon='gtk-dialog-info', wxicon=None,
|
||||
urgent=False, timeout=None):
|
||||
global growl
|
||||
growl.notify(APP_NAME, title, message)
|
||||
|
||||
elif TB:
|
||||
|
||||
def send(title, message, icon='gtk-dialog-info',
|
||||
wxicon=None, urgent=False, timeout=None):
|
||||
if wxicon == None:
|
||||
wxicon = wx.ArtProvider_GetBitmap(wx.ART_INFORMATION,
|
||||
wx.ART_OTHER, (48, 48))
|
||||
tb = TB.ToasterBox(wx.GetApp().GetTopWindow(),
|
||||
TB.TB_COMPLEX, TB.DEFAULT_TB_STYLE, TB.TB_ONTIME)
|
||||
tb.SetPopupSize((300, 80))
|
||||
tb.SetPopupPauseTime(5000)
|
||||
tb.SetPopupScrollSpeed(8)
|
||||
tb.SetPopupPositionByInt(3)
|
||||
|
||||
#wx controls
|
||||
tbpanel = tb.GetToasterBoxWindow()
|
||||
panel = wx.Panel(tbpanel, -1)
|
||||
panel.SetBackgroundColour(wx.WHITE)
|
||||
wxicon = wx.StaticBitmap(panel, -1, wxicon)
|
||||
title = wx.StaticText(panel, -1, title)
|
||||
message = wx.StaticText(panel, -1, message)
|
||||
|
||||
# wx layout controls
|
||||
ver_sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
ver_sizer.Add(title, 0, wx.ALL, 4)
|
||||
ver_sizer.Add(message, 0, wx.ALL, 4)
|
||||
|
||||
hor_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
hor_sizer.Add(wxicon, 0, wx.EXPAND | wx.ALIGN_CENTER_VERTICAL \
|
||||
| wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 4)
|
||||
hor_sizer.Add(ver_sizer, 1, wx.EXPAND)
|
||||
hor_sizer.Layout()
|
||||
panel.SetSizer(hor_sizer)
|
||||
|
||||
tb.AddPanel(panel)
|
||||
tb.Play()
|
||||
|
||||
else:
|
||||
|
||||
def send(*args, **keyw):
|
||||
pass
|
11
bin/work
11
bin/work
|
@ -2,6 +2,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
import notify
|
||||
from signal import signal, SIGINT
|
||||
import sys
|
||||
from time import sleep
|
||||
|
@ -158,8 +159,16 @@ def work_pause(args):
|
|||
if not today_fields:
|
||||
die("no work to take a break from")
|
||||
log("Taking a break at {}".format(hour))
|
||||
|
||||
notify.init("work")
|
||||
# Wait to be stopped by a Ctrl-C
|
||||
sleep(999999)
|
||||
reminder_interval = 5 # In minutes
|
||||
count = 0
|
||||
while True:
|
||||
sleep(reminder_interval * 60)
|
||||
count += 1
|
||||
notify.send("Pause reminder",
|
||||
"It has now been {} minutes".format(count * reminder_interval))
|
||||
|
||||
|
||||
def work_end(args):
|
||||
|
|
Loading…
Reference in a new issue