コード例 #1
0
ファイル: tests.py プロジェクト: versa-syahptr/winotify
    def test_toast_non_english(self):
        toast = Notification(app_id="winotify test",
                             title="السلام عليكم",
                             msg="Peace be upon you!")

        toast.build().show()
        print(toast.script)
コード例 #2
0
ファイル: tests.py プロジェクト: versa-syahptr/winotify
    def test_toast(self):
        toast = Notification(app_id="winotify test",
                             title="Winotify Test Toast",
                             msg="New Notification!")

        toast.build().show()
        print(toast.script)
コード例 #3
0
ファイル: tests.py プロジェクト: versa-syahptr/winotify
    def test_toast_illegal_char(self):
        toast = Notification(app_id="winotify test",
                             title="This is illegal >>",
                             msg="< [YEAH] >")

        toast.build().show()
        print(toast.script)
コード例 #4
0
ファイル: tests.py プロジェクト: versa-syahptr/winotify
    def test_toast_with_icon(self):
        toast = Notification(app_id="winotify test",
                             title="Winotify Test Toast With Icon",
                             msg="New Notification!",
                             icon=os.path.join(
                                 os.path.dirname(os.path.abspath(__file__)),
                                 "icon.png"))

        toast.build().show()
        print(toast.script)
コード例 #5
0
ファイル: tests.py プロジェクト: versa-syahptr/winotify
    def test_toast_with_sound(self):
        toast = Notification(app_id="winotify test",
                             title="Winotify Test Toast",
                             msg="New Notification!")
        toast.set_audio(audio.SMS, loop=False)

        toast.build().show()
        print(toast.script)
コード例 #6
0
def send_notification(app_id, title, msg, icon, action_label, action_link):
    urls = re.findall(URL_REGEX, icon)
    if len(urls) == 1:
        icon = UploaderDynamic.download_resources({'': urls[0]},
                                                  './resource_cache/0')[0]
    toast = Notification(app_id=app_id, title=title, msg=msg, icon=icon)
    toast.add_actions(label=action_label, link=action_link)

    toast.build().show()
コード例 #7
0
ファイル: tests.py プロジェクト: versa-syahptr/winotify
    def test_toast_with_action(self):
        toast = Notification(app_id="winotify test",
                             title="Winotify Test Toast",
                             msg="New Notification with actions!")
        toast.add_actions("go to github",
                          "https://github.com/versa-syahptr/winotify")

        toast.build().show()
        print(toast.script)
コード例 #8
0
ファイル: __main__.py プロジェクト: versa-syahptr/winotify
def main():
    parser = argparse.ArgumentParser(
        prog="winotify[-nc]",
        description="Show notification toast on Windows 10."
        "Use 'winotify-nc' for no console window.")
    parser.version = winotify.__version__
    parser.add_argument('-id',
                        '--app-id',
                        metavar="NAME",
                        default="windows app",
                        help="Your app name")
    parser.add_argument("-t",
                        "--title",
                        default="Winotify Test Toast",
                        help="the notification title")
    parser.add_argument("-m",
                        "--message",
                        default='New Notification!',
                        help="the notification's main messages")
    parser.add_argument(
        "-i",
        "--icon",
        default='',
        metavar="PATH",
        help=
        "the icon path for the notification (note: the path must be absolute)")
    parser.add_argument(
        "--duration",
        default="short",
        choices=("short", "long"),
        help="the duration of the notification should display (default: short)"
    )
    parser.add_argument(
        "--open-url",
        default='',
        metavar='URL',
        help="the URL to open when user click the notification")
    parser.add_argument("--audio",
                        help="type of audio to play (default: silent)")
    parser.add_argument("--loop",
                        action="store_true",
                        help="whether to loop audio")
    parser.add_argument(
        "--action",
        metavar="LABEL",
        action="append",
        help="add button with LABEL as text, you can add up to 5 buttons")
    parser.add_argument("--action-url",
                        metavar="URL",
                        action="append",
                        required=("--action" in sys.argv),
                        help="an URL to launch when the button clicked")
    parser.add_argument("-v", "--version", action="version")

    args = parser.parse_args()

    toast = Notification(args.app_id, args.title, args.message, args.icon,
                         args.duration, args.open_url)

    if args.audio is not None:
        if args.audio not in audio_map.keys():
            sys.exit("Invalid audio " + args.audio)
        else:
            toast.set_audio(audio_map[args.audio], args.loop)

    actions = args.action
    action_urls = args.action_url
    if actions and action_urls:
        if len(actions) == len(action_urls):
            dik = dict(zip(actions, action_urls))
            for action, url in dik.items():
                toast.add_actions(action, url)
        else:
            parser.error(
                "imbalance arguments, "
                "the amount of action specified is not the same as the specified amount of action-url"
            )

    toast.show()