Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 9 additions & 23 deletions plugin/talon_draft_window/draft_talon_helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Optional

from talon import Context, Module, actions, settings, ui
from talon import Context, Module, actions, ui

from .draft_ui import DraftManager

Expand All @@ -17,57 +17,43 @@
title: Talon Draft
"""

SETTING_CHANGE_CAVEAT_DESCRIPTION = ". Seeing the results of changing this setting requires showing the draft window again."
mod.tag("draft_window_showing", desc="Tag set when draft window showing")
mod.setting(
"draft_window_theme",
type=str,
default="dark",
desc="Sets the main colors of the window, one of 'dark' or 'light'",
desc="Sets the main colors of the window, one of 'dark' or 'light'"
+ SETTING_CHANGE_CAVEAT_DESCRIPTION,
)
mod.setting(
"draft_window_label_size",
type=int,
default=20,
desc="Sets the size of the word labels used in the draft window",
desc="Sets the size of the word labels used in the draft window"
+ SETTING_CHANGE_CAVEAT_DESCRIPTION,
)
mod.setting(
"draft_window_label_color",
type=str,
default=None,
desc=(
"Sets the color of the word labels used in the draft window. "
"E.g. 00ff00 would be green"
"E.g. 00ff00 would be green" + SETTING_CHANGE_CAVEAT_DESCRIPTION
),
)
mod.setting(
"draft_window_text_size",
type=int,
default=20,
desc="Sets the size of the text used in the draft window",
desc="Sets the size of the text used in the draft window"
+ SETTING_CHANGE_CAVEAT_DESCRIPTION,
)


draft_manager = DraftManager()


# Update the styling of the draft window dynamically as user settings change
def _update_draft_style(*args):
draft_manager.set_styling(
**{
arg: settings.get(setting)
for setting, arg in (
("user.draft_window_theme", "theme"),
("user.draft_window_label_size", "label_size"),
("user.draft_window_label_color", "label_color"),
("user.draft_window_text_size", "text_size"),
)
}
)


settings.register("", _update_draft_style)


@ctx_focused.action_class("user")
class ContextSensitiveDictationActions:
"""
Expand Down
9 changes: 8 additions & 1 deletion plugin/talon_draft_window/draft_ui.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re
from typing import Optional

from talon import settings
from talon.experimental.textarea import (
DarkThemeLabels,
LightThemeLabels,
Expand Down Expand Up @@ -65,11 +66,15 @@ def __init__(self):
self.area.register("label", self._update_labels)
self.set_styling()

def set_styling(self, theme="dark", text_size=20, label_size=20, label_color=None):
def set_styling(self):
"""
Allow settings the style of the draft window. Will dynamically
update the style based on the passed in parameters.
"""
theme = settings.get("user.draft_window_theme")
text_size = settings.get("user.draft_window_text_size")
label_size = settings.get("user.draft_window_label_size")
label_color = settings.get("user.draft_window_label_color")

area_theme = DarkThemeLabels if theme == "dark" else LightThemeLabels
theme_changes = {
Expand All @@ -86,6 +91,8 @@ def show(self, text: Optional[str] = None):
otherwise set the text to the given value.
"""

self.set_styling()

if text is not None:
self.area.value = text
self.area.show()
Expand Down
1 change: 1 addition & 0 deletions plugin/talon_draft_window/settings.talon.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Put some settings like this in one of your Talon files to override the styling
# of the draft window.
# You must use the draft show command again to see the effects of changing these settings
-
settings():
user.draft_window_theme = "dark" # or light
Expand Down