예제 #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
 def __init__(self):
     bmp = wx.Bitmap('images/cr3.png')
     SplashScreen.__init__(
         self, bmp, wx.adv.SPLASH_CENTRE_ON_SCREEN | wx.adv.SPLASH_TIMEOUT,
         5000, None, -1)
     self.Bind(wx.EVT_CLOSE, self.OnClose)
     self.fc = wx.CallLater(6500, self.show_main)
예제 #3
0
 def __init__(self):
     try:
         img = wx.Image('src/splash.jpg',
                        wx.BITMAP_TYPE_ANY).ConvertToBitmap()
         img = wx.Bitmap(img)
         SplashScreen.__init__(
             self, img,
             wx.adv.SPLASH_CENTRE_ON_SCREEN | wx.adv.SPLASH_TIMEOUT, 2000,
             None, -1)
         self.Bind(wx.EVT_CLOSE, self.OnClose)
         self.fc = wx.CallLater(1000, self.ShowMain)
     except Exception as e:
         print(e)
예제 #4
0
 def display_splash_screen(self):
     bmp = wx.Image("assets/enbarr.png").ConvertToBitmap()
     SplashScreen(bmp, SPLASH_CENTRE_ON_SCREEN | SPLASH_TIMEOUT,
                  config.splash_screen_time, None, -1)
     wx.SafeYield()
     time.sleep(config.splash_screen_time / 1000)
     self.Show()
예제 #5
0
    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)
예제 #6
0
    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
예제 #7
0
def execute(*args):
    #
    #  Run program stand-alone.
    #
    app = xrdApp(*args)
    app.mframe = MainFrame(None, wx.NewIdRef())
    app.SetTopWindow(app.mframe)

    # if len(sys.argv) == 1:
    #     app = xrdApp()
    # else:
    #     app = xrdApp(*sys.argv[1:])
    #     pass
    #
    #  The main window cannot be imported until after the app
    #  is instantiated due to the wx.ColourDatabase() call.
    #
    #
    # Splash screen.
    #
    splashFile = 'hexrd.png'
    splashDir = os.path.dirname(__file__)
    splashImage = wx.Bitmap(os.path.join(splashDir, splashFile),
                            wx.BITMAP_TYPE_PNG)
    #
    splash = SplashScreen(
        splashImage, wx.adv.SPLASH_CENTRE_ON_PARENT | wx.adv.SPLASH_TIMEOUT,
        1000, app.mframe)
    #
    # Main frame
    #
    app.mframe.Show(True)
    #
    # Autload data
    #
    # * turning off autoload, using loadExperiment instead
    #
    # app.mframe.loadProject()
    #
    # wx main loop
    #
    app.MainLoop()
예제 #8
0
    def __init__(self):
        # Splash screen image will depend on currently language
        lang = False

        self.locale = wx.Locale(wx.LANGUAGE_DEFAULT)

        # Language information is available in session configuration
        # file. First we need to check if this file exist, if now, it
        # should be created
        create_session = False
        session = ses.Session()
        if not (session.ReadSession()):
            create_session = True

        install_lang = 0
        lang = session.GetLanguage()
        if lang:
            if (lang != "False"):
                _ = i18n.InstallLanguage(lang)
                install_lang = 1
            else:
                install_lang = 0
        else:
            install_lang = 0

        # If no language is set into session file, show dialog so
        # user can select language
        if install_lang == 0:
            dialog = lang_dlg.LanguageDialog()

            # FIXME: This works ok in linux2, darwin and win32,
            # except on win64, due to wxWidgets bug
            try:
                ok = (dialog.ShowModal() == wx.ID_OK)
            except wx._core.PyAssertionError:
                ok = True
            finally:
                if ok:
                    lang = dialog.GetSelectedLanguage()
                    session.SetLanguage(lang)
                    _ = i18n.InstallLanguage(lang)
                else:
                    homedir = self.homedir = os.path.expanduser('~')
                    invdir = os.path.join(homedir, ".invesalius")
                    shutil.rmtree(invdir)
                    sys.exit()

            dialog.Destroy()

        # Session file should be created... So we set the recent
        # choosen language
        if (create_session):
            session.CreateItens()
            session.SetLanguage(lang)
            session.WriteSessionFile()

        #  session.SaveConfigFileBackup()

           
        # Only after language was defined, splash screen will be
        # shown
        if lang:
            
            #import locale
            #try:
            #    locale.setlocale(locale.LC_ALL, '')
            #except locale.Error:
            #    pass
            
            
            # For pt_BR, splash_pt.png should be used
            if (lang.startswith('pt')):
                icon_file = "splash_pt.png"
            else:
                icon_file = "splash_" + lang + ".png"

            if hasattr(sys,"frozen") and (sys.frozen == "windows_exe"\
                                        or sys.frozen == "console_exe"):
                abs_file_path = os.path.abspath(".." + os.sep)
                path = abs_file_path
                path = os.path.join(path, 'icons', icon_file)
            
            else:

                path = os.path.join(".","icons", icon_file)
                if not os.path.exists(path):
                    path = os.path.join(".", "icons", "splash_en.png")
				
            bmp = wx.Image(path).ConvertToBitmap()

            try:
                style = wx.adv.SPLASH_TIMEOUT | wx.adv.SPLASH_CENTRE_ON_SCREEN
            except AttributeError:
                style = wx.SPLASH_TIMEOUT | wx.SPLASH_CENTRE_ON_SCREEN

            SplashScreen.__init__(self,
                                  bitmap=bmp,
                                  splashStyle=style,
                                  milliseconds=1500,
                                  id=-1,
                                  parent=None)
            self.Bind(wx.EVT_CLOSE, self.OnClose)
            wx.Yield()
            wx.CallLater(200, self.Startup)
