cgozenity 0.1.1
python wrapper for ncruces/zenity
License: MIT

# CGo-Zenity

<p align="center">
  <a href="https://github.com/360modder/cgozenity/actions"><img src="https://github.com/360modder/cgozenity/actions/workflows/tests.yml/badge.svg" alt="tests Workflow"></a>
  <a href="https://github.com/360modder/cgozenity/actions"><img src="https://github.com/360modder/cgozenity/actions/workflows/build-libraries.yml/badge.svg" alt="build-libraries Workflow"></a>
  <a href="LICENSE" title="License: MIT"><img src="https://img.shields.io/badge/License-MIT-blue.svg"></a>
  <a href="https://github.com/360modder/cgozenity"><img src="https://img.shields.io/github/repo-size/360modder/cgozenity.svg" alt="Repository Size"></a>
  <a href="https://pypi.org/project/cgozenity"><img src="https://img.shields.io/pypi/v/cgozenity.svg" alt="PyPi Package Version"></a>
  <a href="https://www.nuget.org/packages/cgozenity-csharp"><img src="https://img.shields.io/nuget/v/cgozenity-csharp.svg" alt="Nuget Package Version"></a>
  <a href="https://www.npmjs.com/package/cgozenity"><img src="https://img.shields.io/npm/v/cgozenity.svg" alt="NPM Package Version"></a>
</p>

