Sketchbook
Sketchbook module for listing and running sketches from the command line.
WIP.
get_sketch_info(sketch_file, sketchbook_folder='./')
Gets information about a specific sketch file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sketch_file |
str
|
Name of the sketch file. |
required |
sketchbook_folder |
str
|
Path to the sketchbook folder. Defaults to current directory. |
'./'
|
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: Dictionary containing sketch information such as name, path, size, modified and created times. |
Source code in src/tolvera/sketchbook.py
get_sketchbook_files(sketchbook_folder='./')
Gets all sketch files from the sketchbook folder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sketchbook_folder |
str
|
Path to the sketchbook folder. Defaults to current directory. |
'./'
|
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: List of sketch file names. |
Source code in src/tolvera/sketchbook.py
get_sketchbook_files_info(sketches, sketchbook_folder='./')
Gets information about all sketch files in the sketchbook folder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sketches |
List[str]
|
List of sketch file names. |
required |
sketchbook_folder |
str
|
Path to the sketchbook folder. Defaults to current directory. |
'./'
|
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: List of sketch information dictionaries. |
Source code in src/tolvera/sketchbook.py
import_sketch(module_name, file_path)
Imports a sketch from a given file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_name |
str
|
Name of the module. |
required |
file_path |
str
|
Path to the file containing the module. |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
Imported module. |
Source code in src/tolvera/sketchbook.py
list_sketches(sketchbook_folder='./', sort='name', direction='ascending')
Lists all sketches in the given sketchbook folder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sketchbook_folder |
str
|
Path to the sketchbook folder. Defaults to current directory. |
'./'
|
sort |
str
|
Sort sketches by name, size, modified or created. Defaults to 'name'. |
'name'
|
direction |
str
|
Sort direction, either 'ascending' or 'descending'. Defaults to 'ascending'. |
'ascending'
|
Source code in src/tolvera/sketchbook.py
main(*args, **kwargs)
Main function for running the sketchbook from the command line.
Source code in src/tolvera/sketchbook.py
pretty_print_sketchbook(sketches, sketchbook_folder='./')
Pretty prints the sketchbook information.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sketches |
List[Dict[str, Any]]
|
List of sketch information dictionaries. |
required |
sketchbook_folder |
str
|
Path to the sketchbook folder. Defaults to current directory. |
'./'
|
Source code in src/tolvera/sketchbook.py
run_random_sketch(sketchbook='./')
Runs a random sketch from the sketchbook.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sketchbook |
str
|
Path to the sketchbook folder. Defaults to current directory. |
'./'
|
Source code in src/tolvera/sketchbook.py
run_sketch_by_index(index, sketchbook_folder='./', *args, **kwargs)
Runs a sketch by its index in the sketchbook.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index |
int
|
Index of the sketch to run. |
required |
sketchbook_folder |
str
|
Path to the sketchbook folder. Defaults to current directory. |
'./'
|
Source code in src/tolvera/sketchbook.py
run_sketch_by_name(sketch_file, sketchbook_folder='./', *args, **kwargs)
Runs a sketch by its file name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sketch_file |
str
|
Name of the sketch file. |
required |
sketchbook_folder |
str
|
Path to the sketchbook folder. Defaults to current directory. |
'./'
|
Source code in src/tolvera/sketchbook.py
run_sketch_function_from_module(module, function_name, file_path, *args, **kwargs)
Runs a specific function from a given module.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module |
Any
|
The imported module. |
required |
function_name |
str
|
Name of the function to run. |
required |
file_path |
str
|
Path to the file containing the module. |
required |
Source code in src/tolvera/sketchbook.py
sort_sketch_files(sketch_files, sort='name', direction='ascending')
Sorts sketch files by name, size, modified or created.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sort |
str
|
Sort sketches by name, size, modified or created. Defaults to 'name'. |
'name'
|
sketch_files |
List[Dict[str, Any]]
|
List of sketch information dictionaries. |
required |
direction |
str
|
Sort direction, either 'ascending' or 'descending'. Defaults to 'ascending'. |
'ascending'
|
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: List of sorted sketch information dictionaries. |
Source code in src/tolvera/sketchbook.py
try_import_and_run_sketch(module_name, file_path, *args, **kwargs)
Tries to import and run a sketch from a given file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_name |
str
|
Name of the module. |
required |
file_path |
str
|
Path to the file containing the module. |
required |
Source code in src/tolvera/sketchbook.py
validate_sketch_file(sketch_file, sketchbook_folder='./')
Validates if the given sketch file exists in the sketchbook folder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sketch_file |
str
|
Name of the sketch file. |
required |
sketchbook_folder |
str
|
Path to the sketchbook folder. Defaults to current directory. |
'./'
|
Raises:
Type | Description |
---|---|
SystemExit
|
If the sketch file does not exist. |
Source code in src/tolvera/sketchbook.py
validate_sketchbook_path(sketchbook_folder='./')
Validates if the given sketchbook folder exists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sketchbook_folder |
str
|
Path to the sketchbook folder. Defaults to current directory. |
'./'
|
Raises:
Type | Description |
---|---|
SystemExit
|
If the sketchbook folder does not exist. |