chart_misc_widgets.py 22 KB
Newer Older
VIGNET Pierre's avatar
VIGNET Pierre committed
1
2
3
## Filename    : charter.py
## Author(s)   : Geoffroy Andrieux
## Created     : 03/2010
4
5
## Revision    :
## Source      :
VIGNET Pierre's avatar
VIGNET Pierre committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
##
## Copyright 2012 : IRISA/IRSET
##
## This library is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published
## by the Free Software Foundation; either version 2.1 of the License, or
## any later version.
##
## This library is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
## MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  The software and
## documentation provided here under is on an "as is" basis, and IRISA has
## no obligations to provide maintenance, support, updates, enhancements
## or modifications.
## In no event shall IRISA be liable to any party for direct, indirect,
## special, incidental or consequential damages, including lost profits,
## arising out of the use of this software and its documentation, even if
## IRISA have been advised of the possibility of such damage.  See
## the GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this library; if not, write to the Free Software Foundation,
## Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
##
## The original code contained here was initially developed by:
##
##     Geoffroy Andrieux.
##     IRISA
##     Symbiose team
##     IRISA  Campus de Beaulieu
36
37
##     35042 RENNES Cedex, FRANCE
##
VIGNET Pierre's avatar
VIGNET Pierre committed
38
39
40
41
42
43
44
45
##
## Contributor(s): Michel Le Borgne
##
"""
Small widgets for Cadbiom gui
"""
import gtk
import re
46
import traceback
VIGNET Pierre's avatar
VIGNET Pierre committed
47
from utils.listDisplay import ToggleList
48
from cadbiom.models.guard_transitions.analyser.ana_visitors import FrontierVisitor
VIGNET Pierre's avatar
VIGNET Pierre committed
49
from utils.warn import cancel_warn
50
from cadbiom.models.guard_transitions.chart_model import ChartModel
51
52
53
from cadbiom.models.guard_transitions.analyser import model_corrections
from cadbiom.models.guard_transitions.translators.chart_xml import \
    MakeModelFromXmlFile
VIGNET Pierre's avatar
VIGNET Pierre committed
54
55
56

from utils.fileHandling import FileChooser
from utils.reporter import CompilReporter
57
from cadbiom.models.guard_transitions.translators.chart_xml_pid import \
VIGNET Pierre's avatar
VIGNET Pierre committed
58
59
60
            MakeModelFromPidFile
from chart_simulator.chart_simul_controler import DisplayError

61
import pkg_resources
VIGNET Pierre's avatar
VIGNET Pierre committed
62
63
64
65
66
67
68
69
70
71

class SearchManager(object):
    """
    List of simple nodes for searching
    """
    def __init__(self, chart, notebook, label):
        self.charter = chart
        self.model = None
        self.model_changed = True
        self.notebook = notebook
72

VIGNET Pierre's avatar
VIGNET Pierre committed
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
        # simple nodes
        sn_frame = gtk.Frame()
        self.sn_frame = sn_frame
        vbox = gtk.VBox(False, 0)
        sn_frame.add(vbox)
        # simple nodes list
        self.sn_viewer = ToggleList()
        label = gtk.Label(label)
        # wrap into scrollwindow
        scroll = gtk.ScrolledWindow()
        scroll.add_with_viewport(self.sn_viewer)
        vbox.pack_start(scroll, True, True, 0)
        # buttons
        hbox = gtk.HBox()
        vbox.pack_start(hbox, False, False, 0)
        but = gtk.Button('Update')
        but.connect("clicked", self.on_update)
        self.show_but = but
        hbox.pack_start(but, False, False, 0)
        but = gtk.Button('Show')
        but.connect("clicked", self.on_show)
        self.show_but = but
        hbox.pack_start(but, False, False, 0)
        but = gtk.Button('Extract')
        but.connect("clicked", self.on_extract)
        self.show_but = but
99
        hbox.pack_start(but, False, False, 0)
VIGNET Pierre's avatar
VIGNET Pierre committed
100
101
102
103
        but = gtk.Button('Clear')
        but.connect("clicked", self.on_clear)
        self.clear_but = but
        hbox.pack_start(but, False, False, 0)
104
        notebook.append_page(sn_frame, label)
VIGNET Pierre's avatar
VIGNET Pierre committed
105
106
        # entry
        self.entry = gtk.Entry()
