mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
Fix error message when solver isn't in the path
See https://github.com/shlomif/PySolFC/issues/51
This commit is contained in:
parent
6f72b4df3b
commit
e543490cfd
2 changed files with 14 additions and 6 deletions
|
@ -791,7 +791,7 @@ class Base_Solver_Hint:
|
||||||
self._v = None
|
self._v = None
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def start_solver(self, command, board):
|
def run_solver(self, command, board):
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print(command)
|
print(command)
|
||||||
kw = {'shell': True,
|
kw = {'shell': True,
|
||||||
|
@ -807,6 +807,11 @@ class Base_Solver_Hint:
|
||||||
bytes_board = bytes(board, 'utf-8')
|
bytes_board = bytes(board, 'utf-8')
|
||||||
pin.write(bytes_board)
|
pin.write(bytes_board)
|
||||||
pin.close()
|
pin.close()
|
||||||
|
if os.name == 'posix':
|
||||||
|
p.wait()
|
||||||
|
if p.returncode in (127, 1):
|
||||||
|
# Linux and Windows return codes for "command not found" error
|
||||||
|
raise RuntimeError('Solver exited with {}'.format(p.returncode))
|
||||||
return pout, perr
|
return pout, perr
|
||||||
|
|
||||||
|
|
||||||
|
@ -969,7 +974,7 @@ class FreeCellSolver_Hint(Base_Solver_Hint):
|
||||||
args += ['--empty-stacks-filled-by', game_type['esf']]
|
args += ['--empty-stacks-filled-by', game_type['esf']]
|
||||||
|
|
||||||
command = FCS_COMMAND+' '+' '.join([str(i) for i in args])
|
command = FCS_COMMAND+' '+' '.join([str(i) for i in args])
|
||||||
pout, perr = self.start_solver(command, board)
|
pout, perr = self.run_solver(command, board)
|
||||||
#
|
#
|
||||||
stack_types = {
|
stack_types = {
|
||||||
'the': game.s.foundations,
|
'the': game.s.foundations,
|
||||||
|
@ -1129,7 +1134,7 @@ class BlackHoleSolver_Hint(Base_Solver_Hint):
|
||||||
|
|
||||||
command = self.BLACK_HOLE_SOLVER_COMMAND + ' ' + \
|
command = self.BLACK_HOLE_SOLVER_COMMAND + ' ' + \
|
||||||
' '.join([str(i) for i in args])
|
' '.join([str(i) for i in args])
|
||||||
pout, perr = self.start_solver(command, board)
|
pout, perr = self.run_solver(command, board)
|
||||||
#
|
#
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
@ -1205,8 +1210,6 @@ class BlackHoleSolver_Hint(Base_Solver_Hint):
|
||||||
|
|
||||||
pout.close()
|
pout.close()
|
||||||
perr.close()
|
perr.close()
|
||||||
if os.name == 'posix':
|
|
||||||
os.wait()
|
|
||||||
|
|
||||||
|
|
||||||
class FreeCellSolverWrapper:
|
class FreeCellSolverWrapper:
|
||||||
|
|
|
@ -161,7 +161,12 @@ class BaseSolverDialog:
|
||||||
max_iters = self.max_iters_var.get()
|
max_iters = self.max_iters_var.get()
|
||||||
progress = self.app.opt.solver_show_progress
|
progress = self.app.opt.solver_show_progress
|
||||||
solver.config(preset=preset, max_iters=max_iters, progress=progress)
|
solver.config(preset=preset, max_iters=max_iters, progress=progress)
|
||||||
solver.computeHints()
|
try:
|
||||||
|
solver.computeHints()
|
||||||
|
except RuntimeError:
|
||||||
|
self.result_label['text'] = \
|
||||||
|
_('Solver not found in the PATH')
|
||||||
|
return
|
||||||
hints_len = len(solver.hints)-1
|
hints_len = len(solver.hints)-1
|
||||||
if hints_len > 0:
|
if hints_len > 0:
|
||||||
t = ungettext('This game is solveable in %d move.',
|
t = ungettext('This game is solveable in %d move.',
|
||||||
|
|
Loading…
Add table
Reference in a new issue