Merge pull request #234 from wierzbowski/handle-pasting-urls-to-sgfs

Handle URL to sgf in clipboard on paste
This commit is contained in:
sanderland authored and GitHub committed 2020-11-15 18:21:55 +09:00
commit d220c99454
2 files changed
+12 -1

No files matched your search

+1 -1
View File
@@ -25,7 +25,7 @@ These commands install [Homebrew](https://brew.sh), which simplifies installing
To upgrade to a newer version, simply run `pip3 install -U katrain`
If you encounter an error about SDL being missing, try ` brew sdl sdl_image sdl_mixer sdl_ttf portmidi`
If you encounter an error about SDL being missing, try ` brew install sdl sdl_image sdl_mixer sdl_ttf portmidi`
### <a name="MacSources"></a>Troubleshooting and Installation from sources
+11
View File
@@ -30,11 +30,13 @@ Config.set("graphics", "width", max(400, int(WINDOW_X * WINDOW_SCALE_FAC)))
Config.set("graphics", "height", max(400, int(WINDOW_Y * WINDOW_SCALE_FAC)))
Config.set("input", "mouse", "mouse,multitouch_on_demand")
import re
import signal
import sys
import threading
import traceback
from queue import Queue
import urllib3
import webbrowser
from kivy.base import ExceptionHandler, ExceptionManager
@@ -400,6 +402,15 @@ class KaTrainGui(Screen, KaTrainBase):
if not clipboard:
self.controls.set_status(f"Ctrl-V pressed but clipboard is empty.", STATUS_INFO)
return
url_match = re.match("(?P<url>https?://[^\s]+)", clipboard)
if url_match:
self.log("Recognized url: " + url_match.group())
http = urllib3.PoolManager()
response = http.request('GET', url_match.group())
clipboard = response.data.decode('utf-8')
try:
move_tree = KaTrainSGF.parse_sgf(clipboard)
except Exception as exc: