PyZenity Module

PyZenity is an easy to use interface to Zenity for Python.

Zenity is normally called from scripts by invoking it with a multitude of command line parameters that it uses to construct its interfaces. This module hides the details of invoking the command and presents simple API functions like:

cancel = Question(‘Should I cancel the operation?’)

Each function takes optional kwargs parameters. This is to allow the use of general Zenity parameters such as:

title - Set the dialog title window_icon - Set the window icon ok_label - Set the text for the Ok label cancel_label - Set the text for the Cancel label height - Set the height width - Set the width timeout - Set the dialog timeout in seconds
PyZenity.GetDate(text=None, selected=None, **kwargs)[source]

Prompt the user for a date.

This will raise a Zenity Calendar Dialog for the user to pick a date. It will return a datetime.date object with the date or None if the user hit cancel.

text - Text to be displayed in the calendar dialog. selected - A datetime.date object that will be the pre-selected date. kwargs - Optional command line parameters for Zenity such as height,

width, etc.
PyZenity.GetFilename(multiple=False, sep='|', **kwargs)[source]

Prompt the user for a filename.

This will raise a Zenity File Selection Dialog. It will return a list with the selected files or None if the user hit cancel.

multiple - True to allow the user to select multiple files. sep - Token to use as the path separator when parsing Zenity’s return

string.
kwargs - Optional command line parameters for Zenity such as height,
width, etc.
PyZenity.GetDirectory(multiple=False, selected=None, sep=None, **kwargs)[source]

Prompt the user for a directory.

This will raise a Zenity Directory Selection Dialog. It will return a list with the selected directories or None if the user hit cancel.

multiple - True to allow the user to select multiple directories. selected - Path to the directory to be selected on startup. sep - Token to use as the path separator when parsing Zenity’s return

string.
kwargs - Optional command line parameters for Zenity such as height,
width, etc.
PyZenity.GetSavename(default=None, **kwargs)[source]

Prompt the user for a filename to save as.

This will raise a Zenity Save As Dialog. It will return the name to save a file as or None if the user hit cancel.

default - The default name that should appear in the save as dialog. kwargs - Optional command line parameters for Zenity such as height,

width, etc.
PyZenity.Notification(text=None, window_icon=None, **kwargs)[source]

Put an icon in the notification area.

This will put an icon in the notification area and return when the user clicks on it.

text - The tooltip that will show when the user hovers over it. window_icon - The stock icon (“question”, “info”, “warning”, “error”) or

path to the icon to show.
kwargs - Optional command line parameters for Zenity such as height,
width, etc.
PyZenity.List(column_names, title=None, boolstyle=None, editable=False, select_col=None, sep='|', data=[], **kwargs)[source]

Present a list of items to select.

This will raise a Zenity List Dialog populated with the colomns and rows specified and return either the cell or row that was selected or None if the user hit cancel.

column_names - A tuple or list containing the names of the columns. title - The title of the dialog box. boolstyle - Whether the first columns should be a bool option (“checklist”,

“radiolist”) or None if it should be a text field.

editable - True if the user can edit the cells. select_col - The column number of the selected cell to return or “ALL” to

return the entire row.
sep - Token to use as the row separator when parsing Zenity’s return.
Cells should not contain this token.
data - A list or tuple of tuples that contain the cells in the row. The
size of the row’s tuple must be equal to the number of columns.
kwargs - Optional command line parameters for Zenity such as height,
width, etc.
PyZenity.ErrorMessage(text, **kwargs)[source]

Show an error message dialog to the user.

This will raise a Zenity Error Dialog with a description of the error.

text - A description of the error. kwargs - Optional command line parameters for Zenity such as height,

width, etc.
PyZenity.InfoMessage(text, **kwargs)[source]

Show an info message dialog to the user.

This will raise a Zenity Info Dialog displaying some information.

text - The information to present to the user. kwargs - Optional command line parameters for Zenity such as height,

width, etc.
PyZenity.Question(text, **kwargs)[source]

Ask the user a question.

This will raise a Zenity Question Dialog that will present the user with an OK/Cancel dialog box. It returns True if the user clicked OK; False on Cancel.

text - The question to ask. kwargs - Optional command line parameters for Zenity such as height,

width, etc.
PyZenity.Warning(text, **kwargs)[source]

Show a warning message dialog to the user.

This will raise a Zenity Warning Dialog with a description of the warning. It returns True if the user clicked OK; False on cancel.

text - A description of the warning. kwargs - Optional command line parameters for Zenity such as height,

width, etc.
PyZenity.Progress(text='', percentage=0, auto_close=False, pulsate=False, **kwargs)[source]

Show a progress dialog to the user.

This will raise a Zenity Progress Dialog. It returns a callback that accepts two arguments. The first is a numeric value of the percent complete. The second is a message about the progress.

NOTE: This function sends the SIGHUP signal if the user hits the cancel
button. You must connect to this signal if you do not want your application to exit.

text - The initial message about the progress. percentage - The initial percentage to set the progress bar to. auto_close - True if the dialog should close automatically if it reaches

100%.

pulsate - True is the status should pulsate instead of progress. kwargs - Optional command line parameters for Zenity such as height,

width, etc.
PyZenity.GetText(text='', entry_text='', password=False, **kwargs)[source]

Get some text from the user.

This will raise a Zenity Text Entry Dialog. It returns the text the user entered or None if the user hit cancel.

text - A description of the text to enter. entry_text - The initial value of the text entry box. password - True if text entered should be hidden by stars. kwargs - Optional command line parameters for Zenity such as height,

width, etc.
PyZenity.TextInfo(filename=None, editable=False, **kwargs)[source]

Show the text of a file to the user.

This will raise a Zenity Text Information Dialog presenting the user with the contents of a file. It returns the contents of the text box.

filename - The path to the file to show. editable - True if the text should be editable. kwargs - Optional command line parameters for Zenity such as height,

width, etc.

Previous topic

scanf Module

Next topic

Rapport pour le projet MPRI Bomberman

This Page