Skip to content

styling_optimizer

styling_optimizer

AppStudio styling optimizer — presets and batch styling for AppStudio apps.

Provides pre-built style presets and functions to apply them consistently across an AppStudio app's definition and all view layouts.

Usage

from crew_dcs.classes.DomoAppStudio.styling_optimizer import ( AppStudioStylePreset, PRESETS, apply_preset_to_definition, apply_preset_to_layout, optimize_app, )

Apply a preset to an app

app = await DomoAppStudio.get_by_id(auth=auth, appstudio_id='667742883') await optimize_app(app, preset=PRESETS["MINIMAL_LIGHT"], save=True)

Or use the convenience method on the app itself

await app.optimize_style(preset_name="minimal_light", save=True)

Or apply to just the definition

await app.Definition.apply_style(preset=PRESETS["EXECUTIVE"])

AppStudioStylePreset dataclass

AppStudioStylePreset(
    name: str,
    nav_orientation: str = "TOP",
    show_domo_navigation: bool = False,
    show_logo: bool = True,
    show_title: bool = True,
    background_color: str = "#FFFFFF",
    text_color: str = "#333333",
    dark_mode: bool = False,
    hide_borders: bool = True,
    hide_margins: bool = True,
    hide_footers: bool = True,
    fit_to_frame: bool = True,
    card_spacing: int = 4,
)

Pre-built styling configuration for AppStudio apps.

Captures the most common styling knobs in a single object so they can be applied consistently to both the app definition and every view layout.

Attributes:

Name Type Description
name str

Human-readable preset name.

nav_orientation str

Navigation bar position — TOP, LEFT, RIGHT, BOTTOM.

show_domo_navigation bool

Whether to show the Domo chrome navigation bar.

show_logo bool

Whether to show the instance logo.

show_title bool

Whether to show the app title.

background_color str

Hex color for the page background.

text_color str

Hex color for text on the background.

dark_mode bool

Whether the background is dark (affects Domo rendering).

hide_borders bool

Whether to hide card borders.

hide_margins bool

Whether to hide card margins.

hide_footers bool

Whether to hide card footers.

fit_to_frame bool

Whether cards should fit to their frame.

card_spacing int

Page density / card spacing in pixels.

apply_preset_to_definition

apply_preset_to_definition(
    definition: AppStudioDefinition,
    preset: AppStudioStylePreset,
) -> AppStudioDefinition

Apply a style preset to an AppStudioDefinition.

Mutates the definition in-place and returns it for chaining.

Sets
  • nav_orientation
  • show_domo_navigation
  • show_logo
  • show_title
  • theme (updated with background_color and text_color if present)

Parameters:

Name Type Description Default
definition AppStudioDefinition

The AppStudioDefinition to modify.

required
preset AppStudioStylePreset

The style preset to apply.

required

Returns:

Type Description
AppStudioDefinition

The same definition object, mutated in-place.

Source code in src/crew_dcs/classes/DomoAppStudio/styling_optimizer.py
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
def apply_preset_to_definition(
    definition: AppStudioDefinition,
    preset: AppStudioStylePreset,
) -> AppStudioDefinition:
    """Apply a style preset to an AppStudioDefinition.

    Mutates the definition in-place and returns it for chaining.

    Sets:
        - nav_orientation
        - show_domo_navigation
        - show_logo
        - show_title
        - theme (updated with background_color and text_color if present)

    Args:
        definition: The AppStudioDefinition to modify.
        preset: The style preset to apply.

    Returns:
        The same definition object, mutated in-place.
    """
    definition.nav_orientation = preset.nav_orientation
    definition.show_domo_navigation = preset.show_domo_navigation
    definition.show_logo = preset.show_logo
    definition.show_title = preset.show_title

    # Update theme dict with preset colors
    if definition.theme is None:
        definition.theme = {}

    definition.theme["backgroundColor"] = preset.background_color
    definition.theme["textColor"] = preset.text_color
    definition.theme["darkMode"] = preset.dark_mode

    return definition

apply_preset_to_layout

apply_preset_to_layout(
    layout, preset: AppStudioStylePreset
)

Apply a style preset to a PageLayout.

Mutates the layout in-place and returns it for chaining.

Sets
  • background.selected_color, text_color, is_darkMode
  • For each CARD content: hide_border, hide_margins, hide_footer, fit_to_frame

Parameters:

Name Type Description Default
layout

The PageLayout to modify.

required
preset AppStudioStylePreset

The style preset to apply.

required

Returns:

Type Description

The same layout object, mutated in-place.

