Пример #1
0
    def display_splash_screen(self, img_name=None, pos=None, size=(320, 240)):
        """Displays a splash screen and the specified position and size."""

        # Prepare the picture.
        w, h = size
        image = wx.Image(img_name, wx.BITMAP_TYPE_PNG)
        image.Rescale(w, h, wx.IMAGE_QUALITY_HIGH)
        bm = image.ConvertToBitmap()

        # Create and show the splash screen.  It will disappear only when the
        # program has entered the event loop AND either the timeout has expired
        # or the user has left clicked on the screen.  Thus any processing
        # performed by the calling routine (including doing imports) will
        # prevent the splash screen from disappearing.
        splash = SplashScreen(
            bitmap=bm,
            splashStyle=(SPLASH_TIMEOUT|SPLASH_CENTRE_ON_SCREEN),
            style=(wx.SIMPLE_BORDER|wx.FRAME_NO_TASKBAR|wx.STAY_ON_TOP),
            milliseconds=SPLASH_TIMEOUT,
            parent=None, id=wx.ID_ANY)
        splash.Bind(wx.EVT_CLOSE, self.OnCloseSplashScreen)

        # Repositon if center of screen placement is overridden by caller.
        if pos is not None:
            splash.SetPosition(pos)
        splash.Show()
Пример #2
0
class PyutApp(wxApp):
    """
    PyutApp : main pyut application class.

    PyutApp is the main pyut application, a wxApp.

    """
    SPLASH_TIMEOUT_MSECS: int = 3000

    def __init__(self,
                 redirect: bool,
                 showSplash: bool = True,
                 showMainFrame: bool = True):

        self.logger: Logger = getLogger(__name__)

        self._showSplash = showSplash
        self._showMainFrame = showMainFrame

        super().__init__(redirect)

    def OnInit(self):
        """
        """
        provider: SimpleHelpProvider = SimpleHelpProvider()

        HelpProvider.Set(provider)
        try:
            # Create the SplashScreen
            if self._showSplash:

                bmp: Bitmap = splashImage.GetBitmap()
                self.splash = SplashScreen(bmp,
                                           SPLASH_CENTRE_ON_PARENT
                                           | SPLASH_TIMEOUT,
                                           PyutApp.SPLASH_TIMEOUT_MSECS,
                                           parent=None,
                                           pos=wxDefaultPosition,
                                           size=wxDefaultSize)

                self.logger.debug(f'Showing splash screen')
                self.splash.Show(True)
                wxYield()

            self._frame: AppFrame = AppFrame(cast(AppFrame, None), ID_ANY,
                                             "Pyut")
            self.SetTopWindow(self._frame)
            self._AfterSplash()

            return True
        except (ValueError, Exception) as e:
            self.logger.error(f'{e}')
            dlg = MessageDialog(
                None, _(f"The following error occurred: {exc_info()[1]}"),
                _("An error occurred..."), OK | ICON_ERROR)
            errMessage: str = ErrorManager.getErrorInfo()
            self.logger.debug(errMessage)
            dlg.ShowModal()
            dlg.Destroy()
            return False

    def _AfterSplash(self):
        """
        AfterSplash : Occurs after the splash screen is launched; launch the application
        """
        try:
            # Handle application parameters in the command line
            prefs: PyutPreferences = PyutPreferences()
            orgPath: str = prefs[PyutPreferences.ORG_DIRECTORY]
            for filename in [el for el in argv[1:] if el[0] != '-']:
                self._frame.loadByFilename(orgPath + osSeparator + filename)
            if self._frame is None:
                self.logger.error("Exiting due to previous errors")
                return False
            del orgPath
            if self._showMainFrame:
                self._frame.Show(True)

            # Show full screen ?
            if prefs.fullScreen is True:
                dc = ScreenDC()
                self._frame.SetSize(dc.GetSize())
                self._frame.CentreOnScreen()

            return True
        except (ValueError, Exception) as e:
            dlg = MessageDialog(
                None, _(f"The following error occurred : {exc_info()[1]}"),
                _("An error occurred..."), OK | ICON_ERROR)
            self.logger.error(f'Exception: {e}')
            self.logger.error(f'Error: {exc_info()[0]}')
            self.logger.error('Msg: {exc_info()[1]}')
            self.logger.error('Trace:')
            for el in extract_tb(exc_info()[2]):
                self.logger.error(el)
            dlg.ShowModal()
            dlg.Destroy()
            return False

    def OnExit(self):
        """
        """
        self.__do = None
        self._frame = None
        self.splash = None
        # Seemed to be removed in latest versions of wxPython ???
        try:
            return wxApp.OnExit(self)
        except (ValueError, Exception) as e:
            self.logger.error(f'OnExit: {e}')
Пример #3
0
class FitUIApp(wx.App):
    """
    BasicSoftware : main BasicSoftware application class.
    BasicSoftware is the main application, a wxApp.
    Called from BasicSoftware.pyw
    """
    def __init__(self, val, splash=True, show=True):
        self._showSplash = splash
        self._showMainFrame = show
        wx.App.__init__(self, val)

    def OnInit(self):
        """
        Constructor.
        """
        provider = wx.SimpleHelpProvider()
        wx.HelpProvider.Set(provider)

        try:
            #Create the SplashScreen
            if self._showSplash:
                wx.InitAllImageHandlers()
                imgPath = "img" + os.sep + "FIT-logo.png"  # TODO Find a logo
                img = wx.Image(imgPath)
                bmp = img.ConvertToBitmap()
                self.splash = SplashScreen(
                    bmp,
                    wx.adv.SPLASH_CENTRE_ON_SCREEN | wx.adv.SPLASH_TIMEOUT, 60,
                    None, -1)

                if self._showSplash:
                    self.splash.Show(True)
                    wx.Yield()

            #Create the application
            displaySize = wx.DisplaySize()
            self._frame = RibbonFrame(parent=None,
                                      id=wx.ID_ANY,
                                      title='FitSoftware',
                                      size=(displaySize[0] / (4 / 3),
                                            displaySize[1] / (4 / 3)))
            self.SetTopWindow(self._frame)

            if self._showSplash:
                self.splash.Show(False)
            self._AfterSplash()

            return True
        except Exception as err:  #Display all errors
            msg = "Failed to init the software : %s" % err
            raise ValueError(msg)

    def _AfterSplash(self):
        """
        AfterSplash : Occure after the splash screen; launch the application
        FitUI : main FitUI application class
    
        """
        try:
            if self._showMainFrame:
                self._frame.Show(True)

            if self._showSplash:
                self.splash.Close()

            return True
        except:
            msg = "Failed to launch the qfterSplash screen"
            ValueError(msg, 'BasicSoftware.AfterSplash Error')

    def OnExit(self):
        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