class ThemeInfo
ThemeInfo is a class that represents and manages theme information for a SharePoint site, providing access to theme properties and font configurations.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/webs/theme_info.py
6 - 36
moderate
Purpose
This class serves as an entity wrapper for SharePoint site themes, allowing retrieval of theme-specific information such as fonts, background images, and accessibility descriptions. It inherits from Entity and provides methods to query theme fonts by name and language, as well as properties to access theme metadata. The class is designed to work within the Office365 SharePoint API context, enabling programmatic access to site theming information.
Source Code
class ThemeInfo(Entity):
"""Specifies a theme for a site"""
def get_theme_font_by_name(self, name, lcid):
"""
Returns the name of the theme font for the specified font slot name and language code identifier (LCID).
MUST return null if the font slot does not exist.
:param str name: Name of the font slot.
:param int lcid: The language code identifier (LCID) for the required language.
"""
return_type = ClientResult(self.context, str())
payload = {"name": name, "lcid": lcid}
qry = ServiceOperationQuery(
self, "GetThemeFontByName", None, payload, None, return_type
)
self.context.add_query(qry)
return return_type
@property
def accessible_description(self):
"""Specifies the accessible description for this theme.
:rtype: str or None
"""
return self.properties.get("AccessibleDescription", None)
@property
def theme_background_image_uri(self):
"""Specifies the URI of the background image for this theme.
:rtype: str or None
"""
return self.properties.get("ThemeBackgroundImageUri", None)
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
Entity | - |
Parameter Details
bases: Inherits from Entity class, which provides base functionality for SharePoint entities including context management and property handling. The Entity base class manages the connection to SharePoint and handles property storage and retrieval.
Return Value
Instantiation returns a ThemeInfo object that represents a SharePoint site theme. The get_theme_font_by_name method returns a ClientResult object containing a string with the theme font name, or null if the font slot doesn't exist. Properties return strings or None if the property is not set.
Class Interface
Methods
get_theme_font_by_name(name: str, lcid: int) -> ClientResult
Purpose: Retrieves the name of the theme font for a specified font slot name and language code identifier (LCID)
Parameters:
name: Name of the font slot to query (e.g., 'body', 'heading', 'monospace')lcid: Language Code Identifier (LCID) for the required language (e.g., 1033 for US English)
Returns: ClientResult object containing a string with the font name, or null if the font slot does not exist. Must call context.execute_query() to retrieve the actual value.
@property accessible_description -> str | None
property
Purpose: Gets the accessible description text for this theme, used for accessibility purposes
Returns: String containing the accessible description for the theme, or None if not set
@property theme_background_image_uri -> str | None
property
Purpose: Gets the URI of the background image associated with this theme
Returns: String containing the URI of the theme's background image, or None if not set
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
context |
ClientContext | Inherited from Entity base class. Stores the SharePoint client context used for executing queries and managing the connection to SharePoint | instance |
properties |
dict | Inherited from Entity base class. Dictionary storing the theme's properties retrieved from SharePoint, accessed by property getters | instance |
Dependencies
office365-runtimeoffice365-sharepoint
Required Imports
from office365.runtime.client_result import ClientResult
from office365.runtime.queries.service_operation import ServiceOperationQuery
from office365.sharepoint.entity import Entity
Usage Example
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.theme_info import ThemeInfo
# Authenticate and get context
ctx = ClientContext(site_url).with_credentials(credentials)
# Get theme info (typically retrieved from site)
theme = ctx.web.theme_info
ctx.load(theme)
ctx.execute_query()
# Get theme font for a specific language
font_result = theme.get_theme_font_by_name('body', 1033)
ctx.execute_query()
font_name = font_result.value
# Access theme properties
description = theme.accessible_description
background_uri = theme.theme_background_image_uri
print(f'Font: {font_name}')
print(f'Description: {description}')
print(f'Background: {background_uri}')
Best Practices
- Always execute queries using context.execute_query() after calling get_theme_font_by_name to retrieve actual values from SharePoint
- Check if property values are None before using them, as theme properties may not be set
- Use appropriate LCID (Language Code Identifier) values when querying fonts - 1033 for US English is common
- Load the ThemeInfo object using context.load() before accessing properties to ensure data is populated
- The get_theme_font_by_name method returns a ClientResult object, access the actual value via the .value property after query execution
- Font slot names should match SharePoint's predefined theme font slots (e.g., 'body', 'heading', 'monospace')
- Handle null returns from get_theme_font_by_name gracefully as the method returns null for non-existent font slots
- This class is typically not instantiated directly but retrieved from a Site or Web object's theme_info property
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class ThemeProperties 73.3% similar
-
class ThemeManager 68.7% similar
-
class WebInformation 64.1% similar
-
class GroupSiteInfo 64.0% similar
-
class MembersInfo 63.3% similar