This commit is contained in:
Sander Land committed 2020-06-22 14:43:23 +02:00
1 parent 91f0cff372
commit 0b6041a312
2 files changed
+20 -18

No files matched your search

+4 -7
View File
@@ -24,7 +24,7 @@ from katrain.core.constants import (
)
from katrain.core.engine import KataGoEngine
from katrain.core.lang import i18n
from katrain.core.utils import find_package_resource, PATHS
from katrain.core.utils import PATHS, find_package_resource
from katrain.gui.kivyutils import BackgroundMixin, I18NSpinner
from katrain.gui.style import DEFAULT_FONT, EVAL_COLORS
from katrain.gui.widgets.progress_loader import ProgressLoader
@@ -344,9 +344,6 @@ class ConfigPopup(QuickConfigGui):
self.model_files.text = models_available_msg
MODELS = {
# "pure 20b": "https://github.com/lightvector/KataGo/releases/download/v1.4.0/g170-b20c256x2-s4384473088-d968438914.bin.gz",
# "pure 30b": "https://github.com/lightvector/KataGo/releases/download/v1.4.0/g170-b30c320x2-s3530176512-d968463914.bin.gz",
# "pure 40b": "https://github.com/lightvector/KataGo/releases/download/v1.4.0/g170-b40c256x2-s3708042240-d967973220.bin.gz",
"final 20b": "https://github.com/lightvector/KataGo/releases/download/v1.4.5/g170e-b20c256x2-s5303129600-d1228401921.bin.gz",
"final 30b": "https://github.com/lightvector/KataGo/releases/download/v1.4.5/g170-b30c320x2-s4824661760-d1229536699.bin.gz",
"final 40b": "https://github.com/lightvector/KataGo/releases/download/v1.4.5/g170-b40c256x2-s5095420928-d1229425124.bin.gz",
@@ -362,7 +359,7 @@ class ConfigPopup(QuickConfigGui):
self.check_models()
for c in self.download_progress_box.children:
if isinstance(c,ProgressLoader) and c.request:
if isinstance(c, ProgressLoader) and c.request:
c.request.cancel()
self.download_progress_box.clear_widgets()
downloading = False
@@ -380,10 +377,10 @@ class ConfigPopup(QuickConfigGui):
download_complete=lambda req, tmp=savepath_tmp, path=savepath, model=name: download_complete(
req, tmp, path, model
),
download_redirected=lambda req,mname=name: self.katrain.log(
download_redirected=lambda req, mname=name: self.katrain.log(
f"Download {mname} redirected {req.resp_headers}", OUTPUT_DEBUG
),
download_error=lambda req,error,mname=name: self.katrain.log(
download_error=lambda req, error, mname=name: self.katrain.log(
f"Download of {mname} failed or cancelled ({error}) {req.resp_headers}", OUTPUT_ERROR
),
)
+16 -11
View File
@@ -1,9 +1,9 @@
# From KivyMD which will remove it in their next version, with some fixes
from kivy.clock import Clock
from kivy.animation import Animation
from kivy.network.urlrequest import UrlRequest
from kivy.clock import Clock
from kivy.lang import Builder
from kivy.properties import StringProperty, ObjectProperty
from kivy.network.urlrequest import UrlRequest
from kivy.properties import ObjectProperty, StringProperty
from kivy.uix.boxlayout import BoxLayout
Builder.load_string(
@@ -86,16 +86,18 @@ class ProgressLoader(BoxLayout):
on_progress=self.update_progress,
on_success=self.handle_success,
on_redirect=self.handle_redirect,
on_error=lambda req,error: self.handle_error(req,error),
on_failure=lambda req,res: self.handle_error(req,"Failure"),
on_cancel=lambda req: self.handle_error(req,"Cancelled"),
on_error=lambda req, error: self.handle_error(req, error),
on_failure=lambda req, res: self.handle_error(req, "Failure"),
on_cancel=lambda req: self.handle_error(req, "Cancelled"),
)
def handle_redirect(self, request, *_args):
new_url = request.resp_headers.get("location")
new_url = request.resp_headers.get("location") or request.resp_headers.get("Location")
if new_url:
self.download_url = new_url
self.request_download_file(self.download_url, self.path_to_file)
else:
self.handle_error()
if self.download_redirected:
self.download_redirected(request)
@@ -103,15 +105,18 @@ class ProgressLoader(BoxLayout):
self.root_instance.remove_widget(self)
def handle_error(self, request, error):
self.cleanup()
status = error
if request.resp_status:
status += f" ({request.resp_status})"
self.label_downloading_text = self.downloading_text.format(status)
if self.download_error:
self.download_error(request,error)
self.download_error(request, error)
def update_progress(self, request, current_size, total_size):
if total_size < 1e4:
current_size = 0
percent = current_size * 100 // max(total_size, 1)
self.label_downloading_text = self.downloading_text.format(percent)
percent = current_size / max(total_size, 1)
self.label_downloading_text = self.downloading_text.format(f"{percent:.1%}")
def handle_success(self, request, result):
self.cleanup()