Eclectic Media Git toast / a4412f9
Updated docstrings to have useful information Ariana Giroux 1 year, 1 month ago
1 changed file(s) with 36 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
0 """ To spawn a toast notification, import :py:func:`toast.toast` and provide its arguments:
1 ::
2
3 >>> from toast import toast
4 >>> toast('test', title='test title')
5 """
06 from subprocess import Popen, PIPE
17
28
39 def check_for_toast():
10 """ :returns: True if toast is :term:`BurntToast` is installed via powershell
11 :rtype: boolean
12 """
413 command = ['powershell.exe', 'Get-Module', '-ListAvailable']
514 p = Popen(command, stdout=PIPE, stderr=PIPE)
615 p.wait()
1221 return False
1322
1423
15 class Message:
24 class _Message:
25 """ Concatenates a title and body string together in the correct syntax for a
26 :term:`Toast` notification via :term:`BurntToast`."""
1627 def __init__(self, body, title=''):
28 """ :param str body: The body of the message
29 :param str title: The title of the message
30 """
1731 self.title = title
1832 self.body = body
1933
2034 def __str__(self):
35 """ Concaenates the title and body together in the following format:
36
37 "title, body"
38
39 :returns: The message in the correct syntax
40 :rtype: str
41 """
2142 if self.title != '':
2243 return "'%s', '%s'" % (self.title, self.body)
2344 else:
2445 return self.body
2546
2647
27 def parse_command(message):
48 def _parse_command(message):
49 """ Appends a :py:class:`_Message` to a :term:`BurntToast` command.
50
51 :param Message message: A :py:class:`_Message` object
52 :returns: The command for :term:`BurntToast` as a
53 :py:func:`subprocess.Popen` ready argument list
54 :rtype: list
55 """
2856 return ['powershell.exe', 'New-BurntToastNotification', '-Text %s' % message]
2957
3058
3159 def toast(body, title=''):
32 message = Message(body, title)
33 p = Popen(parse_command(message), stdout=PIPE, stderr=PIPE)
60 """ Creates a :term:`Toast` notification.
61 :param str body: The body of the :term:`Toast` notification
62 :param str title: The body of the :term:`Toast` notification
63 """
64 message = _Message(body, title)
65 p = Popen(_parse_command(message), stdout=PIPE, stderr=PIPE)
3466 p.wait()
3567 stdout, stderr = p.communicate()
3668