desktop-wrapper


Namedesktop-wrapper JSON
Version 0.0.12 PyPI version JSON
download
home_page
SummaryA Python package to Build Python Desktop applications using React as GUI.
upload_time2023-12-21 19:13:54
maintainer
docs_urlNone
author
requires_python>=3.8
license
keywords interface gui react desktop python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Desktop Wrapper Tool

Build Python + React desktop applications in seconds

Dependencies:
* [Pywebview](https://pywebview.flowrl.com/)
* [Flask](https://pypi.org/project/Flask/)
* [React](https://react.dev/)


### Installation

```
$ pip install desktop-wrapper
```

### Create a new app

```bash
# With the cli tool
$ dw-create-app your_app_name

# With the python module
from desktop_wrapper import create_new_app

create_new_app("your_app_name")
```


### Use __BaseApp__ and add the assets and templates folders

```python
from desktop_wrapper import BaseApp

app = BaseApp(
    'File Recovery',
    __name__,
    static_folder='./your_app_name/assets',
    template_folder='./your_app_name/templates'
)
```

### Add your custom functions with the __@app.bind__ decorator

```python
@app.bind()
def custom_function(name):
    # Do some stuff
    return "Finish"
```

### Start the app and you are ready to go

```python
app.start(gui=True, debug=True, port='5000')
```

![](screenshots/screenshot-1.PNG)

You can also check at http://localhost:5000

### Full Code

```python
from desktop_wrapper import BaseApp

app = BaseApp(
    'My App',
    __name__,
    static_folder='./your_app_name/assets',
    template_folder='./your_app_name/templates'
)

@app.bind()
def custom_function(name):
    print(name)
    return "Finish"

if __name__ = '__main__':
    app.start(gui=True, debug=True, port='5000')

```

## AutoGenerated Files

Each custom function will be translated as javascript interface modules under __your_app_name/assets/js/generated__.

those will follow the pattern
```javascript
/*
Autogenerated File, any change will be overwriten at reload
TODO:
    Add a way to block modifications when Debugging
*/
async function customFunctionInterface(value) {
    try {
        console.log(pywebview);
        let res = await pywebview.api.custom_function(value);
        return res;
    } catch (err) {
        let res = await fetch('/api/v1/customFunction', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({values: [value]})
        });
        if (res.status == 200) {
            return (await res.json()).response;
        }
    }
}

export {
    customFunctionInterface
}

```

This allows the interface to:
* First, try to fetch the pywebview object
* Then if the pywebview is not available it can perform a request to the Flask http server

## Functions List (Javascript)

__your_app_name/assets/js/functions.js__

Contains the organized map of custom functions accesible for the React Components.

Note: This file is autogenerated please do not modify

```javascript
/*
Auto Generated File
Do not modify this file, it could break the app
List of Available custom functions imported from the Autogenerated interfaces
*/
import { customFunctionInterface } from './generated/customFunction.js';

const customFunction = (value) => { return customFunctionInterface(value) };

const FunctionsMap = {
    customFunction: customFunction
}


export {
    customFunction,
    FunctionsMap
}

```

You can then use this map as following in the __*editable Files*__
 __your_app_name/assets/js/App.js__

```javascript
import { FunctionsMap } from './functions.js';

class App extends React.Component {
    ...
    render() {
        ...
        return (
            <div>
                ...
                <button onClick={()=>FunctionsMap.customFunction('value')}></button>
                ...
            </div>
        )
    }
}
...
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "desktop-wrapper",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "interface,gui,react,Desktop,Python",
    "author": "",
    "author_email": "Daniel Rodriguez <danrodcastillo1994@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/fe/96/d43ef72376b5cbd4d59a83f36c77162ebe67e5022cb58f3d400833329a5b/desktop_wrapper-0.0.12.tar.gz",
    "platform": null,
    "description": "# Desktop Wrapper Tool\r\n\r\nBuild Python + React desktop applications in seconds\r\n\r\nDependencies:\r\n* [Pywebview](https://pywebview.flowrl.com/)\r\n* [Flask](https://pypi.org/project/Flask/)\r\n* [React](https://react.dev/)\r\n\r\n\r\n### Installation\r\n\r\n```\r\n$ pip install desktop-wrapper\r\n```\r\n\r\n### Create a new app\r\n\r\n```bash\r\n# With the cli tool\r\n$ dw-create-app your_app_name\r\n\r\n# With the python module\r\nfrom desktop_wrapper import create_new_app\r\n\r\ncreate_new_app(\"your_app_name\")\r\n```\r\n\r\n\r\n### Use __BaseApp__ and add the assets and templates folders\r\n\r\n```python\r\nfrom desktop_wrapper import BaseApp\r\n\r\napp = BaseApp(\r\n    'File Recovery',\r\n    __name__,\r\n    static_folder='./your_app_name/assets',\r\n    template_folder='./your_app_name/templates'\r\n)\r\n```\r\n\r\n### Add your custom functions with the __@app.bind__ decorator\r\n\r\n```python\r\n@app.bind()\r\ndef custom_function(name):\r\n    # Do some stuff\r\n    return \"Finish\"\r\n```\r\n\r\n### Start the app and you are ready to go\r\n\r\n```python\r\napp.start(gui=True, debug=True, port='5000')\r\n```\r\n\r\n![](screenshots/screenshot-1.PNG)\r\n\r\nYou can also check at http://localhost:5000\r\n\r\n### Full Code\r\n\r\n```python\r\nfrom desktop_wrapper import BaseApp\r\n\r\napp = BaseApp(\r\n    'My App',\r\n    __name__,\r\n    static_folder='./your_app_name/assets',\r\n    template_folder='./your_app_name/templates'\r\n)\r\n\r\n@app.bind()\r\ndef custom_function(name):\r\n    print(name)\r\n    return \"Finish\"\r\n\r\nif __name__ = '__main__':\r\n    app.start(gui=True, debug=True, port='5000')\r\n\r\n```\r\n\r\n## AutoGenerated Files\r\n\r\nEach custom function will be translated as javascript interface modules under __your_app_name/assets/js/generated__.\r\n\r\nthose will follow the pattern\r\n```javascript\r\n/*\r\nAutogenerated File, any change will be overwriten at reload\r\nTODO:\r\n    Add a way to block modifications when Debugging\r\n*/\r\nasync function customFunctionInterface(value) {\r\n    try {\r\n        console.log(pywebview);\r\n        let res = await pywebview.api.custom_function(value);\r\n        return res;\r\n    } catch (err) {\r\n        let res = await fetch('/api/v1/customFunction', {\r\n            method: 'POST',\r\n            headers: { 'Content-Type': 'application/json' },\r\n            body: JSON.stringify({values: [value]})\r\n        });\r\n        if (res.status == 200) {\r\n            return (await res.json()).response;\r\n        }\r\n    }\r\n}\r\n\r\nexport {\r\n    customFunctionInterface\r\n}\r\n\r\n```\r\n\r\nThis allows the interface to:\r\n* First, try to fetch the pywebview object\r\n* Then if the pywebview is not available it can perform a request to the Flask http server\r\n\r\n## Functions List (Javascript)\r\n\r\n__your_app_name/assets/js/functions.js__\r\n\r\nContains the organized map of custom functions accesible for the React Components.\r\n\r\nNote: This file is autogenerated please do not modify\r\n\r\n```javascript\r\n/*\r\nAuto Generated File\r\nDo not modify this file, it could break the app\r\nList of Available custom functions imported from the Autogenerated interfaces\r\n*/\r\nimport { customFunctionInterface } from './generated/customFunction.js';\r\n\r\nconst customFunction = (value) => { return customFunctionInterface(value) };\r\n\r\nconst FunctionsMap = {\r\n    customFunction: customFunction\r\n}\r\n\r\n\r\nexport {\r\n    customFunction,\r\n    FunctionsMap\r\n}\r\n\r\n```\r\n\r\nYou can then use this map as following in the __*editable Files*__\r\n __your_app_name/assets/js/App.js__\r\n\r\n```javascript\r\nimport { FunctionsMap } from './functions.js';\r\n\r\nclass App extends React.Component {\r\n    ...\r\n    render() {\r\n        ...\r\n        return (\r\n            <div>\r\n                ...\r\n                <button onClick={()=>FunctionsMap.customFunction('value')}></button>\r\n                ...\r\n            </div>\r\n        )\r\n    }\r\n}\r\n...\r\n```\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A Python package to Build Python Desktop applications using React as GUI.",
    "version": "0.0.12",
    "project_urls": {
        "Homepage": "https://github.com/Danucas/desktop_wrapper"
    },
    "split_keywords": [
        "interface",
        "gui",
        "react",
        "desktop",
        "python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fe96d43ef72376b5cbd4d59a83f36c77162ebe67e5022cb58f3d400833329a5b",
                "md5": "dcdd593eb34beb7778039c8b2f89fef7",
                "sha256": "1abb47c50ec13da39baddcf98c28eb2112d723c9c2f981dff2f7502515454b7e"
            },
            "downloads": -1,
            "filename": "desktop_wrapper-0.0.12.tar.gz",
            "has_sig": false,
            "md5_digest": "dcdd593eb34beb7778039c8b2f89fef7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 25010,
            "upload_time": "2023-12-21T19:13:54",
            "upload_time_iso_8601": "2023-12-21T19:13:54.526353Z",
            "url": "https://files.pythonhosted.org/packages/fe/96/d43ef72376b5cbd4d59a83f36c77162ebe67e5022cb58f3d400833329a5b/desktop_wrapper-0.0.12.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-21 19:13:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Danucas",
    "github_project": "desktop_wrapper",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "desktop-wrapper"
}
        
Elapsed time: 0.15454s