pygame-imslider


Namepygame-imslider JSON
Version 1.0.2 PyPI version JSON
download
home_pagehttps://github.com/anxuae/pygame-imslider
SummaryFlexible images slider highly customizable for pygame.
upload_time2023-05-28 12:23:14
maintainer
docs_urlNone
authorAntoine Rousseaux
requires_python>=3.6
license
keywords pygame widget
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            pygame-imslider
---------------

|PythonVersions| |PypiPackage| |Downloads|

Flexible images slider for Pygame engine.

Default
^^^^^^^

.. image:: https://raw.githubusercontent.com/anxuae/pygame-imslider/master/screenshots/default.gif
   :align: center
   :alt: default

.. code-block:: python

   slider = ImSlider((800, 300))

Multiple Slides
^^^^^^^^^^^^^^^

.. image:: https://raw.githubusercontent.com/anxuae/pygame-imslider/master/screenshots/multiple.gif
   :align: center
   :alt: multiple

.. code-block:: python

   slider = ImSlider((800, 300), per_page=3, rewind=True)

1 Slide Per Move
^^^^^^^^^^^^^^^^

.. image:: https://raw.githubusercontent.com/anxuae/pygame-imslider/master/screenshots/one_per_move.gif
   :align: center
   :alt: one_per_move

.. code-block:: python

   slider = ImSlider((800, 300), stype=STYPE_LOOP, per_page=3, per_move=1)

Focus Center
^^^^^^^^^^^^

.. image:: https://raw.githubusercontent.com/anxuae/pygame-imslider/master/screenshots/focus.gif
   :align: center
   :alt: focus

.. code-block:: python

   slider = ImSlider((800, 300), stype=STYPE_LOOP, per_page=3, per_move=2, focus='center')

Fade Transition
^^^^^^^^^^^^^^^

.. image:: https://raw.githubusercontent.com/anxuae/pygame-imslider/master/screenshots/fade.gif
   :align: center
   :alt: fade

.. code-block:: python

   slider = ImSlider((800, 300), stype=STYPE_FADE, rewind=True, focus=False)

Install
-------

::

    $ pip3 install pygame-imslider

Basic usage
-----------

``ImSlider`` only require a pygame surface to be displayed on and a index consumer function, as
in the following example :

.. code-block:: python

    from pygame_imslider import *

    def consumer(index):
        print('Current index : %s' % index)

    # Initializes and activates ImSlider
    slider = ImSlider((300, 100), callback=consumer)
    slider.load_images(['image1.png', 'image2.png', 'image3.png',])

The slider has the following optional parameters:

- **stype**: determine a slider type: STYPE_SLIDE, STYPE_LOOP or STYPE_FADE
- **per_page**: determine how many slides should be displayed per page. Ignored if
  stype=STYPE_FADE.
- **per_move**: determine how many slides should be moved when a slider goes
  to next or perv. Ignored if stype=STYPE_FADE.
- **focus**: determine which slide should be focused if there are multiple
  slides in a page. A string "center" is acceptable for centering slides.
- **rewind**: whether to rewind a slider before the first slide or after the
  last one. Ignored if stype=STYPE_LOOP.
- **speed**: transition duration in seconds.
- **renderer**: a ImSliderRenderer to customize colors of the slider
- **callback**: callback called each time the selection is changed.

Event management
----------------

A ``ImSlider`` object handles the following pygame event :

- **MOUSEBUTTONDOWN**
- **MOUSEBUTTONUP**
- **FINGERDOWN**
- **FINGERUP**
- **KEYDOWN**
- **KEYUP**
- **JOYHATMOTION**

In order to process those events, slider instance event handling method should be called like
in the following example:

.. code-block:: python

    while True:

        events = pygame.event.get()

        # Update internal variables
        slider.update(events)

        # Draw the slider
        slider.draw(surface)

        #
        # Perform other tasks here
        #

        # Update the display
        pygame.display.flip()

The **global performances can be improved avoiding to flip the entire display** at each
loop by using the ``pygame.display.update()`` function.

.. code-block:: python

   while True:

       # Draw the slider
       rects = slider.draw(surface)

       # Update only the dirty rectangles of the display
       pygame.display.update(rects)

.. note:: the ``surface`` parameter of the ``draw()`` method is optional, it is used to
          clear/hide the slider when it is necessary and may be mandatory if the surface
          has changed.

Custom rendering using ImSliderRenderer
---------------------------------------

If you want to customize slider rendering you could provide a ``ImSliderRenderer``
instance at ``ImSlider`` construction.

