File: PaletteMapping.py

package info (click to toggle)
boa-constructor 0.3.0-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 8,188 kB
  • ctags: 8,857
  • sloc: python: 54,163; sh: 66; makefile: 36
file content (148 lines) | stat: -rw-r--r-- 5,598 bytes parent folder | download
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#----------------------------------------------------------------------
# Name:        PaletteMapping.py
# Purpose:     Module that initialises the Palette's data and provides
#              the namespace in which design time code is evaluated
#
# Author:      Riaan Booysen
#
# Created:     1999
# RCS-ID:      $Id: PaletteMapping.py,v 1.24 2004/08/16 13:15:39 riaan Exp $
# Copyright:   (c) 1999 - 2004 Riaan Booysen
# Licence:     GPL
#----------------------------------------------------------------------

""" Based on core support preferences this module initialises Companion, Model,
View and Controller classes. It also executes all active Plug-ins.

The namespace of this module is used to evalute code at Design-Time with evalCtrl.
Hence the needed import * and execfile.

"""

# XXX This module should be renamed it's function has changed over time
# XXX Maybe: BoaNamespace/DesignTimeNamespace

import os

import Preferences, Utils, Plugins
from Preferences import IS
import PaletteStore

from wxPython.wx import *

if Preferences.csWxPythonSupport:
    # This should be the first time the Companion classes are imported
    # As the modules are imported they add themselves to the PaletteStore
    from Companions.Companions import *

    from Companions.FrameCompanions import *
    from Companions.WizardCompanions import *
    from Companions.ContainerCompanions import *
    if Preferences.dsUseSizers:
        from Companions.SizerCompanions import *
    from Companions.BasicCompanions import *
    from Companions.ButtonCompanions import *
    from Companions.ListCompanions import *
    from Companions.GizmoCompanions import *
    from Companions.LibCompanions import *
    if Utils.IsComEnabled():
        from Companions.ComCompanions import *
    # Define and add a User page to the palette
    PaletteStore.paletteLists['User'] = upl = []
    PaletteStore.palette.append(['User', 'Editor/Tabs/User', upl])
    from Companions.UtilCompanions import *
    from Companions.DialogCompanions import *

# Zope requires spesific support
if Plugins.transportInstalled('ZopeLib.ZopeExplorer'):
    from ZopeLib.ZopeCompanions import *

#-Controller imports which auto-registers themselves on the Palette-------------

from Models import EditorHelper

if Preferences.csPythonSupport:
    import Models.PythonControllers

if Preferences.csWxPythonSupport:
    import Models.wxPythonControllers

if Preferences.csPythonSupport and not Preferences.csWxPythonSupport:
    # useful hack to alias wxApp modules to PyApp modules when wxPython support
    # is not loaded
    from Models.PythonEditorModels import PyAppModel
    EditorHelper.modelReg['App'] = PyAppModel

# The text and makepy controllers are registered outside the Controllers
# module so that their palette order can be fine tuned
from Models import Controllers
PaletteStore.newControllers['Text'] = Controllers.TextController
PaletteStore.paletteLists['New'].append('Text')

#-Registration of other built in support----------------------------------------
if Preferences.csConfigSupport: from Models import ConfigSupport
if Preferences.csCppSupport: from Models import CPPSupport
if Preferences.csHtmlSupport: from Models import HTMLSupport
if Preferences.csXmlSupport: from Models import XMLSupport

if Plugins.transportInstalled('ZopeLib.ZopeExplorer'):
    import ZopeLib.ZopeEditorModels

if Utils.IsComEnabled():
    PaletteStore.newControllers['MakePy-Dialog'] = Controllers.MakePyController
    PaletteStore.paletteLists['New'].append('MakePy-Dialog')

#-Plug-ins initialisation-------------------------------------------------------
if Preferences.pluginPaths:
    print 'executing plug-ins...'
    fails = Preferences.failedPlugins
    succeeded = Preferences.installedPlugins

    for pluginFilename, ordered, enabled in Plugins.buildPluginExecList():
        if not enabled:
            continue

        pluginBasename = os.path.basename(pluginFilename)
        filename = pluginFilename.lower()
        try:
            execfile(pluginFilename)
            succeeded.append(filename)
        except Plugins.SkipPluginSilently, msg:
            fails[filename] = ('Skipped', msg)
        except Plugins.SkipPlugin, msg:
            fails[filename] = ('Skipped', msg)
            wxLogWarning('Plugin skipped: %s, %s'%(pluginBasename, msg))
        except Exception, error:
            fails[filename] = ('Error', str(error))
            if Preferences.pluginErrorHandling == 'raise':
                raise
            elif Preferences.pluginErrorHandling == 'report':
                wxLogError('Problem executing plug-in %s:\n%s' %\
                    (pluginBasename, str(error)) )
            # else ignore

# XXX legacy references
palette = PaletteStore.palette
newPalette = PaletteStore.newPalette
dialogPalette = PaletteStore.dialogPalette
zopePalette = PaletteStore.zopePalette
helperClasses = PaletteStore.helperClasses
compInfo = PaletteStore.compInfo

_NB = None
def evalCtrl(expr, localsDct=None):
    """ Function usually used to evaluate source snippets.

    Uses the namespace of this module which contain all the wxPython libs
    and also adds param localDct.
    """
    global _NB
    if not _NB:
        _NB = IS.load('Images/Inspector/wxNullBitmap.png')
    if not localsDct:
        localsDct = {'wxNullBitmap': _NB}
    else:
        localsDct['wxNullBitmap'] = _NB
    localsDct['_'] = str

    return eval(expr, globals(), localsDct)