cgozenity provides functional wrappers for [ncruces/zenity](https://github.com/ncruces/zenity) (written in go). cgozenity provides wrappers for languages such as C, C++, Python, C#, JavaScript, Java and Lua. Wrapper packages are only compiled to support *linux/amd64*, *windows/amd64* and *darwin/amd64* architecture. Checkout [Makefile](https://github.com/360modder/cgozenity/blob/main/Makefile) and [build-libraries.yml](https://github.com/360modder/cgozenity/blob/main/.github/workflows/build-libraries.yml) for building libraries and wrappers on different platforms.

| Language   | Wrapper Type                                                    | Packages                                                      | Examples                                                                                             |
|------------|-----------------------------------------------------------------|---------------------------------------------------------------|------------------------------------------------------------------------------------------------------|
| C/C++      | [cgo](https://pkg.go.dev/cmd/cgo)                               | [github.com](https://github.com/360modder/cgozenity/releases) | [examples](https://github.com/360modder/cgozenity/tree/main/examples)                                |
| Python     | [ctypes](https://docs.python.org/3/library/ctypes.html)         | [pypi.org](https://pypi.org/project/cgozenity)                | [example.py](https://github.com/360modder/cgozenity/blob/main/cgozenity-python/example.py)           |
| C#         | [swig](http://www.swig.org)                                     | [nuget.org](https://www.nuget.org/packages/cgozenity-csharp)  | [example.cs](https://github.com/360modder/cgozenity/blob/main/cgozenity-csharp/example/example.cs)   |
| JavaScript | [node-ffi-napi](https://github.com/node-ffi-napi/node-ffi-napi) | [npmjs.com](https://www.npmjs.com/package/cgozenity)          | [example.js](https://github.com/360modder/cgozenity/blob/main/cgozenity-javascript/example.js)       |
| Java       | [swig](http://www.swig.org)                                     | [github.com](https://github.com/360modder/cgozenity/releases) | [example.java](https://github.com/360modder/cgozenity/blob/main/cgozenity-java/example/example.java) |
| Lua        | [swig](http://www.swig.org)                                     | [github.com](https://github.com/360modder/cgozenity/releases) | [example.lua](https://github.com/360modder/cgozenity/blob/main/cgozenity-lua/example.lua)            |

## C Example

```c
#include <stdio.h>
#include <stdbool.h>
#include <cgozenity/cgozenity.h>

int main(int argc, char const *argv[])
{
    bool proceed = zenQuestion("Are you sure you want to proceed?", "Question");

    if (proceed) {
        printf("user clicked on ok button\n");
    } else {
        printf("user canceled the dialog\n");
    }

    return 0;
}
```

- Static Linking

```bash
gcc -fPIC -c -Iinclude -Ilib/windows/static -o example.o example.c
gcc -o example.exe example.o lib/windows/static/libzenity-c.a
# enable -pthreads in linux
```

- Dynamic Linking

```bash
gcc -fPIC -c -Iinclude -Ilib/windows/dynamic -o example.o example.c
gcc -Llib/windows/dynamic -lzenity-c -o example.exe example.o
```

- Executing Program

```bash
# set library path in linux
# LD_LIBRARY_PATH=lib/linux/dynamic

> example.exe
  user clicked on ok button
```

<p align="center">
  <img src="https://raw.githubusercontent.com/wiki/ncruces/zenity/screenshots/question_windows.png" alt="C/C++ Example" height=200>
</p>

## API

Check [cgozenity/examples](https://github.com/360modder/cgozenity/tree/main/examples) directory for c examples. All other languages wrappers have same api.

- Arguments Definations
    - text -> *string*: the message text to be displayed in dialog.
    - title -> *string*: title for dialog window.
    - items -> *string*: list of items to displayed in dialog separated by a **,** symbol.
    - filter_name -> *string*: name for the filter to be shown in the file dialog.
    - filters -> *string*: list of filters to be applied in file dialog separated by a **,** symbol.
    - filename -> *string*: default file to select on opening of file dialog.
    - value -> *int*: value of progress bar, closed interval (0-100).
    - millisec -> *int*: number of milli seconds to sleep.

- Notifications
    - [zenNotify](https://github.com/360modder/cgozenity/blob/main/examples/notify.c#L5)(*text*, *title*): push a system notification.

- Messages
    - [zenInfo](https://github.com/360modder/cgozenity/blob/main/examples/message.c#L6)(*text*, *title*): display information dialog.
    - [zenWarning](https://github.com/360modder/cgozenity/blob/main/examples/message.c#L7)(*text*, *title*): display warning dialog.
    - [zenError](https://github.com/360modder/cgozenity/blob/main/examples/message.c#L8)(*text*, *title*): display error dialog.
    - [zenQuestion](https://github.com/360modder/cgozenity/blob/main/examples/message.c#L11)(*text*, *title*) -> *bool*: display question dialog.

- Text Entry
    - [zenEntry](https://github.com/360modder/cgozenity/blob/main/examples/entry.c#L6)(*text*, *title*) -> *string*: display text entry dialog.
    - [zenPassword](https://github.com/360modder/cgozenity/blob/main/examples/password.c#L6)(*title*) -> *string*: display the password entry dialog.

- Selections
    - [zenList](https://github.com/360modder/cgozenity/blob/main/examples/list.c#L6-L10)(*items*, *text*, *title*) -> *string*: display list of items in a dialog.
    - [zenSelectColor](https://github.com/360modder/cgozenity/blob/main/examples/color.c#L6)(*title*) -> *struct*: display a color selection palette dialog.

- File Selection Dialogs
    - [zenSelectDirectory](https://github.com/360modder/cgozenity/blob/main/examples/file.c#L11)() -> *string*: display single directory selection dialog.
    - [zenSelectFile](https://github.com/360modder/cgozenity/blob/main/examples/file.c#L15)() -> *string*: display single file selection dialog.
    - [zenSelectFileWithFilter](https://github.com/360modder/cgozenity/blob/main/examples/file.c#L19)(*filter_name*, *filters*, *filename*) -> *string*: display single file selection dialog with one custom filter.
    - [zenSelectFileMultiple](https://github.com/360modder/cgozenity/blob/main/examples/file.c#L23)() -> *string*: display multiple file selection dialog.
    - [zenSelectFileMultipleWithFilter](https://github.com/360modder/cgozenity/blob/main/examples/file.c#L33)(*filter_name*, *filters*, *filename*) -> *string*: display multiple file selection dialog with one custom filter.
    - [zenSelectFileSave](https://github.com/360modder/cgozenity/blob/main/examples/file.c#L43)() -> *string*: display save file selection dialog.
    - [zenSelectFileSaveWithFilter](https://github.com/360modder/cgozenity/blob/main/examples/file.c#L47)(*filter_name*, *filters*, *filename*) -> *string*: display save file selection dialog with one custom filter.

- Progress Bars
    - [zenProgress](https://github.com/360modder/cgozenity/blob/main/examples/progress.c#L7)(*title*): display progress indication bar in a dialog.
    - [zenProgressPulsate](https://github.com/360modder/cgozenity/blob/main/examples/progress.c#L24)(*title*): display progress indication bar with a pulsating animation in a dialog.

- Utilities
    - [zenProgressUpdate](https://github.com/360modder/cgozenity/blob/main/examples/progress.c#L9-L21)(*value*, *title*): updates value and text of progress bar.
    - [zenProgressPulsateUpdate](https://github.com/360modder/cgozenity/blob/main/examples/progress.c#L26-38)(*value*, *title*): updates value and text of pulsating progress bar.
    - [zenSleep](https://github.com/360modder/cgozenity/blob/main/examples/progress.c#L10)(*millisec*): number of milliseconds to sleep.

## Building From Source

Requires*

- [Go](https://go.dev/dl)
- [gcc](https://www.mingw-w64.org/downloads)
- [swig](http://www.swig.org)
- cgozenity-python
    - [python](https://www.python.org/downloads)
- cgozenity-csharp
    - [.NET](https://dotnet.microsoft.com/en-us/download)
- cgozenity-javascript
    - [nodejs](https://nodejs.org/en/download)
- cgozenity-java
    - [JDK](https://www.oracle.com/java/technologies/downloads)
- cgozenity-lua
    - [lua](https://www.lua.org/download.html)
    - [luarocks](https://luarocks.org/#quick-start)

First clone cgozenity repo.

```bash
git clone https://github.com/360modder/cgozenity.git
```

Then build core c libraries.

```bash
make static-c PLATFORM=windows
make windows-c
```

Checkout [Makefile](https://github.com/360modder/cgozenity/blob/main/Makefile) and [build-libraries.yml](https://github.com/360modder/cgozenity/blob/main/.github/workflows/build-libraries.yml) for building libraries and wrappers on different platforms.

## License

&copy; 2022 360modder

This repository is licensed under the MIT license. See LICENSE for details.