예제 #9
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}')
예제 #10
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
예제 #11
0
    def __init__(self):
        # Splash screen image will depend on currently language
        lang = False

        self.locale = wx.Locale(wx.LANGUAGE_DEFAULT)

        # Language information is available in session configuration
        # file. First we need to check if this file exist, if now, it
        # should be created
        create_session = False
        session = ses.Session()
        if not (session.ReadSession()):
            create_session = True

        install_lang = 0
        lang = session.GetLanguage()
        if lang:
            if (lang != "False"):
                _ = i18n.InstallLanguage(lang)
                install_lang = 1
            else:
                install_lang = 0
        else:
            install_lang = 0

        # If no language is set into session file, show dialog so
        # user can select language
        if install_lang == 0:
            dialog = lang_dlg.LanguageDialog()

            # FIXME: This works ok in linux2, darwin and win32,
            # except on win64, due to wxWidgets bug
            try:
                ok = (dialog.ShowModal() == wx.ID_OK)
            except wx._core.PyAssertionError:
                ok = True
            finally:
                if ok:
                    lang = dialog.GetSelectedLanguage()
                    session.SetLanguage(lang)
                    _ = i18n.InstallLanguage(lang)
                else:
                    homedir = self.homedir = os.path.expanduser('~')
                    invdir = os.path.join(homedir, ".invesalius")
                    shutil.rmtree(invdir)
                    sys.exit()

            dialog.Destroy()

        # Session file should be created... So we set the recent
        # choosen language
        if (create_session):
            session.CreateItens()
            session.SetLanguage(lang)
            session.WriteSessionFile()

        #  session.SaveConfigFileBackup()

           
        # Only after language was defined, splash screen will be
        # shown
        if lang:
            
            #import locale
            #try:
            #    locale.setlocale(locale.LC_ALL, '')
            #except locale.Error:
            #    pass
            
            
            # For pt_BR, splash_pt.png should be used
            if (lang.startswith('pt')):
                icon_file = "splash_pt.png"
            else:
                icon_file = "splash_" + lang + ".png"

            if hasattr(sys,"frozen") and (sys.frozen == "windows_exe"\
                                        or sys.frozen == "console_exe"):
                abs_file_path = os.path.abspath(".." + os.sep)
                path = abs_file_path
                path = os.path.join(path, 'icons', icon_file)
            
            else:

                path = os.path.join(".","icons", icon_file)
                if not os.path.exists(path):
                    path = os.path.join(".", "icons", "splash_en.png")
				
            bmp = wx.Image(path).ConvertToBitmap()

            try:
                style = wx.adv.SPLASH_TIMEOUT | wx.adv.SPLASH_CENTRE_ON_SCREEN
            except AttributeError:
                style = wx.SPLASH_TIMEOUT | wx.SPLASH_CENTRE_ON_SCREEN

            SplashScreen.__init__(self,
                                  bitmap=bmp,
                                  splashStyle=style,
                                  milliseconds=1500,
                                  id=-1,
                                  parent=None)
            self.Bind(wx.EVT_CLOSE, self.OnClose)
            wx.Yield()
            wx.CallLater(200, self.Startup)