107
108
        vbox.pack_start(self.entry, False, False, 0)

VIGNET Pierre's avatar
VIGNET Pierre committed
109
110
111
112
113
    def update(self):
        """
        As it says
        """
        self.model_changed = True
114

VIGNET Pierre's avatar
VIGNET Pierre committed
115
116
117
118
119
120
121
122
123
124
125
126
127
128
    def set_model(self, model):
        """
        As it says
        """
        if self.model:
            self.model.detach(self)
        self.model = model
        self.model.attach(self)
        self.model_changed = False
        # get node names
        lnode = model.get_simple_node_names()
        lnode.sort()
        # display node names
        self.sn_viewer.refresh(lnode)
129

VIGNET Pierre's avatar
VIGNET Pierre committed
130
131
132
133
134
135
136
137
138
    def on_clear(self, widget):
        """
        clear button callback
        """
        self.sn_viewer.clear(widget)
        self.entry.set_text('')
        if self.model:
            self.model.search_unmark()
            self.model_changed = False # search_mark implies a notify
139

VIGNET Pierre's avatar
VIGNET Pierre committed
140
141
142
143
144
145
146
147
148
149
150
151
    def on_update(self, widget):
        """
        update button callback
        """
        if self.model:
            self.model.search_unmark()
            # get node names
            lnode = self.model.get_simple_node_names()
            lnode.sort()
            # display node names
            self.sn_viewer.refresh(lnode)
            self.model_changed = False
152

VIGNET Pierre's avatar
VIGNET Pierre committed
153
154
155
156
157
158
159
160
161
162
163
164
165
    def on_show(self, widget):
        """
        show button callback
        """
        if not self.model:
            return
        # check model
        if self.model_changed:
            cancel_warn("Model is modified: update?")
        # mark nodes and show
        lnode = self.sn_viewer.get_selected_items()
        if lnode == []:
            regex = self.entry.get_text()
166
            if len(regex) == 0:
VIGNET Pierre's avatar
VIGNET Pierre committed
167
168
169
170
171
172
173
                return
            try:
                regex_obj = re.compile(regex)
            except:
                cancel_warn("Incorrect regular expression")
                return
            lnode = self.model.get_matching_node_names(regex_obj)
174

VIGNET Pierre's avatar
VIGNET Pierre committed
175
176
        self.model.search_mark(lnode)
        self.model_changed = False # search_mark implies a notify
177

VIGNET Pierre's avatar
VIGNET Pierre committed
178
179
180
181
182
183
184
185
186
187
188
189
190
    def on_extract(self, widget):
        """
        extract node environment
        """
        if not self.model:
            return
        # check model
        if self.model_changed:
            cancel_warn("Model is modified: update?")
        # mark nodes and show
        lnode_n = self.sn_viewer.get_selected_items()
        if lnode_n == []:
            regex = self.entry.get_text()
191
            if len(regex)==0:
VIGNET Pierre's avatar
VIGNET Pierre committed
192
193
194
195
196
197
198
                return
            try:
                regex_obj = re.compile(regex)
            except:
                cancel_warn("Incorrect regular expression")
                return
            lnode_n = self.model.get_matching_node_names(regex_obj)
199

VIGNET Pierre's avatar
VIGNET Pierre committed
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
        submodel = ChartModel(self.model.name + "_extract")
        tnode = submodel.get_root()
        for node_n in lnode_n:
            # avoid double node declaration
            try:
                extn = submodel.node_dict[node_n]
                break
            except:
                node = self.model.node_dict[node_n]
                nsn = tnode.add_copy(node)
            extn = self.model.node_dict[node_n]
            # incoming and out going transitions except with start or trap
            for trans in extn.incoming_trans:
                ori_n = trans.ori.name
                try:
                    ori = submodel.node_dict[ori_n]
                except:
                    ori = tnode.add_copy(trans.ori)
                ntr = tnode.add_transition(ori, nsn)
                if ntr:
                    ntr.set_condition(trans.condition)
                    ntr.set_event(trans.event)
                    ntr.set_action(trans.action)
223
            for trans in extn.outgoing_trans:
