bgdev.tools.toolbar.utils

Utility method used in the toolbar.

created

12/11/2018

author

Benoit GIELLY <benoit.gielly@gmail.com>

check_image(icon, normalized=True)[source]

Convert the given image path to full path name.

Parameters
  • icon (str) – Name of the icon to check

  • normalized (bool) – Normalize the path to work on all OS

Returns

Updated icon path so it’s ready to be used.

Return type

str

check_modpath_has_init(path, parts)[source]

Check if given module parts all contains an __init__ file.

Parameters
  • path (str) – Path to python file.

  • parts (list) – Each parts of a module path. (Eg. [“sanity”, “core”]).

Returns

True if each part as an __init__ file as sibling else False.

Return type

bool

create_module_callback(source)[source]

Set the command for each buttons.

Parameters

source (str) – Source python code to execute.

Returns

A callable function

Return type

function

get_dcc()[source]

Get current DCC application.

get_dcc_package()[source]

Get the current DCC’s “check” package.

modpath_from_file(filename)[source]

Get the module import path from its filename.

Parameters

filename (str) – Path to python file.

Raises

ImportError – When module cannot be found in sys.path.

Returns

The module import path.

Return type

str

yaml_dump(data, path, ordered=False, **kwargs)[source]

Export YAML file.

Parameters
  • data (dict) – Dictionary to export as JSON

  • path (str) – YAML file path to save data

  • ordered (bool) – Dump data ordered when True.

  • kwargs (dict) – Any extra flags to pass in the json.dump() command

Returns

given file path

Return type

str

yaml_load(path, ordered=False, **kwargs)[source]

Import YAML file.

Parameters
  • path (str) – YAML file path to save data

  • ordered (bool) – Load data in an orderedDict when True.

  • kwargs (dict) – Any extra flags to pass in the json.load() command

Returns

the loaded data

Return type

dict