Commit 187dac9b authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

[gui] Refactor Charter: on_delete_tab_callback, add_edit_mvc

- Delete redondant code
- Add doc
parent ce3bc7ed
......@@ -410,7 +410,7 @@ class ChartSimulControler(object):
mex = ModelExtractorVisitor('sim_extract', ex_type)
self.model.accept(mex)
model = mex.sub_model
self.edit_mvc.charter.add_display_mvc(model.name, model, False)
self.edit_mvc.charter.add_edit_mvc(model.name, model=model, layout=False, w_destroy=False)
self.edit_mvc.charter.do_layout(None,"hierarchical_LR")
def on_select_front(self, widget):
......
......@@ -511,54 +511,43 @@ class Charter(object):
"""
self.main_window.show_all()
def delete_tab_callback(self, widget):
"""
Delete current edit_MVC and corresponding view
"""
self.remove_edit_mvc()
def add_edit_mvc(self, model_name, model=None, layout=False):
"""
create, register and display a new edit_mvc - close all windows
associated with a previous edit_mvc
"""
# edit MVC
def add_edit_mvc(self, model_name, model=None, layout=False, w_destroy=True):
"""Create, register and display a new edit_mvc with the given model
:param model_name: Name of the model
:key model: (optional) Chart model
:key layout: (optional) Flag to activate the default layout (hierarchical_LR).
Default False.
:key w_destroy: (optional) If True, we will allow the closing
of all windows associated with the EditMVC when it will be closed.
If False, we will not allow the closing of auxiliary windows;
This is the case when it is called by
:meth:`cadbiom_gui.gt_gui.chart_simulator.chart_simul_controler.ChartSimulControler.on_extract`
in order to extract the part of a model used in last simulation.
:type model_name: <str>
:type model: <ChartModel>
:type layout: <boolean>
:type w_destroy: <boolean>
"""
# New edit MVC
edm = EditMVC(self, model_name, model, layout)
(eventbox, button) = create_custom_tab(edm.title)
button.connect("clicked", self.delete_tab_callback)
edm.tab_button = button
# Create tab with custom button and icon
(eventbox, tab_close_button) = create_custom_tab(edm.title)
tab_close_button.connect("clicked", self.on_delete_tab_callback)
edm.tab_button = tab_close_button
# insert in emvc management
page_index = self.graph_notebook.append_page(edm.viewpage, eventbox)
self.edit_mvc_list.append(edm)
self.set_current_edit_mvc(edm)
self.graph_notebook.set_current_page(page_index)
def add_display_mvc(self, model_name, model=None, layout=False):
"""
create, register and display a new edit_mvc
"""
# edit MVC
edm = EditMVC(self, model_name, model, layout)
(eventbox, button) = create_custom_tab(edm.title)
button.connect("clicked", self.delete_tab_callback)
edm.tab_button = button
# insert in emvc management
page_index = self.graph_notebook.append_page(edm.viewpage, eventbox)
self.edit_mvc_list.append(edm)
self.set_current_edit_mvc(edm, False) # do not destroy aux windows
# If w_destroy is False, do not destroy aux windows
self.set_current_edit_mvc(edm, w_destroy=w_destroy)
self.graph_notebook.set_current_page(page_index)
@check_curent_model
def remove_edit_mvc(self):
"""
Remove current edit_MVC
"""
def on_delete_tab_callback(self, widget):
"""Delete current edit_MVC and corresponding view"""
eimvc = self.current_edit_mvc
# Test if the model has been modified
ask = True
......@@ -588,7 +577,7 @@ class Charter(object):
macro_node.model.attach(edm.view)
(eventbox, button) = create_custom_tab(edm.title)
button.connect("clicked", self.delete_tab_callback)
button.connect("clicked", self.on_delete_tab_callback)
edm.tab_button = button
page_index = self.graph_notebook.append_page(edm.viewpage, eventbox)
self.edit_mvc_list.append(edm)
......@@ -597,7 +586,12 @@ class Charter(object):
self.graph_notebook.set_current_page(page_index)
def set_current_edit_mvc(self, edm, w_destroy=True):
"""Register and display a new current edit item"""
"""Register and display a new current edit item
:key w_destroy: (optional) If True (default), the window and its children
are destroyed.
:type w_destroy: <boolean>
"""
# disconnect the current one if any
if self.current_edit_mvc:
self.save_constraints(None)
......
......@@ -68,9 +68,12 @@ class EditMVC(object):
"""
:param chart: The charter using the edit mvc
:param model_name: Name of the model
:param layout: Flag to activate the default layout (hierarchical_LR)
:key model: (optional) Chart model
:key layout: (optional) Flag to activate the default layout (hierarchical_LR).
Default False.
:type chart: <Charter>
:type model_name: <str>
:type model: <ChartModel>
:type layout: <boolean>
"""
self.charter = chart
......@@ -157,7 +160,12 @@ class EditMVC(object):
chart.overview_window.get_child().add(self.nav_view)
def disconnect(self, chart, w_destroy):
"""Inverse connect operation"""
"""Inverse connect operation
:param w_destroy: If true the window and its children are destroyed.
If False, Subordinate windows are not destroyed.
:type w_destroy: <boolean>
"""
if w_destroy:
chart.drawing_button_disconnect()
chart.drawing_button_enable()
......
......@@ -72,7 +72,13 @@ def add_icon_to_button(button):
def create_custom_tab(text):
"""Customized tab with label and close button"""
"""Customized tab with label and close button
:return: eventBox and tab button.
eventBox is useful since it allows you to catch events for widgets
which do not have their own window.
:rtype: <tuple <gtk.EventBox>, <gtk.Button>>
"""
# event box creation
eventBox = gtk.EventBox()
# hbox
......
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