Skip to content

ponty/psidialogs

Repository files navigation

psidialogs (Python Simple Dialogs) is a wrapper for different standard dialogs: message, warning, error, ask_ok_cancel, ask_yes_no, ask_string, ask_file, ask_folder, choice.

Links:

workflow

back-ends:

Installation

$ python3 -m pip install psidialogs

Install all back-ends on Ubuntu 22.04:

$ sudo apt-get install python3-tk
$ sudo apt-get install python3-pyqt5
$ sudo apt-get install python3-pyside2.qtwidgets
$ sudo apt-get install python3-dialog
$ sudo apt-get install python3-easygui
$ sudo apt-get install python3-wxgtk4.0
$ sudo apt-get install zenity
$ sudo apt-get install gxmessage

Usage

# psidialogs/examples/message.py

import psidialogs

psidialogs.message("Hello!")

# psidialogs/examples/warning.py

import psidialogs

psidialogs.warning("Warning text.")

# psidialogs/examples/error.py

import psidialogs

psidialogs.error("Error text.")

# psidialogs/examples/ask_ok_cancel.py

import psidialogs

ok = psidialogs.ask_ok_cancel("Do you want to continue?")
if ok:
    print("continue")

# psidialogs/examples/ask_yes_no.py

import psidialogs

yes = psidialogs.ask_yes_no("Yes or no?")
if yes:
    print("yes!")

# psidialogs/examples/ask_string.py

import psidialogs

name = psidialogs.ask_string("What is your name?")
if name is not None:
    print(name)

# psidialogs/examples/ask_file.py

import psidialogs

f = psidialogs.ask_file("Select a file!")
if f is not None:
    print(f)

# psidialogs/examples/ask_folder.py

import psidialogs

f = psidialogs.ask_folder("Select a folder!")
if f is not None:
    print(f)

# psidialogs/examples/choice.py

import psidialogs

s = psidialogs.choice(["1", "2", "3"], "Choose a number!")
if s is not None:
    print(s)

The implemented backends can be listed, the order is the preference, which can be changed:

# psidialogs/examples/backends.py

import psidialogs

print(psidialogs.backends())
psidialogs.set_backend_preference(["tkinter", "zenity"])
print(psidialogs.backends())
$ python3 -m psidialogs.examples.backends
['pyside2', 'tkinter', 'zenity']
['tkinter', 'zenity', 'pyside2']

Changing the backend preference:

# psidialogs/examples/set_backend_preference.py

import psidialogs

psidialogs.set_backend_preference(["tkinter", "zenity"])
psidialogs.message("Hello!")

Demo

All backends and all dialog types can be tested with the demo:

$ python3 -m psidialogs.examples.demo

The demo can be started with one backend:

$ python3 -m psidialogs.examples.demo --backend zenity

The demo can be started with one backend and one dialog type:

$ python3 -m psidialogs.examples.demo --backend zenity --dialogtype message

Demo full help:

$ python3 -m psidialogs.examples.demo --help
usage: demo.py [-h] [-b BACKEND] [-d DIALOGTYPE] [-t TITLE] [--debug]

optional arguments:
  -h, --help            show this help message and exit
  -b BACKEND, --backend BACKEND
  -d DIALOGTYPE, --dialogtype DIALOGTYPE
  -t TITLE, --title TITLE
  --debug               set logging level to DEBUG

Screenshots

Screenshots are created on Ubuntu 22.04 server with Xvfb.

Versions:

$ python3 -m psidialogs.check.versions
python               3.8.10
psidialogs           0.2.0
pyside2              5.14.0
tkinter              8.6
zenity               3.32.0

message(), warning(), error()

backend message warning error
zenity
gmessage
wxpython
tkinter
easygui
pyqt5
pyside2
pythondialog
console

ask_ok_cancel(), ask_yes_no(), ask_string()

backend ask_ok_cancel ask_yes_no ask_string
zenity
gmessage
wxpython
tkinter
easygui
pyqt5
pyside2
pythondialog
console

ask_file(), ask_folder()

backend ask_file ask_folder
zenity
gmessage
wxpython
tkinter
easygui
pyqt5
pyside2
pythondialog
console

choice()

backend choice
zenity
gmessage
wxpython
tkinter
easygui
pyqt5
pyside2
pythondialog
console

Hierarchy

Alt text