コード例 #1
0
ファイル: __init__.py プロジェクト: remcohaszing/exaile
    def __init_notify(self):
        can_continue = True
        caps = None
        if not Notify.is_initted():
            can_continue = Notify.init('Exaile')
        if not can_continue:
            LOGGER.error("Notify.init() returned false.")

        if can_continue:
            # This is the first synchronous call to the Notify server.
            # This call might fail if no server is present or it is broken.
            # Test it on window manager sessions (e.g. Weston) without
            # libnotify support, not on a Desktop Environment (such as
            # GNOME, KDE) to reproduce.
            available, name, vendor, version, spec_version = \
                Notify.get_server_info()
            if available:
                LOGGER.info(
                    "Connected with notify server %s (version %s) by %s", name,
                    version, vendor)
                LOGGER.info("Supported spec version: %s", spec_version)
                # This is another synchronous, blocking call:
                caps = Notify.get_server_caps()
                # Example from Fedora 26 Linux with GNOME on Wayland:
                # ['actions', 'body', 'body-markup', 'icon-static', 'persistence', 'sound']
                LOGGER.debug("Notify server caps: %s", caps)
                if not caps or not isinstance(caps, list):
                    can_continue = False
            else:
                LOGGER.error(
                    "Failed to retrieve capabilities from notify server. "
                    "This may happen if the desktop environment does not support "
                    "the org.freedesktop.Notifications DBus interface.")
                can_continue = False
        self.__handle_init(can_continue, caps)
コード例 #2
0
def send_notification(title, message, urgent=False, timeout=10000):
    """Send a notification."""
    try:
        import gi
        gi.require_version("Notify", "0.7")
        from gi.repository import Notify
        Notify.init("Qtile")
        info = Notify.get_server_info()
        if info[0]:
            notifier = Notify.Notification.new(title, message)
            notifier.set_timeout(timeout)
            if urgent:
                notifier.set_urgency(Notify.Urgency.CRITICAL)
            notifier.show()
    except Exception as exception:
        logger.error(exception)
コード例 #3
0
def send_notification(title, message, urgent=False, timeout=10000, id=None):
    """
    Send a notification.

    The id argument, if passed, requests the notification server to replace a visible
    notification with the same ID. An ID is returned for each call; this would then be
    passed when calling this function again to replace that notification. See:
    https://developer.gnome.org/notification-spec/
    """
    if _can_notify and Notify.get_server_info()[0]:
        notifier = Notify.Notification.new(title, message)
        if urgent:
            notifier.set_urgency(Notify.Urgency.CRITICAL)
        notifier.set_timeout(timeout)
        if id is None:
            id = randint(10, 1000)
        notifier.set_property('id', id)
        notifier.show()
        return id
コード例 #4
0
ファイル: notifications.py プロジェクト: frankzimper/epoptes
def main():
    """Run a notifications test from the command line.
    If epoptes isn't installed, `import epoptes.ui.common` must be removed."""
    print("get_server_info =", Notify.get_server_info())
    print("get_server_caps =", Notify.get_server_caps())
    events = [("Connected:", "user1 on host1"),
              ("Connected:", "user2 on host2"),
              ("Disconnected:", "user3 from host3"), ("Shut down:", "host4"),
              ("Connected:", "user5 on host5"),
              ("Connected:", "user6 on host6"), ("Shut down:", "host7"),
              ("Shut down:", "host8"), ("Connected:", "user9 on host9"),
              ("Connected:", "user10 on host10")]
    i = 0
    notq = NotifyQueue('Epoptes', 'dialog-information')
    while i < len(events):
        notq.enqueue(events[i][0], events[i][1])
        time.sleep(1)
        i += 1
        if i == 5:
            # Wait for the bubble to autoclose, then a new one should show up
            time.sleep(10)
コード例 #5
0
ファイル: __init__.py プロジェクト: exaile/exaile
    def __init_notify(self):
        can_continue = True
        caps = None
        if not Notify.is_initted():
            can_continue = Notify.init('Exaile')
        if not can_continue:
            LOGGER.error("Notify.init() returned false.")

        if can_continue:
            # This is the first synchronous call to the Notify server.
            # This call might fail if no server is present or it is broken.
            # Test it on window manager sessions (e.g. Weston) without
            # libnotify support, not on a Desktop Environment (such as
            # GNOME, KDE) to reproduce.
            available, name, vendor, version, spec_version = Notify.get_server_info()
            if available:
                LOGGER.info(
                    "Connected with notify server %s (version %s) by %s",
                    name,
                    version,
                    vendor,
                )
                LOGGER.info("Supported spec version: %s", spec_version)
                # This is another synchronous, blocking call:
                caps = Notify.get_server_caps()
                # Example from Fedora 26 Linux with GNOME on Wayland:
                # ['actions', 'body', 'body-markup', 'icon-static', 'persistence', 'sound']
                LOGGER.debug("Notify server caps: %s", caps)
                if not caps or not isinstance(caps, list):
                    can_continue = False
            else:
                LOGGER.error(
                    "Failed to retrieve capabilities from notify server. "
                    "This may happen if the desktop environment does not support "
                    "the org.freedesktop.Notifications DBus interface."
                )
                can_continue = False
        self.__handle_init(can_continue, caps)
