mirror of https://github.com/kivy/kivy.git
core: introduce CoreCriticalException. When this one is fired while trying to use a core lib, then the exception is raised to the user.
This is actually used for window provider, while trying to create the window. + if an import error is detected, just warn the user about a missing module.
This commit is contained in:
parent
4afd39798d
commit
343d71b495
|
@ -22,6 +22,9 @@ import os
|
|||
import kivy
|
||||
from kivy.logger import Logger
|
||||
|
||||
class CoreCriticalException(Exception):
|
||||
pass
|
||||
|
||||
if 'KIVY_DOC' in os.environ:
|
||||
# stub for sphinx generation
|
||||
def core_select_lib(category, llist, create_instance=False):
|
||||
|
@ -55,10 +58,24 @@ else:
|
|||
cls = cls()
|
||||
return cls
|
||||
|
||||
except ImportError as e:
|
||||
Logger.warning('%s: Unable to use <%s> as %s'
|
||||
'provider' % (category.capitalize(), option, category))
|
||||
Logger.warning('%s: Associated module are missing' %
|
||||
(category.capitalize()))
|
||||
Logger.debug('', exc_info=e)
|
||||
|
||||
except CoreCriticalException as e:
|
||||
Logger.error('%s: Unable to use <%s> as %s'
|
||||
'provider' % (category.capitalize(), option, category))
|
||||
Logger.error('%s: The module raised an important error' %
|
||||
(category.capitalize()))
|
||||
raise
|
||||
|
||||
except Exception as e:
|
||||
Logger.warning('%s: Unable to use <%s> as %s'
|
||||
'provider' % (category.capitalize(), option, category))
|
||||
Logger.debug('', exc_info = e)
|
||||
Logger.debug('', exc_info=e)
|
||||
|
||||
Logger.critical('%s: Unable to find any valuable %s provider '
|
||||
'at all!' % (category.capitalize(), category.capitalize()))
|
||||
|
|
|
@ -4,8 +4,11 @@ Window Pygame: windowing provider based on Pygame
|
|||
|
||||
__all__ = ('WindowPygame', )
|
||||
|
||||
from . import WindowBase
|
||||
# fail early if possible
|
||||
import pygame
|
||||
|
||||
from . import WindowBase
|
||||
from kivy.core import CoreCriticalException
|
||||
import os
|
||||
import sys
|
||||
from os.path import exists
|
||||
|
@ -15,12 +18,6 @@ from kivy.logger import Logger
|
|||
from kivy.base import stopTouchApp, EventLoop
|
||||
from kivy.clock import Clock
|
||||
|
||||
try:
|
||||
import pygame
|
||||
except:
|
||||
Logger.warning('WinPygame: Pygame is not installed !')
|
||||
raise
|
||||
|
||||
# late binding
|
||||
glReadPixels = GL_RGB = GL_UNSIGNED_BYTE = None
|
||||
|
||||
|
@ -45,7 +42,10 @@ class WindowPygame(WindowBase):
|
|||
if sys.platform == 'linux2':
|
||||
self.flags |= pygame.RESIZABLE
|
||||
|
||||
pygame.display.init()
|
||||
try:
|
||||
pygame.display.init()
|
||||
except pygame.error, e:
|
||||
raise CoreCriticalException(e.message)
|
||||
|
||||
multisamples = Config.getint('graphics', 'multisamples')
|
||||
|
||||
|
|
Loading…
Reference in New Issue