Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/kandid.py
blob: 12f3f16676ddf890231081f9875527e38d7bebe7 (plain)
1
2
3
4
5
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# coding: UTF-8
# Copyright 2009, 2010 Thomas Jourdan
# This source code is based on the helloworld.py example from
# PyGTK 2.0 Tutorial. see: http://www.pygtk.org/pygtk2tutorial/
#
# This program 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 3 of the License, or
# (at your option) any later version.
#
# This program 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.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import pygtk
pygtk.require('2.0')
import gtk
gtk.gdk.threads_init()
import ka_debug
import ka_controller
import ka_widget

TESTPATH = '/home/strom/.sugar/1/net.sourceforge.kandid/'
TESTMODEL = TESTPATH + 'kmodel'
REFFERENCEMODEL = '/home/strom/minimal/MinimalSzenario/kmodel.v'

class KandidApplication(object):

    def delete_event(self, widget, event, data=None):
        # If you return FALSE in the "delete_event" signal handler,
        # GTK will emit the "destroy" signal. Returning TRUE means
        # you don't want the window to be destroyed.
        # This is useful for popping up 'are you sure you want to quit?'
        # type dialogs.
        ka_debug.info('Kandid application: delete event occurred')
        # Change FALSE to TRUE and the main window will not be destroyed
        # with a "delete_event".
        return False

    def destroy(self, widget, data=None):
        """Application will be closed."""
        ka_debug.info('Kandid application: destroy signal occurred')
        self._controller.write_file(TESTMODEL)
        self._controller.close()
        gtk.main_quit()

    def __init__(self):
        ka_debug.info('KandidApplication.__init__')
        # create a new window
        self._window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self._window.connect('destroy', self.destroy)
        
        # Create GUI
        # Create the main container
        main_view = gtk.HBox()
        self._widget = ka_widget.KandidWidget(main_view)
        self._window.add(main_view)
        # Create a controller to connect view and model
        self._controller = ka_controller.KandidController( \
                                                    self._widget.widget_tree,
                                                    TESTPATH)
        self._controller.read_file(TESTMODEL)

        # Display everything
        self._window.set_default_size(1200, 800)
        self._controller.autoconnect_events()
        self._window.show_all()
#        self._controller.start_all_calculations()

    def main(self):
        """
        All PyGTK applications must have a gtk.main(). Control ends here
        and waits for an event to occur (like a key press or mouse event).
        """
        gtk.main()


# If the program is run directly or passed as an argument to the python
# interpreter then create a Kandid instance and show it
if __name__ == "__main__":
    ka_debug.info('starting Minimal Kandid')
    KandidApplication().main()