Determines which context is used: * DrawBotContext --> 'DrawBot' * FlatContext --> 'Flat' * HtmlContext --> 'Html' * InDesignContext --> 'InDesign' * SvgContext --> 'Svg' * SketchContext --> 'Sketch' NOTE: the global DEFAULT_CONTEXT sets the last loaded context to
(contextType=None)
| 54 | print(traceback.format_exc()) |
| 55 | |
| 56 | def getContext(contextType=None): |
| 57 | """Determines which context is used: |
| 58 | * DrawBotContext --> 'DrawBot' |
| 59 | * FlatContext --> 'Flat' |
| 60 | * HtmlContext --> 'Html' |
| 61 | * InDesignContext --> 'InDesign' |
| 62 | * SvgContext --> 'Svg' |
| 63 | * SketchContext --> 'Sketch' |
| 64 | |
| 65 | NOTE: the global DEFAULT_CONTEXT sets the last loaded context to default |
| 66 | for caching purposes. Switching context type will reload it. |
| 67 | |
| 68 | NOTE: See doctests/contexts-linux.txt and doctests/context-osx.txt for |
| 69 | # platform-specific testing of contexts. |
| 70 | """ |
| 71 | global DEFAULT_CONTEXT, CONTEXT_TYPE |
| 72 | |
| 73 | if contextType is None: |
| 74 | if platform == 'darwin': |
| 75 | contextType = 'drawbot' |
| 76 | else: |
| 77 | contextType = 'flat' |
| 78 | |
| 79 | contextType = contextType.lower() |
| 80 | |
| 81 | if CONTEXT_TYPE and contextType != CONTEXT_TYPE: |
| 82 | # Switching contexts, so resetting the buffered global object. |
| 83 | DEFAULT_CONTEXT = None |
| 84 | |
| 85 | |
| 86 | if DEFAULT_CONTEXT is None: |
| 87 | if platform == 'darwin': |
| 88 | if contextType == 'drawbot' and hasDrawBot:# and DrawBotContext is not None: |
| 89 | DEFAULT_CONTEXT = getDrawBotContext() |
| 90 | elif contextType == 'DrawBot' and not hasDrawBot: |
| 91 | print('Cannot find the pagebotosx module.') |
| 92 | print('Using Flat instead of DrawBot.') |
| 93 | DEFAULT_CONTEXT = getFlatContext() |
| 94 | elif contextType == 'flat': |
| 95 | DEFAULT_CONTEXT = getFlatContext() |
| 96 | elif contextType == 'sketch': |
| 97 | DEFAULT_CONTEXT = getSketchContext() |
| 98 | elif contextType == 'html': |
| 99 | DEFAULT_CONTEXT = getHtmlContext() |
| 100 | elif contextType == 'svg': |
| 101 | DEFAULT_CONTEXT = getSvgContext() |
| 102 | |
| 103 | else: |
| 104 | if contextType in ('DrawBot', 'Sketch'): |
| 105 | print('%s is not available on platform %s.' % (contextType, platform)) |
| 106 | print('Using Flat instead of %s.' % contextType) |
| 107 | DEFAULT_CONTEXT = getFlatContext() |
| 108 | elif contextType == 'flat': |
| 109 | DEFAULT_CONTEXT = getFlatContext() |
| 110 | elif contextType == 'html': |
| 111 | DEFAULT_CONTEXT = getHtmlContext() |
| 112 | elif contextType == 'svg': |
| 113 | DEFAULT_CONTEXT = getSvgContext() |
no test coverage detected