.. code-block:: python

    slider = ImSlider(size, renderer=ImSliderRenderer.DARK)

Here is the list of default renderers provided with ``pygame-imslider``:

- ImSliderRenderer.DEFAULT
- ImSliderRenderer.DARK

A custom ``ImSliderRenderer`` can be built using following constructor :

.. code-block:: python

    renderer = ImSliderRenderer(
        # RGB tuple for arrow color (one tuple per state: released, pressed).
        ((255, 255, 255), (54, 54, 54)),
        # RGB tuple for page-dot color (one tuple per state: released, pressed).
        ((120, 120, 120), (54, 54, 54)),
        # RGB tuple for slide color.
        (242, 195, 195),
        # RGB tuple for selected image color.
        (245, 95, 76),
        # RGB tuple for selected page-dot color.
        (255, 255, 255),
        # RGB tuple for background color.
        (32, 135, 156)
        )

You can also create your own renderer. Just override ``ImSliderRenderer`` class and
override any of the following methods:

- **draw_arrow(surface, arrow)**: Draw an arrow.
- **draw_arrow_state(surface, arrow)**: Draw arrow state.
- **draw_dot(surface, dot)**: Draw a dot.
- **draw_dot_state(surface, dot)**: Draw page-dot state
- **draw_slide(surface, slide)**: Draw a slide.
- **draw_slide_state(surface, slide)**: Draw slide state.
- **draw_background(surface)**: Draw background.

Getting/Setting data
--------------------

Several information can be retrieved from the slider:

.. code-block:: python

    slider = ImSlider(...)

    # Load a sequence of image files.
    slider.load_images(['image1.png', 'image2.png', 'image3.png'])

    # Get a pygame.Rect object in which the slider is included.
    slider.get_rect()

    # Get the current pygame image (optionally resized).
    slider.get_image(resized=False)

    # Get the current index.
    slider.get_index()

    # Set the current index.
    slider.set_index(2)
    
    # Hide left and right arrows
    slider.set_arrows_visible(False)


Run examples
------------

Several examples are provided with the **pygame_imslider** library.
To run the examples, simply execute these commands in a terminal:

.. code-block:: bash

    python -m pygame_imslider.examples.default
    python -m pygame_imslider.examples.multiple
    python -m pygame_imslider.examples.one_per_move
    python -m pygame_imslider.examples.small_loop
    python -m pygame_imslider.examples.focus
    python -m pygame_imslider.examples.fade

Contributing
------------

If you develop you own renderer please share it ! I will keep a collection of
rendering class in this repository. Don't hesitate to report bug, feedback,
suggestion into the repository issues section.


.. |PythonVersions| image:: https://img.shields.io/badge/python-3.6+-red.svg
   :target: https://www.python.org/downloads
   :alt: Python 3.6+

.. |PypiPackage| image:: https://badge.fury.io/py/pygame-imslider.svg
   :target: https://pypi.org/project/pygame-imslider
   :alt: PyPi package