VIGNET Pierre's avatar
VIGNET Pierre committed
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
                ext_n = trans.ext.name
                try:
                    target = submodel.node_dict[ext_n]
                except:
                    target = tnode.add_copy(trans.ext)
                ntr = tnode.add_transition(nsn, target)
                if ntr:
                    ntr.set_condition(trans.condition)
                    ntr.set_event(trans.event)
                    ntr.set_action(trans.action)
            # transitions conditioned by node
            try:
                trl = self.model.signal_transition_dict[node]
            except:
                trl = []
            for trans in trl:
                ori_n = trans.ori.name
                try:
                    ori = submodel.node_dict[ori_n]
                except:
                    ori = tnode.add_copy(trans.ori)
                ext_n = trans.ext.name
                try:
                    target = submodel.node_dict[ext_n]
                except:
                    target = tnode.add_copy(trans.ext)
                ntr = tnode.add_transition(ori, target)
                if ntr:
                    ntr.set_condition(trans.condition)
                    ntr.set_event(trans.event)
                    ntr.set_action(trans.action)
        # display in charter
        self.charter.add_edit_mvc(submodel.name, submodel, False)
        self.charter.do_layout(None, "hierarchical_LR")
258

VIGNET Pierre's avatar
VIGNET Pierre committed
259
260
261
262
263
    def get_selected_keywords(self):
        """
        As it says
        """
        return self.sn_viewer.get_selected_items()
264

VIGNET Pierre's avatar
VIGNET Pierre committed
265
266
267
268
269
    def clear(self):
        """
        It is clear
        """
        self.sn_viewer.refresh([])
270

VIGNET Pierre's avatar
VIGNET Pierre committed
271
272
273
274
275
276
class SearchFrontier(SearchManager):
    """
    Same as SearchManager but specialized on frontier nodes
    """
    def __init__(self, chart, notebook, label):
        SearchManager.__init__(self, chart, notebook, label)
277

VIGNET Pierre's avatar
VIGNET Pierre committed
278
279
280
281
282
283
284
285
286
287
288
289
290
291
    def set_model(self, model):
        """
        As it says
        """
        if self.model:
            self.model.detach(self)
        self.model = model
        self.model.attach(self)
        self.model_changed = False
        # get node names
        lnode = self.get_frontier_node_names()
        lnode.sort()
        # display node names
        self.sn_viewer.refresh(lnode)
292

VIGNET Pierre's avatar
VIGNET Pierre committed
293
294
295
296
297
298
299
300
    def on_update(self, widget):
        self.model.search_unmark()
        # get node names
        lnode = self.get_frontier_node_names()
        lnode.sort()
        # display node names
        self.sn_viewer.refresh(lnode)
        self.model_changed = False
301

VIGNET Pierre's avatar
VIGNET Pierre committed
302
303
304
305
306
307
308
    def get_frontier_node_names(self):
        """
        As it says
        """
        fvi = FrontierVisitor()
        self.model.accept(fvi)
        return fvi.frontier
309

VIGNET Pierre's avatar
VIGNET Pierre committed
310
311
    def clear(self):
        self.sn_viewer.refresh([])
312
313


VIGNET Pierre's avatar
VIGNET Pierre committed
314
315
316
317
318
319
320
321
322
class LegendWindow(object):
    """
    Widget to display the legend
    """
    def __init__(self, parent=None):
        self.win = gtk.Window()
        self.win.set_title("CADBIOM-Chart Legend")
        self.win.set_position(gtk.WIN_POS_CENTER)
        self.win.connect("destroy", self.on_destroy)
323
        self.win.connect('key_press_event', self.on_escape)
VIGNET Pierre's avatar
VIGNET Pierre committed
324
        image = gtk.Image()
325
326
327
328
329
        template = pkg_resources.resource_filename(
            __name__,
            "legend.png"
        )
        image.set_from_file(template)
VIGNET Pierre's avatar
VIGNET Pierre committed
330
        image.show()
331

VIGNET Pierre's avatar
VIGNET Pierre committed
332
333
334
335
336
337
338
        self.win.add(image)
        self.win.show_all()
        # register itself for parent or emvc
        if parent:
            parent.win_register(self)

        self.parent = parent
339

VIGNET Pierre's avatar
VIGNET Pierre committed
340
341
342
343
344
345
346
347
348
349
350
351
352
    def on_destroy(self, widget):
        """
        standard destroy callback
        """
        if self.parent:
            self.parent.win_remove(self)

    def destroy(self):
        """
        if registered as a child
        """
        if self.win:
            self.win.destroy()
353

