class FreeStationApp2(object):
    
    __name__ = APP_NAME #@ReservedAssignment
    
    # Class variable referring to the one and only app for use
    _self = None
    
    def __init__(self, alive_time = None, enable_gui = True):
        """
            @param alive_time msec for live app, normally used by test. Default None for ignore
        """
        #Thread.__init__(self)
        #self.setDaemon(True) 
        self.finished = False
        
        if FreeStationApp2._self != None:
            raise RuntimeError('Only a single instance of a FreeStationApp can be instantiated.')
        
        FreeStationApp2._self = self

    def run(self, ):
        LOG.debug('Parent PID: {0}'.format(os.getppid()))
        LOG.debug('FreeStationApp PID: {0}'.format(os.getpid()))
        #LOG.debug('Thread name: {0}'.format(self.getName()))

        GObject.threads_init()

        Gdk.threads_enter()    
        from widgets.webkitview import App #@UnresolvedImport
        self.gui = App(self)
        self.gui.show_html()
            #self.gui.run()
        Gdk.threads_leave()
  
        Gdk.threads_enter()    
        Gtk.main()
        Gdk.threads_leave()
    
    # Destroy the object. Wait for the thread to terminate and cleanup
    # the internal state.
    def destroy(self):
        # Wait for the thread to terminate
        Gdk.threads_leave()
        FreeStationApp2._self = None
        from signal import SIGTERM

        self.finished = True

                  
    def on_destroy(self, widget, event):
        LOG.debug('Destroying application')
        LOG.debug('Parent PID: {0}'.format(os.getppid()))
        LOG.debug('FreeStationApp PID: {0}'.format(os.getpid()))

        Gtk.main_quit()
        if Gtk.main_level() > 0:
            Gtk.main_quit()
            
        self.destroy()
    def run(self, ):
        LOG.debug('Parent PID: {0}'.format(os.getppid()))
        LOG.debug('FreeStationApp PID: {0}'.format(os.getpid()))
        #LOG.debug('Thread name: {0}'.format(self.getName()))

        GObject.threads_init()

        Gdk.threads_enter()    
        from widgets.webkitview import App #@UnresolvedImport
        self.gui = App(self)
        self.gui.show_html()
            #self.gui.run()
        Gdk.threads_leave()
  
        Gdk.threads_enter()    
        Gtk.main()
        Gdk.threads_leave()