1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
Description: Making traitsui dependency optional
If users don't have traitsui, then GUI-specific functions now do nothing
instead of crashing the application. This really helps for running unit tests
on build machines without any X-server which have problems when running
traitsui functions. Failure to import traitsui is no longer fatal. traitsui
is only Recommended until we can get it python3'd. This lets us keep ~98% of
functionality.
Author: Stewart Fergusonm <stew@ferg.aero>
Forwarded: https://github.com/enthought/apptools/pull/86
Last-Update: 2019-02-03
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/apptools/naming/trait_defs/naming_traits.py
+++ b/apptools/naming/trait_defs/naming_traits.py
@@ -22,8 +22,11 @@ from traits.api \
from traits.trait_base \
import class_of, get_module_name
-from traitsui.api \
- import DropEditor
+try:
+ from traitsui.api \
+ import DropEditor
+except ImportError:
+ pass
from apptools.naming.api \
import Binding
@@ -101,11 +104,15 @@ class NamingTraitHandler ( TraitHandler
def get_editor ( self, trait ):
if self.editor is None:
- from traitsui.api import DropEditor
+ try:
+ from traitsui.api import DropEditor
+
+ self.editor = DropEditor( klass = self.aClass,
+ binding = True,
+ readonly = False )
+ except ImportError:
+ pass
- self.editor = DropEditor( klass = self.aClass,
- binding = True,
- readonly = False )
return self.editor
def post_setattr ( self, object, name, value ):
--- a/apptools/__init__.py
+++ b/apptools/__init__.py
@@ -7,6 +7,5 @@ except ImportError:
__version__ = 'not-built'
__requires__ = [
- 'traitsui',
'configobj',
]
|