pygrille


Namepygrille JSON
Version 0.3.2 PyPI version JSON
download
home_page
SummaryA quick way to write and visualise any code involving grids of squares in python.
upload_time2023-04-28 10:35:05
maintainer
docs_urlNone
author
requires_python
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Pygrille

Pygrille is a Python library that uses Pygame to make it easier to do many things involving a square grid.

## Installation

Use the package manager [pip](https://pip.pypa.io/en/stable/) to install Pygrille.

```bash
pip install pygrille
```

## Usage

```python
import pygrille

PIXEL_SIZE = 40 # The size of each square in the grid.
GRID_DIMENSIONS = (6, 5) # The number of squares in the x and y directions in the grid.

# Initiate the grid. PIXEL_SIZE and GRID_DIMENSIONS are required and everything else is optional. 
# The extras variable is a list of values that you want contained in each pixel - for example a temporary distance in Dijkstra's algorithm.
grid = pygrille.Grid(PIXEL_SIZE, GRID_DIMENSIONS, extras = ["Hello", "World"], framerate = 60, default_colour = pygrille.random_colour(), border_width = 10)

# Ensures the grid has not been closed each frame. 
# Also updates the newclick and newkey variables (booleans - True if there is a new click or key press) 
# And the lastclick (tuple - grid location of most recent click) and lastkey (string - name of most recent key pressed) variables.
while grid.check_open():

    # If the user clicks on a square, set it to a random colour and set the border to a random colour.
    if grid.new_mouse_up:
        grid[grid.last_mouse_up[0]][grid.last_mouse_up[1]].colour = pygrille.random_colour()
        grid[grid.last_mouse_up[0]][grid.last_mouse_up[1]].extras["Hello"] = "Clicked"
        grid.border_colour = pygrille.random_colour()

    # If the spacebar is pressed, print the status of the extra value "Hello" in the top left pixel.
    if grid.newkey:
        if grid.lastkey == "space":
            print(grid[0][0].extras["Hello"])

    # Draw the grid to the screen
    grid.draw()

    # Keep the grid running.
    grid.tick()

# Once pygrille is closed, finish quitting it.
grid.quit()

```

## Updates

### 0.3.2
* Fixed bug with image sizes when images were used multiple times.

### 0.3.1
* Fixed bug with mouse-down on UI elements.

### 0.3.0
* Added support for border size overrides - this allows for certain border lines to be wider than others.
* Added mouse-down and mouse-over support. Replaced "lastclick" and "newclick" with "last_mouse_up" and "new_mouse_up". Please update any past code that used these attributes to reflect this.

### 0.2.1
* Added a check for clicking UI elements via the Grid.newclick_ui and Grid.clicked_ui attributes.
* Fixed an error in the example code in this README.
* Other minor changes.

### 0.2.0.1
* Reupload due to issue with first upload of 0.2.0.

### 0.2.0  
* Updated grid initialisation.
* Added text as a UI option.
* Added image caching to speed up programs.
* Other code refactoring and minor changes.

### 0.1.0 (Mistakenly uploaded to PyPI as 0.1.1)
* Added the ability to force a window size and set the position of the grid in relation to this as desired.
* Added the possibility for UI elements.
* Added methods to Grid to get global coordinates from grid coordinates or vice-versa
* Other minor changes


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pygrille",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/72/bf/6530238d3c5dc921272b563431a74a0cec29772c762a645c599d4edafe94/pygrille-0.3.2.tar.gz",
    "platform": null,
    "description": "# Pygrille\r\n\r\nPygrille is a Python library that uses Pygame to make it easier to do many things involving a square grid.\r\n\r\n## Installation\r\n\r\nUse the package manager [pip](https://pip.pypa.io/en/stable/) to install Pygrille.\r\n\r\n```bash\r\npip install pygrille\r\n```\r\n\r\n## Usage\r\n\r\n```python\r\nimport pygrille\r\n\r\nPIXEL_SIZE = 40 # The size of each square in the grid.\r\nGRID_DIMENSIONS = (6, 5) # The number of squares in the x and y directions in the grid.\r\n\r\n# Initiate the grid. PIXEL_SIZE and GRID_DIMENSIONS are required and everything else is optional. \r\n# The extras variable is a list of values that you want contained in each pixel - for example a temporary distance in Dijkstra's algorithm.\r\ngrid = pygrille.Grid(PIXEL_SIZE, GRID_DIMENSIONS, extras = [\"Hello\", \"World\"], framerate = 60, default_colour = pygrille.random_colour(), border_width = 10)\r\n\r\n# Ensures the grid has not been closed each frame. \r\n# Also updates the newclick and newkey variables (booleans - True if there is a new click or key press) \r\n# And the lastclick (tuple - grid location of most recent click) and lastkey (string - name of most recent key pressed) variables.\r\nwhile grid.check_open():\r\n\r\n    # If the user clicks on a square, set it to a random colour and set the border to a random colour.\r\n    if grid.new_mouse_up:\r\n        grid[grid.last_mouse_up[0]][grid.last_mouse_up[1]].colour = pygrille.random_colour()\r\n        grid[grid.last_mouse_up[0]][grid.last_mouse_up[1]].extras[\"Hello\"] = \"Clicked\"\r\n        grid.border_colour = pygrille.random_colour()\r\n\r\n    # If the spacebar is pressed, print the status of the extra value \"Hello\" in the top left pixel.\r\n    if grid.newkey:\r\n        if grid.lastkey == \"space\":\r\n            print(grid[0][0].extras[\"Hello\"])\r\n\r\n    # Draw the grid to the screen\r\n    grid.draw()\r\n\r\n    # Keep the grid running.\r\n    grid.tick()\r\n\r\n# Once pygrille is closed, finish quitting it.\r\ngrid.quit()\r\n\r\n```\r\n\r\n## Updates\r\n\r\n### 0.3.2\r\n* Fixed bug with image sizes when images were used multiple times.\r\n\r\n### 0.3.1\r\n* Fixed bug with mouse-down on UI elements.\r\n\r\n### 0.3.0\r\n* Added support for border size overrides - this allows for certain border lines to be wider than others.\r\n* Added mouse-down and mouse-over support. Replaced \"lastclick\" and \"newclick\" with \"last_mouse_up\" and \"new_mouse_up\". Please update any past code that used these attributes to reflect this.\r\n\r\n### 0.2.1\r\n* Added a check for clicking UI elements via the Grid.newclick_ui and Grid.clicked_ui attributes.\r\n* Fixed an error in the example code in this README.\r\n* Other minor changes.\r\n\r\n### 0.2.0.1\r\n* Reupload due to issue with first upload of 0.2.0.\r\n\r\n### 0.2.0  \r\n* Updated grid initialisation.\r\n* Added text as a UI option.\r\n* Added image caching to speed up programs.\r\n* Other code refactoring and minor changes.\r\n\r\n### 0.1.0 (Mistakenly uploaded to PyPI as 0.1.1)\r\n* Added the ability to force a window size and set the position of the grid in relation to this as desired.\r\n* Added the possibility for UI elements.\r\n* Added methods to Grid to get global coordinates from grid coordinates or vice-versa\r\n* Other minor changes\r\n\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A quick way to write and visualise any code involving grids of squares in python.",
    "version": "0.3.2",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ab425a3107fdab6ffb53827e7d48eff298e6d257167e99fa4277141058182262",
                "md5": "0632d9c904f93311748b61d9b9fdfed7",
                "sha256": "4cdc17cd6ae78970387b22f5dbd20d7e640c456ecf8d1ad4cfbb0f021e9705a5"
            },
            "downloads": -1,
            "filename": "pygrille-0.3.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0632d9c904f93311748b61d9b9fdfed7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 8244,
            "upload_time": "2023-04-28T10:35:03",
            "upload_time_iso_8601": "2023-04-28T10:35:03.337058Z",
            "url": "https://files.pythonhosted.org/packages/ab/42/5a3107fdab6ffb53827e7d48eff298e6d257167e99fa4277141058182262/pygrille-0.3.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "72bf6530238d3c5dc921272b563431a74a0cec29772c762a645c599d4edafe94",
                "md5": "e636719d2d5bb41d5394dba3cb6ef775",
                "sha256": "d53818eabee1905387c2c388bfc08c4e2ec1b83e78c0dbe5a772d7fff29bb7e2"
            },
            "downloads": -1,
            "filename": "pygrille-0.3.2.tar.gz",
            "has_sig": false,
            "md5_digest": "e636719d2d5bb41d5394dba3cb6ef775",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7201,
            "upload_time": "2023-04-28T10:35:05",
            "upload_time_iso_8601": "2023-04-28T10:35:05.613280Z",
            "url": "https://files.pythonhosted.org/packages/72/bf/6530238d3c5dc921272b563431a74a0cec29772c762a645c599d4edafe94/pygrille-0.3.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-28 10:35:05",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "pygrille"
}
        
Elapsed time: 0.06058s