Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Add type hints to the addon functions #19

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions client/ayon_third_party/download_ui.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import uuid
import threading
from functools import partial
from typing import Optional, Callable

from qtpy import QtWidgets, QtCore

Expand All @@ -15,7 +16,7 @@


class DownloadItem:
def __init__(self, title, func):
def __init__(self, title: str, func: Callable):
self._id = uuid.uuid4().hex
progress = TransferProgress()
self._func = partial(func, progress)
Expand All @@ -24,11 +25,11 @@ def __init__(self, title, func):
self._thread = None

@property
def id(self):
def id(self) -> str:
return self._id

@property
def finished(self):
def finished(self) -> bool:
if self._thread is None:
return True
return not self._thread.is_alive()
Expand All @@ -46,7 +47,7 @@ def finish(self):


class DownloadController:
def __init__(self, ffmpeg, oiio):
def __init__(self, ffmpeg: bool, oiio: bool):
items = []
if ffmpeg:
items.append(DownloadItem("FFmpeg", download_ffmpeg))
Expand All @@ -71,15 +72,15 @@ def download_items(self):
yield item

@property
def download_started(self):
def download_started(self) -> bool:
return self._download_started

@property
def download_finished(self):
def download_finished(self) -> bool:
return self._download_finished

@property
def is_downloading(self):
def is_downloading(self) -> bool:
if not self._download_started or self._download_finished:
return False

Expand All @@ -104,8 +105,8 @@ def finish_download(self):


class DownloadItemWidget(QtWidgets.QWidget):
def __init__(self, download_item, parent):
super(DownloadItemWidget, self).__init__(parent)
def __init__(self, download_item: DownloadItem, parent: QtWidgets.QWidget):
super().__init__(parent)

title_label = QtWidgets.QLabel(download_item.title, self)
progress_label = QtWidgets.QLabel("0%", self)
Expand Down Expand Up @@ -147,8 +148,12 @@ def update_progress(self):
class DownloadWindow(QtWidgets.QWidget):
finished = QtCore.Signal()

def __init__(self, controller, parent=None):
super(DownloadWindow, self).__init__(parent=parent)
def __init__(
self,
controller: DownloadController,
parent: Optional[QtWidgets.QWidget] = None,
):
super().__init__(parent=parent)

self.setWindowTitle("Downloading 3rd party dependencies")

Expand Down Expand Up @@ -178,7 +183,7 @@ def __init__(self, controller, parent=None):
self._start_on_show = False

def showEvent(self, event):
super(DownloadWindow, self).showEvent(event)
super().showEvent(event)
if self._first_show:
self._first_show = False
# Set stylesheet and resize
Expand Down Expand Up @@ -219,7 +224,11 @@ def start(self):
self._timer.start()


def show_download_window(ffmpeg, oiio, parent=None):
def show_download_window(
ffmpeg: bool,
oiio: bool,
parent: Optional[QtWidgets.QWidget] = None,
) -> DownloadWindow:
controller = DownloadController(ffmpeg, oiio)
window = DownloadWindow(controller, parent=parent)
window.show()
Expand Down
Loading
Loading