Skip to content

Commit

Permalink
Added some code to support esc in linux
Browse files Browse the repository at this point in the history
  • Loading branch information
fork-while-fork committed Sep 11, 2011
1 parent 82b339b commit 8b75a6a
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions pyevolve/GSimpleGA.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,28 @@
# Platform dependant code for the Interactive Mode
if sys_platform[:3] == "win":
import msvcrt
elif sys_platform[:3] == "lin":
import tty
import termios
from sys import stdin as sys_stdin
def linux_getch():
try:
fd = sys_stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys_stdin.fileno())
ch = sys_stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
except:
return

import signal
TIMEOUT = 1




def RawScoreCriteria(ga_engine):
""" Terminate the evolution using the **bestrawscore** and **rounddecimal**
Expand Down Expand Up @@ -802,6 +824,20 @@ def evolve(self, freq_stats=0):
print
code.interact(interact_banner, local=session_locals)

if sys_platform[:3] == "lin":
if ord(msvcrt.getch()) == Consts.CDefESCKey:
print "Loading modules for Interactive Mode...",
logging.debug("Windows Interactive Mode key detected ! generation=%d", self.getCurrentGeneration())
from pyevolve import Interaction
print " done !"
interact_banner = "## Pyevolve v.%s - Interactive Mode ##\nPress CTRL-Z to quit interactive mode." % (pyevolve.__version__,)
session_locals = { "ga_engine" : self,
"population" : self.getPopulation(),
"pyevolve" : pyevolve,
"it" : Interaction}
print
code.interact(interact_banner, local=session_locals)

if (self.getInteractiveGeneration() >= 0) and (self.getInteractiveGeneration() == self.getCurrentGeneration()):
print "Loading modules for Interactive Mode...",
logging.debug("Manual Interactive Mode key detected ! generation=%d", self.getCurrentGeneration())
Expand Down

0 comments on commit 8b75a6a

Please sign in to comment.