root/branch/UmitPlugins/umitGUI/App.py @ 3009

Revision 3009, 4.5 kB (checked in by nopper, 5 years ago)

Adding a terminal plugin and implementing some apis

Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#
4# Copyright (C) 2005-2006 Insecure.Com LLC.
5# Copyright (C) 2007-2008 Adriano Monteiro Marques
6#
7# Authors: Adriano Monteiro Marques <adriano@umitproject.org>
8#          Cleber Rodrigues <cleber.gnu@gmail.com>
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
24import os
25import os.path
26import sys
27
28from umitCore.Paths import Path
29from umitCore.UmitOptionParser import option_parser
30from umitCore.UmitConf import is_maemo
31from umitCore.I18N import _
32from umitCore.UmitLogging import log
33
34from umitPlugin.Engine import PluginEngine
35
36# Script found at http://www.py2exe.org/index.cgi/HowToDetermineIfRunningFromExe
37import imp
38frozen = (hasattr(sys, "frozen") or # new py2exe
39          hasattr(sys, "importers") # old py2exe
40          or imp.is_frozen("__main__")) # tools/freeze
41del(imp)
42
43def main_is_frozen():
44    return frozen
45
46
47class App:
48    def __init__(self, args=sys.argv):
49        # Initialite the PluginEngine
50        PluginEngine()
51
52    def __parse_cmd_line(self):
53        pass
54
55    def __create_show_main_window(self):
56        from umitGUI.MainWindow import MainWindow
57        self.main_window = MainWindow()
58       
59        if is_maemo():
60            import hildon
61            self.hildon_app = hildon.Program()
62            self.hildon_app.add_window(self.main_window)
63
64        self.main_window.show_all()
65
66        # Set the mainwindow and load the selected plugins
67        PluginEngine().core.mainwindow = self.main_window
68        PluginEngine().load_selected_plugins()
69   
70    def safe_shutdown(self, signum, stack):
71        log.debug("\n\n%s\nSAFE SHUTDOWN!\n%s\n" % ("#" * 30, "#" * 30))
72        log.debug("SIGNUM: %s" % signum)
73
74        try:
75            scans = self.main_window.scan_notebook.get_children()
76            for scan in scans:
77                log.debug(">>> Killing Scan: %s" % scan.get_tab_label())
78                scan.kill_scan()
79                scan.close_tab()
80                self.main_window.scan_notebook.remove(scan)
81                del(scan)
82        except NameError:
83            pass
84
85        self.main_window._exit_cb()
86        sys.exit(signum)
87
88    def run(self):
89        # Try to load psyco module, saving this information
90        # if we care to use it later (such as in a About Dialog)
91        try:
92            import psyco
93            psyco.profile()
94            self.using_psyco = True
95        except:
96            log.warning(_("RUNNING WITHOUT PSYCO!"))
97            log.warning(_("""Psyco is a module that speeds up the execution \
98of this application. It is not a requirement, and Umit runs perfectly \
99with or without it, but you're encourajed to install it to have a better \
100speed experience. Download it at http://psyco.sf.net/"""))
101            self.using_psyco = False
102
103        self.diff = option_parser.get_diff()
104        if self.diff:
105            self.__run_text()
106        else:
107            self.__run_gui()
108
109    def __run_text(self):
110        log.info(">>> Text Mode")
111
112    def __run_gui(self):
113        log.info(">>> GUI Mode")
114        import warnings
115        warnings.filterwarnings("error", module = "gtk")
116        try:
117            import gtk
118        except Warning, e:
119            print e.message
120            sys.exit(-1)
121        warnings.resetwarnings()
122
123        import gobject
124        from umitGUI.Splash import Splash
125        log.info(">>> Pixmaps path: %s" % Path.pixmaps_dir)
126
127        if not is_maemo():
128            pixmap_d = Path.pixmaps_dir
129            if pixmap_d:
130                pixmap_file = os.path.join(pixmap_d, 'splash.png')
131                self.splash = Splash(pixmap_file, 1400)
132
133        if main_is_frozen():
134            # This is needed by py2exe
135            gtk.gdk.threads_init()
136            gtk.gdk.threads_enter()
137
138        # Create and show the main window as soon as possible
139        gobject.idle_add(self.__create_show_main_window)
140
141        # Run main loop
142        #gobject.threads_init()
143        gtk.main()
144
145        if main_is_frozen():
146            gtk.gdk.threads_leave()
Note: See TracBrowser for help on using the browser.