354
355
356
357
358
359
360
    def on_escape(self, widget, event):
        """On ESC key_press_event, destroy this window."""
        if gtk.gdk.keyval_name(event.keyval) == "Escape":
            self.destroy()
            return False


361
class ImportPIDParam(object):
VIGNET Pierre's avatar
VIGNET Pierre committed
362
363
364
    """
    Widget for model importing
    """
365
    def __init__(self, chart, parent):
VIGNET Pierre's avatar
VIGNET Pierre committed
366
        self.charter = chart
367

VIGNET Pierre's avatar
VIGNET Pierre committed
368
        # window creation
369
370
371
372
373
        template = pkg_resources.resource_filename(
            __name__,
            "chart_glade/import_parameter.glade"
        )
        self.wtree = gtk.glade.XML(template)
VIGNET Pierre's avatar
VIGNET Pierre committed
374
375
376
377
378
379
380
        self.main_window = self.wtree.get_widget("window1")
        self.main_window.set_title("Import window")

        self.main_window.set_resizable(True)
        hei = gtk.gdk.screen_height()
        hei = int(hei * 0.20)
        self.main_window.set_size_request(350, hei)
381

382
383
384
385
386
        # Set modal mode for the window (above all windows & block inputs)
        self.main_window.set_modal(True)
        self.main_window.set_transient_for(parent)

        if self.main_window:
VIGNET Pierre's avatar
VIGNET Pierre committed
387
            self.main_window.connect("destroy", self.on_destroy)
388
            self.main_window.connect('key_press_event', self.on_escape)
389

VIGNET Pierre's avatar
VIGNET Pierre committed
390
        self.main_window.set_position(gtk.WIN_POS_CENTER)
391

VIGNET Pierre's avatar
VIGNET Pierre committed
392
393
394
        # init param
        self.ai_inter = 0
        self.has_clock = False
395

VIGNET Pierre's avatar
VIGNET Pierre committed
396
397
398
399
        # interpretation radio button
        rbut = self.wtree.get_widget("or_rb")
        rb_name = rbut.get_name()
        rbut.connect("toggled", self.ai_inter_rb_callback, rb_name)
400

VIGNET Pierre's avatar
VIGNET Pierre committed
401
402
403
        rbut = self.wtree.get_widget("and_rb")
        rb_name = rbut.get_name()
        rbut.connect("toggled", self.ai_inter_rb_callback, rb_name)
404

VIGNET Pierre's avatar
VIGNET Pierre committed
405
406
407
408
        # Uncomment to add new buttons
#        rb = self.wtree.get_widget("or_and_rb")
#        rb_name = rb.get_name()
#        rb.connect("toggled", self.ai_inter_rb_callback, rb_name)
409
#
VIGNET Pierre's avatar
VIGNET Pierre committed
410
411
412
#        rb = self.wtree.get_widget("and_or_rb")
#        rb_name = rb.get_name()
#        rb.connect("toggled", self.ai_inter_rb_callback, rb_name)
413

VIGNET Pierre's avatar
VIGNET Pierre committed
414
415
416
        # clock radio button
        rbut = self.wtree.get_widget("withoutClock_rb")
        rbut.connect("toggled", self.clock_rb_callback, False)
417

VIGNET Pierre's avatar
VIGNET Pierre committed
418
419
        rbut = self.wtree.get_widget("withClock_rb")
        rbut.connect("toggled", self.clock_rb_callback, True)
420

VIGNET Pierre's avatar
VIGNET Pierre committed
421
422
423
        # import button
        button = self.wtree.get_widget("importButton")
        button.connect("clicked", self.on_import)
424

VIGNET Pierre's avatar
VIGNET Pierre committed
425
426
        # display
        self.main_window.show_all()
427

VIGNET Pierre's avatar
VIGNET Pierre committed
428
429
430
431
432
433
434
    def ai_inter_rb_callback(self, widget, ai_name):
        """
        set activator/inhibitor interpretation (and or or)
        """
        if ai_name == "or_rb":
            self.ai_inter = 0
        elif ai_name == "and_rb":
435
436
            self.ai_inter = 1

VIGNET Pierre's avatar
VIGNET Pierre committed
437
438
        # Uncomment to add new buttons
#        elif ai_name == "or_and_rb":
439
#            self.ai_inter = 2
VIGNET Pierre's avatar
VIGNET Pierre committed
440
441
#        else :
#            self.ai_inter = 3
442

