1
#----------------------------------------------------------------------
2
# Name: PaletteMapping.py
3
# Purpose: Module that initialises the Palette's data and provides
4
# the namespace in which design time code is evaluated
6
# Author: Riaan Booysen
9
# RCS-ID: $Id: PaletteMapping.py,v 1.27 2005/05/18 13:20:13 riaan Exp $
10
# Copyright: (c) 1999 - 2005 Riaan Booysen
12
#----------------------------------------------------------------------
14
""" Based on core support preferences this module initialises Companion, Model,
15
View and Controller classes. It also executes all active Plug-ins.
17
The namespace of this module is used to evalute code at Design-Time with evalCtrl.
18
Hence the needed import * and execfile.
22
# XXX This module should be renamed it's function has changed over time
23
# XXX Maybe: BoaNamespace/DesignTimeNamespace
27
import Preferences, Utils, Plugins
28
from Preferences import IS
31
# keep until 2.5 upgrade complete
32
#from wxPython.wx import *
36
if Preferences.csWxPythonSupport:
37
# This should be the first time the Companion classes are imported
38
# As the modules are imported they add themselves to the PaletteStore
39
from Companions.Companions import *
41
from Companions.FrameCompanions import *
42
from Companions.WizardCompanions import *
43
from Companions.ContainerCompanions import *
44
if Preferences.dsUseSizers:
45
from Companions.SizerCompanions import *
46
from Companions.BasicCompanions import *
47
from Companions.DateTimeCompanions import *
48
from Companions.ButtonCompanions import *
49
from Companions.ListCompanions import *
50
from Companions.GizmoCompanions import *
51
from Companions.LibCompanions import *
52
if Utils.IsComEnabled():
53
from Companions.ComCompanions import *
54
# Define and add a User page to the palette
55
PaletteStore.paletteLists['User'] = upl = []
56
PaletteStore.palette.append(['User', 'Editor/Tabs/User', upl])
57
from Companions.UtilCompanions import *
58
from Companions.DialogCompanions import *
60
# Zope requires spesific support
61
if Plugins.transportInstalled('ZopeLib.ZopeExplorer'):
62
from ZopeLib.ZopeCompanions import *
64
#-Controller imports which auto-registers themselves on the Palette-------------
66
from Models import EditorHelper
68
if Preferences.csPythonSupport:
69
import Models.PythonControllers
71
if Preferences.csWxPythonSupport:
72
import Models.wxPythonControllers
74
if Preferences.csPythonSupport and not Preferences.csWxPythonSupport:
75
# useful hack to alias wx.App modules to PyApp modules when wxPython support
77
from Models.PythonEditorModels import PyAppModel
78
EditorHelper.modelReg['App'] = PyAppModel
80
# The text and makepy controllers are registered outside the Controllers
81
# module so that their palette order can be fine tuned
82
from Models import Controllers
83
PaletteStore.newControllers['Text'] = Controllers.TextController
84
PaletteStore.paletteLists['New'].append('Text')
86
#-Registration of other built in support----------------------------------------
87
if Preferences.csConfigSupport: from Models import ConfigSupport
88
if Preferences.csCppSupport: from Models import CPPSupport
89
if Preferences.csHtmlSupport: from Models import HTMLSupport
90
if Preferences.csXmlSupport: from Models import XMLSupport
92
if Plugins.transportInstalled('ZopeLib.ZopeExplorer'):
93
import ZopeLib.ZopeEditorModels
95
if Utils.IsComEnabled():
96
PaletteStore.newControllers['MakePy-Dialog'] = Controllers.MakePyController
97
PaletteStore.paletteLists['New'].append('MakePy-Dialog')
99
#-Plug-ins initialisation-------------------------------------------------------
100
if Preferences.pluginPaths:
101
print 'executing plug-ins...'
102
fails = Preferences.failedPlugins
103
succeeded = Preferences.installedPlugins
105
for pluginFilename, ordered, enabled in Plugins.buildPluginExecList():
109
pluginBasename = os.path.basename(pluginFilename)
110
filename = pluginFilename.lower()
112
execfile(pluginFilename)
113
succeeded.append(filename)
114
except Plugins.SkipPluginSilently, msg:
115
fails[filename] = ('Skipped', msg)
116
except Plugins.SkipPlugin, msg:
117
fails[filename] = ('Skipped', msg)
118
wx.LogWarning('Plugin skipped: %s, %s'%(pluginBasename, msg))
119
except Exception, error:
120
fails[filename] = ('Error', str(error))
121
if Preferences.pluginErrorHandling == 'raise':
123
elif Preferences.pluginErrorHandling == 'report':
124
wx.LogError('Problem executing plug-in %s:\n%s' %\
125
(pluginBasename, str(error)) )
128
# XXX legacy references
129
palette = PaletteStore.palette
130
newPalette = PaletteStore.newPalette
131
dialogPalette = PaletteStore.dialogPalette
132
zopePalette = PaletteStore.zopePalette
133
helperClasses = PaletteStore.helperClasses
134
compInfo = PaletteStore.compInfo
137
def evalCtrl(expr, localsDct=None):
138
""" Function usually used to evaluate source snippets.
140
Uses the namespace of this module which contain all the wxPython libs
141
and also adds param localDct.
145
_NB = IS.load('Images/Inspector/wxNullBitmap.png')
146
if localsDct is None:
148
localsDct['_'] = Utils.I18nStringFactory
151
return eval(expr, globals(), localsDct)
1
#----------------------------------------------------------------------
2
# Name: PaletteMapping.py
3
# Purpose: Module that initialises the Palette's data and provides
4
# the namespace in which design time code is evaluated
6
# Author: Riaan Booysen
9
# RCS-ID: $Id: PaletteMapping.py,v 1.35 2007/07/05 11:53:43 riaan Exp $
10
# Copyright: (c) 1999 - 2007 Riaan Booysen
12
#----------------------------------------------------------------------
14
""" Based on core support preferences this module initialises Companion, Model,
15
View and Controller classes. It also executes all active Plug-ins.
17
The namespace of this module is used to evalute code at Design-Time with evalCtrl.
18
Hence the needed import * and execfile.
22
# XXX This module should be renamed it's function has changed over time
23
# XXX Maybe: BoaNamespace/DesignTimeNamespace
27
import Preferences, Utils, Plugins
28
from Preferences import IS
33
# keep until 2.5 upgrade complete
34
#from wxPython.wx import *
38
if Preferences.csWxPythonSupport:
39
# This should be the first time the Companion classes are imported
40
# As the modules are imported they add themselves to the PaletteStore
41
from Companions.Companions import *
43
from Companions.FrameCompanions import *
44
from Companions.WizardCompanions import *
45
from Companions.ContainerCompanions import *
46
if Preferences.dsUseSizers:
47
from Companions.SizerCompanions import *
48
from Companions.BasicCompanions import *
49
from Companions.DateTimeCompanions import *
50
from Companions.ButtonCompanions import *
51
from Companions.ListCompanions import *
52
from Companions.GizmoCompanions import *
53
from Companions.LibCompanions import *
54
if Utils.IsComEnabled():
55
from Companions.ComCompanions import *
56
# Define and add a User page to the palette
57
PaletteStore.paletteLists['User'] = upl = []
58
PaletteStore.palette.append([_('User'), 'Editor/Tabs/User', upl])
59
from Companions.UtilCompanions import *
60
from Companions.DialogCompanions import *
62
# Zope requires spesific support
63
if Plugins.transportInstalled('ZopeLib.ZopeExplorer'):
64
from ZopeLib.ZopeCompanions import *
66
#-Controller imports which auto-registers themselves on the Palette-------------
68
from Models import EditorHelper
70
if Preferences.csPythonSupport:
71
import Models.PythonControllers
73
if Preferences.csWxPythonSupport:
74
import Models.wxPythonControllers
76
if Preferences.csPythonSupport and not Preferences.csWxPythonSupport:
77
# useful hack to alias wx.App modules to PyApp modules when wxPython support
79
from Models.PythonEditorModels import PyAppModel
80
EditorHelper.modelReg['App'] = PyAppModel
82
# The text and makepy controllers are registered outside the Controllers
83
# module so that their palette order can be fine tuned
84
from Models import Controllers
85
PaletteStore.newControllers['Text'] = Controllers.TextController
86
PaletteStore.paletteLists['New'].append('Text')
88
#-Registration of other built in support----------------------------------------
89
if Preferences.csConfigSupport: from Models import ConfigSupport
90
if Preferences.csCppSupport: from Models import CPPSupport
91
if Preferences.csHtmlSupport: from Models import HTMLSupport
92
if Preferences.csXmlSupport: from Models import XMLSupport
94
if Plugins.transportInstalled('ZopeLib.ZopeExplorer'):
95
import ZopeLib.ZopeEditorModels
97
if Utils.IsComEnabled():
98
PaletteStore.newControllers['MakePy-Dialog'] = Controllers.MakePyController
99
PaletteStore.paletteLists['New'].append('MakePy-Dialog')
101
#-Plug-ins initialisation-------------------------------------------------------
102
if Preferences.pluginPaths:
103
print 'executing plug-ins...'
104
fails = Preferences.failedPlugins
105
succeeded = Preferences.installedPlugins
107
for pluginFilename, ordered, enabled in Plugins.buildPluginExecList():
111
pluginBasename = os.path.basename(pluginFilename)
113
print 'executing %s'% os.path.splitext(pluginBasename)[0]
115
filename = pluginFilename.lower()
117
execfile(pluginFilename)
118
succeeded.append(filename)
119
except Plugins.SkipPluginSilently, msg:
120
fails[filename] = ('Skipped', msg)
121
except Plugins.SkipPlugin, msg:
122
fails[filename] = ('Skipped', msg)
123
wx.LogWarning(_('Plugin skipped: %s, %s')%(pluginBasename, msg))
124
except Exception, error:
125
fails[filename] = ('Error', str(error))
126
if Preferences.pluginErrorHandling == 'raise':
128
elif Preferences.pluginErrorHandling == 'report':
129
wx.LogError(_('Problem executing plug-in %s:\n%s') %\
130
(pluginBasename, str(error)) )
133
# XXX legacy references
134
palette = PaletteStore.palette
135
newPalette = PaletteStore.newPalette
136
dialogPalette = PaletteStore.dialogPalette
137
zopePalette = PaletteStore.zopePalette
138
helperClasses = PaletteStore.helperClasses
139
compInfo = PaletteStore.compInfo
141
class DesignTimeExpressionError(Exception): pass
144
def evalCtrl(expr, localsDct=None, preserveExc=True):
145
""" Function usually used to evaluate source snippets.
147
Uses the namespace of this module which contain all the wxPython libs
148
and also adds param localDct.
152
_NB = IS.load('Images/Inspector/wxNullBitmap.png')
153
if localsDct is None:
155
localsDct['_'] = lambda x: x
158
return eval(expr, globals(), localsDct)
159
except Exception, err:
163
clsName = err.__class__.__name__
164
raise DesignTimeExpressionError, clsName+': '+str(err)