notify2-0.3.1/0000775000175000017500000000000013100645655015212 5ustar takluyvertakluyver00000000000000notify2-0.3.1/docs/0000775000175000017500000000000013100645655016142 5ustar takluyvertakluyver00000000000000notify2-0.3.1/docs/Makefile0000664000175000017500000001270013100644752017577 0ustar takluyvertakluyver00000000000000# Makefile for Sphinx documentation # # You can set these variables from the command line. SPHINXOPTS = SPHINXBUILD = sphinx-build PAPER = BUILDDIR = _build # Internal variables. PAPEROPT_a4 = -D latex_paper_size=a4 PAPEROPT_letter = -D latex_paper_size=letter ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . # the i18n builder cannot share the environment and doctrees with the others I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext help: @echo "Please use \`make ' where is one of" @echo " html to make standalone HTML files" @echo " dirhtml to make HTML files named index.html in directories" @echo " singlehtml to make a single large HTML file" @echo " pickle to make pickle files" @echo " json to make JSON files" @echo " htmlhelp to make HTML files and a HTML help project" @echo " qthelp to make HTML files and a qthelp project" @echo " devhelp to make HTML files and a Devhelp project" @echo " epub to make an epub" @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" @echo " latexpdf to make LaTeX files and run them through pdflatex" @echo " text to make text files" @echo " man to make manual pages" @echo " texinfo to make Texinfo files" @echo " info to make Texinfo files and run them through makeinfo" @echo " gettext to make PO message catalogs" @echo " changes to make an overview of all changed/added/deprecated items" @echo " linkcheck to check all external links for integrity" @echo " doctest to run all doctests embedded in the documentation (if enabled)" clean: -rm -rf $(BUILDDIR)/* html: $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." dirhtml: $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." singlehtml: $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml @echo @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." pickle: $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle @echo @echo "Build finished; now you can process the pickle files." json: $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json @echo @echo "Build finished; now you can process the JSON files." htmlhelp: $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp @echo @echo "Build finished; now you can run HTML Help Workshop with the" \ ".hhp project file in $(BUILDDIR)/htmlhelp." qthelp: $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp @echo @echo "Build finished; now you can run "qcollectiongenerator" with the" \ ".qhcp project file in $(BUILDDIR)/qthelp, like this:" @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/notify2.qhcp" @echo "To view the help file:" @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/notify2.qhc" devhelp: $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp @echo @echo "Build finished." @echo "To view the help file:" @echo "# mkdir -p $$HOME/.local/share/devhelp/notify2" @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/notify2" @echo "# devhelp" epub: $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub @echo @echo "Build finished. The epub file is in $(BUILDDIR)/epub." latex: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." @echo "Run \`make' in that directory to run these through (pdf)latex" \ "(use \`make latexpdf' here to do that automatically)." latexpdf: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through pdflatex..." $(MAKE) -C $(BUILDDIR)/latex all-pdf @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." text: $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text @echo @echo "Build finished. The text files are in $(BUILDDIR)/text." man: $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man @echo @echo "Build finished. The manual pages are in $(BUILDDIR)/man." texinfo: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." @echo "Run \`make' in that directory to run these through makeinfo" \ "(use \`make info' here to do that automatically)." info: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo "Running Texinfo files through makeinfo..." make -C $(BUILDDIR)/texinfo info @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." gettext: $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale @echo @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." changes: $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes @echo @echo "The overview file is in $(BUILDDIR)/changes." linkcheck: $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck @echo @echo "Link check complete; look for any errors in the above output " \ "or in $(BUILDDIR)/linkcheck/output.txt." doctest: $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest @echo "Testing of doctests in the sources finished, look at the " \ "results in $(BUILDDIR)/doctest/output.txt." notify2-0.3.1/docs/license.rst0000664000175000017500000000331213100644752020312 0ustar takluyvertakluyver00000000000000License and Contributors ======================== notify2 is under the BSD 2-Clause License. Some of the examples (icon.py, default-action.py, multi-actions.py and qt-app.py) are derived from pynotify examples, and are therefore `LGPL-2.1 `_, © 2006 Christian Hammond . Contributors ------------ * Thomas Kluyver * John Terry License text ------------ Copyright (c) 2012, Thomas Kluyver & contributors All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. notify2-0.3.1/docs/make.bat0000664000175000017500000001175213100644752017552 0ustar takluyvertakluyver00000000000000@ECHO OFF REM Command file for Sphinx documentation if "%SPHINXBUILD%" == "" ( set SPHINXBUILD=sphinx-build ) set BUILDDIR=_build set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . set I18NSPHINXOPTS=%SPHINXOPTS% . if NOT "%PAPER%" == "" ( set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% ) if "%1" == "" goto help if "%1" == "help" ( :help echo.Please use `make ^` where ^ is one of echo. html to make standalone HTML files echo. dirhtml to make HTML files named index.html in directories echo. singlehtml to make a single large HTML file echo. pickle to make pickle files echo. json to make JSON files echo. htmlhelp to make HTML files and a HTML help project echo. qthelp to make HTML files and a qthelp project echo. devhelp to make HTML files and a Devhelp project echo. epub to make an epub echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter echo. text to make text files echo. man to make manual pages echo. texinfo to make Texinfo files echo. gettext to make PO message catalogs echo. changes to make an overview over all changed/added/deprecated items echo. linkcheck to check all external links for integrity echo. doctest to run all doctests embedded in the documentation if enabled goto end ) if "%1" == "clean" ( for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i del /q /s %BUILDDIR%\* goto end ) if "%1" == "html" ( %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html if errorlevel 1 exit /b 1 echo. echo.Build finished. The HTML pages are in %BUILDDIR%/html. goto end ) if "%1" == "dirhtml" ( %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml if errorlevel 1 exit /b 1 echo. echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. goto end ) if "%1" == "singlehtml" ( %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml if errorlevel 1 exit /b 1 echo. echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. goto end ) if "%1" == "pickle" ( %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can process the pickle files. goto end ) if "%1" == "json" ( %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can process the JSON files. goto end ) if "%1" == "htmlhelp" ( %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can run HTML Help Workshop with the ^ .hhp project file in %BUILDDIR%/htmlhelp. goto end ) if "%1" == "qthelp" ( %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can run "qcollectiongenerator" with the ^ .qhcp project file in %BUILDDIR%/qthelp, like this: echo.^> qcollectiongenerator %BUILDDIR%\qthelp\notify2.qhcp echo.To view the help file: echo.^> assistant -collectionFile %BUILDDIR%\qthelp\notify2.ghc goto end ) if "%1" == "devhelp" ( %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp if errorlevel 1 exit /b 1 echo. echo.Build finished. goto end ) if "%1" == "epub" ( %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub if errorlevel 1 exit /b 1 echo. echo.Build finished. The epub file is in %BUILDDIR%/epub. goto end ) if "%1" == "latex" ( %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex if errorlevel 1 exit /b 1 echo. echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. goto end ) if "%1" == "text" ( %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text if errorlevel 1 exit /b 1 echo. echo.Build finished. The text files are in %BUILDDIR%/text. goto end ) if "%1" == "man" ( %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man if errorlevel 1 exit /b 1 echo. echo.Build finished. The manual pages are in %BUILDDIR%/man. goto end ) if "%1" == "texinfo" ( %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo if errorlevel 1 exit /b 1 echo. echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. goto end ) if "%1" == "gettext" ( %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale if errorlevel 1 exit /b 1 echo. echo.Build finished. The message catalogs are in %BUILDDIR%/locale. goto end ) if "%1" == "changes" ( %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes if errorlevel 1 exit /b 1 echo. echo.The overview file is in %BUILDDIR%/changes. goto end ) if "%1" == "linkcheck" ( %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck if errorlevel 1 exit /b 1 echo. echo.Link check complete; look for any errors in the above output ^ or in %BUILDDIR%/linkcheck/output.txt. goto end ) if "%1" == "doctest" ( %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest if errorlevel 1 exit /b 1 echo. echo.Testing of doctests in the sources finished, look at the ^ results in %BUILDDIR%/doctest/output.txt. goto end ) :end notify2-0.3.1/docs/conf.py0000664000175000017500000001765513100644752017454 0ustar takluyvertakluyver00000000000000# -*- coding: utf-8 -*- # # notify2 documentation build configuration file, created by # sphinx-quickstart on Fri Jun 14 11:35:07 2013. # # This file is execfile()d with the current directory set to its containing dir. # # Note that not all possible configuration values are present in this # autogenerated file. # # All configuration values have a default; values that are commented out # serve to show the default. import sys, os # To get docstrings, we need to be able to import dbus, but we don't need to # actually use it. try: import dbus except ImportError: sys.modules['dbus'] = object() # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. #sys.path.insert(0, os.path.abspath('.')) # -- General configuration ----------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. #needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx', 'sphinx.ext.viewcode'] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # The suffix of source filenames. source_suffix = '.rst' # The encoding of source files. #source_encoding = 'utf-8-sig' # The master toctree document. master_doc = 'index' # General information about the project. project = u'notify2' copyright = u'2013, Thomas Kluyver' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. version = '0.3' # The full version, including alpha/beta/rc tags. release = '0.3' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. #language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: #today = '' # Else, today_fmt is used as the format for a strftime call. #today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = ['_build'] # The reST default role (used for this markup: `text`) to use for all documents. #default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. #add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). #add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. #show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # A list of ignored prefixes for module index sorting. #modindex_common_prefix = [] # -- Options for HTML output --------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. html_theme = 'default' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. #html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. #html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". #html_title = None # A shorter title for the navigation bar. Default is the same as html_title. #html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. #html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. #html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. #html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. #html_use_smartypants = True # Custom sidebar templates, maps document names to template names. #html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. #html_additional_pages = {} # If false, no module index is generated. #html_domain_indices = True # If false, no index is generated. #html_use_index = True # If true, the index is split into individual pages for each letter. #html_split_index = False # If true, links to the reST sources are added to the pages. #html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. #html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. #html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. #html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). #html_file_suffix = None # Output file base name for HTML help builder. htmlhelp_basename = 'notify2doc' # -- Options for LaTeX output -------------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). #'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). #'pointsize': '10pt', # Additional stuff for the LaTeX preamble. #'preamble': '', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ ('index', 'notify2.tex', u'notify2 Documentation', u'Thomas Kluyver', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of # the title page. #latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. #latex_use_parts = False # If true, show page references after internal links. #latex_show_pagerefs = False # If true, show URL addresses after external links. #latex_show_urls = False # Documents to append as an appendix to all manuals. #latex_appendices = [] # If false, no module index is generated. #latex_domain_indices = True # -- Options for manual page output -------------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ ('index', 'notify2', u'notify2 Documentation', [u'Thomas Kluyver'], 1) ] # If true, show URL addresses after external links. #man_show_urls = False # -- Options for Texinfo output ------------------------------------------------ # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ ('index', 'notify2', u'notify2 Documentation', u'Thomas Kluyver', 'notify2', 'One line description of project.', 'Miscellaneous'), ] # Documents to append as an appendix to all manuals. #texinfo_appendices = [] # If false, no module index is generated. #texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. #texinfo_show_urls = 'footnote' # Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = {'http://docs.python.org/': None} notify2-0.3.1/docs/index.rst0000664000175000017500000000430613100644752020003 0ustar takluyvertakluyver00000000000000notify2 API documentation ========================= notify2 is a replacement for pynotify which can be used from different GUI toolkits and from programs without a GUI. The API is largely the same as that of pynotify, but some less important parts are left out. You can alternatively use the GObject Introspection bindings to libnotify (``from gi.repository import Notify``). I'd recommend that for GTK applications, while notify2 has fewer dependencies for non-GTK applications. It should be easy to switch between the two. Notifications are sent to a notification daemon over `D-Bus `_, according to the `Desktop notifications spec `_, and the server is responsible for displaying them to the user. So your application has limited control over when and how a notification appears. For example, Ubuntu uses the `NotifyOSD daemon `_. .. toctree:: :maxdepth: 1 license .. module:: notify2 .. autofunction:: init .. autofunction:: get_server_caps .. autofunction:: get_server_info Creating and showing notifications ---------------------------------- .. autoclass:: Notification .. automethod:: show .. automethod:: update .. automethod:: close Extra parameters ---------------- .. class:: Notification .. automethod:: set_urgency .. automethod:: set_timeout .. automethod:: set_category .. automethod:: set_location .. automethod:: set_icon_from_pixbuf .. automethod:: set_hint .. automethod:: set_hint_byte Callbacks --------- To receive callbacks, you must have set a D-Bus event loop when you called :func:`init`. .. class:: Notification .. automethod:: connect .. automethod:: add_action Constants --------- .. data:: URGENCY_LOW URGENCY_NORMAL URGENCY_CRITICAL Urgency levels to pass to :meth:`Notification.set_urgency`. .. data:: EXPIRES_DEFAULT EXPIRES_NEVER Special expiration times to pass to :meth:`Notification.set_timeout`. Indices and tables ================== * :ref:`genindex` * :ref:`modindex` * :ref:`search` notify2-0.3.1/setup.cfg0000644000175000017500000000003213100645367017024 0ustar takluyvertakluyver00000000000000[bdist_wheel] universal=1 notify2-0.3.1/notify2.py0000664000175000017500000003264013100645543017157 0ustar takluyvertakluyver00000000000000"""This is a pure-python replacement for notify-python, using python-dbus to communicate with the notifications server directly. It's compatible with Python 2 and 3, and its callbacks can work with Gtk 3 or Qt 4 applications. To use it, first call ``notify2.init('app name')``, then create and show notifications:: n = notify2.Notification("Summary", "Some body text", "notification-message-im" # Icon name ) n.show() API docs are `available on ReadTheDocs `_, or you can refer to docstrings. Based on the notifications spec at: http://developer.gnome.org/notification-spec/ Porting applications from pynotify ---------------------------------- There are a few differences from pynotify you should be aware of: - If you need callbacks from notifications, notify2 must know about your event loop. The simplest way is to pass 'glib' or 'qt' as the ``mainloop`` parameter to ``init``. - The methods ``attach_to_widget`` and ``attach_to_status_icon`` are not implemented. You can calculate the location you want the notification to appear and call ``Notification``. - ``set_property`` and ``get_property`` are not implemented. The summary, body and icon are accessible as attributes of a ``Notification`` instance. - Various methods that pynotify Notification instances got from gobject do not exist, or only implement part of the functionality. Several pynotify functions, especially getters and setters, are only supported for compatibility. You are encouraged to use more direct, Pythonic alternatives. """ import dbus __version__ = '0.3.1' # Constants EXPIRES_DEFAULT = -1 EXPIRES_NEVER = 0 URGENCY_LOW = 0 URGENCY_NORMAL = 1 URGENCY_CRITICAL = 2 urgency_levels = [URGENCY_LOW, URGENCY_NORMAL, URGENCY_CRITICAL] # Initialise the module (following pynotify's API) ----------------------------- initted = False appname = "" _have_mainloop = False class UninittedError(RuntimeError): """Error raised if you try to communicate with the server before calling :func:`init`. """ pass class UninittedDbusObj(object): def __getattr__(self, name): raise UninittedError("You must call notify2.init() before using the " "notification features.") dbus_iface = UninittedDbusObj() def init(app_name, mainloop=None): """Initialise the D-Bus connection. Must be called before you send any notifications, or retrieve server info or capabilities. To get callbacks from notifications, DBus must be integrated with a mainloop. There are three ways to achieve this: - Set a default mainloop (dbus.set_default_main_loop) before calling init() - Pass the mainloop parameter as a string 'glib' or 'qt' to integrate with those mainloops. (N.B. passing 'qt' currently makes that the default dbus mainloop, because that's the only way it seems to work.) - Pass the mainloop parameter a DBus compatible mainloop instance, such as dbus.mainloop.glib.DBusGMainLoop(). If you only want to display notifications, without receiving information back from them, you can safely omit mainloop. """ global appname, initted, dbus_iface, _have_mainloop if mainloop == 'glib': from dbus.mainloop.glib import DBusGMainLoop mainloop = DBusGMainLoop() elif mainloop == 'qt': from dbus.mainloop.qt import DBusQtMainLoop # For some reason, this only works if we make it the default mainloop # for dbus. That might make life tricky for anyone trying to juggle two # event loops, but I can't see any way round it. mainloop = DBusQtMainLoop(set_as_default=True) bus = dbus.SessionBus(mainloop=mainloop) dbus_obj = bus.get_object('org.freedesktop.Notifications', '/org/freedesktop/Notifications') dbus_iface = dbus.Interface(dbus_obj, dbus_interface='org.freedesktop.Notifications') appname = app_name initted = True if mainloop or dbus.get_default_main_loop(): _have_mainloop = True dbus_iface.connect_to_signal('ActionInvoked', _action_callback) dbus_iface.connect_to_signal('NotificationClosed', _closed_callback) return True def is_initted(): """Has init() been called? Only exists for compatibility with pynotify. """ return initted def get_app_name(): """Return appname. Only exists for compatibility with pynotify. """ return appname def uninit(): """Undo what init() does.""" global initted, dbus_iface, _have_mainloop initted = False _have_mainloop = False dbus_iface = UninittedDbusObj() # Retrieve basic server information -------------------------------------------- def get_server_caps(): """Get a list of server capabilities. These are short strings, listed `in the spec `_. Vendors may also list extra capabilities with an 'x-' prefix, e.g. 'x-canonical-append'. """ return [str(x) for x in dbus_iface.GetCapabilities()] def get_server_info(): """Get basic information about the server. """ res = dbus_iface.GetServerInformation() return {'name': str(res[0]), 'vendor': str(res[1]), 'version': str(res[2]), 'spec-version': str(res[3]), } # Action callbacks ------------------------------------------------------------- notifications_registry = {} def _action_callback(nid, action): nid, action = int(nid), str(action) try: n = notifications_registry[nid] except KeyError: #this message was created through some other program. return n._action_callback(action) def _closed_callback(nid, reason): nid, reason = int(nid), int(reason) try: n = notifications_registry[nid] except KeyError: #this message was created through some other program. return n._closed_callback(n) del notifications_registry[nid] def no_op(*args): """No-op function for callbacks. """ pass # Controlling notifications ---------------------------------------------------- ActionsDictClass = dict # fallback for old version of Python try: from collections import OrderedDict ActionsDictClass = OrderedDict except ImportError: pass class Notification(object): """A notification object. summary : str The title text message : str The body text, if the server has the 'body' capability. icon : str Path to an icon image, or the name of a stock icon. Stock icons available in Ubuntu are `listed here `_. You can also set an icon from data in your application - see :meth:`set_icon_from_pixbuf`. """ id = 0 timeout = -1 # -1 = server default settings _closed_callback = no_op def __init__(self, summary, message='', icon=''): self.summary = summary self.message = message self.icon = icon self.hints = {} self.actions = ActionsDictClass() self.data = {} # Any data the user wants to attach def show(self): """Ask the server to show the notification. Call this after you have finished setting any parameters of the notification that you want. """ nid = dbus_iface.Notify(appname, # app_name (spec names) self.id, # replaces_id self.icon, # app_icon self.summary, # summary self.message, # body self._make_actions_array(), # actions self.hints, # hints self.timeout, # expire_timeout ) self.id = int(nid) if _have_mainloop: notifications_registry[self.id] = self return True def update(self, summary, message="", icon=None): """Replace the summary and body of the notification, and optionally its icon. You should call :meth:`show` again after this to display the updated notification. """ self.summary = summary self.message = message if icon is not None: self.icon = icon def close(self): """Ask the server to close this notification.""" if self.id != 0: dbus_iface.CloseNotification(self.id) def set_hint(self, key, value): """n.set_hint(key, value) <--> n.hints[key] = value See `hints in the spec `_. Only exists for compatibility with pynotify. """ self.hints[key] = value set_hint_string = set_hint_int32 = set_hint_double = set_hint def set_hint_byte(self, key, value): """Set a hint with a dbus byte value. The input value can be an integer or a bytes string of length 1. """ self.hints[key] = dbus.Byte(value) def set_urgency(self, level): """Set the urgency level to one of URGENCY_LOW, URGENCY_NORMAL or URGENCY_CRITICAL. """ if level not in urgency_levels: raise ValueError("Unknown urgency level specified", level) self.set_hint_byte("urgency", level) def set_category(self, category): """Set the 'category' hint for this notification. See `categories in the spec `_. """ self.hints['category'] = category def set_timeout(self, timeout): """Set the display duration in milliseconds, or one of the special values EXPIRES_DEFAULT or EXPIRES_NEVER. This is a request, which the server might ignore. Only exists for compatibility with pynotify; you can simply set:: n.timeout = 5000 """ if not isinstance(timeout, int): raise TypeError("timeout value was not int", timeout) self.timeout = timeout def get_timeout(self): """Return the timeout value for this notification. Only exists for compatibility with pynotify; you can inspect the timeout attribute directly. """ return self.timeout def add_action(self, action, label, callback, user_data=None): """Add an action to the notification. Check for the 'actions' server capability before using this. action : str A brief key. label : str The text displayed on the action button callback : callable A function taking at 2-3 parameters: the Notification object, the action key and (if specified) the user_data. user_data : An extra argument to pass to the callback. """ self.actions[action] = (label, callback, user_data) def _make_actions_array(self): """Make the actions array to send over DBus. """ arr = [] for action, (label, callback, user_data) in self.actions.items(): arr.append(action) arr.append(label) return arr def _action_callback(self, action): """Called when the user selects an action on the notification, to dispatch it to the relevant user-specified callback. """ try: label, callback, user_data = self.actions[action] except KeyError: return if user_data is None: callback(self, action) else: callback(self, action, user_data) def connect(self, event, callback): """Set the callback for the notification closing; the only valid value for event is 'closed' (the parameter is kept for compatibility with pynotify). The callback will be called with the :class:`Notification` instance. """ if event != 'closed': raise ValueError("'closed' is the only valid value for event", event) self._closed_callback = callback def set_data(self, key, value): """n.set_data(key, value) <--> n.data[key] = value Only exists for compatibility with pynotify. """ self.data[key] = value def get_data(self, key): """n.get_data(key) <--> n.data[key] Only exists for compatibility with pynotify. """ return self.data[key] def set_icon_from_pixbuf(self, icon): """Set a custom icon from a GdkPixbuf. """ struct = ( icon.get_width(), icon.get_height(), icon.get_rowstride(), icon.get_has_alpha(), icon.get_bits_per_sample(), icon.get_n_channels(), dbus.ByteArray(icon.get_pixels()) ) self.hints['icon_data'] = struct def set_location(self, x, y): """Set the notification location as (x, y), if the server supports it. """ if (not isinstance(x, int)) or (not isinstance(y, int)): raise TypeError("x and y must both be ints", (x,y)) self.hints['x'] = x self.hints['y'] = y notify2-0.3.1/examples/0000775000175000017500000000000013100645655017030 5ustar takluyvertakluyver00000000000000notify2-0.3.1/examples/default-action.py0000775000175000017500000000201713100644752022301 0ustar takluyvertakluyver00000000000000#!/usr/bin/env python from gi.repository import Gtk import notify2 import sys # Ubuntu's notify-osd doesn't officially support actions. However, it does have # a dialog fallback which we can use for this demonstration. In real use, please # respect the capabilities the notification server reports! OVERRIDE_NO_ACTIONS = True def default_cb(n, action): assert action == "default" print("You clicked the default action") n.close() def closed_cb(n): print("Notification closed") Gtk.main_quit() if __name__ == '__main__': if not notify2.init("Default Action Test", mainloop='glib'): sys.exit(1) server_capabilities = notify2.get_server_caps() n = notify2.Notification("Matt is online") n.set_category("presence.online") if ('actions' in server_capabilities) or OVERRIDE_NO_ACTIONS: n.add_action("default", "Default Action", default_cb) n.connect('closed', closed_cb) if not n.show(): print("Failed to send notification") sys.exit(1) Gtk.main() notify2-0.3.1/examples/icon.py0000775000175000017500000000205313100644752020332 0ustar takluyvertakluyver00000000000000#!/usr/bin/env python from __future__ import print_function import notify2 from gi.repository import Gtk import sys import os if __name__ == '__main__': if not notify2.init("Images Test"): sys.exit(1) # Stock icon n = notify2.Notification("Icon Test", "Testing stock icon", "notification-message-email") if not n.show(): print("Failed to send notification") sys.exit(1) # Image URI uri = "file://" + os.path.abspath(os.path.curdir) + "/applet-critical.png" print("Sending", uri) n = notify2.Notification("Alert!", "Testing URI icons", uri) if not n.show(): print("Failed to send notification") sys.exit(1) # Raw image n = notify2.Notification("Raw image test", "Testing sending raw pixbufs") helper = Gtk.Button() icon = helper.render_icon(Gtk.STOCK_DIALOG_QUESTION, Gtk.IconSize.DIALOG) n.set_icon_from_pixbuf(icon) if not n.show(): print("Failed to send notification") sys.exit(1) notify2-0.3.1/examples/basic.py0000775000175000017500000000072213100644752020464 0ustar takluyvertakluyver00000000000000#!/usr/bin/env python """This illustrates the basic functionality of notify2 - creating and displaying a notification message. """ import notify2 # This must be called before using notify2 notify2.init("Demo application") # A number of stock n = notify2.Notification("Summary", "Body text goes here", "notification-message-im") # A stock icon name. For more icon # options, see icon.py in this folder. n.show() notify2-0.3.1/examples/notify2.py0000777000175000017500000000000013100644752023143 2../notify2.pyustar takluyvertakluyver00000000000000notify2-0.3.1/examples/qt-app.py0000775000175000017500000000347213100644752020612 0ustar takluyvertakluyver00000000000000#!/usr/bin/env python """Callbacks from notify2 work with PyQt applications as well. """ from PyQt4.QtCore import QCoreApplication import notify2 import sys # Ubuntu's notify-osd doesn't officially support actions. However, it does have # a dialog fallback which we can use for this demonstration. In real use, please # respect the capabilities the notification server reports! OVERRIDE_NO_ACTIONS = True class MyApp(QCoreApplication): def __init__(self, argv): super(MyApp, self).__init__(argv) # This needs to be before any other use of notify2, but after the Qt # application has been instantiated. notify2.init("Multi Action Test", mainloop='qt') server_capabilities = notify2.get_server_caps() n = notify2.Notification("Low disk space", "You can free up some disk space by " + "emptying the trash can.") n.set_urgency(notify2.URGENCY_CRITICAL) n.set_category("device") if ('actions' in server_capabilities) or OVERRIDE_NO_ACTIONS: n.add_action("help", "Help", self.help_cb) n.add_action("ignore", "Ignore", self.ignore_cb) n.add_action("empty", "Empty Trash", self.empty_cb) n.connect('closed', self.closed_cb) n.show() def help_cb(self, n, action): assert action == "help" print("You clicked Help") n.close() def ignore_cb(self, n, action): assert action == "ignore" print("You clicked Ignore") n.close() def empty_cb(self, n, action): assert action == "empty" print("You clicked Empty Trash") n.close() def closed_cb(self, n): print("Notification closed") self.quit() if __name__ == "__main__": MyApp(sys.argv).exec_() notify2-0.3.1/examples/applet-critical.png0000664000175000017500000000257313100644752022617 0ustar takluyvertakluyver00000000000000PNG  IHDRĴl; pHYs  d_tIME 6^'bKGDIDAT8eU]UU]{spQWs4M 1A%-Q^DzK!{W@S2TAKp39w{f:a;ko}k#{~W>B枛P{rK (< nsdocQؿg <\|:XҌrU*B3l[mc>;},| s,1ʕ[rMD=EdTc{H{?<i"wwt܍EX/'N`m2T1u^^QjTMcO_-oS]˔i tq5kVžS8FP 0\|7<2j8P. @\CP*!@ TSqe˓ܽ[fl6oF~:&'9zSc7nel& V BJl"pZνrQݤ#H#ßI6(BDi2(׭{`,+&"n95CPP$)- d׮H1D b۶3$˶&d \L. IƎ,cf -8[6_x)d""`H!iv°0-VK4<9s*GL"v]ksI{BeW k~MMpL+F4V:7%c\{߳drҵ ׅjvp(C7/yc-daς HTzm7Y(mZg[&#mڔLEPۨ)gi|VǸnLdw8>sΈxBآSN@o %$&߀Z׃|Om˟i2=J=q,ḨK3Y]2Ư_,p~gw¸mPr1 &FZ)0Kהi.=J jxA e֣fg?J*NE=Kd:quu&lg'=> )yzft|ژ{Fxe81Ȳt9MUQ SK̯JGf6 YAwIb۝cm 1VSy8󴒅(4pu4`_, © 2006 Christian Hammond . Contributors ------------ * Thomas Kluyver * John Terry License text ------------ Copyright (c) 2012, Thomas Kluyver & contributors All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. notify2-0.3.1/PKG-INFO0000664000175000017500000000471213100645655016313 0ustar takluyvertakluyver00000000000000Metadata-Version: 1.1 Name: notify2 Version: 0.3.1 Summary: Python interface to DBus notifications Home-page: https://bitbucket.org/takluyver/pynotify2 Author: Thomas Kluyver Author-email: takowl@gmail.com License: UNKNOWN Description: This is a pure-python replacement for notify-python, using python-dbus to communicate with the notifications server directly. It's compatible with Python 2 and 3, and its callbacks can work with Gtk 3 or Qt 4 applications. To use it, first call ``notify2.init('app name')``, then create and show notifications:: n = notify2.Notification("Summary", "Some body text", "notification-message-im" # Icon name ) n.show() API docs are `available on ReadTheDocs `_, or you can refer to docstrings. Based on the notifications spec at: http://developer.gnome.org/notification-spec/ Porting applications from pynotify ---------------------------------- There are a few differences from pynotify you should be aware of: - If you need callbacks from notifications, notify2 must know about your event loop. The simplest way is to pass 'glib' or 'qt' as the ``mainloop`` parameter to ``init``. - The methods ``attach_to_widget`` and ``attach_to_status_icon`` are not implemented. You can calculate the location you want the notification to appear and call ``Notification``. - ``set_property`` and ``get_property`` are not implemented. The summary, body and icon are accessible as attributes of a ``Notification`` instance. - Various methods that pynotify Notification instances got from gobject do not exist, or only implement part of the functionality. Several pynotify functions, especially getters and setters, are only supported for compatibility. You are encouraged to use more direct, Pythonic alternatives. Platform: UNKNOWN Classifier: License :: OSI Approved :: BSD License Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 3 Classifier: Topic :: Desktop Environment Classifier: Topic :: Software Development :: Libraries :: Python Modules