Skip to content

Commit

Permalink
refactor(gui): fix type hints for self object
Browse files Browse the repository at this point in the history
  • Loading branch information
YisusChrist committed Aug 10, 2024
1 parent d25ddc4 commit 9b2fb0c
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions AnimeSnap/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class App(QMainWindow):
QMainWindow (QMainWindow): The main window of the application.
"""

def __init__(self: QMainWindow):
def __init__(self):
"""Constructor of the class"""
super().__init__()

Expand Down Expand Up @@ -123,7 +123,7 @@ def __init__(self: QMainWindow):
# Set the current page to the main menu
self.resize_to_main_menu()

def social_media_links(self: QMainWindow, layout: QVBoxLayout) -> None:
def social_media_links(self, layout: QVBoxLayout) -> None:
"""
Create the social media links.
Expand Down Expand Up @@ -173,7 +173,7 @@ def open_twitter() -> None:
"""Open the Twitter profile in the default browser."""
webbrowser.open(twitter_link, new=1)

def show_about(self: QMainWindow):
def show_about(self):
"""Show the about message."""
about_message = (
f"{NAME} - {DESC}\n\n"
Expand All @@ -184,7 +184,7 @@ def show_about(self: QMainWindow):

QMessageBox.about(self, "About", about_message)

def show_help(self: QMainWindow) -> None:
def show_help(self) -> None:
"""Show the help message."""
help_message = (
"How to Use AnimeSnap:\n"
Expand All @@ -196,7 +196,7 @@ def show_help(self: QMainWindow) -> None:
)
QMessageBox.information(self, "Help", help_message)

def create_main_menu_widget(self: QMainWindow) -> QWidget:
def create_main_menu_widget(self) -> QWidget:
"""
Create the main menu widget.
Expand Down Expand Up @@ -273,7 +273,7 @@ def create_main_menu_widget(self: QMainWindow) -> QWidget:
central_widget.setLayout(layout)
return central_widget

def create_result_widget(self: QMainWindow) -> QWidget:
def create_result_widget(self) -> QWidget:
"""
Create the result widget.
Expand All @@ -298,17 +298,17 @@ def create_result_widget(self: QMainWindow) -> QWidget:
widget.setLayout(layout)
return widget

def resize_to_main_menu(self: QMainWindow) -> None:
def resize_to_main_menu(self) -> None:
"""Resize the window to the main menu."""
self.setWindowTitle("AnimeSnap")
self.setGeometry(X, Y, 450, 150)

def resize_to_result_page(self: QMainWindow) -> None:
def resize_to_result_page(self) -> None:
"""Resize the window to the result page."""
self.setWindowTitle("AnimeSnap - Results")
self.setGeometry(X, Y, WIDTH, HEIGHT)

def switch_to_page(self: QMainWindow, page: QWidget) -> None:
def switch_to_page(self, page: QWidget) -> None:
"""Switch to the specified page.
Args:
Expand All @@ -321,7 +321,7 @@ def switch_to_page(self: QMainWindow, page: QWidget) -> None:
else:
self.resize_to_main_menu()

def open_image(self: QMainWindow) -> None:
def open_image(self) -> None:
"""Open a file dialog to select an image file."""
options = QFileDialog.Option.ReadOnly
image_extensions = " ".join(get_image_extensions())
Expand All @@ -338,22 +338,22 @@ def open_image(self: QMainWindow) -> None:
if file_path:
self.img_source_entry.setText(file_path)

def return_to_menu(self: QMainWindow) -> None:
def return_to_menu(self) -> None:
"""Return to the main menu."""
self.switch_to_page(self.main_menu_widget)

self.img_source_entry.clear()
self.anilist_entry.clear()

def on_click_theme_icon(self: QMainWindow) -> None:
def on_click_theme_icon(self) -> None:
"""Switch the theme of the application."""
# We set the icon to the opposite of the current theme
self.themes_button.setIcon(QIcon(f"{ICONS_PATH}/{self.ctheme}.png"))
self.ctheme = self.switch_theme_name()
palette = LightPalette if self.ctheme == "light" else None
self.setStyleSheet(load_stylesheet(qt_api="pyqt6", palette=palette))

def switch_theme_name(self: QMainWindow) -> str:
def switch_theme_name(self) -> str:
"""
Switch the theme name.
Expand All @@ -362,7 +362,7 @@ def switch_theme_name(self: QMainWindow) -> str:
"""
return "light" if self.ctheme == "dark" else "dark"

def on_click_search(self: QMainWindow) -> None:
def on_click_search(self) -> None:
"""Conduct an anime search."""
anilist_id = None
if self.anilist_entry.text():
Expand All @@ -386,7 +386,7 @@ def on_click_search(self: QMainWindow) -> None:
json_to_tabular(data=self.search_result, include_all_details=iad_status)
)

def write_to_json(self: QMainWindow) -> None:
def write_to_json(self) -> None:
"""Write the JSON result to a file."""
# Open a file dialog to select a file to write to
dialog = QFileDialog(self)
Expand All @@ -408,7 +408,7 @@ def write_to_json(self: QMainWindow) -> None:
except Exception as e:
QMessageBox.critical(self, "Error", str(e))

def run(self: QMainWindow):
def run(self):
"""Run the application."""
self.show()
self.raise_()
Expand Down

0 comments on commit 9b2fb0c

Please sign in to comment.