Alto
dev

alto.ui.theme_editor

The editor for a theme of the user’s own: a name, and a color for every part of its light and dark versions.

Examples

>>> editor = ThemeEditor()
>>> editor.load(None)
>>> editor.record()["name"]
'My theme'

theme_of

def theme_of(
    colors: dict[str, str],
    *,
    dark: bool,
) -> CustomTheme

Make a theme from a set of colors, to draw a picture of it.

Parameters

  • colors (dict of str to str): A color for every part, as “#rrggbb”.
  • dark (bool): True if it is the dark version. Keyword-only.

Returns

  • CustomTheme: The theme, without a key or a name of its own.

Examples

>>> theme_of({part: "#102030" for part in PARTS}, dark=True).window
'#102030'

ThemeEditor

ThemeEditor(parent: QWidget | None = None)

Bases: QWidget

A form to make a theme, or change one: its name, and the colors of its light and dark versions.

A small picture of each version follows the colors as they are chosen. Choosing a theme in the “Start from” list takes its colors at once.

Attributes

  • name_edit (QLineEdit): The theme’s name.
  • start_from (FieldComboBox): The themes whose colors can be taken; choosing one takes them.
  • colors (dict of str to dict of str to str): The colors being made, by “light” or “dark”, and then by part.
  • buttons (dict of str to dict of str to QPushButton): The button of each color, which opens the color picker, by version and part.
  • pictures (dict of str to ThemeThumb): The picture of each version.
  • save_button (QPushButton): Saves the theme.
  • delete_button (QPushButton): Deletes the theme; it is only there for a theme that has been saved.
  • saved (Signal): Emitted with the theme’s key when it is saved.
  • canceled (Signal): Emitted when the editing is given up.
  • deleted (Signal): Emitted with the theme’s key when it is deleted.

Examples

>>> ThemeEditor().save_button.text()
'Save'

Constructor

Build the form, ready to make a new theme.

Parameters

  • parent (QWidget or None, default None): The widget that owns it.

Constructor examples

>>> sorted(ThemeEditor().colors)
['dark', 'light']

ThemeEditor.eventFilter

def eventFilter(
    watched: QObject,
    event: QEvent,
) -> bool

Light up the code written beside a color while the pointer is over the color.

Parameters

  • watched (QObject): The object the event is for.
  • event (QEvent): The event.

Returns

  • bool: Always False: the color button still gets the event.

Examples

>>> editor = ThemeEditor()
>>> button = editor.buttons["light"]["accent"]
>>> _ = editor.eventFilter(button, QEvent(QEvent.Type.Enter))
>>> "bold" in editor._values["light"]["accent"].styleSheet()
True
>>> _ = editor.eventFilter(button, QEvent(QEvent.Type.Leave))
>>> "bold" in editor._values["light"]["accent"].styleSheet()
False

ThemeEditor.load

def load(record: ThemeRecord | None) -> None

Fill the form from a theme that was saved, or for a new one that starts as Studio.

Parameters

  • record (ThemeRecord or None): The theme to change; None for a new theme.

Examples

>>> editor = ThemeEditor()
>>> editor.load(None)
>>> editor.delete_button.isHidden(), editor.name_edit.text()
(True, 'My theme')

ThemeEditor.record

def record() -> ThemeRecord

Give the theme as it is now in the form.

Returns

  • ThemeRecord: The key, the name and the colors of both versions.

Examples

>>> editor = ThemeEditor()
>>> editor.record()["light"]["window"] == editor.colors["light"]["window"]
True