diff --git a/README.md b/README.md index dfe6c90..b99f3ab 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,8 @@ Play * Analysis * Copy the SGF into the text box. Note that branches are not supported and will lead to strange results. * Choose whether or not to turn on `fast` to make the AI weaker but analyze faster. - * Click `Analyze` + * Click `Load` + * Alternatively click `Load` when the text box is empty to get a file chooser dialog. * Save game * Click save to get an sgf with comments saved in the sgfout/ directory (and a short version in the text box). diff --git a/board.py b/board.py index 5994416..4ebf691 100644 --- a/board.py +++ b/board.py @@ -1,5 +1,5 @@ -from datetime import datetime import os +from datetime import datetime class IllegalMoveException(Exception): diff --git a/controller.py b/controller.py index 6c7732a..d131d04 100644 --- a/controller.py +++ b/controller.py @@ -1,5 +1,6 @@ import copy import json +import os import random import re import shlex @@ -9,9 +10,11 @@ import threading import time from queue import Queue -from kivy.storage.jsonstore import JsonStore -from kivy.uix.gridlayout import GridLayout from kivy.clock import Clock +from kivy.storage.jsonstore import JsonStore +from kivy.uix.filechooser import FileChooserListView +from kivy.uix.gridlayout import GridLayout +from kivy.uix.popup import Popup from board import Board, IllegalMoveException, Move @@ -182,8 +185,21 @@ class EngineControls(GridLayout): def _do_analyze_sgf(self, sgf): sgfprops = {k: v for k, v in re.findall(r"\b(\w+)\[(.*?)\]", sgf)} size = int(sgfprops.get("SZ", self.board_size)) - self._do_init(size, sgfprops.get("KM")) sgfmoves = re.findall(r"\b([BW])\[([a-z]{2})\]", sgf) + if not sgfmoves and not sgfprops: + fileselect_popup = Popup(title="Double Click SGF file to analyze", size_hint=(0.8, 0.8)) + + def readfile(files, mouse): + fileselect_popup.dismiss() + with open(files[0]) as f: + self.action("analyze-sgf", f.read()) + + fc = FileChooserListView(multiselect=False, path=os.path.expanduser("~"), filters=["*.sgf"]) + fc.on_submit = readfile + fileselect_popup.add_widget(fc) + fileselect_popup.open() + return + self._do_init(size, sgfprops.get("KM")) moves = [Move(player=Move.PLAYERS.index(p.upper()), sgfcoords=(mv, self.board_size)) for p, mv in sgfmoves] handicap = int(sgfprops.get("HA", 0)) self.board.place_handicap_stones(handicap) # not technically correct, should parse AB/AW diff --git a/katrain.kv b/katrain.kv index 42a47c2..35cc4d3 100644 --- a/katrain.kv +++ b/katrain.kv @@ -264,11 +264,11 @@ size_hint: 1, 0.05 StyledButton: text: 'Save' - size_hint: 0.37, 1 + size_hint: 0.5, 1 on_press: info.text = root.output_sgf() StyledButton: - text: 'Analyze' - size_hint: 0.49, 1 + text: 'Load' + size_hint: 0.5, 1 margin: (0,1) on_press: root.action("analyze-sgf",info.text) GridLayout: