From d904b4b299bbc86a490cbddca5f82b1c054370f7 Mon Sep 17 00:00:00 2001 From: brief <91160+brief@users.noreply.github.com> Date: Mon, 15 Jan 2024 07:33:31 -0800 Subject: [PATCH] Use settings.get() in more places (#1351) Builds on #1349 by converting most uses of `setting = mod.setting()` in community to `settings.get()`. @lunixbochs, would appreciate a quick look to make sure this is correctly using settings. --------- Co-authored-by: Nicholas Riley --- apps/emacs/emacs.py | 6 +- apps/mintty/mintty_win.py | 6 +- apps/tmux/tmux.py | 6 +- core/deprecations.py | 6 +- core/help/help.py | 30 ++++---- core/help/help_scope.py | 9 +-- core/mouse_grid/mouse_grid.py | 12 ++-- core/snippets/snippets.py | 13 ++-- core/text/text_and_dictation.py | 6 +- core/windows_and_tabs/window_snap.py | 6 +- plugin/command_history/command_history.py | 10 +-- plugin/draft_editor/draft_editor.py | 6 +- plugin/mode_indicator/mode_indicator.py | 85 +++++++++++------------ plugin/mouse/mouse.py | 48 +++++++------ plugin/paste_to_insert.py | 2 +- plugin/screenshot/screenshot.py | 6 +- plugin/text_navigation/text_navigation.py | 16 ++--- tags/file_manager/file_manager.py | 58 +++++++++++----- 18 files changed, 180 insertions(+), 151 deletions(-) diff --git a/apps/emacs/emacs.py b/apps/emacs/emacs.py index c69709e390..8c47b13b35 100644 --- a/apps/emacs/emacs.py +++ b/apps/emacs/emacs.py @@ -1,10 +1,10 @@ import logging from typing import Optional -from talon import Context, Module, actions +from talon import Context, Module, actions, settings mod = Module() -setting_meta = mod.setting( +mod.setting( "emacs_meta", type=str, default="esc", @@ -28,7 +28,7 @@ def meta(keys): - m = setting_meta.get() + m = settings.get("user.emacs_meta") if m == "alt": return " ".join("alt-" + k for k in keys.split()) elif m == "cmd": diff --git a/apps/mintty/mintty_win.py b/apps/mintty/mintty_win.py index 338973672e..783a30a860 100644 --- a/apps/mintty/mintty_win.py +++ b/apps/mintty/mintty_win.py @@ -1,6 +1,6 @@ import subprocess -from talon import Context, Module, actions, ui +from talon import Context, Module, actions, settings, ui mod = Module() mod.apps.mintty = """ @@ -26,7 +26,7 @@ directories_to_remap = {} directories_to_exclude = {} -setting_cyg_path = mod.setting( +mod.setting( "cygpath", type=str, default="C:\\cygwin64\\bin\\cygpath.exe", @@ -41,7 +41,7 @@ def get_win_path(cyg_path): si.dwFlags |= subprocess.STARTF_USESHOWWINDOW path = ( subprocess.check_output( - [setting_cyg_path.get(), "-w", cyg_path], startupinfo=si + [settings.get("user.cygpath"), "-w", cyg_path], startupinfo=si ) .strip(b"\n") .decode() diff --git a/apps/tmux/tmux.py b/apps/tmux/tmux.py index 66402bcaab..1f2114a4a2 100644 --- a/apps/tmux/tmux.py +++ b/apps/tmux/tmux.py @@ -1,4 +1,4 @@ -from talon import Context, Module, actions +from talon import Context, Module, actions, settings mod = Module() @@ -7,7 +7,7 @@ and tag: user.tmux """ -setting_tmux_prefix_key = mod.setting( +mod.setting( "tmux_prefix_key", type=str, default="ctrl-b", @@ -19,7 +19,7 @@ class TmuxActions: def tmux_prefix(): """press control and the configured tmux prefix key""" - actions.key(f"{setting_tmux_prefix_key.get()}") + actions.key(settings.get("user.tmux_prefix_key")) def tmux_keybind(key: str): """press tmux prefix followed by a key bind""" diff --git a/core/deprecations.py b/core/deprecations.py index feee5a5393..00abe45f97 100644 --- a/core/deprecations.py +++ b/core/deprecations.py @@ -53,12 +53,12 @@ def legacy_capture(m) -> str: import os.path import warnings -from talon import Module, actions, speech_system +from talon import Module, actions, settings, speech_system REPO_DIR = os.path.dirname(os.path.dirname(__file__)) mod = Module() -setting_deprecate_warning_interval_hours = mod.setting( +mod.setting( "deprecate_warning_interval_hours", type=float, desc="""How long, in hours, to wait before notifying the user again of a @@ -98,7 +98,7 @@ def deprecate_notify(id: str, message: str): maybe_last_shown = notification_last_shown.get(id) now = datetime.datetime.now() - interval = setting_deprecate_warning_interval_hours.get() + interval = settings.get("user.deprecate_warning_interval_hours") threshold = now - datetime.timedelta(hours=interval) if maybe_last_shown is not None and maybe_last_shown > threshold: return diff --git a/core/help/help.py b/core/help/help.py index 1342bd87bc..b9ca147a3b 100644 --- a/core/help/help.py +++ b/core/help/help.py @@ -5,18 +5,18 @@ from itertools import islice from typing import Iterable -from talon import Context, Module, actions, imgui, registry +from talon import Context, Module, actions, imgui, registry, settings mod = Module() mod.list("help_contexts", desc="list of available contexts") mod.tag("help_open", "tag for commands that are available only when help is visible") -setting_help_max_contexts_per_page = mod.setting( +mod.setting( "help_max_contexts_per_page", type=int, default=20, desc="Max contexts to display per page in help", ) -setting_help_max_command_lines_per_page = mod.setting( +mod.setting( "help_max_command_lines_per_page", type=int, default=50, @@ -109,20 +109,22 @@ def format_context_button(index: int, context_label: str, context_name: str) -> # translates 1-based index -> actual index in sorted_context_map_keys def get_context_page(index: int) -> int: - return math.ceil(index / setting_help_max_contexts_per_page.get()) + return math.ceil(index / settings.get("user.help_max_contexts_per_page")) def get_total_context_pages() -> int: return math.ceil( - len(sorted_display_list) / setting_help_max_contexts_per_page.get() + len(sorted_display_list) / settings.get("user.help_max_contexts_per_page") ) def get_current_context_page_length() -> int: - start_index = (current_context_page - 1) * setting_help_max_contexts_per_page.get() + start_index = (current_context_page - 1) * settings.get( + "user.help_max_contexts_per_page" + ) return len( sorted_display_list[ - start_index : start_index + setting_help_max_contexts_per_page.get() + start_index : start_index + settings.get("user.help_max_contexts_per_page") ] ) @@ -150,9 +152,8 @@ def get_pages(item_line_counts: list[int]) -> list[int]: current_page = 1 pages = [] for line_count in item_line_counts: - if ( - line_count + current_page_line_count - > setting_help_max_command_lines_per_page.get() + if line_count + current_page_line_count > settings.get( + "user.help_max_command_lines_per_page" ): if current_page_line_count == 0: # Special case, render a larger page. @@ -468,7 +469,7 @@ def hide_all_help_guis(): def paginate_list(data, SIZE=None): - chunk_size = SIZE or setting_help_max_command_lines_per_page.get() + chunk_size = SIZE or settings.get("user.help_max_command_lines_per_page") it = iter(data) for i in range(0, len(data), chunk_size): yield {k: data[k] for k in islice(it, chunk_size)} @@ -630,8 +631,9 @@ def help_select_index(index: int): """Select the context by a number""" global sorted_display_list, selected_context if gui_context_help.showing: - if index < setting_help_max_contexts_per_page.get() and ( - (current_context_page - 1) * setting_help_max_contexts_per_page.get() + if index < settings.get("user.help_max_contexts_per_page") and ( + (current_context_page - 1) + * settings.get("user.help_max_contexts_per_page") + index < len(sorted_display_list) ): @@ -639,7 +641,7 @@ def help_select_index(index: int): selected_context = display_name_to_context_name_map[ sorted_display_list[ (current_context_page - 1) - * setting_help_max_contexts_per_page.get() + * settings.get("user.help_max_contexts_per_page") + index ] ] diff --git a/core/help/help_scope.py b/core/help/help_scope.py index 02ba0263a8..0478573e08 100644 --- a/core/help/help_scope.py +++ b/core/help/help_scope.py @@ -1,10 +1,10 @@ -from talon import Context, Module, actions, imgui, scope, ui +from talon import Context, Module, actions, imgui, scope, settings, ui ctx = Context() mod = Module() mod.tag("help_scope_open", "tag for showing the scope help gui") -setting_max_length = mod.setting( +mod.setting( "help_scope_max_length", type=int, default=50, @@ -52,8 +52,9 @@ def print_value(gui: imgui.GUI, path: str, value, ignore: set[str] = {}): def format_value(value): if isinstance(value, (list, set)): value = ", ".join(sorted(value)) - if isinstance(value, str) and len(value) > setting_max_length.get() + 4: - return f"{value[:setting_max_length.get()]} ..." + setting_max_length = settings.get("user.help_scope_max_length") + if isinstance(value, str) and len(value) > setting_max_length + 4: + return f"{value[:setting_max_length]} ..." return value diff --git a/core/mouse_grid/mouse_grid.py b/core/mouse_grid/mouse_grid.py index 115ee5c89e..0bb226d394 100644 --- a/core/mouse_grid/mouse_grid.py +++ b/core/mouse_grid/mouse_grid.py @@ -8,13 +8,13 @@ from talon.types.point import Point2d mod = Module() -narrow_expansion = mod.setting( +mod.setting( "grid_narrow_expansion", type=int, default=0, desc="""After narrowing, grow the new region by this many pixels in every direction, to make things immediately on edges easier to hit, and when the grid is at its smallest, it allows you to still nudge it around""", ) -grids_put_one_bottom_left = mod.setting( +mod.setting( "grids_put_one_bottom_left", type=bool, default=False, @@ -24,7 +24,7 @@ mod.tag("mouse_grid_showing", desc="Tag indicates whether the mouse grid is showing") mod.tag( "mouse_grid_enabled", - desc="Deprecated: do not use. Activates legacy m grid command", + desc="Deprecated: do not use. Activates legacy m grid command", ) ctx = Context() @@ -152,7 +152,7 @@ def draw_text(offset_x, offset_y, width, height): for row in range(3): for col in range(3): text_string = "" - if settings["user.grids_put_one_bottom_left"]: + if settings.get("user.grids_put_one_bottom_left"): text_string = f"{(2 - row)*3+col+1}" else: text_string = f"{row*3+col+1}" @@ -207,10 +207,10 @@ def draw_text(offset_x, offset_y, width, height): def calc_narrow(self, which, rect): rect = rect.copy() - bdr = narrow_expansion.get() + bdr = settings.get("user.grid_narrow_expansion") row = int(which - 1) // 3 col = int(which - 1) % 3 - if settings["user.grids_put_one_bottom_left"]: + if settings.get("user.grids_put_one_bottom_left"): row = 2 - row rect.x += int(col * rect.width // 3) - bdr rect.y += int(row * rect.height // 3) - bdr diff --git a/core/snippets/snippets.py b/core/snippets/snippets.py index d36e87c0e1..ddd7ebb788 100644 --- a/core/snippets/snippets.py +++ b/core/snippets/snippets.py @@ -2,7 +2,7 @@ from collections import defaultdict from pathlib import Path -from talon import Context, Module, actions, app, fs +from talon import Context, Module, actions, app, fs, settings from ..modes.language_modes import language_ids from .snippet_types import Snippet @@ -16,11 +16,11 @@ mod.list("snippet_with_phrase", "List of insertion snippets containing a text phrase") mod.list("snippet_wrapper", "List of wrapper snippets") -setting_dir = mod.setting( +mod.setting( "snippets_dir", - str, - desc="Directory(relative to Talon user) containing additional snippets", + type=str, default=None, + desc="Directory (relative to Talon user) containing additional snippets", ) context_map = { @@ -37,10 +37,11 @@ def get_setting_dir(): - if not setting_dir.get(): + setting_dir = settings.get("user.snippets_dir") + if not setting_dir: return None - dir = Path(setting_dir.get()) + dir = Path(setting_dir) if not dir.is_absolute(): user_dir = Path(actions.path.talon_user()) diff --git a/core/text/text_and_dictation.py b/core/text/text_and_dictation.py index 5304fc86c7..fe5189f0da 100644 --- a/core/text/text_and_dictation.py +++ b/core/text/text_and_dictation.py @@ -2,11 +2,11 @@ import re from typing import Callable, Optional -from talon import Context, Module, actions, grammar, ui +from talon import Context, Module, actions, grammar, settings, ui mod = Module() -setting_context_sensitive_dictation = mod.setting( +mod.setting( "context_sensitive_dictation", type=bool, default=False, @@ -375,7 +375,7 @@ def dictation_insert_raw(text: str): def dictation_insert(text: str, auto_cap: bool = True) -> str: """Inserts dictated text, formatted appropriately.""" add_space_after = False - if setting_context_sensitive_dictation.get(): + if settings.get("user.context_sensitive_dictation"): # Peek left if we might need leading space or auto-capitalization; # peek right if we might need trailing space. NB. We peek right # BEFORE insertion to avoid breaking the undo-chain between the diff --git a/core/windows_and_tabs/window_snap.py b/core/windows_and_tabs/window_snap.py index 519a7ab89c..ef56cc83fb 100644 --- a/core/windows_and_tabs/window_snap.py +++ b/core/windows_and_tabs/window_snap.py @@ -10,14 +10,14 @@ import logging from typing import Optional -from talon import Context, Module, actions, ui +from talon import Context, Module, actions, settings, ui mod = Module() mod.list( "window_snap_positions", "Predefined window positions for the current window. See `RelativeScreenPos`.", ) -setting_window_snap_screen = mod.setting( +mod.setting( "window_snap_screen", type=str, default="proportional", @@ -116,7 +116,7 @@ def _move_to_screen( dest = dest_screen.visible_rect src = src_screen.visible_rect - how = setting_window_snap_screen.get() + how = settings.get("user.window_snap_screen") if how == "size aware": r = window.rect left, right = interpolate_interval( diff --git a/plugin/command_history/command_history.py b/plugin/command_history/command_history.py index 6f3dbd7164..564f4f4069 100644 --- a/plugin/command_history/command_history.py +++ b/plugin/command_history/command_history.py @@ -5,10 +5,8 @@ # We keep command_history_size lines of history, but by default display only # command_history_display of them. mod = Module() -setting_command_history_size = mod.setting("command_history_size", int, default=50) -setting_command_history_display = mod.setting( - "command_history_display", int, default=10 -) +mod.setting("command_history_size", type=int, default=50) +mod.setting("command_history_display", type=int, default=10) hist_more = False history = [] @@ -33,7 +31,9 @@ def gui(gui: imgui.GUI): gui.text("Command History") gui.line() text = ( - history[:] if hist_more else history[-setting_command_history_display.get() :] + history[:] + if hist_more + else history[-settings.get("user.command_history_display") :] ) for line in text: gui.text(line) diff --git a/plugin/draft_editor/draft_editor.py b/plugin/draft_editor/draft_editor.py index f6a81f977f..84f14e25c7 100644 --- a/plugin/draft_editor/draft_editor.py +++ b/plugin/draft_editor/draft_editor.py @@ -1,4 +1,4 @@ -from talon import Context, Module, actions, ui +from talon import Context, Module, actions, settings, ui mod = Module() mod.tag("draft_editor_active", "Indicates whether the draft editor has been activated") @@ -23,7 +23,7 @@ def remove_tag(tag: str): default_names = ["Visual Studio Code", "Code", "VSCodium", "Codium", "code-oss"] -setting_editor_names = mod.setting( +mod.setting( "draft_editor", type=str, default=None, @@ -32,7 +32,7 @@ def remove_tag(tag: str): def get_editor_names(): - names_csv = setting_editor_names.get() + names_csv = settings.get("user.draft_editor") return names_csv.split(", ") if names_csv else default_names diff --git a/plugin/mode_indicator/mode_indicator.py b/plugin/mode_indicator/mode_indicator.py index fd2dea58c8..8daf199f41 100644 --- a/plugin/mode_indicator/mode_indicator.py +++ b/plugin/mode_indicator/mode_indicator.py @@ -1,4 +1,4 @@ -from talon import Module, app, registry, scope, skia, ui +from talon import Module, app, registry, scope, settings, skia, ui from talon.canvas import Canvas from talon.screen import Screen from talon.skia.canvas import Canvas as SkiaCanvas @@ -9,80 +9,77 @@ current_mode = "" mod = Module() -setting_show = mod.setting( +mod.setting( "mode_indicator_show", - bool, - desc="If true the mode indicator is shown", + type=bool, default=False, + desc="If true the mode indicator is shown", ) -setting_size = mod.setting( +mod.setting( "mode_indicator_size", - float, + type=float, desc="Mode indicator diameter in pixels", ) -setting_x = mod.setting( +mod.setting( "mode_indicator_x", - float, + type=float, desc="Mode indicator center X-position in percentages(0-1). 0=left, 1=right", ) -setting_y = mod.setting( +mod.setting( "mode_indicator_y", - float, + type=float, desc="Mode indicator center Y-position in percentages(0-1). 0=top, 1=bottom", ) -setting_color_alpha = mod.setting( +mod.setting( "mode_indicator_color_alpha", - float, + type=float, desc="Mode indicator alpha/opacity in percentages(0-1). 0=fully transparent, 1=fully opaque", ) -setting_color_gradient = mod.setting( +mod.setting( "mode_indicator_color_gradient", - float, + type=float, desc="Mode indicator gradient brightness in percentages(0-1). 0=darkest, 1=brightest", ) -setting_color_sleep = mod.setting("mode_indicator_color_sleep", str) -setting_color_dictation = mod.setting("mode_indicator_color_dictation", str) -setting_color_mixed = mod.setting("mode_indicator_color_mixed", str) -setting_color_command = mod.setting("mode_indicator_color_command", str) -setting_color_other = mod.setting("mode_indicator_color_other", str) +mod.setting("mode_indicator_color_sleep", type=str) +mod.setting("mode_indicator_color_dictation", type=str) +mod.setting("mode_indicator_color_mixed", type=str) +mod.setting("mode_indicator_color_command", type=str) +mod.setting("mode_indicator_color_other", type=str) setting_paths = { - s.path - for s in [ - setting_show, - setting_size, - setting_x, - setting_y, - setting_color_alpha, - setting_color_gradient, - setting_color_sleep, - setting_color_dictation, - setting_color_mixed, - setting_color_command, - setting_color_other, - ] + "user.mode_indicator_show", + "user.mode_indicator_size", + "user.mode_indicator_x", + "user.mode_indicator_y", + "user.mode_indicator_color_alpha", + "user.mode_indicator_color_gradient", + "user.mode_indicator_color_sleep", + "user.mode_indicator_color_dictation", + "user.mode_indicator_color_mixed", + "user.mode_indicator_color_command", + "user.mode_indicator_color_other", } def get_mode_color() -> str: if current_mode == "sleep": - return setting_color_sleep.get() + return settings.get("user.mode_indicator_color_sleep") elif current_mode == "dictation": - return setting_color_dictation.get() + return settings.get("user.mode_indicator_color_dictation") elif current_mode == "mixed": - return setting_color_mixed.get() + return settings.get("user.mode_indicator_color_mixed") elif current_mode == "command": - return setting_color_command.get() + return settings.get("user.mode_indicator_color_command") else: - return setting_color_other.get() + return settings.get("user.mode_indicator_color_other") def get_alpha_color() -> str: - return f"{int(setting_color_alpha.get() * 255):02x}" + return f"{int(settings.get('user.mode_indicator_color_alpha') * 255):02x}" def get_gradient_color(color: str) -> str: - factor = setting_color_gradient.get() + factor = settings.get("user.mode_indicator_color_gradient") # hex -> rgb (r, g, b) = tuple(int(color[i : i + 2], 16) for i in (0, 2, 4)) # Darken rgb @@ -118,15 +115,15 @@ def move_indicator(): screen: Screen = ui.main_screen() rect = screen.rect scale = screen.scale if app.platform != "mac" else 1 - radius = setting_size.get() * scale / 2 + radius = settings.get("user.mode_indicator_size") * scale / 2 x = rect.left + min( - max(setting_x.get() * rect.width - radius, 0), + max(settings.get("user.mode_indicator_x") * rect.width - radius, 0), rect.width - 2 * radius, ) y = rect.top + min( - max(setting_y.get() * rect.height - radius, 0), + max(settings.get("user.mode_indicator_y") * rect.height - radius, 0), rect.height - 2 * radius, ) @@ -149,7 +146,7 @@ def hide_indicator(): def update_indicator(): - if setting_show.get(): + if settings.get("user.mode_indicator_show"): if not canvas: show_indicator() move_indicator() diff --git a/plugin/mouse/mouse.py b/plugin/mouse/mouse.py index 6762dc0723..a86f5d9ed8 100644 --- a/plugin/mouse/mouse.py +++ b/plugin/mouse/mouse.py @@ -1,6 +1,6 @@ import os -from talon import Context, Module, actions, app, clip, cron, ctrl, imgui, ui +from talon import Context, Module, actions, app, clip, cron, ctrl, imgui, settings, ui from talon_plugins import eye_zoom_mouse key = actions.key @@ -47,49 +47,49 @@ mod.tag( "mouse_cursor_commands_enable", desc="Tag enables hide/show mouse cursor commands" ) -setting_mouse_enable_pop_click = mod.setting( +mod.setting( "mouse_enable_pop_click", type=int, default=0, desc="Pop noise clicks left mouse button. 0 = off, 1 = on with eyetracker but not with zoom mouse mode, 2 = on but not with zoom mouse mode", ) -setting_mouse_enable_pop_stops_scroll = mod.setting( +mod.setting( "mouse_enable_pop_stops_scroll", type=int, default=0, desc="When enabled, pop stops continuous scroll modes (wheel upper/downer/gaze)", ) -setting_mouse_enable_hiss_scroll = mod.setting( +mod.setting( "mouse_enable_hiss_scroll", type=bool, default=False, desc="Hiss noise scrolls down when enabled", ) -setting_mouse_wake_hides_cursor = mod.setting( +mod.setting( "mouse_wake_hides_cursor", type=int, default=0, desc="When enabled, mouse wake will hide the cursor. mouse_wake enables zoom mouse.", ) -setting_mouse_hide_mouse_gui = mod.setting( +mod.setting( "mouse_hide_mouse_gui", type=int, default=0, desc="When enabled, the 'Scroll Mouse' GUI will not be shown.", ) -setting_mouse_continuous_scroll_amount = mod.setting( +mod.setting( "mouse_continuous_scroll_amount", type=int, default=80, desc="The default amount used when scrolling continuously", ) -setting_mouse_wheel_down_amount = mod.setting( +mod.setting( "mouse_wheel_down_amount", type=int, default=120, desc="The amount to scroll up/down (equivalent to mouse wheel on Windows by default)", ) -setting_mouse_wheel_horizontal_amount = mod.setting( +mod.setting( "mouse_wheel_horizontal_amount", type=int, default=40, @@ -126,7 +126,7 @@ def mouse_wake(): """Enable control mouse, zoom mouse, and disables cursor""" actions.tracking.control_zoom_toggle(True) - if setting_mouse_wake_hides_cursor.get() >= 1: + if settings.get("user.mouse_wake_hides_cursor") >= 1: show_cursor_helper(False) def mouse_drag(button: int): @@ -159,42 +159,46 @@ def mouse_sleep(): def mouse_scroll_down(amount: float = 1): """Scrolls down""" - mouse_scroll(amount * setting_mouse_wheel_down_amount.get())() + mouse_scroll(amount * settings.get("user.mouse_wheel_down_amount"))() def mouse_scroll_down_continuous(): """Scrolls down continuously""" global continuous_scoll_mode continuous_scoll_mode = "scroll down continuous" - mouse_scroll(setting_mouse_continuous_scroll_amount.get())() + mouse_scroll(settings.get("user.mouse_continuous_scroll_amount"))() if scroll_job is None: start_scroll() - if setting_mouse_hide_mouse_gui.get() == 0: + if settings.get("user.mouse_hide_mouse_gui") == 0: gui_wheel.show() def mouse_scroll_up(amount: float = 1): """Scrolls up""" - mouse_scroll(-amount * setting_mouse_wheel_down_amount.get())() + mouse_scroll(-amount * settings.get("user.mouse_wheel_down_amount"))() def mouse_scroll_up_continuous(): """Scrolls up continuously""" global continuous_scoll_mode continuous_scoll_mode = "scroll up continuous" - mouse_scroll(-setting_mouse_continuous_scroll_amount.get())() + mouse_scroll(-settings.get("user.mouse_continuous_scroll_amount"))() if scroll_job is None: start_scroll() - if setting_mouse_hide_mouse_gui.get() == 0: + if settings.get("user.mouse_hide_mouse_gui") == 0: gui_wheel.show() def mouse_scroll_left(amount: float = 1): """Scrolls left""" - actions.mouse_scroll(0, -amount * setting_mouse_wheel_horizontal_amount.get()) + actions.mouse_scroll( + 0, -amount * settings.get("user.mouse_wheel_horizontal_amount") + ) def mouse_scroll_right(amount: float = 1): """Scrolls right""" - actions.mouse_scroll(0, amount * setting_mouse_wheel_horizontal_amount.get()) + actions.mouse_scroll( + 0, amount * settings.get("user.mouse_wheel_horizontal_amount") + ) def mouse_scroll_stop(): """Stops scrolling""" @@ -206,7 +210,7 @@ def mouse_gaze_scroll(): continuous_scoll_mode = "gaze scroll" start_cursor_scrolling() - if setting_mouse_hide_mouse_gui.get() == 0: + if settings.get("user.mouse_hide_mouse_gui") == 0: gui_wheel.show() # enable 'control mouse' if eye tracker is present and not enabled already @@ -274,14 +278,14 @@ def show_cursor_helper(show): @ctx.action_class("user") class UserActions: def noise_trigger_pop(): - if setting_mouse_enable_pop_stops_scroll.get() >= 1 and ( + if settings.get("user.mouse_enable_pop_stops_scroll") >= 1 and ( gaze_job or scroll_job ): # Allow pop to stop scroll stop_scroll() else: # Otherwise respect the mouse_enable_pop_click setting - setting_val = setting_mouse_enable_pop_click.get() + setting_val = settings.get("user.mouse_enable_pop_click") is_using_eye_tracker = ( actions.tracking.control_zoom_enabled() @@ -299,7 +303,7 @@ def noise_trigger_pop(): ctrl.mouse_click(button=0, hold=16000) def noise_trigger_hiss(active: bool): - if setting_mouse_enable_hiss_scroll.get(): + if settings.get("user.mouse_enable_hiss_scroll"): if active: if hiss_scroll_up: actions.user.mouse_scroll_up_continuous() diff --git a/plugin/paste_to_insert.py b/plugin/paste_to_insert.py index c51529982e..a89dfd04e5 100644 --- a/plugin/paste_to_insert.py +++ b/plugin/paste_to_insert.py @@ -5,7 +5,7 @@ mod = Module() ctx = Context() -paste_to_insert_threshold_setting = mod.setting( +mod.setting( "paste_to_insert_threshold", type=int, default=-1, diff --git a/plugin/screenshot/screenshot.py b/plugin/screenshot/screenshot.py index 8b1093a7f5..650a161656 100644 --- a/plugin/screenshot/screenshot.py +++ b/plugin/screenshot/screenshot.py @@ -2,7 +2,7 @@ from datetime import datetime from typing import Optional -from talon import Context, Module, actions, app, clip, cron, screen, ui +from talon import Context, Module, actions, app, clip, cron, screen, settings, ui from talon.canvas import Canvas mod = Module() @@ -13,7 +13,7 @@ if not os.path.isdir(default_folder): default_folder = os.path.join("~", "Pictures") -screenshot_folder = mod.setting( +mod.setting( "screenshot_folder", type=str, default=default_folder, @@ -82,7 +82,7 @@ def get_screenshot_path(title: str = ""): title = f" - {title.replace('.', '_')}" date = datetime.now().strftime("%Y-%m-%dT%H-%M-%S") filename = f"Screenshot {date}{title}.png" - folder_path = screenshot_folder.get() + folder_path = settings.get("user.screenshot_folder") path = os.path.expanduser(os.path.join(folder_path, filename)) return os.path.normpath(path) diff --git a/plugin/text_navigation/text_navigation.py b/plugin/text_navigation/text_navigation.py index 828e7ed354..050345c97c 100644 --- a/plugin/text_navigation/text_navigation.py +++ b/plugin/text_navigation/text_navigation.py @@ -1,30 +1,30 @@ import itertools import re -from talon import Context, Module, actions +from talon import Context, Module, actions, settings ctx = Context() mod = Module() -text_navigation_max_line_search = mod.setting( +mod.setting( "text_navigation_max_line_search", type=int, default=10, - desc="the maximum number of rows that will be included in the search for the keywords above and below in ", + desc="The maximum number of rows that will be included in the search for the keywords above and below in ", ) mod.list( "navigation_action", - desc="actions to perform, for instance move, select, cut, etc", + desc="Actions to perform, for instance move, select, cut, etc", ) mod.list( "before_or_after", - desc="words to indicate if the cursor should be moved before or after a given reference point", + desc="Words to indicate if the cursor should be moved before or after a given reference point", ) mod.list( "navigation_target_name", - desc="names for regular expressions for common things to navigate to, for instance a word with or without underscores", + desc="Names for regular expressions for common things to navigate to, for instance a word with or without underscores", ) ctx.lists["self.navigation_action"] = { @@ -132,7 +132,7 @@ def get_text_right(): def get_text_up(): actions.edit.up() actions.edit.line_end() - for j in range(0, text_navigation_max_line_search.get()): + for j in range(0, settings.get("user.text_navigation_max_line_search")): actions.edit.extend_up() actions.edit.extend_line_start() text = actions.edit.selected_text() @@ -143,7 +143,7 @@ def get_text_up(): def get_text_down(): actions.edit.down() actions.edit.line_start() - for j in range(0, text_navigation_max_line_search.get()): + for j in range(0, settings.get("user.text_navigation_max_line_search")): actions.edit.extend_down() actions.edit.extend_line_end() text = actions.edit.selected_text() diff --git a/tags/file_manager/file_manager.py b/tags/file_manager/file_manager.py index 35f575f9b0..7062275ebb 100644 --- a/tags/file_manager/file_manager.py +++ b/tags/file_manager/file_manager.py @@ -31,31 +31,31 @@ "exe", ] -setting_auto_show_pickers = mod.setting( +mod.setting( "file_manager_auto_show_pickers", type=int, default=0, desc="Enable to show the file/directories pickers automatically", ) -setting_folder_limit = mod.setting( +mod.setting( "file_manager_folder_limit", type=int, default=1000, desc="Maximum number of files/folders to iterate", ) -setting_file_limit = mod.setting( +mod.setting( "file_manager_file_limit", type=int, default=1000, desc="Maximum number of files to iterate", ) -setting_imgui_limit = mod.setting( +mod.setting( "file_manager_imgui_limit", type=int, default=20, desc="Maximum number of files/folders to display in the imgui", ) -setting_imgui_string_limit = mod.setting( +mod.setting( "file_manager_string_limit", type=int, default=20, @@ -134,13 +134,17 @@ def file_manager_hide_pickers(): def file_manager_get_directory_by_index(index: int) -> str: """Returns the requested directory for the imgui display by index""" - index = (current_folder_page - 1) * setting_imgui_limit.get() + index + index = (current_folder_page - 1) * settings.get( + "user.file_manager_imgui_limit" + ) + index assert index < len(folder_selections) return folder_selections[index] def file_manager_get_file_by_index(index: int) -> str: """Returns the requested directory for the imgui display by index""" - index = (current_file_page - 1) * setting_imgui_limit.get() + index + index = (current_file_page - 1) * settings.get( + "user.file_manager_imgui_limit" + ) + index assert index < len(file_selections) return file_selections[index] @@ -234,21 +238,29 @@ def get_file_map(current_path): def gui_folders(gui: imgui.GUI): global current_folder_page, total_folder_pages total_folder_pages = math.ceil( - len(ctx.lists["self.file_manager_directories"]) / setting_imgui_limit.get() + len(ctx.lists["self.file_manager_directories"]) + / settings.get("user.file_manager_imgui_limit") ) gui.text(f"Select a directory ({current_folder_page}/{total_folder_pages})") gui.line() index = 1 - current_index = (current_folder_page - 1) * setting_imgui_limit.get() + current_index = (current_folder_page - 1) * settings.get( + "user.file_manager_imgui_limit" + ) - while index <= setting_imgui_limit.get() and current_index < len(folder_selections): + while index <= settings.get( + "user.file_manager_imgui_limit" + ) and current_index < len(folder_selections): name = ( ( - folder_selections[current_index][: setting_imgui_string_limit.get()] + folder_selections[current_index][ + : settings.get("user.file_manager_string_limit") + ] + ".." ) - if len(folder_selections[current_index]) > setting_imgui_string_limit.get() + if len(folder_selections[current_index]) + > settings.get("user.file_manager_string_limit") else folder_selections[current_index] ) gui.text(f"{index}: {name} ") @@ -272,17 +284,29 @@ def gui_folders(gui: imgui.GUI): @imgui.open(y=10, x=1300) def gui_files(gui: imgui.GUI): global file_selections, current_file_page, total_file_pages - total_file_pages = math.ceil(len(file_selections) / setting_imgui_limit.get()) + total_file_pages = math.ceil( + len(file_selections) / settings.get("user.file_manager_imgui_limit") + ) gui.text(f"Select a file ({current_file_page}/{total_file_pages})") gui.line() index = 1 - current_index = (current_file_page - 1) * setting_imgui_limit.get() + current_index = (current_file_page - 1) * settings.get( + "user.file_manager_imgui_limit" + ) - while index <= setting_imgui_limit.get() and current_index < len(file_selections): + while index <= settings.get( + "user.file_manager_imgui_limit" + ) and current_index < len(file_selections): name = ( - (file_selections[current_index][: setting_imgui_string_limit.get()] + "..") - if len(file_selections[current_index]) > setting_imgui_string_limit.get() + ( + file_selections[current_index][ + : settings.get("user.file_manager_string_limit") + ] + + ".." + ) + if len(file_selections[current_index]) + > settings.get("user.file_manager_string_limit") else file_selections[current_index] )