.. |Downloads| image:: https://img.shields.io/pypi/dm/pygame-imslider?color=purple
   :target: https://pypi.org/project/pygame-imslider
   :alt: PyPi downloads

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/anxuae/pygame-imslider",
    "name": "pygame-imslider",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "pygame,widget",
    "author": "Antoine Rousseaux",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/16/7f/696fc9809cf8a5bae15715465f8ad1f01d2f701ee1aec93fa56b73b629db/pygame-imslider-1.0.2.tar.gz",
    "platform": "unix",
    "description": "pygame-imslider\n---------------\n\n|PythonVersions| |PypiPackage| |Downloads|\n\nFlexible images slider for Pygame engine.\n\nDefault\n^^^^^^^\n\n.. image:: https://raw.githubusercontent.com/anxuae/pygame-imslider/master/screenshots/default.gif\n   :align: center\n   :alt: default\n\n.. code-block:: python\n\n   slider = ImSlider((800, 300))\n\nMultiple Slides\n^^^^^^^^^^^^^^^\n\n.. image:: https://raw.githubusercontent.com/anxuae/pygame-imslider/master/screenshots/multiple.gif\n   :align: center\n   :alt: multiple\n\n.. code-block:: python\n\n   slider = ImSlider((800, 300), per_page=3, rewind=True)\n\n1 Slide Per Move\n^^^^^^^^^^^^^^^^\n\n.. image:: https://raw.githubusercontent.com/anxuae/pygame-imslider/master/screenshots/one_per_move.gif\n   :align: center\n   :alt: one_per_move\n\n.. code-block:: python\n\n   slider = ImSlider((800, 300), stype=STYPE_LOOP, per_page=3, per_move=1)\n\nFocus Center\n^^^^^^^^^^^^\n\n.. image:: https://raw.githubusercontent.com/anxuae/pygame-imslider/master/screenshots/focus.gif\n   :align: center\n   :alt: focus\n\n.. code-block:: python\n\n   slider = ImSlider((800, 300), stype=STYPE_LOOP, per_page=3, per_move=2, focus='center')\n\nFade Transition\n^^^^^^^^^^^^^^^\n\n.. image:: https://raw.githubusercontent.com/anxuae/pygame-imslider/master/screenshots/fade.gif\n   :align: center\n   :alt: fade\n\n.. code-block:: python\n\n   slider = ImSlider((800, 300), stype=STYPE_FADE, rewind=True, focus=False)\n\nInstall\n-------\n\n::\n\n    $ pip3 install pygame-imslider\n\nBasic usage\n-----------\n\n``ImSlider`` only require a pygame surface to be displayed on and a index consumer function, as\nin the following example :\n\n.. code-block:: python\n\n    from pygame_imslider import *\n\n    def consumer(index):\n        print('Current index : %s' % index)\n\n    # Initializes and activates ImSlider\n    slider = ImSlider((300, 100), callback=consumer)\n    slider.load_images(['image1.png', 'image2.png', 'image3.png',])\n\nThe slider has the following optional parameters:\n\n- **stype**: determine a slider type: STYPE_SLIDE, STYPE_LOOP or STYPE_FADE\n- **per_page**: determine how many slides should be displayed per page. Ignored if\n  stype=STYPE_FADE.\n- **per_move**: determine how many slides should be moved when a slider goes\n  to next or perv. Ignored if stype=STYPE_FADE.\n- **focus**: determine which slide should be focused if there are multiple\n  slides in a page. A string \"center\" is acceptable for centering slides.\n- **rewind**: whether to rewind a slider before the first slide or after the\n  last one. Ignored if stype=STYPE_LOOP.\n- **speed**: transition duration in seconds.\n- **renderer**: a ImSliderRenderer to customize colors of the slider\n- **callback**: callback called each time the selection is changed.\n\nEvent management\n----------------\n\nA ``ImSlider`` object handles the following pygame event :\n\n- **MOUSEBUTTONDOWN**\n- **MOUSEBUTTONUP**\n- **FINGERDOWN**\n- **FINGERUP**\n- **KEYDOWN**\n- **KEYUP**\n- **JOYHATMOTION**\n\nIn order to process those events, slider instance event handling method should be called like\nin the following example:\n\n.. code-block:: python\n\n    while True:\n\n        events = pygame.event.get()\n\n        # Update internal variables\n        slider.update(events)\n\n        # Draw the slider\n        slider.draw(surface)\n\n        #\n        # Perform other tasks here\n        #\n\n        # Update the display\n        pygame.display.flip()\n\nThe **global performances can be improved avoiding to flip the entire display** at each\nloop by using the ``pygame.display.update()`` function.\n\n.. code-block:: python\n\n   while True:\n\n       # Draw the slider\n       rects = slider.draw(surface)\n\n       # Update only the dirty rectangles of the display\n       pygame.display.update(rects)\n\n.. note:: the ``surface`` parameter of the ``draw()`` method is optional, it is used to\n          clear/hide the slider when it is necessary and may be mandatory if the surface\n          has changed.\n\nCustom rendering using ImSliderRenderer\n---------------------------------------\n\nIf you want to customize slider rendering you could provide a ``ImSliderRenderer``\ninstance at ``ImSlider`` construction.\n\n.. code-block:: python\n\n    slider = ImSlider(size, renderer=ImSliderRenderer.DARK)\n\nHere is the list of default renderers provided with ``pygame-imslider``:\n\n- ImSliderRenderer.DEFAULT\n- ImSliderRenderer.DARK\n\nA custom ``ImSliderRenderer`` can be built using following constructor :\n\n.. code-block:: python\n\n    renderer = ImSliderRenderer(\n        # RGB tuple for arrow color (one tuple per state: released, pressed).\n        ((255, 255, 255), (54, 54, 54)),\n        # RGB tuple for page-dot color (one tuple per state: released, pressed).\n        ((120, 120, 120), (54, 54, 54)),\n        # RGB tuple for slide color.\n        (242, 195, 195),\n        # RGB tuple for selected image color.\n        (245, 95, 76),\n        # RGB tuple for selected page-dot color.\n        (255, 255, 255),\n        # RGB tuple for background color.\n        (32, 135, 156)\n        )\n\nYou can also create your own renderer. Just override ``ImSliderRenderer`` class and\noverride any of the following methods:\n\n- **draw_arrow(surface, arrow)**: Draw an arrow.\n- **draw_arrow_state(surface, arrow)**: Draw arrow state.\n- **draw_dot(surface, dot)**: Draw a dot.\n- **draw_dot_state(surface, dot)**: Draw page-dot state\n- **draw_slide(surface, slide)**: Draw a slide.\n- **draw_slide_state(surface, slide)**: Draw slide state.\n- **draw_background(surface)**: Draw background.\n\nGetting/Setting data\n--------------------\n\nSeveral information can be retrieved from the slider:\n\n.. code-block:: python\n\n    slider = ImSlider(...)\n\n    # Load a sequence of image files.\n    slider.load_images(['image1.png', 'image2.png', 'image3.png'])\n\n    # Get a pygame.Rect object in which the slider is included.\n    slider.get_rect()\n\n    # Get the current pygame image (optionally resized).\n    slider.get_image(resized=False)\n\n    # Get the current index.\n    slider.get_index()\n\n    # Set the current index.\n    slider.set_index(2)\n    \n    # Hide left and right arrows\n    slider.set_arrows_visible(False)\n\n\nRun examples\n------------\n\nSeveral examples are provided with the **pygame_imslider** library.\nTo run the examples, simply execute these commands in a terminal:\n\n.. code-block:: bash\n\n    python -m pygame_imslider.examples.default\n    python -m pygame_imslider.examples.multiple\n    python -m pygame_imslider.examples.one_per_move\n    python -m pygame_imslider.examples.small_loop\n    python -m pygame_imslider.examples.focus\n    python -m pygame_imslider.examples.fade\n\nContributing\n------------\n\nIf you develop you own renderer please share it ! I will keep a collection of\nrendering class in this repository. Don't hesitate to report bug, feedback,\nsuggestion into the repository issues section.\n\n\n.. |PythonVersions| image:: https://img.shields.io/badge/python-3.6+-red.svg\n   :target: https://www.python.org/downloads\n   :alt: Python 3.6+\n\n.. |PypiPackage| image:: https://badge.fury.io/py/pygame-imslider.svg\n   :target: https://pypi.org/project/pygame-imslider\n   :alt: PyPi package\n\n.. |Downloads| image:: https://img.shields.io/pypi/dm/pygame-imslider?color=purple\n   :target: https://pypi.org/project/pygame-imslider\n   :alt: PyPi downloads\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Flexible images slider highly customizable for pygame.",
    "version": "1.0.2",
    "project_urls": {
        "Download": "https://github.com/anxuae/pygame-imslider/archive/1.0.2.tar.gz",
        "Homepage": "https://github.com/anxuae/pygame-imslider"
    },
    "split_keywords": [
        "pygame",
        "widget"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9af515fdb3c66891ef44570147205d4b266ac2de01dba386c906f240db28d845",
                "md5": "9dc7d48af8956b34299e0dbe0a986fa2",
                "sha256": "7cb68d72fe32fe064c04797fc35b3611315c67b11e7c031c69443b49e43d8dd3"
            },
            "downloads": -1,
            "filename": "pygame_imslider-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9dc7d48af8956b34299e0dbe0a986fa2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 156727,
            "upload_time": "2023-05-28T12:23:12",
            "upload_time_iso_8601": "2023-05-28T12:23:12.861383Z",
            "url": "https://files.pythonhosted.org/packages/9a/f5/15fdb3c66891ef44570147205d4b266ac2de01dba386c906f240db28d845/pygame_imslider-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "167f696fc9809cf8a5bae15715465f8ad1f01d2f701ee1aec93fa56b73b629db",
                "md5": "176468eed57bc1dee23ead20d97b4329",
                "sha256": "b999935ba94952230e79970ea9d990ac7d1f48d64da959ea43fecba64f1fabd8"
            },
            "downloads": -1,
            "filename": "pygame-imslider-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "176468eed57bc1dee23ead20d97b4329",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 152473,
            "upload_time": "2023-05-28T12:23:14",
            "upload_time_iso_8601": "2023-05-28T12:23:14.556963Z",
            "url": "https://files.pythonhosted.org/packages/16/7f/696fc9809cf8a5bae15715465f8ad1f01d2f701ee1aec93fa56b73b629db/pygame-imslider-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-28 12:23:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "anxuae",
    "github_project": "pygame-imslider",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pygame-imslider"
}
        
Elapsed time: 0.53086s