PyutApp.py :  » UML » Python-UML-Tool » pyut-1.4.0 » src » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » UML » Python UML Tool 
Python UML Tool » pyut 1.4.0 » src » PyutApp.py
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

__version__ = "$Revision: 1.15 $"
__author__ = "EI5, eivd, Group Burgbacher - Waelti"
__date__ = "2001-11-14"

##from wxPython.wx import wxApp, wxMessageDialog
from AppFrame import *
#from PyutFileDropTarget import *
from wx import SplashScreen
#from PyutPreferences import PyutPreferences
##from wxPython.help   import *
import wx, os, __builtin__
import locale
__builtin__.__dict__['oldFloat'] = float


def pythonFloat(s):
    c = locale.localeconv()["decimal_point"]
    s = s.replace('.', c)
    return oldFloat(s)
    #try:
        #return oldFloat(s)
    #except:
        #s = str(x)
        #s = s.replace(',', '.')
        #return oldFloat(s)



#---------------------------------------------------------------------------

def opj(path):
    """Convert paths to the platform-specific separator"""
    return apply(os.path.join, tuple(path.split('/')))


#---------------------------------------------------------------------------



class PyutApp(wx.App):
    """
    PyutApp : main pyut application class.

    PyutApp is the main pyut application, a wxApp. 

    Called from pyut.pyw

    :author:  C.Dutoit
    :contact: <dutoitc@hotmail.com>
    :version: $Revision: 1.15 $
    """
    def __init__(self, val, splash=True, show=True):
        self._showSplash = splash

        # TODO - DEBUG
        #self._showSplash = False
        self._showMainFrame = show
        #print "DBG1-",float(48.3)
        #print "DBG1-",float("48.3")
        wx.App.__init__(self, val)
        #print "DBG2-",float(48.3)
        #print "DBG2-",float("48.3")


    #>------------------------------------------------------------------------

    def OnInit(self):
        """
        Constructor.

        @since 1.0
        @author C.Dutoit
        """
        # Correct wxPython BUG of float localization
        def newPythonFloat(x):
            # Try standard float
            try:
                return oldFloat(x)
            except:
                pass

            # Try localized float
            try:
                x = x.replace(".", ",")
            except:
                pass
            return pythonFloat(x)
        import __builtin__
        __builtin__.__dict__['float'] = newPythonFloat


        #print "DBG3-",float(48.3)
        #print "DBG3-",pythonFloat("48.3")
        #float = pythonFloat
        #print "DBG4-",float(48.3)
        #print "DBG4-",float("48.3")
        # Init help system
        provider = wx.SimpleHelpProvider()
        wx.HelpProvider_Set(provider)

        try:
            #Create the SplashScreen
            if self._showSplash:
                wx.InitAllImageHandlers()
                imgPath = "img" + os.sep + "splash.png"
                img = wx.Image(imgPath)
                bmp = img.ConvertToBitmap()
                self.splash=SplashScreen(bmp, \
                         wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT, \
                         3000, None, -1)

                self.splash.Show(True)
                wx.Yield()

            #Create the application
            self._frame=AppFrame(None, -1, "Pyut")
            self.SetTopWindow(self._frame)
            #TODO remove this
            #self.__do=PyutFileDropTarget(self._frame)
            #self._frame.SetDropTarget(self.__do)
            if self._showSplash:
                self.splash.Show(False)
            self._AfterSplash()

            return True
        except: #Display all errors
            import sys, traceback
            dlg=wx.MessageDialog(None, _("The following error occured : %s") \
                %sys.exc_info()[1], _("An error occured..."),
                wx.OK | wx.ICON_ERROR)
            print "==========================================================="
            print "Error : %s" % sys.exc_info()[0]
            print "Msg   : %s" % sys.exc_info()[1]
            print "Trace :"
            for el in traceback.extract_tb(sys.exc_info()[2]):
                print el
            dlg.ShowModal()
            dlg.Destroy()
            dlg = None
            return False


    #>------------------------------------------------------------------------

    def _AfterSplash(self):
        """
        AfterSplash : Occure after the splash screen; launch the application
        PyutApp : main pyut application class

        @since  : 1.5
        @author : C.Dutoit<dutoitc@hotmail.com>
        """
        try:
            #Handle application parameters in the command line
            import sys, PyutPreferences
            prefs = PyutPreferences.PyutPreferences()
            orgPath = prefs["orgDirectory"]
            for filename in [el for el in sys.argv[1:] if el[0]!='-']:
                self._frame.loadByFilename(orgPath + os.sep + filename)
            if self._frame is None:
                print "Exiting due to previous errors"
                return False
            del orgPath
            if self._showMainFrame:
                self._frame.Show(True)

            # Show full screen ?
            fullScreen = prefs["full_screen"]
            if fullScreen is None:
                fullScreen = 0
            else:
                if fullScreen :
                    fullScreen = 1
                else :
                    fullScreen = 0
                #fullScreen = int(fullScreen)
            if fullScreen==1:
                dc = wx.ScreenDC()
                self._frame.SetSize(dc.GetSize())
                self._frame.CentreOnScreen()

                # Doesn't works well
                #self._frame.ShowFullScreen(True, 0)

                # Only on windows
                #self._frame.Maximize()

            if self._showSplash:
                self.splash.Close(True)
            return True
        except: #Display all errors
            import sys, traceback
            dlg=wx.MessageDialog(None, _("The following error occured : %s") \
                %sys.exc_info()[1], _("An error occured..."),
                wx.OK | wx.ICON_ERROR)
            print "==========================================================="
            print "Error : %s" % sys.exc_info()[0]
            print "Msg   : %s" % sys.exc_info()[1]
            print "Trace :"
            for el in traceback.extract_tb(sys.exc_info()[2]):
                print el
            dlg.ShowModal()
            dlg.Destroy()
            dlg = None
            return False




    #>------------------------------------------------------------------------

    def OnExit(self):
        """
        Clean exit

        @since  : 1.6.2.2
        @author : C.Dutoit<dutoitc@hotmail.com>
        """
        self.__do   = None
        self._frame  = None
        self.splash = None
        # Seemed to be removed in latest versions of wxPython ???
        try:
            return wx.App.OnExit(self)
        except:
            pass


www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.