VIGNET Pierre's avatar
VIGNET Pierre committed
443
444
445
446
447
448
449
    def clock_rb_callback(self, widget, has_clock):
        """
        set clock generation
        """
        if has_clock :
            self.has_clock = True
        else :
450
451
            self.has_clock = False

VIGNET Pierre's avatar
VIGNET Pierre committed
452
453
454
    def on_import(self, widget):
        """
        lauch import
455
        """
VIGNET Pierre's avatar
VIGNET Pierre committed
456
457
        fch = FileChooser("Import from PID xml", "xml files", "*.xml")
        fch.do_action(self.import_from_pid_file)
458

VIGNET Pierre's avatar
VIGNET Pierre committed
459
460
461
462
463
    def import_from_pid_file(self, file):
        """
        compile a pid file
        """
        crep = CompilReporter()
464
        parser = MakeModelFromPidFile(file, crep,
VIGNET Pierre's avatar
VIGNET Pierre committed
465
                                          self.has_clock, self.ai_inter)
466
        if crep.error :
VIGNET Pierre's avatar
VIGNET Pierre committed
467
468
469
470
471
472
            DisplayError(crep, parser.model.name)
        else :
            model = parser.model
            model.modified = False
            self.charter.add_edit_mvc(model.name, model)
            self.destroy()
473

VIGNET Pierre's avatar
VIGNET Pierre committed
474
475
476
477
478
479
    def on_destroy(self, widget):
        """
        standard destroy callback
        """
        if self.main_window:
            self.main_window.destroy()
480

VIGNET Pierre's avatar
VIGNET Pierre committed
481
482
483
484
485
    def destroy(self):
        """
        for parents
        """
        self.on_destroy(None)
486

487
488
489
490
491
492
    def on_escape(self, widget, event):
        """On ESC key_press_event, destroy this window."""
        if gtk.gdk.keyval_name(event.keyval) == "Escape":
            self.destroy()
            return False

VIGNET Pierre's avatar
VIGNET Pierre committed
493

494
class ImportBioPAXParams(object):
495
496
    """
    Widget for BioPAX model importing
497

498
    .. note:: requires biopax2cadbiom module
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
    """
    def __init__(self, chart, parent):
        self.charter = chart

        try:
            from biopax2cadbiom.commons import SPARQL_PATH
        except ImportError:
            d_err = DisplayError(
                None, "biopax2cadbiom module is missing.",
                "biopax2cadbiom project is required to perform this task.\n" + \
                "Please install it via the usual command:\n" + \
                "pip install biopax2cadbiom"
            )
            d_err.main_window.set_modal(True)
            d_err.main_window.set_transient_for(parent)
            return

        # Init class variables (settings of the window)
        self.cadbiom_file = ''
        self.convert_full_graph = True
        self.graph_uris = list()
        self.full_compartments_names = True
        self.blacklist_file = None
        self.triplestore_url = SPARQL_PATH
        self.remove_strongly_connected_components = True

        # window creation
        template = pkg_resources.resource_filename(
            __name__,
            "chart_glade/import_BioPAX_parameters.glade"
        )
        self.wtree = gtk.glade.XML(template)
        self.main_window = self.wtree.get_widget("window1")
        self.main_window.set_title("Import window")
        self.main_window.set_resizable(True)
        self.main_window.set_position(gtk.WIN_POS_CENTER)

        # Set modal mode for the window (above all windows & block inputs)
        self.main_window.set_modal(True)
        self.main_window.set_transient_for(parent)

540
        if self.main_window:
541
            self.main_window.connect("destroy", self.on_destroy)
542
            self.main_window.connect('key_press_event', self.on_escape)
543
544
545
546
547
548
549
550

        # Init interface
        # Triplestore
        # Graphs URIs
        self.wtree.get_widget('text_graphs_uris').set_text(
            "http://reactome.org/mycobacterium"
        )
        # Triplestore URL
