observable-variable


Nameobservable-variable JSON
Version 0.0.1 PyPI version JSON
download
home_page
SummaryBind functions to a value. When the value changes, the functions are called.
upload_time2023-10-02 16:32:42
maintainer
docs_urlNone
authorAndré Herber
requires_python
license
keywords python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# observable_variable

[GitHub](https://github.com/ICreedenI/observable_variable) | [PyPI](https://pypi.org/project/observable-variable/)  





Do you want to call a function every time a variable gets a new value?

This package allows you to create an observable. This instance of the `ObservableVariable` class has an attribute `value`. If you set a new value to this attribute, every callback will be called. You can add callbacks by calling the method `bind` with the function and arguments to be passed to the callback. Removing is as easy as to call `unbind` with the same callback and arguments or by calling `unbind_all` to remove all bound callbacks for this observable. By default the new value will be the first argument to be passed to the callback. To disable this set the attribute `send_value` to False.



```python

obs = ObservableVariable()



def my_callback(value, first_arg, second_arg):

    print("New value:", value)

    print("First argument:", first_arg)

    print("Second argument:", second_arg)



# binding a callback

obs.bind(my_callback, "arg 1", "arg 2")

obs.value = 1

>>> New value: 1

>>> First argument: arg 1

>>> Second argument: arg 2



# unbinding a specific function-args-combination

obs.unbind(my_callback, "arg 1", "arg 2")

obs.value = 2

# callback not called



obs.bind(lambda value: print(value))

# unbind all callbacks

obs.unbind_all()

obs.value = 3

# again callback not called



# deactivating the sending of the new value as the first argument

obs.send_value = False

```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "observable-variable",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "python",
    "author": "Andr\u00e9 Herber",
    "author_email": "andre.herber.programming@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/51/e4/c1ed021cd562732e7987f67d7205a0c59126e63702821c3230784b573eab/observable_variable-0.0.1.tar.gz",
    "platform": null,
    "description": "\n# observable_variable\n\n[GitHub](https://github.com/ICreedenI/observable_variable) | [PyPI](https://pypi.org/project/observable-variable/)  \n\n\n\n\n\nDo you want to call a function every time a variable gets a new value?\n\nThis package allows you to create an observable. This instance of the `ObservableVariable` class has an attribute `value`. If you set a new value to this attribute, every callback will be called. You can add callbacks by calling the method `bind` with the function and arguments to be passed to the callback. Removing is as easy as to call `unbind` with the same callback and arguments or by calling `unbind_all` to remove all bound callbacks for this observable. By default the new value will be the first argument to be passed to the callback. To disable this set the attribute `send_value` to False.\n\n\n\n```python\n\nobs = ObservableVariable()\n\n\n\ndef my_callback(value, first_arg, second_arg):\n\n    print(\"New value:\", value)\n\n    print(\"First argument:\", first_arg)\n\n    print(\"Second argument:\", second_arg)\n\n\n\n# binding a callback\n\nobs.bind(my_callback, \"arg 1\", \"arg 2\")\n\nobs.value = 1\n\n>>> New value: 1\n\n>>> First argument: arg 1\n\n>>> Second argument: arg 2\n\n\n\n# unbinding a specific function-args-combination\n\nobs.unbind(my_callback, \"arg 1\", \"arg 2\")\n\nobs.value = 2\n\n# callback not called\n\n\n\nobs.bind(lambda value: print(value))\n\n# unbind all callbacks\n\nobs.unbind_all()\n\nobs.value = 3\n\n# again callback not called\n\n\n\n# deactivating the sending of the new value as the first argument\n\nobs.send_value = False\n\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Bind functions to a value. When the value changes, the functions are called.",
    "version": "0.0.1",
    "project_urls": null,
    "split_keywords": [
        "python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3f0a1926ef6f45b637dbf2f2d7f60a6a56695423e0b8fb9a2370cbe71f837a5d",
                "md5": "21bc66c6074a5edd5a6ac0d3115193c3",
                "sha256": "325e0fde670d3b1b502c1ceaff4f8b2c155e3794f04801a4b7253347ee5b2018"
            },
            "downloads": -1,
            "filename": "observable_variable-0.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "21bc66c6074a5edd5a6ac0d3115193c3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 4102,
            "upload_time": "2023-10-02T16:32:39",
            "upload_time_iso_8601": "2023-10-02T16:32:39.767746Z",
            "url": "https://files.pythonhosted.org/packages/3f/0a/1926ef6f45b637dbf2f2d7f60a6a56695423e0b8fb9a2370cbe71f837a5d/observable_variable-0.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "51e4c1ed021cd562732e7987f67d7205a0c59126e63702821c3230784b573eab",
                "md5": "733109254bf09dbcd2e8333885e6de18",
                "sha256": "7d1244823c5358c3672d20964d368c19e27048a8e1412b0fa9ca8a2585cfd3d7"
            },
            "downloads": -1,
            "filename": "observable_variable-0.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "733109254bf09dbcd2e8333885e6de18",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4050,
            "upload_time": "2023-10-02T16:32:42",
            "upload_time_iso_8601": "2023-10-02T16:32:42.204737Z",
            "url": "https://files.pythonhosted.org/packages/51/e4/c1ed021cd562732e7987f67d7205a0c59126e63702821c3230784b573eab/observable_variable-0.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-02 16:32:42",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "observable-variable"
}
        
Elapsed time: 0.11233s