GUI Functions

Functions

Details

Miscellaneous user interface utilities for

  • getting the screen size

  • selecting files or directories. If nothing or a non-existing file/direcoty is selected, the return is “0”. Otherwise the file/directory is returned.

  • Selection from a list.

  • waitbar

  • listbox

ui.getfile(FilterSpec='*', DialogTitle='Select File: ', DefaultName='')[source]

Selecting an existing file.

Parameters
FilterSpecquery-string

File filters

DialogTitlestring

Window title

DefaultNamestring

Can be a directory AND filename

Returns
filenamestring

selected existing file, or empty string if nothing is selected

pathname: string

selected path, or empty string if nothing is selected

Examples

>>> (myFile, myPath) = thLib.ui.getfile('*.py', 'Testing file-selection', 'c:\temp\test.py')
ui.getdir(DialogTitle='Select Directory', DefaultName='.')[source]

Select a directory

Parameters
DialogTitlestring

Window title

DefaultNamestring

Can be a directory AND filename

Returns
directorystring

Selected directory, or empty string if nothing is selected.

Examples

>>> myDir = thLib.ui.getdir('c:\temp', 'Pick your directory')
ui.get_screensize()[source]

Get the height and width of the screen.

Parameters
None
Returns
widthint

width of the current screen

height: int

height of the current screen

Examples

>>> (width, height) = thLib.ui.get_screensize()
ui.listbox(items)[source]

GUI for a listbox selection

Parameters
itemslist

Items for selection.

frametkinter Frame

If provided, the list is put in the given frame. Otherwise, a new frame is created.

Returns
selectedstring

Selected item. If no selection is made, and empty string (‘’) is returned.

Examples

>>> selData = thLib.ui.listbox(['Peter', 'Paul', 'Mary'])
ui.progressbar(it, prefix='', size=60)[source]

Shows a progress-bar on the commandline. This has the advantage that you don’t need to bother with windows managers. Nifty coding!

Parameters
itinteger array

index variable

prefixstring

Text preceding the progress-bar

sizeinteger

Length of progress-bar

Examples

>>> import time
>>> for ii in progressbar(range(50), 'Computing ', 25):
>>>    #print(ii)
>>>    time.sleep(0.05)
ui.savefile(FilterSpec='*', DialogTitle='Save File: ', DefaultName='')[source]

Selecting an existing or new file:

Parameters
FilterSpecstring

File filters.

DialogTitlestring

Window title.

DefaultNamestring

Can be a directory AND filename.

Returns
filenamestring

Selected file.

pathnamestring

Selecte path.

Examples

>>> (myFile, myPath) = thLib.ui.savefile('*.py', 'Testing file-selection', 'c:\temp\test.py')