Skip to main content

A single virtual slider control

Project description

PySinglSlider

PyPI version

PySinglSlider is a customizable, simple single slider widget built with Pygame. Designed for quick setup and theming, it lets you add an interactive slider for Pygame applications that need fine-grained control over a value range.

Features

  • Easily customizable for different themes and styles.
  • Supports adjustable value ranges.
  • Includes event listening for smooth handling of slider interactions.
  • Simple integration into any Pygame-based project.

Installation

Install PySinglSlider via PyPI:

pip install PySinglSlider

Getting Started

Importing and Setting Up the Slider

To integrate PySinglSlider into your Pygame project, follow these steps:

  1. Import PySinglSlider in your Pygame script.
  2. Initialize the slider with optional parameters such as position, value range, initial value, and theme settings.
  3. Handle events and render the slider in your game loop.

Example Usage

Here's a basic example to get started:

import pygame
from PySinglSlider import PySinglSlider

pygame.init()
screen = pygame.display.set_mode((800, 600))
clock = pygame.time.Clock()

# Create slider

slider = PySinglSlider(x=100, y=250, min_value=0, max_value=100, initial_value=50, theme_name='default_theme')

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        # Pass events to the slider
        slider.listen_event(event)

    # Clear the screen
    screen.fill((255, 255, 255))
    
    # Render the slider
    slider.render(screen)
    
    # Display the current slider value
    font = pygame.font.Font(None, 36)
    value_text = font.render(f"Value: {slider.value:.2f}", True, (0, 0, 0))
    screen.blit(value_text, (100, 400))

    pygame.display.flip()
    clock.tick(30)

pygame.quit()

Parameters

  • x (int): X-coordinate for slider position.
  • y (int): Y-coordinate for slider position.
  • min_value (int): Minimum value of the slider range.
  • max_value (int): Maximum value of the slider range.
  • initial_value (int): Starting value of the slider.
  • theme_name (str): Name of the theme folder containing assets (images for handler, bar, etc.).
  • theme_path (str, optional): Custom path to the theme directory if assets are not located in the default theme folder.

Documentation

Methods

load_image(image_name, theme_name, theme_folder_path=None)

Loads an image from the specified theme directory.

get_rect()

Returns the Pygame rectangle (Rect) of the slider bar.

listen_event(event)

Listens to and handles mouse or touch events for updating the slider’s handler position.

get_current_value()

Calculates and returns the slider's current value based on handler position.

render(screen)

Renders the slider's components (bar, handler) on the specified screen.

Asset Customization

To customize the slider's appearance, you can create new images for the slider's handler and bar components in a folder with your chosen theme_name. Place this folder in the theme directory or specify the path using theme_path.

Example Theme Folder Structure

project_root/
├── theme/
│   ├── default_theme/
│      ├── handler.png
│      ├── bar_center.png
│      ├── bar_corner.png
│   └── custom_theme/
│       ├── handler.png
│       ├── bar_center.png
│       ├── bar_corner.png
└── main.py

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Enjoy using PySinglSlider! Contributions, bug reports, and suggestions are welcome.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_singl_slider-1.0.5.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

py_singl_slider-1.0.5-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file py_singl_slider-1.0.5.tar.gz.

File metadata

  • Download URL: py_singl_slider-1.0.5.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for py_singl_slider-1.0.5.tar.gz
Algorithm Hash digest
SHA256 165235d2c0d92560aa80a2d44fb8672e3ec5ca21778900b05bff00256fb325ce
MD5 990b356a9e82102fae29543d120d344b
BLAKE2b-256 e304b9ae3c4cf2e251f48f856907542ea98fd48017fbfbfa8848ae7a855284cc

See more details on using hashes here.

File details

Details for the file py_singl_slider-1.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for py_singl_slider-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c7ae5847b4e5a74b1384885ae607c62044bc1ca4bbd4e29b18333c46e58efa13
MD5 d612f39e52e76e86aced0887ac126444
BLAKE2b-256 62e30a3671d1f74c8c0609ea98394d214bca330dcc6e3599efc6d5bd947a36fc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page