Commit 7e103a0b authored by VIGNET Pierre's avatar VIGNET Pierre

Add decorator to remove auto-check if current model is present on functions that require it

parent b73fd4d4
......@@ -216,6 +216,24 @@ class Charter(object):
self.overview_window = self.wtree.get_widget("Overview")
def check_curent_model(function):
"""Decorator that checks if there is a current model.
It is used before the call of functions that do some processing on
models.
If there is no model, the function juste returns None.
"""
def modified_func(self, *args, **kwargs):
"""Returned modified function"""
if not self.current_edit_mvc:
return
return function(self, *args, **kwargs)
return modified_func
def refresh(self):
"""
TODO
......@@ -465,13 +483,11 @@ class Charter(object):
self.set_current_edit_mvc(edm, False) # do not destroy aux windows
self.graph_notebook.set_current_page(page_index)
@check_curent_model
def remove_edit_mvc(self):
"""
Remove current edit_MVC
"""
if not self.current_edit_mvc:
return
eimvc = self.current_edit_mvc
# modified model??
ask = True
......@@ -598,12 +614,11 @@ class Charter(object):
dialog.destroy()
return response
@check_curent_model
def export_to_xml(self, widget):
"""
open a window to save as xml file
"""
if not self.current_edit_mvc:
return
fch = FileChooser("Export to xml Cadbiom model", "bcx files", "*.bcx")
fch.set_current_name(self.current_edit_mvc.model.name + ".bcx")
fch.do_action(self.create_xml_file)
......@@ -696,12 +711,11 @@ class Charter(object):
# Pass the parent window to set modal mode on the child
ImportBioPAXParams(self, self.main_window)
@check_curent_model
def export_to_lang(self, widget):
"""
Export to CadLang
"""
if not self.current_edit_mvc:
return
fch = FileChooser("Export to Cadbiom-chart lang", "cadbiom-l", "*.cal")
fch.set_current_name(self.current_edit_mvc.model.name + ".cal")
fch.do_action(self.compile_to_lang)
......@@ -713,13 +727,8 @@ class Charter(object):
out = open(file_name, "w")
# decompiler visitor
lvi = LangVisitor(out)
edm = self.current_edit_mvc
if edm:
edm.model.accept(lvi)
out.close()
else:
return
self.current_edit_mvc.model.accept(lvi)
out.close()
def show_doc(self, widget):
"""
......@@ -735,26 +744,23 @@ class Charter(object):
"""
self.legend = LegendWindow(self)
@check_curent_model
def export_picture(self, widget):
"""
Export a picture (png,jpg) of the current model
"""
if not self.current_edit_mvc:
return
fch = FileChooser("Export picture", "pictures", "*.png")
fch.set_current_name(self.current_edit_mvc.model.name + ".png")
fch.get_filter().add_pattern("*.png")
fch.do_action(self.export_picture_to_file)
@check_curent_model
def export_picture_to_file(self, file_name):
"""
As it says
"""
if self.current_edit_mvc:
edm = self.current_edit_mvc
else:
return
edm = self.current_edit_mvc
fns = file_name.split('.')
if len(fns)!= 2:
cancel_warn("Incorrect picture file name" )
......@@ -771,79 +777,63 @@ class Charter(object):
else:
cancel_warn("Unknown picture format")
@check_curent_model
def do_layout(self, widget, layout_style):
"""
Compute a layout of the model
"""
if self.current_edit_mvc:
edm = self.current_edit_mvc
else:
return
edm = self.current_edit_mvc
lvi = LayoutVisitor(edm.view, layout_style)
edm.model.accept(lvi)
edm.display()
# simulation
# Simulation
@check_curent_model
def on_simulate(self, widget):
"""
Call simulation
"""
reporter = CompilReporter()
if self.current_edit_mvc:
chart_simul = ChartSimulControler(self.current_edit_mvc,
True, reporter)
# static analysis
# def on_static(self, widget):
# """
# Call static analysis
# """
# if self.current_edit_mvc:
# reporter = CompilReporter()
# chart_static = ChartStatControler(self.current_edit_mvc, reporter)
ChartSimulControler(self.current_edit_mvc, True, reporter)
# Static analysis
@check_curent_model
def on_stats_info(self, widget):
"""
Fill window with model informations.
"""
if self.current_edit_mvc:
reporter = CompilReporter()
# get stats from StaticAnalyzer
stan = StaticAnalyzer(reporter)
stan.build_from_chart_model(self.current_edit_mvc.model)
ststat = stan.get_statistics()
window = STATWindow(ststat, self.current_edit_mvc, reporter, self)
# Get Main widget and connect its "destroy" event
window.window.connect("destroy", self.win_remove)
reporter = CompilReporter()
# get stats from StaticAnalyzer
stan = StaticAnalyzer(reporter)
stan.build_from_chart_model(self.current_edit_mvc.model)
ststat = stan.get_statistics()
window = STATWindow(ststat, self.current_edit_mvc, reporter, self)
# Get Main widget and connect its "destroy" event
window.window.connect("destroy", self.win_remove)
@check_curent_model
def on_frontier_scc(self, widget):
"""
Compute connected components which are on the frontier
"""
if self.current_edit_mvc:
reporter = CompilReporter()
stan = StaticAnalyzer(reporter)
stan.build_from_chart_model(self.current_edit_mvc.model)
# errors??
lscc = stan.get_frontier_scc()
window = SCCWindow(lscc, self.current_edit_mvc, reporter, self)
# Get Main widget and connect its "destroy" event
window.window.connect("destroy", self.win_remove)
reporter = CompilReporter()
stan = StaticAnalyzer(reporter)
stan.build_from_chart_model(self.current_edit_mvc.model)
# errors??
lscc = stan.get_frontier_scc()
window = SCCWindow(lscc, self.current_edit_mvc, reporter, self)
# Get Main widget and connect its "destroy" event
window.window.connect("destroy", self.win_remove)
@check_curent_model
def on_basal_activated_genes(self, widget):
"""
Compute basal activated genes
"""
if self.current_edit_mvc:
reporter = CompilReporter()
stan = StaticAnalyzer(reporter)
stan.build_from_chart_model(self.current_edit_mvc.model)
lwbag = stan.get_why_basal_genes()
window = BAGWindow(lwbag, self.current_edit_mvc, reporter, self)
# Get Main widget and connect its "destroy" event
window.window.connect("destroy", self.win_remove)
reporter = CompilReporter()
stan = StaticAnalyzer(reporter)
stan.build_from_chart_model(self.current_edit_mvc.model)
lwbag = stan.get_why_basal_genes()
window = BAGWindow(lwbag, self.current_edit_mvc, reporter, self)
# Get Main widget and connect its "destroy" event
window.window.connect("destroy", self.win_remove)
@check_curent_model
def on_dependency_graph(self, widget):
"""
Computation and export of the dependency graph
......@@ -873,10 +863,8 @@ class Charter(object):
"""
Launch checker
"""
if self.current_edit_mvc:
reporter = CompilReporter()
chart_check = ChartChecker(self.current_edit_mvc, reporter)
reporter = CompilReporter()
ChartChecker(self.current_edit_mvc, reporter, self)
def get_em_with_model_name(self, name):
"""
......
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