551
552
        self.wtree.get_widget('text_triplestore_url').set_text(
            self.triplestore_url)
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
        # BioPAX level
        self.wtree.get_widget('radio_biopax_level3').set_active(True)
        # BioPAX options
        self.wtree.get_widget('checkbox_convert_full_graph').set_active(False)
        self.wtree.get_widget('checkbox_full_compartment_names').set_active(True)
        self.wtree.get_widget('checkbox_remove_scc').set_active(True)

        # Connect buttons
        # Files
        self.wtree.get_widget("button_blacklist").connect(
            "clicked", self.on_import_blacklist_file
        )
        self.wtree.get_widget("button_output").connect(
            "clicked", self.on_set_output_file
        )
        self.wtree.get_widget("button_make_model").connect(
            "clicked", self.import_BioPAX_data
        )

        # Display
        self.main_window.show_all()


    def on_import_blacklist_file(self, widget):
        """
        Choose blacklist file of entities
        """
        fch = FileChooser("Choose the blacklist file", "txt files", "*.txt")
        fch.do_action(self.set_blacklist_file)


    def on_set_output_file(self, widget):
        """
        Choose output model file
        """
        fch = FileChooser("Choose the output file name", "bcx files", "*.bcx")
        fch.do_action(self.set_output_file)


    def set_blacklist_file(self, file):
        self.blacklist_file = file


    def set_output_file(self, file):
        self.cadbiom_file = file


    def import_BioPAX_data(self, widget):
        """
        Import from BioPAX data on triplestore
        """
        from biopax2cadbiom import biopax_converter

        # Return if output file is not set
        if self.cadbiom_file == '':
            red = gtk.gdk.color_parse("red")
            self.wtree.get_widget("button_output").modify_bg(
                gtk.STATE_NORMAL, red)
            return

        # Get parameters
        # List of graphs URIs
        self.graph_uris = \
            self.wtree.get_widget('text_graphs_uris').get_text().split(',')

        # Triplestore URL
        self.triplestore_url = \
            self.wtree.get_widget('text_triplestore_url').get_text()

        # BioPAX level
        biopax2 = self.wtree.get_widget('radio_biopax_level2').get_active()
        self.graph_uris.append(
            'http://biopax.org/lvl2' if biopax2 else 'http://biopax.org/lvl3'
        )

        # BioPAX convertion
        self.convert_full_graph = \
            self.wtree.get_widget('checkbox_convert_full_graph').get_active()
        self.full_compartments_names = \
            self.wtree.get_widget('checkbox_full_compartment_names').get_active()
        self.remove_strongly_connected_components = \
            self.wtree.get_widget('checkbox_remove_scc').get_active()

636
        # Color the button in green when the form is valid
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
        green = gtk.gdk.color_parse("green")
        self.wtree.get_widget("button_make_model").modify_bg(
            gtk.STATE_NORMAL, green)
        self.wtree.get_widget("button_make_model").set_label(
            "Make model. Please wait...")

        # Do the magick
        # Build parameters for biopax2cadbiom
        params = {
            'cadbiomFile': self.cadbiom_file,
            'convertFullGraph': self.convert_full_graph,
            'listOfGraphUri': self.graph_uris,
            'pickleBackup': False,
            'pickleDir': '', # don't care, because pickleBackup = False
            'fullCompartmentsNames': self.full_compartments_names,
            'blacklist': self.blacklist_file,
            'triplestore': self.triplestore_url,
654
            'no_scc_fix': True, # StartNodes are added here
655
656
657
        }

        try:
658
659
660
661
662
663
664
665
            # StartNodes are added here, (not in biopax2cadbiom)
            # so we can load the model in memory
            biopax_converter.main(params)

            if self.remove_strongly_connected_components:
                model = model_corrections.add_start_nodes(self.cadbiom_file)
            else:
                model = MakeModelFromXmlFile(self.cadbiom_file).get_model()
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693

            model.modified = False # ?????
            self.charter.add_edit_mvc(model.name, model)
            self.destroy()

        except Exception as e:

            d_err = DisplayError(
                None, "Biopax2cadbiom",
                "Biopax2cadbiom exception: " + \
                e.__class__.__name__ + ". Please check logs.\n" + \
                traceback.format_exc()
            )
            d_err.main_window.set_modal(True)


    def on_destroy(self, widget):
        """
        standard destroy callback
        """
        if self.main_window:
            self.main_window.destroy()

    def destroy(self):
        """
        for parents
        """
        self.on_destroy(None)
694
695
696
697
698
699

    def on_escape(self, widget, event):
        """On ESC key_press_event, destroy this window."""
        if gtk.gdk.keyval_name(event.keyval) == "Escape":
            self.destroy()
            return False