Skip to content

Commit

Permalink
clean up further
Browse files Browse the repository at this point in the history
  • Loading branch information
C-Loftus committed Feb 27, 2024
1 parent c3afe34 commit 4f3e3ed
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 30 deletions.
5 changes: 2 additions & 3 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"recommendations": [
"ms-python.python",
"ms-python.vscode-pylance",
"charliermarsh.ruff",
"ms-python.black-formatter"
]
"charliermarsh.ruff"
]
}
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"editor.codeActionsOnSave": {
"source.fixAll": "always"
},
"editor.defaultFormatter": "ms-python.black-formatter"
"editor.defaultFormatter": "charliermarsh.ruff"
},
}
1 change: 0 additions & 1 deletion nvda/nvda-parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def nvda_set_setting(setting: str, value: bool):
@ctx.action_class("user")
class UserActions:
def nvda_set_setting(setting: str, value: bool):

# Load the nvda.ini file, skipping the first line
with open(PATH, "r") as f:
next(f) # Skip the first line
Expand Down
6 changes: 2 additions & 4 deletions utils/access-focus.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def dynamic_children(phrase) -> dict[str, str]:
"""ctx.selection lists are returned as a new string separated by 2 newlines"""
selection_string = ""
for e in elements:
assert (
type(e.name) == str
assert isinstance(
e.name, str
), f"Element name is not a string: {e.name} {e} {type(e)}"
selection_string += str(e.name).lower() + "\n\n"

Expand All @@ -55,13 +55,11 @@ def dynamic_children(phrase) -> dict[str, str]:

@mod.action_class
class Actions:

def focus_element_by_name(name: str, permissive: bool = True):
"""Focuses on an element by name. Change permissive to False to require an exact match."""
root = ui.active_window().element
elements = list(get_every_child(root))
for element in elements:

if element.name.lower() == name.lower() or (
permissive and name.lower() in element.name.lower()
):
Expand Down
72 changes: 51 additions & 21 deletions utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
from ..lib.HTMLbuilder import Builder
import threading


class VisibleTextParser(HTMLParser):
def __init__(self):
super().__init__()
self.text = []
self.ignore = False
self.ignore_tags = ['style', 'script', 'head', 'title', 'meta', '[document]']
self.ignore_tags = ["style", "script", "head", "title", "meta", "[document]"]

def handle_starttag(self, tag, attrs):
if tag in self.ignore_tags:
Expand All @@ -28,43 +29,74 @@ def handle_data(self, data):

mod = Module()

if os.name == 'nt':
if os.name == "nt":
import winsound


def remove_special(text):
specialChars = ["'", '"', "(", ")", "[", "]", "{", "}",
"<", ">", "|", "\\", "/", "_", "-", "+",
"=", "*", "&", "^", "%", "$", "#", "@",
"!", "`", "~", "?", ",", ".", ":", ";"]

specialChars = [
"'",
'"',
"(",
")",
"[",
"]",
"{",
"}",
"<",
">",
"|",
"\\",
"/",
"_",
"-",
"+",
"=",
"*",
"&",
"^",
"%",
"$",
"#",
"@",
"!",
"`",
"~",
"?",
",",
".",
":",
";",
]

for char in specialChars:
text = text.replace(char, "")

return text


@mod.action_class
class Actions:
def indentation_level(text: str) -> int:
'''count how many tabs are at the start of the line'''
"""count how many tabs are at the start of the line"""

space_count = 0
tab_count = 0
for char in text:
if char == '\t':
if char == "\t":
tab_count += 1
elif char == ' ':
elif char == " ":
space_count += 1
else:
break # Stop counting when a non-tab character is encountered
# every 4 spaces is a tab
tab_count += (space_count // 4)
tab_count += space_count // 4
return tab_count

def echo_context(include_title: bool = False):
"""Echo the current context"""
friendly_name = actions.app.name()
title = ui.active_window().title
friendly_name = actions.app.name()
title = ui.active_window().title
output = f"{friendly_name} {title}" if include_title else friendly_name
actions.user.tts(output)

Expand Down Expand Up @@ -116,27 +148,25 @@ def get_website_text(url: str) -> str:

# Parse HTML and extract visible text
parser = VisibleTextParser()
parser.feed(html_content.decode('utf-8', errors='ignore'))
parser.feed(html_content.decode("utf-8", errors="ignore"))

# Combine and return the visible text
return ' '.join(parser.text)
return " ".join(parser.text)

except Exception as e:
print("Error Parsing:", e)
return "Error Parsing"




ctxWindows = Context()
ctxWindows.matches = r"""
os: windows
"""


@ctxWindows.action_class("user")
class ActionsWin:

def beep(freq: int = 440, duration: int = 1000):
"""Beep"""
t = threading.Thread(target=winsound.Beep, args=(freq, duration))
t.start()
t.start()

0 comments on commit 4f3e3ed

Please sign in to comment.