sgzentry is a library for python which was inspired by Zenity. When you write scripts, you can use sgzentry to create simple dialogs that interact graphically with the user.
Project description
SGZenity
SGZenity is a library for python which was inspired by Zenity.
When you write scripts, you can use SGZenity to create simple dialogs that interact graphically with the user.
Requirements
- Python 3
- GTK+4
- python3-gi
Installation
Install using pip:
$ pip install sgzenity
Or clone the repo:
$ git clone https://github.com/SoftGeekRo/sgzenity.git
$ cd ./sgzenity
$ python setup.py install
Example
Simple dialog:
API
Simple message
message(title='', text='', width=330, height=120, timeout=None)
Display a simple message
Parameters:
- text (str) โ text inside the window
- title (str) โ title of the window
- width (int) โ window width
- height (int) โ window height
- timeout (int) โ close the window after n seconds
Error
error(title='', text='', width=330, height=120, timeout=None)
Display a simple error
Parameters:
- text (str) โ text inside the window
- title (str) โ title of the window
- width (int) โ window width
- height (int) โ window height
- timeout (int) โ close the window after n seconds
Warning
warning(title='', text='', width=330, height=120, timeout=None)
Display a simple warning
Parameters:
- text (str) โ text inside the window
- title (str) โ title of the window
- width (int) โ window width
- height (int) โ window height
- timeout (int) โ close the window after n seconds
Question
question(title='', text='', width=330, height=120, timeout=None)
Display a question, possible answer are yes/no.
Parameters:
- text (str) โ text inside the window
- title (str) โ title of the window
- width (int) โ window width
- height (int) โ window height
- timeout (int) โ close the window after n seconds
Returns: The answer as a boolean
Return type: bool
Progress Bar
progress_bar(title, text, pulse_mode, callback)
Display a text input
Parameters:
- title (str) โ Title of the progress window
- text (str) โ Text that will be present on top of the progress bar
- pulse_mode (bool) โ Character of the progress bar, pulse of progress based on the callback returns values from 0.0 to 1
- callback (int) โ callback function for control the progress bar. Returns a value between 0.0 and 1
Demo
import time
from sgzenity.thread import WorkerThread
from sgzenity import ProgressBar
class WorkingThread(WorkerThread):
def payload(self):
loading = self.data
steps = 10
for s in range(steps):
if self.stop:
break
loading.heartbeat()
print('Pulse {}.'.format(s))
time.sleep(1)
if self.stop:
print('Working thread canceled.')
else:
print('Working thread ended.')
loading.close()
def sg_progress_bar():
loading = ProgressBar("DEMO TITLE", "DEMO TEXT", pulse_mode=True)
workthread = WorkingThread(loading)
loading.show(workthread)
workthread.start()
Gtk.main()
sg_progress_bar()
Entry
entry(text='', placeholder='', title='', width=330, height=120, timeout=None)
Display a text input
Parameters:
- text (str) โ text inside the window
- placeholder (str) โ placeholder for the input
- title (str) โ title of the window
- width (int) โ window width
- height (int) โ window height
- timeout (int) โ close the window after n seconds
Returns: The content of the text input Return type: str
Password
password(text='', placeholder='', title='', width=330, height=120, timeout=None)
Display a text input with hidden characters
Parameters:
- text (str) โ text inside the window
- placeholder (str) โ placeholder for the input
- title (str) โ title of the window
- width (int) โ window width
- height (int) โ window height
- timeout (int) โ close the window after n seconds
Returns: The content of the text input
Return type: str
List of values
zlist(columns, items, print_columns=None, text='', title='', width=330, height=120, timeout=None)
Display a list of values
Parameters:
- columns (list of strings) โ a list of columns name
- items (list of strings) โ a list of values
- print_columns (int* (None if all the columns)*) โ index of a column (return just the values from this column)
- text (str) โ text inside the window
- title (str) โ title of the window
- width (int) โ window width
- height (int) โ window height
- timeout (int) โ close the window after n seconds
Returns: A row of values from the table
Return type: list
File selection
file_selection(multiple=False, directory=False, save=False, confirm_overwrite=False, filename=None, title='', width=330, height=120, timeout=None)
Open a file selection window
Parameters:
- multiple (bool) โ allow multiple file selection
- directory (bool) โ only directory selection
- save (bool) โ save mode
- confirm_overwrite (bool) โ confirm when a file is overwritten
- filename (str) โ placeholder for the filename
- text (str) โ text inside the window
- title (str) โ title of the window
- width (int) โ window width
- height (int) โ window height
- timeout (int) โ close the window after n seconds
Returns: path of files selected.
Return type: string or list if multiple enabled
Calendar
calendar(text='', day=None, month=None, title='', width=330, height=120, timeout=None)
Display a calendar
Parameters:
- text (str) โ text inside the window
- day (int) โ default day
- month (int) โ default month
- text โ text inside the window
- title (str) โ title of the window
- width (int) โ window width
- height (int) โ window height
- timeout (int) โ close the window after n seconds
Returns: (year, month, day)
Return type: tuple
And display the result :
$ python demo.py
$ (year=2017, month=6, day=4)
Color selection
color_selection(show_palette=False, opacity_control=False, title='', width=330, height=120, timeout=None)
Display a color selection dialog
Parameters:
- show_palette (bool) โ hide/show the palette with preselected colors
- opacity_control (bool) โ allow to control opacity
- title (str) โ title of the window
- width (int) โ window width
- height (int) โ window height
- timeout (int) โ close the window after n seconds
Returns: the color selected by the user
Return type: str
Scale
scale(text='', value=0, min=0, max=100, step=1, draw_value=True, title='', width=330, height=120, timeout=None)
Select a number with a range widget
Parameters:
- text (str) โ text inside window
- value (int) โ current value
- min (int) โ minimum value
- max (int) โ maximum value
- step (int) โ incrementation value
- draw_value (bool) โ hide/show cursor value
- title (str) โ title of the window
- width (int) โ window width
- height (int) โ window height
- timeout (int) โ close the window after n seconds
Returns: The value selected by the user
Return type: float
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
Built Distribution
File details
Details for the file sgzenity-0.1.9.tar.gz
.
File metadata
- Download URL: sgzenity-0.1.9.tar.gz
- Upload date:
- Size: 24.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f2785a1572fd3666c524f1714ff23718bb1dee67254374800f30788c1aea05e |
|
MD5 | b50a829ab969a8750296462f54f922d6 |
|
BLAKE2b-256 | c629737e57d9ab84747056aa854b148a2c9166eccf5ea9e30bc03666328f4dcd |
File details
Details for the file sgzenity-0.1.9-py3-none-any.whl
.
File metadata
- Download URL: sgzenity-0.1.9-py3-none-any.whl
- Upload date:
- Size: 27.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11cd688a71f8fb6bd2ed543f2364ff5e3d1119249f7a0149bcab98c929803874 |
|
MD5 | 64092879757b03268f76598f1c84567b |
|
BLAKE2b-256 | a4d8b2ecbb8a045ebedb6933cdc0c4d3b2802d55dbd308ea1f9870a72c388f33 |