root/branch/PacketManipulator/PM/Gui/Core/App.py @ 4147

Revision 4147, 3.3 kB (checked in by nopper, 4 years ago)

Win32 fixes

Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# Copyright (C) 2008 Adriano Monteiro Marques
4#
5# Author: Francesco Piccinno <stack.box@gmail.com>
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
21"""
22This module contains the PMApp singleton object that gives access to
23the all PacketManipulator functionalities
24"""
25
26import gtk
27import gobject
28
29import os
30import sys
31
32from PM.Core.I18N import _
33from PM.Core.Atoms import Singleton
34from PM.Gui.Core.Splash import SplashScreen
35from PM.Gui.Plugins.Engine import PluginEngine
36
37class PMApp(Singleton):
38    "The PacketManipulator application singleton object"
39
40    def __init__(self):
41        gobject.threads_init()
42
43        root = False
44
45        try:
46            # FIXME: add maemo
47            if sys.platform == 'win32':
48                import ctypes
49                root = bool(ctypes.windll.shell32.IsUserAnAdmin())
50            elif os.getuid() == 0:
51                root = True
52        except: pass
53
54        if not root:
55            dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL,
56                                       gtk.MESSAGE_WARNING,
57                                       gtk.BUTTONS_YES_NO,
58                                       _('You are running Packet Manipulator as non-root user!\n'
59                                         'Some functionalities need root privileges to work\n\n'
60                                         'Do you want to continue?'))
61            ret = dialog.run()
62            dialog.hide()
63            dialog.destroy()
64           
65            if ret == gtk.RESPONSE_NO:
66                sys.exit(-1)
67
68        self.phase = 0
69        self.splash = SplashScreen()
70
71    def _idle(self):
72
73        if self.phase == 0:
74            self.splash.text = _("Registering icons ...")
75           
76            from Icons import register_icons
77            register_icons()
78        elif self.phase == 1:
79            self.splash.text = _("Loading preferences ...")
80           
81            from PM.Manager.PreferenceManager import Prefs
82            self.prefs = Prefs()
83        elif self.phase == 2:
84            self.splash.text = _("Creating main window ...")
85           
86            from MainWindow import MainWindow
87            self.main_window = MainWindow()
88            self.main_window.connect_tabs_signals()
89            self.plugin_engine = PluginEngine()
90            self.plugin_engine.load_selected_plugins()
91           
92            # Destroy the splash screen
93            self.splash.hide()
94            self.splash.destroy()
95            self.splash.finished = True
96           
97            del self.splash
98           
99            return False
100       
101        self.phase += 1
102        return True
103
104    def run(self):
105        self.splash.show_all()
106        gobject.idle_add(self._idle)
107        gtk.main()
Note: See TracBrowser for help on using the browser.