Skip to content

Commit

Permalink
refactor into classvar for mpypy (#50)
Browse files Browse the repository at this point in the history
We need global state. Global vars are ugly but having in a class
variable annotated with the proper typing makes mypy happy :)

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
C-Loftus and pre-commit-ci[bot] authored Apr 6, 2024
1 parent 4364635 commit aa0a33b
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions GPT/gpt.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import os
from concurrent.futures import ThreadPoolExecutor
from typing import Any, Literal
from typing import Any, ClassVar, Literal

import requests
from talon import Module, actions, clip, imgui, registry, settings
Expand All @@ -11,15 +11,17 @@

mod = Module()

text_to_confirm = ""

class GuiState:
text_to_confirm: ClassVar[str] = ""


@imgui.open()
def confirmation_gui(gui: imgui.GUI):
gui.text("Confirm model output before pasting")
gui.line()
gui.spacer()
gui.text(text_to_confirm)
gui.text(GuiState.text_to_confirm)

gui.spacer()
if gui.button("Paste model output"):
Expand Down Expand Up @@ -73,26 +75,25 @@ def gpt_generate_shell(text_to_process: str) -> str:

def add_to_confirmation_gui(model_output: str):
"""Add text to the confirmation gui"""
global text_to_confirm
text_to_confirm = model_output
GuiState.text_to_confirm = model_output
confirmation_gui.show()

def close_model_confirmation_gui():
"""Close the model output without pasting it"""
global text_to_confirm
text_to_confirm = ""
GuiState.text_to_confirm = ""
confirmation_gui.hide()

def copy_model_confirmation_gui():
"""Copy the model output to the clipboard"""
global text_to_confirm
clip.set_text(text_to_confirm)
text_to_confirm = ""
clip.set_text(GuiState.text_to_confirm)
GuiState.text_to_confirm = ""

confirmation_gui.hide()

def paste_model_confirmation_gui():
"""Paste the model output"""
actions.user.paste(text_to_confirm)
actions.user.paste(GuiState.text_to_confirm)
GuiState.text_to_confirm = ""
confirmation_gui.hide()

def gpt_apply_prompt(prompt: str, text_to_process: str | list[str]) -> str:
Expand Down

0 comments on commit aa0a33b

Please sign in to comment.