Commit 66dd2c05 authored by VIGNET Pierre's avatar VIGNET Pierre

[gui][lib] Simulator: Fix typos; add few doc

parent a1370fed
......@@ -43,7 +43,7 @@ Controller and auxiliary widgets for simulations with gui.
"""
import gtk
from time import clock
import pkg_resources
from chart_chrono import ChartChrono
from cadbiom_gui.gt_gui.utils.warn import cancel_warn
......@@ -55,7 +55,8 @@ from cadbiom.models.guard_transitions.analyser.ana_visitors import FrontierVisit
from cadbiom_gui.gt_gui.utils.listDisplay import ToggleList
from cadbiom_gui.gt_gui.utils.fileHandling import FileChooser
import pkg_resources
from cadbiom import commons as cm
class ChartSimulControler(object):
"""
......@@ -240,39 +241,40 @@ class ChartSimulControler(object):
def on_input_file_selected(self, widget):
"""
chose an input file
"""
"""Choose an input file"""
fch = FileChooser("Input file", "", "*", save_window=False)
fch.do_action(self.set_input_file)
def set_input_file(self, filename):
"""
connect an input file
"""Open an input file
Test first line of the input file
=> must begin with one of these words:
"$inputs" or "%", or any word (full scenario, where the first line
is a set of place names)
"""
inputfile = open(filename, 'r')
fline = inputfile.readline()
line_split = fline.split()
line_split = inputfile.readline().split()
inputfile.close()
# test type of file on first line
if line_split[0] == "$inputs": # old coded input
try:
self.sim.set_cfile_input_stream(filename)
except Exception as exc:
cancel_warn("Error in coded input file loading" + exc.__str__())
cancel_warn("Error in coded input file loading" + str(exc))
return
elif line_split[0] == "%": # activated input
try:
self.sim.set_act_file_input_stream(filename)
except Exception as exc:
mess = "Error in active input file loading" + exc.__str__()
cancel_warn(mess)
cancel_warn("Error in active input file loading" + str(exc))
return
else: # assume scenario
else:
# assume correct scenario
try:
self.sim.set_sce_file_input_stream(filename)
except Exception as exc:
cancel_warn("Error in scenario loading" + exc.__str__())
cancel_warn("Error in scenario loading" + str(exc))
return
......
......@@ -174,7 +174,7 @@ class ChartSimulator(object):
try:
self.invariant_prop = compile_cond(prop, self.__model_symb_tab, reporter)
except Exception as exc:
raise SimulException("Error in property " + exc.__str__())
raise SimulException("Error in property " + str(exc))
def set_reachable_prop(self, prop):
"""
......@@ -185,7 +185,7 @@ class ChartSimulator(object):
try:
self.reachable_prop = compile_cond(prop, self.__model_symb_tab, reporter)
except Exception as exc:
raise SimulException("Error in property " + exc.__str__())
raise SimulException("Error in property " + str(exc))
def set_sce_file_input_stream(self, filename):
"""
......@@ -196,6 +196,7 @@ class ChartSimulator(object):
self.input_file = filename
try:
self.input_buffer = ActInput(filename)
# Read set of frontier places
init_places = self.input_buffer.input_buffer[0].split()
self.simul_init_places(init_places)
except SimulException as sexc:
......@@ -204,7 +205,7 @@ class ChartSimulator(object):
except Exception as exc:
self.input_buffer = None
raise SimulException("Problem reading input file: " + exc.__str__())
raise SimulException("Problem reading input file: " + str(exc))
def set_act_file_input_stream(self, filename):
"""
......@@ -221,7 +222,7 @@ class ChartSimulator(object):
except Exception as exc:
self.input_buffer = None
raise SimulException("Problem reading input file:" + exc.__str__())
raise SimulException("Problem reading input file:" + str(exc))
def set_act_input_stream(self, act_input_list):
"""
......@@ -243,7 +244,7 @@ class ChartSimulator(object):
except Exception as exc:
self.input_buffer = None
raise SimulException("Problem reading input file:" + exc.__str__())
raise SimulException("Problem reading input file:" + str(exc))
# check coherence with model
inames = self.input_buffer.input_names
nb_inames = self.input_buffer.nb_inputs
......@@ -277,10 +278,10 @@ class ChartSimulator(object):
evt.set_activated(False)
# read input if any
if self.input_buffer:
nin = self.input_buffer.next_input()
for evn in nin:
events = self.input_buffer.next_input()
for event in events:
try:
self.__symb_tab[evn].set_activated(True)
self.__symb_tab[event].set_activated(True)
except KeyError:
raise SimulException("Simul set_event: Unknown event")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment