utils

The guidata.utils module provides various utility helper functions (pure python).

guidata.utils.min_equals_max(min, max)[source]

Return True if minimium value equals maximum value Return False if not, or if maximum or minimum value is not defined

guidata.utils.pairs(iterable)[source]

A simple generator that takes a list and generates pairs [ (l[0],l[1]), ..., (l[n-2], l[n-1])]

guidata.utils.add_extension(item, value)[source]

Add extension to filename item: data item representing a file path value: possible value for data item

guidata.utils.bind(fct, value)[source]

Returns a callable representing the function ‘fct’ with it’s first argument bound to the value

if g = bind(f,1) and f is a function of x,y,z then g(y,z) will return f(1,y,z)

guidata.utils.trace(fct)[source]

A decorator that traces function entry/exit used for debugging only

guidata.utils.decode_fs_string(string)[source]

Convert string from file system charset to unicode

guidata.utils.utf8_to_unicode(string)[source]

Convert UTF-8 string to Unicode

guidata.utils.unicode_to_stdout(ustr)[source]

convert a unicode string to a byte string encoded for stdout output

guidata.utils.update_dataset(dest, source, visible_only=False)[source]

Update dest dataset items from source dataset

dest should inherit from DataSet, whereas source can be:
  • any Python object containing matching attribute names
  • or a dictionary with matching key names

For each DataSet item, the function will try to get the attribute of the same name from the source.

visible_only: if True, update only visible items

guidata.utils.restore_dataset(source, dest)[source]

Restore dest dataset items from source dataset

This function is almost the same as update_dataset but requires the source to be a DataSet instead of the destination.

Symetrically from update_dataset, dest may also be a dictionary.

guidata.utils.assert_interface_supported(klass, iface)[source]

Makes sure a class supports an interface

guidata.utils.assert_interfaces_valid(klass)[source]

Makes sure a class supports the interfaces it declares

guidata.utils.localtime_to_isodate(time_struct)[source]

Convert local time to ISO date

guidata.utils.isodate_to_localtime(datestr)[source]

Convert ISO date to local time

class guidata.utils.FormatTime(hours_fmt='%d H ', min_fmt='%d min ', sec_fmt='%d s')[source]

Helper object that substitute as a string to format seconds into (nn H mm min ss s)

class guidata.utils.Timer[source]

MATLAB-like timer: tic, toc

tic(cat)[source]

Starting timer

toc(cat, msg='delta:')[source]

Stopping timer

guidata.utils.get_module_path(modname)[source]

Return module modname base path

guidata.utils.is_program_installed(basename)[source]

Return program absolute path if installed in PATH Otherwise, return None

guidata.utils.run_program(name, args='', cwd=None, shell=True, wait=False)[source]

Run program in a separate process

guidata.utils.is_module_available(module_name)[source]

Return True if Python module is available

guidata.utils.get_package_data(name, extlist, exclude_dirs=[])[source]

Return data files for package name with extensions in extlist (search recursively in package directories)

guidata.utils.get_subpackages(name)[source]

Return subpackages of package name

guidata.utils.cythonize_all(relpath)[source]

Cythonize all Cython modules in relative path