Skip to content

Commit

Permalink
Merge pull request #75 from samirg1/typing-update
Browse files Browse the repository at this point in the history
Typing update
  • Loading branch information
samirg1 authored Sep 29, 2023
2 parents 95bcdca + d5a78a8 commit 08ca1f7
Show file tree
Hide file tree
Showing 27 changed files with 113 additions and 105 deletions.
2 changes: 1 addition & 1 deletion exe_setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys

from cx_Freeze import Executable, setup # type: ignore
from cx_Freeze import Executable, setup # pyright: ignore[reportMissingTypeStubs, reportUnknownVariableType]

build_exe = {
"excludes": ["pytest", "PyQt6", "PyQt5", "cv2", "numpy", "mypy", "test", "email", "pydoc_data", "multiprocessing", "rubicon"],
Expand Down
8 changes: 4 additions & 4 deletions src/App.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@


class App(tkinter.Tk):
def __init__(self):
def __init__(self) -> None:
super().__init__()
maxWidth = self.winfo_screenwidth()
width = 360
height = self.winfo_screenheight()
self.geometry(f"{width}x{height}+{maxWidth - width}+0")
self.title("AutoSMX")
self.attributes("-topmost", 1) # type: ignore
self.attributes("-topmost", 1) # pyright: ignore
self.iconphoto(True, PhotoImage(file=pathlib.Path(_APPLICATION_PATH, "autosmx.png")))

self.columnconfigure(0, weight=1)
Expand All @@ -50,7 +50,7 @@ def _frame(self) -> ttk.Frame:
frame.columnconfigure(3, weight=1)
return frame

def change_page(self, page: TPAGES):
def change_page(self, page: TPAGES) -> None:
if self.current_page is not None:
self.current_page.frame.grid_remove()
for widget in self.current_page.frame.winfo_children():
Expand All @@ -61,7 +61,7 @@ def change_page(self, page: TPAGES):
self.current_page.frame.grid(row=0, column=0, sticky="nsew")


def main():
def main() -> None:
App().mainloop()


Expand Down
2 changes: 1 addition & 1 deletion src/design/Job.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Job:
tests: list[Test] = field(factory=list, init=False, hash=False, eq=False)
test_breakdown: dict[str, int] = field(factory=dict, init=False, hash=False, eq=False)

def add_test(self, test: Test):
def add_test(self, test: Test) -> None:
self.tests.append(test)
self.test_breakdown[test.script.nickname] = self.test_breakdown.get(test.script.nickname, 0) + 1

Expand Down
4 changes: 2 additions & 2 deletions src/design/Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ def determine_script(self) -> Script:

raise ScriptError("No script found")

def add_testjob(self, testjob: TestJob):
def add_testjob(self, testjob: TestJob) -> None:
self.testjobs.append(testjob)

def complete(self, comment: str, final_result: str, script_answers: list[str]):
def complete(self, comment: str, final_result: str, script_answers: list[str]) -> None:
self.script_answers = ["" if a == " " else "N/A" if a == "" else a for a in script_answers]
self.comment = comment.strip()
self.final_result = final_result
Expand Down
6 changes: 3 additions & 3 deletions src/design/TestJobManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@


class TestJobManager:
def __init__(self):
def __init__(self) -> None:
self.job_to_testjobs: dict[Job, list[TestJob]] = {}
self.testjob_to_item: dict[TestJob, Item] = {}

def add_testjob(self, item: Item, job: Job, testjob: TestJob):
def add_testjob(self, item: Item, job: Job, testjob: TestJob) -> None:
self.job_to_testjobs.setdefault(job, []).append(testjob)
self.testjob_to_item[testjob] = item

def delete_testjob(self, job: Job, testjob: TestJob):
def delete_testjob(self, job: Job, testjob: TestJob) -> None:
self.job_to_testjobs[job].pop()
del self.testjob_to_item[testjob]
2 changes: 1 addition & 1 deletion src/design/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pyright: reportUnusedImport=false
from design.Script import Script
from design.data import SCRIPTS
from design.data import SCRIPTS, SCRIPT_DOWNS
from design.Item import Item
from design.Job import Job
from design.Test import Test, ScriptError, TEST_RESULTS
Expand Down
28 changes: 14 additions & 14 deletions src/gui/automations.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

try:
import pyautogui
import pyperclip # type: ignore
import pyperclip # pyright: ignore
from pynput import mouse
except KeyError:
pyautogui = None
Expand All @@ -18,9 +18,9 @@


def _automation_wrapper(default: Any | None = None) -> Callable[[Callable[..., Any]], Any]: # testing decorator for printing, delaying, and returning default values
def decorator(func: Callable[..., Any]):
def decorator(func: Callable[..., Any]): # type: ignore[no-untyped-def]
@functools.wraps(func)
def wrapper(*args: Any, **kwargs: Any):
def wrapper(*args: Any, **kwargs: Any) -> Any | None:
if _DELAY:
pyautogui.sleep(_DELAY) # pyright: ignore[reportOptionalMemberAccess]

Expand All @@ -36,23 +36,23 @@ def wrapper(*args: Any, **kwargs: Any):


@_automation_wrapper()
def click_key(*keys: str, times: int = 1):
def click_key(*keys: str, times: int = 1) -> None:
for _ in range(times):
pyautogui.hotkey(*keys) # pyright: ignore[reportOptionalMemberAccess]


@_automation_wrapper()
def wait(seconds: float):
def wait(seconds: float) -> None:
pyautogui.sleep(seconds) # pyright: ignore[reportOptionalMemberAccess]


@_automation_wrapper()
def type(text: str):
def type(text: str) -> None:
pyautogui.typewrite(text) # pyright: ignore[reportOptionalMemberAccess]


@_automation_wrapper()
def click(position: tuple[int, int], /, *, times: int = 1):
def click(position: tuple[int, int], /, *, times: int = 1) -> None:
for _ in range(times):
pyautogui.click(position) # pyright: ignore[reportOptionalMemberAccess]

Expand All @@ -61,24 +61,24 @@ def click(position: tuple[int, int], /, *, times: int = 1):
def get_click_position() -> tuple[int, int]:
position: tuple[int, int] = -1, -1

def on_click(x: float, y: float, button: mouse.Button, pressed: bool):
if button == mouse.Button.left and pressed:
def on_click(x: float, y: float, button: mouse.Button, pressed: bool) -> Literal[False] | None: # type: ignore
if button == mouse.Button.left and pressed: # pyright: ignore[reportOptionalMemberAccess]
nonlocal position
position = int(x), int(y)
return False

listener = mouse.Listener(on_click=on_click)
listener = mouse.Listener(on_click=on_click) # pyright: ignore
listener.start()
listener.join()

return position


@_automation_wrapper("selected text")
def get_selected_text():
old = pyperclip.paste()
def get_selected_text() -> str:
old = pyperclip.paste() # pyright: ignore[reportOptionalMemberAccess]
pyautogui.hotkey("ctrl" if os.name == "nt" else "command", "c", interval=0.05) # pyright: ignore[reportOptionalMemberAccess]
pyautogui.sleep(0.01) # pyright: ignore[reportOptionalMemberAccess]
selected = pyperclip.paste()
pyperclip.copy(old) # type: ignore
selected: str = pyperclip.paste() # pyright: ignore[reportOptionalMemberAccess]
pyperclip.copy(old) # pyright: ignore
return selected
2 changes: 1 addition & 1 deletion src/pages/CalibrationPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class CalibrationPage(Page):
def setup(self):
def setup(self) -> None:
if self.shared.storage.calibrated:
return self.change_page("JOB")
self.positions_set = 0
Expand Down
8 changes: 4 additions & 4 deletions src/pages/JobPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class JobPage(Page):
def setup(self):
def setup(self) -> None:
# top row
ttk.Label(self.frame, text="Jobs").grid(column=0, row=0, columnspan=1)
ttk.Button(self.frame, text="+", width=1, command=self.add_tests).grid(column=1, row=0, columnspan=1)
Expand All @@ -18,7 +18,7 @@ def setup(self):
# tree setup
tree = ttk.Treeview(self.frame, columns=("text", "number"), show="tree headings", height=10, selectmode="browse")
style = ttk.Style(self.frame)
style.configure("Treeview", rowheight=60) # type: ignore
style.configure("Treeview", rowheight=60) # pyright: ignore
tree.column("#0", width=0)
tree.column("text", anchor=tkinter.W)
tree.column("number", width=10, anchor=tkinter.CENTER)
Expand Down Expand Up @@ -48,7 +48,7 @@ def setup(self):
tree.insert(test_node, tkinter.END, values=(f"{script_name}", value))

# completing tree setup
scrollbar = ttk.Scrollbar(self.frame, orient=tkinter.VERTICAL, command=tree.yview) # type: ignore
scrollbar = ttk.Scrollbar(self.frame, orient=tkinter.VERTICAL, command=tree.yview) # pyright: ignore
tree.configure(yscroll=scrollbar.set) # type: ignore
scrollbar.grid(row=row, column=4, sticky=tkinter.NS)
tree.grid(row=row, column=0, columnspan=4, sticky=tkinter.EW)
Expand All @@ -62,7 +62,7 @@ def setup(self):

tree.bind("<<TreeviewSelect>>", lambda _: self.on_first_select(tree, button1, button2))

def on_first_select(self, tree: ttk.Treeview, *buttons: ttk.Button):
def on_first_select(self, tree: ttk.Treeview, *buttons: ttk.Button) -> None:
for button in buttons:
button.configure(state="normal")
tree.unbind("<<TreeviewSelect>>")
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Page.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ def __init__(self, frame: ttk.Frame, change_page: Callable[[TPAGES], None], shar
self.shared = shared

@abstractmethod
def setup(self):
def setup(self) -> None:
...
22 changes: 11 additions & 11 deletions src/pages/TestPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


class TestPage(Page):
def setup(self):
def setup(self) -> None:
ttk.Button(self.frame, text="< Jobs", command=lambda: self.change_page("JOB")).grid(column=0, row=0, sticky="w")

ttk.Label(self.frame, text="Item Number").grid(column=0, row=1, columnspan=2)
Expand All @@ -38,12 +38,12 @@ def setup(self):

item_number.trace_add("write", lambda _, __, ___: self.edit_button_reconfigure(item_number))

def edit_button_reconfigure(self, item_number: StringVar):
def edit_button_reconfigure(self, item_number: StringVar) -> None:
tested = item_number.get() in self.shared.item_number_to_description
self.edit_button.configure(state=("normal" if tested else "disabled"))

def get_items(self, item_number: str, item_entry: ttk.Entry, /, *, choose_script: bool = False, editing: bool = False) -> None:
item_entry.state(["disabled"]) # type: ignore
item_entry.state(["disabled"]) # pyright: ignore
self.frame.focus()
assert self.shared.job

Expand Down Expand Up @@ -81,7 +81,7 @@ def get_test(self, item: Item, *, choose_script: bool = False) -> None:
script_popup.protocol("WM_DELETE_WINDOW", lambda: self.reset_page(item.number))
script_popup.mainloop()

def display_test(self, script: Script, test: Test):
def display_test(self, script: Script, test: Test) -> None:
test.script = script
self.test = test
self.choose_button.destroy()
Expand Down Expand Up @@ -157,19 +157,19 @@ def display_test(self, script: Script, test: Test):
save.bind("<Return>", lambda _: self.save_test([s.get() for s in actual_answers], result.get()))
row += 1

def add_testjob(self):
def add_testjob(self) -> None:
assert self.shared.job is not None
testjob_popup = TestJobPopup(self.frame, self.shared.job.department, self.shared.job.company, self.save_testjob)
testjob_popup.mainloop()

def save_testjob(self, testjob: TestJob):
def save_testjob(self, testjob: TestJob) -> None:
self.comment.insert(tkinter.END, testjob.test_comment + "\n\n")
self.test.add_testjob(testjob)
self.shared.testjob_manager.add_testjob(self.test.item, cast(Job, self.shared.job), testjob)
self.add_job_button.configure(text=f"Add Job ({len(self.test.testjobs)})")
self.delete_job_button.grid(column=3, row=self.add_job_button.grid_info()["row"], sticky="e")

def delete_test_job(self):
def delete_test_job(self) -> None:
testjob = self.test.testjobs.pop()
self.shared.testjob_manager.delete_testjob(cast(Job, self.shared.job), testjob)
current_comment = self.comment.get("1.0", tkinter.END).strip()
Expand All @@ -183,7 +183,7 @@ def delete_test_job(self):
add_job_text += f" ({len(self.test.testjobs)})"
self.add_job_button.configure(text=add_job_text)

def save_test(self, script_answers: list[str], result: str):
def save_test(self, script_answers: list[str], result: str) -> None:
assert self.shared.job # must have created a job by now
turn_off_capslock()
comment = self.comment.get("1.0", tkinter.END)
Expand Down Expand Up @@ -214,7 +214,7 @@ def reset_page(self, item_number: str) -> None:
self.shared.previous_item_number = item_number
self.change_page("TEST")

def update_storage(self, actual_script_answers: list[str]):
def update_storage(self, actual_script_answers: list[str]) -> None:
if self.saved_script_answers == actual_script_answers:
return

Expand All @@ -226,9 +226,9 @@ def update_storage(self, actual_script_answers: list[str]):
storage.item_model_to_script_answers[self.test.item_model] = actual_script_answers

def failsafe(self, current_item_number: str) -> None:
messagebox.showerror("Process Aborted", "Fail safe activated") # type: ignore
messagebox.showerror("Process Aborted", "Fail safe activated") # pyright: ignore
self.reset_page(current_item_number)

def item_not_found(self, current_item_number: str) -> None:
messagebox.showerror("Not Found", f"Item number '{current_item_number}' not tested yet") # type: ignore
messagebox.showerror("Not Found", f"Item number '{current_item_number}' not tested yet") # pyright: ignore
self.reset_page(current_item_number)
10 changes: 5 additions & 5 deletions src/pages/TutorialPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@


class TutorialPage(Page):
def setup(self):
def setup(self) -> None:
if self.shared.storage.tutorial_complete:
return self.change_page("CALIBRATION")

Expand All @@ -65,7 +65,7 @@ def setup(self):
# tree setup
tree = ttk.Treeview(self.frame, columns=("#1"), show="tree", height=15, selectmode=tkinter.NONE)
style = ttk.Style(self.frame)
style.configure("Treeview", rowheight=60) # type: ignore
style.configure("Treeview", rowheight=60) # pyright: ignore[reportUnknownMemberType]
tree.column("#0", width=0)
column = tree.column(tree["columns"][0])
assert column
Expand All @@ -79,12 +79,12 @@ def setup(self):
text.write(line + ("\n" if i != len(group) - 1 else ""))
tree.insert(section_node, tkinter.END, values=(text.getvalue(),))

scrollbar_y = ttk.Scrollbar(self.frame, orient=tkinter.VERTICAL, command=tree.yview) # type: ignore
scrollbar_y = ttk.Scrollbar(self.frame, orient=tkinter.VERTICAL, command=tree.yview) # pyright: ignore
tree.configure(yscroll=scrollbar_y.set) # type: ignore
scrollbar_y.grid(row=2, column=4, sticky=tkinter.NS)
tree.grid(row=2, column=0, columnspan=4, sticky=tkinter.EW)

def adjust_newlines(self, val: str, width: int):
def adjust_newlines(self, val: str, width: int) -> list[str]:
font = Font(font="TkDefaultFont")
words = val.split()
lines: list[str] = [""]
Expand All @@ -97,7 +97,7 @@ def adjust_newlines(self, val: str, width: int):

return lines

def end_tutorial(self):
def end_tutorial(self) -> None:
with self.shared.storage.edit() as storage:
storage.tutorial_complete = True
self.change_page("CALIBRATION")
4 changes: 2 additions & 2 deletions src/popups/CalibrationHelpPopup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def __init__(self, master: Misc | None, image_name: str):

img = Image.open(f"{_APPLICATION_PATH}/img/{image_name}.png")
img = img.resize((width, 500), resample=Image.LANCZOS)
img = ImageTk.PhotoImage(img) # type: ignore
panel = ttk.Label(self, image=img) # type: ignore
img = ImageTk.PhotoImage(img)
panel = ttk.Label(self, image=img)
panel.image = img # type: ignore
panel.grid(column=0, row=0, sticky="nsew")

Expand Down
2 changes: 1 addition & 1 deletion src/popups/OptionSelectPopup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, master: Misc | None, options: list[_T], callback: Callable[[_
for row, option in enumerate(options):
tree.insert("", tkinter.END, f"{row}", text=display(option), open=row == 0)

scrollbar = ttk.Scrollbar(self, orient=tkinter.VERTICAL, command=tree.yview) # type: ignore
scrollbar = ttk.Scrollbar(self, orient=tkinter.VERTICAL, command=tree.yview) # pyright: ignore[reportUnknownMemberType, reportUnknownArgumentType]
tree.configure(yscroll=scrollbar.set) # type: ignore
scrollbar.grid(row=0, column=2, sticky=tkinter.NS)
tree.grid(row=0, column=0, columnspan=2, sticky=tkinter.EW)
Expand Down
4 changes: 2 additions & 2 deletions src/popups/Popup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ def __init__(self, master: tkinter.Misc | None, title: str, /, *, width: int = 3
start_height = (max_height - height) // 2

self.geometry(f"{width}x{height}+{max_width - width}+{start_height}")
self.attributes("-topmost", 2) # type: ignore
self.attributes("-topmost", 2) # pyright: ignore
self.resizable(False, False)

for i in range(columns):
self.columnconfigure(i, weight=1)

def grid_remove(self): # ensure it gets cleaned up
def grid_remove(self) -> None: # ensure it gets cleaned up
self.destroy()
Loading

0 comments on commit 08ca1f7

Please sign in to comment.