Add more docs and signals.
This commit is contained in:
@@ -2,28 +2,85 @@
|
||||
Plugins
|
||||
=========
|
||||
|
||||
Signals
|
||||
-------
|
||||
How to use plugins
|
||||
------------------
|
||||
|
||||
.. data:: sigal.signals.img_resized
|
||||
:noindex:
|
||||
Plugins must be specified with the ``plugins`` setting:
|
||||
|
||||
Called after the image is resized.
|
||||
.. code-block:: python
|
||||
|
||||
from sigal.plugins import copyright
|
||||
plugins = ['sigal.plugins.adjust', copyright]
|
||||
|
||||
You can either specify the name of the module which contains the plugin, or
|
||||
import the plugin before adding it to the list. The ``plugin_paths`` setting
|
||||
can be used to specify paths to search for plugins (if they are not in the
|
||||
python path).
|
||||
|
||||
Write a new plugin
|
||||
------------------
|
||||
|
||||
See an example with the copyright plugin:
|
||||
Plugins are based on signals with the blinker_ library. A plugin must
|
||||
subscribe to a signal (the list is given below). New signals can be added if
|
||||
need. See an example with the copyright plugin:
|
||||
|
||||
.. _blinker: http://pythonhosted.org/blinker/
|
||||
|
||||
.. literalinclude:: ../sigal/plugins/copyright.py
|
||||
:language: python
|
||||
|
||||
Signals
|
||||
-------
|
||||
|
||||
.. function:: sigal.signals.album_initialized(album)
|
||||
:noindex:
|
||||
|
||||
Called after the :class:`~sigal.gallery.Album` is initialized.
|
||||
|
||||
:param album: the :class:`~sigal.gallery.Album` object.
|
||||
|
||||
.. data:: sigal.signals.gallery_initialized(gallery)
|
||||
:noindex:
|
||||
|
||||
Called after the gallery is initialized.
|
||||
|
||||
:param gallery: the :class:`Gallery` object.
|
||||
|
||||
.. data:: sigal.signals.media_initialized(media)
|
||||
:noindex:
|
||||
|
||||
Called after the :class:`~sigal.gallery.Media`
|
||||
(:class:`~sigal.gallery.Image` or :class:`~sigal.gallery.Video`) is
|
||||
initialized.
|
||||
|
||||
:param media: the media object.
|
||||
|
||||
.. data:: sigal.signals.gallery_build(gallery)
|
||||
:noindex:
|
||||
|
||||
Called after the gallery is build (after media are resized and html files
|
||||
are written).
|
||||
|
||||
:param gallery: the :class:`Gallery` object.
|
||||
|
||||
.. data:: sigal.signals.img_resized(img, settings=settings)
|
||||
:noindex:
|
||||
|
||||
Called after the image is resized. This signal work differently, the
|
||||
modified image object must be returned by the registered funtion.
|
||||
|
||||
:param img: the PIL image object.
|
||||
:param settings: the settings dict.
|
||||
|
||||
List of plugins
|
||||
---------------
|
||||
|
||||
Adjust plugin
|
||||
-------------
|
||||
=============
|
||||
|
||||
.. automodule:: sigal.plugins.adjust
|
||||
|
||||
Copyright plugin
|
||||
----------------
|
||||
================
|
||||
|
||||
.. automodule:: sigal.plugins.copyright
|
||||
|
||||
@@ -37,7 +37,7 @@ from datetime import datetime
|
||||
from os.path import isfile, join, splitext
|
||||
from PIL import Image as PILImage
|
||||
|
||||
from . import image, video
|
||||
from . import image, video, signals
|
||||
from .compat import UnicodeMixin, strxfrm, url_quote
|
||||
from .image import process_image, get_exif_tags
|
||||
from .log import colored, BLUE
|
||||
@@ -80,6 +80,7 @@ class Media(UnicodeMixin):
|
||||
self.raw_exif = None
|
||||
self.exif = None
|
||||
self.date = None
|
||||
signals.media_initialized.send(self)
|
||||
|
||||
def __repr__(self):
|
||||
return "<%s>(%r)" % (self.__class__.__name__, str(self))
|
||||
@@ -221,6 +222,8 @@ class Album(UnicodeMixin):
|
||||
|
||||
medias.sort(key=key, reverse=settings['medias_sort_reverse'])
|
||||
|
||||
signals.album_initialized.send(self)
|
||||
|
||||
def __repr__(self):
|
||||
return "<%s>(path=%r, title=%r)" % (self.__class__.__name__, self.path,
|
||||
self.title)
|
||||
@@ -458,6 +461,7 @@ class Gallery(object):
|
||||
albums[relpath] = album
|
||||
|
||||
self.logger.debug('Albums:\n%r', albums.values())
|
||||
signals.gallery_initialized.send(self)
|
||||
|
||||
def init_pool(self, ncpu):
|
||||
try:
|
||||
@@ -527,6 +531,8 @@ class Gallery(object):
|
||||
for album in self.albums.values():
|
||||
self.writer.write(album)
|
||||
|
||||
signals.gallery_build.send(self)
|
||||
|
||||
def process_dir(self, album, force=False):
|
||||
"""Process a list of images in a directory."""
|
||||
|
||||
|
||||
@@ -3,3 +3,8 @@
|
||||
from blinker import signal
|
||||
|
||||
img_resized = signal('img_resized')
|
||||
|
||||
album_initialized = signal('album_initialized')
|
||||
gallery_initialized = signal('gallery_initialized')
|
||||
gallery_build = signal('gallery_build')
|
||||
media_initialized = signal('media_initialized')
|
||||
|
||||
Reference in New Issue
Block a user