API for Tags¶
The Tags Class¶
- class digikamdb.tags.Tags(digikam)[source]¶
Bases:
DigikamTableOffers access to the tags in the Digikam instance.
Tagsrepresents all tags present in the Digikam database. It is usually accessed through theDigikampropertytags.Basic usage:
dk = Digikam(...) mytag = dk.tags['My Tag'] # access by name mytag2 = dk.tags['parent/child'] # access by hierarchical name mytag3 = dk.tags[42] # access by id newtag = dk.tags.add('New Tag', 0) # creates new tag with name 'New Tag'
Access via
[]raises an exception if the name or id cannot be found, or if there are multiple matches.- Parameters:
digikam (Digikam) – Digikam object for access to database and other classes.
- Raises:
DigikamObjectNotFoundError – No matching tag was found.
DigikamMultipleObjectsFoundError – Multiple tags where found when one was expected.
See also
Class
Tag
- add(name, parent, icon=None)[source]¶
Adds a new tag.
To create a Tag at the root of the tag tree, set
parentto 0.namecan be a hierarchical name (e.g. “locations/cities/Amsterdam”), in which case the intermediate tags (“locations” and “cities” in the given example) are created too, without setting an icon if one is specified.- Parameters:
name (str) – The new tag’s name
parent (int | Tag) – The new tag’s parent as an id or a Tag object
icon (Image | str | int | None) – The new tag’s icon. If given as an Image, the icon is set to this Image from the Digikam collection. If given as an int, the icon is set to the image with the id icon. If given as a str, the icon is set to the corresponding KDE icon.
- Returns:
The newly created tag object.
- Return type:
- check()[source]¶
Checks the integrity of the Tags table.
Checks that
each tag is among the children of its parent
each tag is contained in its ancestors
there are no circular parent-child relations
the nested sets and adjacency list structures are consistent (MySQL with DBVersion <= 10 only)
- Raises:
DigikamDataIntegrityError – Table is in an inconsistent state.
Changed in version 0.2.2: Do not check nested sets for DBVersion > 10
The Tag Class (mapped)¶
- class _sqla.Tag(**kwargs)¶
Bases:
DigikamObjectDigikam tag.
Tags in Digikam are hierarchical.
Tagreflects this by providing:tag1 in tag2can be used to test iftag2is an ancestor oftag1.The
hierarchicalname()method.
Note
The tree structure differs between SQLite and MySQL:
On SQLite, tags at the top level have a
pid == 0, and there is no row withid == 0. There can be many tags without a parent tag.On MySQL, there is a tag
_Digikam_Root_Tag_withid == 0andpid == -1, and there is no tag withid == -1. All other tags are descendents of_Digikam_Root_Tag_.On MySQL with DBVersion <= 10, the
Tagstable implements an additional nested sets structure with columnslftandrgt.
See also
Class
Tags
- hierarchicalname()¶
Returns the name including parents, separated by
/.- Return type:
str
- property icon: Image | str | None¶
Returns the tag’s icon.
Possible types are:
- Image:
The icon is an image from the Digikam collection. When setting, you can also specify the image’s id.
- Str:
The icon is a KDE icon string
- None:
No icon is set
- property id: int¶
The tag’s id (read-only)
- property name: str¶
The tag’s name
- property parent: Tag | None¶
Returns the tag’s parent object.
Returns
Noneforthe root tag on MySQL or
tags at top level on SQLite
- property pid: int¶
The parent tag’s id (read-only)
- property properties: TagProperties¶
Returns the tag’s properties
Tag Properties¶
- class digikamdb.tags.TagProperties(parent)[source]¶
Bases:
BasicPropertiesTag Properties