コード例 #6
0
ファイル: test-gir.py プロジェクト: Distrotech/libnotify
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA  02111-1307, USA.

import os

# use our local typelib
os.environ['GI_TYPELIB_PATH'] = 'libnotify:' + os.environ.get('GI_TYPELIB_PATH', '')

from gi.repository import Notify

assert Notify.is_initted() == False
Notify.init('test')
assert Notify.is_initted() == True

print 'server info:', Notify.get_server_info()
print 'server capabilities:', Notify.get_server_caps()

n = Notify.Notification.new('title', None, None)
n.show()
n = Notify.Notification.new('title', 'text', None)
n.show()
n = Notify.Notification.new('title', 'text', 'gtk-ok')
n.show()

n.update('New Title', None, None)
n.show()
n.update('Newer Title', 'New Body', None)
n.show()

def callback():
コード例 #7
0
def main():
    if os.environ.get('INVOCATION_ID', False):
        logging.basicConfig(level=logging.INFO,
                            format='[%(levelname)s] %(message)s')
    else:
        logging.basicConfig(level=logging.INFO,
                            format='%(asctime)s [%(levelname)s] %(message)s')

    config_path = os.path.join(os.environ.get('XDG_CONFIG_HOME', '~/.config'),
                               'maildirwatch.conf')
    argv = Gtk.init(sys.argv)

    epilog = (
        'In addition to these arguments, you can also specify GTK options,\n'
        'see man page gtk-options(7) for details.')

    parser = argparse.ArgumentParser(
        description=__doc__,
        epilog=epilog,
        formatter_class=argparse.RawTextHelpFormatter)
    parser.add_argument(
        '-c',
        '--config',
        metavar='PATH',
        help='path to configuration file \n(default {})'.format(config_path),
        default=config_path)
    parser.add_argument('-d',
                        '--debug',
                        action='store_true',
                        help='set debug logging level')
    parser.add_argument('--version',
                        action='version',
                        version='%(prog)s {}'.format(__version__))

    args = parser.parse_args(argv[1:])

    if args.debug:
        logger.setLevel(logging.DEBUG)

    user_config_path = os.path.expanduser(args.config)
    logger.info('Loading config file %s', user_config_path)
    config.read(user_config_path)

    if not Notify.init('maildir-watch'):
        logger.critical('Could not init Notify')
        sys.exit(1)
    else:
        logger.debug('Notify server info: %s', Notify.get_server_info())
        logger.debug('Notify server capabilities: %s',
                     Notify.get_server_caps())

    app = App()
    app.start()

    success = True

    try:
        GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT,
                             Gtk.main_quit)

        def unhandled_exception_hook(etype, value, traceback):
            logger.exception('Unhandled exception, exiting',
                             exc_info=(etype, value, traceback))
            Gtk.main_quit()

            nonlocal success
            success = False

        # Install an unhandled exception handler which stops GTK event loop.
        sys.excepthook = unhandled_exception_hook

        Gtk.main()
    finally:
        logger.debug('About to exit, cleaning up')
        app.stop()
        Notify.uninit()

    sys.exit(0 if success else 1)
コード例 #8
0
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA  02111-1307, USA.

import os

# use our local typelib
os.environ['GI_TYPELIB_PATH'] = 'libnotify:' + os.environ.get(
    'GI_TYPELIB_PATH', '')

from gi.repository import Notify

assert Notify.is_initted() == False
Notify.init('test')
assert Notify.is_initted() == True

print 'server info:', Notify.get_server_info()
print 'server capabilities:', Notify.get_server_caps()

n = Notify.Notification.new('title', None, None)
n.show()
n = Notify.Notification.new('title', 'text', None)
n.show()
n = Notify.Notification.new('title', 'text', 'gtk-ok')
n.show()

n.update('New Title', None, None)
n.show()
n.update('Newer Title', 'New Body', None)
n.show()