Source code in src/crew_dcs/classes/DomoAppStudio/styling_optimizer.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
def apply_preset_to_layout(layout, preset: AppStudioStylePreset):
    """Apply a style preset to a PageLayout.

    Mutates the layout in-place and returns it for chaining.

    Sets:
        - background.selected_color, text_color, is_darkMode
        - For each CARD content: hide_border, hide_margins, hide_footer, fit_to_frame

    Args:
        layout: The PageLayout to modify.
        preset: The style preset to apply.

    Returns:
        The same layout object, mutated in-place.
    """
    # Update page-level background
    if layout.background is not None:
        layout.background.selected_color = preset.background_color
        layout.background.text_color = preset.text_color
        layout.background.is_darkMode = preset.dark_mode

    # Update each CARD content slot
    for content in layout.content:
        if content.type == "CARD":
            content.hide_border = preset.hide_borders
            content.hide_margins = preset.hide_margins
            content.hide_footer = preset.hide_footers
            content.fit_to_frame = preset.fit_to_frame

    return layout

get_preset_by_name

get_preset_by_name(name: str) -> AppStudioStylePreset

Look up a preset by name (case-insensitive).

Parameters:

Name Type Description Default
name str

Preset name, e.g. "minimal_light" or "MINIMAL_LIGHT".

required

Returns:

Type Description
AppStudioStylePreset

The matching AppStudioStylePreset.

Raises:

Type Description
ValueError

If no preset matches the given name.

Source code in src/crew_dcs/classes/DomoAppStudio/styling_optimizer.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
def get_preset_by_name(name: str) -> AppStudioStylePreset:
    """Look up a preset by name (case-insensitive).

    Args:
        name: Preset name, e.g. "minimal_light" or "MINIMAL_LIGHT".

    Returns:
        The matching AppStudioStylePreset.

    Raises:
        ValueError: If no preset matches the given name.
    """
    key = name.upper()
    if key not in PRESETS:
        available = ", ".join(sorted(PRESETS.keys()))
        raise ValueError(f"Unknown preset '{name}'. Available presets: {available}")
    return PRESETS[key]

optimize_app async

optimize_app(
    app,
    preset: AppStudioStylePreset | None = None,
    save: bool = True,
    *,
    context: RouteContext | None = None,
    **context_kwargs
) -> AppStudioDefinition

Apply a style preset to an entire AppStudio app.

Fetches the definition (if not already loaded), applies the preset to the definition, fetches all views, applies the preset to each view's layout, and optionally saves all changes.

Parameters:

Name Type Description Default
app

A DomoAppStudio instance.

required
preset AppStudioStylePreset | None

The style preset to apply. Defaults to MINIMAL_LIGHT.

None
save bool

If True, saves definition and layout changes to the API.

True
context RouteContext | None

Optional RouteContext for request configuration.

None
**context_kwargs

Additional context parameters.

{}

Returns:

Type Description
AppStudioDefinition

The AppStudioDefinition after applying the preset.

Source code in src/crew_dcs/classes/DomoAppStudio/styling_optimizer.py
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
async def optimize_app(
    app,
    preset: AppStudioStylePreset | None = None,
    save: bool = True,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
) -> AppStudioDefinition:
    """Apply a style preset to an entire AppStudio app.

    Fetches the definition (if not already loaded), applies the preset
    to the definition, fetches all views, applies the preset to each
    view's layout, and optionally saves all changes.

    Args:
        app: A DomoAppStudio instance.
        preset: The style preset to apply. Defaults to MINIMAL_LIGHT.
        save: If True, saves definition and layout changes to the API.
        context: Optional RouteContext for request configuration.
        **context_kwargs: Additional context parameters.

    Returns:
        The AppStudioDefinition after applying the preset.
    """
    from ...utils import chunk_execution as dmce

    context = RouteContext.build_context(context=context, **context_kwargs)
    preset = preset or MINIMAL_LIGHT

    # 1. Fetch definition if not loaded
    if not app.Definition.definition:
        await app.Definition.get(context=context)

    # 2. Apply preset to definition
    apply_preset_to_definition(app.Definition.definition, preset)

    # 3. Save definition if requested
    if save:
        await app.Definition.update(context=context)

    # 4. Fetch all views
    if not app.Views.views:
        await app.Views.get(context=context)

    # 5. Apply preset to each view's layout and save
    async def _apply_and_save_layout(view):
        if not view.Layout.layout:
            await view.Layout.get(context=context)

        apply_preset_to_layout(view.Layout.layout, preset)

        if save:
            await view.Layout.update(context=context)

    if app.Views.views:
        await dmce.gather_with_concurrency(
            n=10,
            *[_apply_and_save_layout(view) for view in app.Views.views],  # noqa: B026
        )

    return app.Definition.definition