# 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') population_controller = self._controller.find_page('PopulationController') if population_controller is not None: population_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.pack_start(self._widget.get_widget_tree()) self._window.add(main_view) # Create a controller to connect view and model self._controller = ka_controller.KandidController(self._widget, TESTPATH, # not os.path.exists(TESTMODEL)) True) self._controller.create_pages() # Display everything self._window.set_default_size(1200, 800) self._window.show_all() population_controller = self._controller.find_page('PopulationController') if population_controller is not None: population_controller.read_file(TESTMODEL) 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__": KandidApplication().main()