~ubuntu-branches/ubuntu/trusty/boa-constructor/trusty

« back to all changes in this revision

Viewing changes to PaletteMapping.py

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna
  • Date: 2008-04-29 16:05:23 UTC
  • mfrom: (3.1.6 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080429160523-24y12jcjem5m8z80
Tags: 0.6.1-4
* Urgency high to fix RC bugs.
* debian/control:
  - Move to XS-Python-Version: >= 2.4 (Closes: #476929, #477145).

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
5
 
#
6
 
# Author:      Riaan Booysen
7
 
#
8
 
# Created:     1999
9
 
# RCS-ID:      $Id: PaletteMapping.py,v 1.27 2005/05/18 13:20:13 riaan Exp $
10
 
# Copyright:   (c) 1999 - 2005 Riaan Booysen
11
 
# Licence:     GPL
12
 
#----------------------------------------------------------------------
13
 
 
14
 
""" Based on core support preferences this module initialises Companion, Model,
15
 
View and Controller classes. It also executes all active Plug-ins.
16
 
 
17
 
The namespace of this module is used to evalute code at Design-Time with evalCtrl.
18
 
Hence the needed import * and execfile.
19
 
 
20
 
"""
21
 
 
22
 
# XXX This module should be renamed it's function has changed over time
23
 
# XXX Maybe: BoaNamespace/DesignTimeNamespace
24
 
 
25
 
import os
26
 
 
27
 
import Preferences, Utils, Plugins
28
 
from Preferences import IS
29
 
import PaletteStore
30
 
 
31
 
# keep until 2.5 upgrade complete
32
 
#from wxPython.wx import *
33
 
 
34
 
import wx
35
 
 
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 *
40
 
 
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 *
59
 
 
60
 
# Zope requires spesific support
61
 
if Plugins.transportInstalled('ZopeLib.ZopeExplorer'):
62
 
    from ZopeLib.ZopeCompanions import *
63
 
 
64
 
#-Controller imports which auto-registers themselves on the Palette-------------
65
 
 
66
 
from Models import EditorHelper
67
 
 
68
 
if Preferences.csPythonSupport:
69
 
    import Models.PythonControllers
70
 
 
71
 
if Preferences.csWxPythonSupport:
72
 
    import Models.wxPythonControllers
73
 
 
74
 
if Preferences.csPythonSupport and not Preferences.csWxPythonSupport:
75
 
    # useful hack to alias wx.App modules to PyApp modules when wxPython support
76
 
    # is not loaded
77
 
    from Models.PythonEditorModels import PyAppModel
78
 
    EditorHelper.modelReg['App'] = PyAppModel
79
 
 
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')
85
 
 
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
91
 
 
92
 
if Plugins.transportInstalled('ZopeLib.ZopeExplorer'):
93
 
    import ZopeLib.ZopeEditorModels
94
 
 
95
 
if Utils.IsComEnabled():
96
 
    PaletteStore.newControllers['MakePy-Dialog'] = Controllers.MakePyController
97
 
    PaletteStore.paletteLists['New'].append('MakePy-Dialog')
98
 
 
99
 
#-Plug-ins initialisation-------------------------------------------------------
100
 
if Preferences.pluginPaths:
101
 
    print 'executing plug-ins...'
102
 
    fails = Preferences.failedPlugins
103
 
    succeeded = Preferences.installedPlugins
104
 
 
105
 
    for pluginFilename, ordered, enabled in Plugins.buildPluginExecList():
106
 
        if not enabled:
107
 
            continue
108
 
 
109
 
        pluginBasename = os.path.basename(pluginFilename)
110
 
        filename = pluginFilename.lower()
111
 
        try:
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':
122
 
                raise
123
 
            elif Preferences.pluginErrorHandling == 'report':
124
 
                wx.LogError('Problem executing plug-in %s:\n%s' %\
125
 
                    (pluginBasename, str(error)) )
126
 
            # else ignore
127
 
 
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
135
 
 
136
 
_NB = None
137
 
def evalCtrl(expr, localsDct=None):
138
 
    """ Function usually used to evaluate source snippets.
139
 
 
140
 
    Uses the namespace of this module which contain all the wxPython libs
141
 
    and also adds param localDct.
142
 
    """
143
 
    global _NB
144
 
    if not _NB:
145
 
        _NB = IS.load('Images/Inspector/wxNullBitmap.png')
146
 
    if localsDct is None:
147
 
        localsDct = {}
148
 
    localsDct['_'] = Utils.I18nStringFactory
149
 
    wx.NullBitmap = _NB
150
 
 
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
 
5
#
 
6
# Author:      Riaan Booysen
 
7
#
 
8
# Created:     1999
 
9
# RCS-ID:      $Id: PaletteMapping.py,v 1.35 2007/07/05 11:53:43 riaan Exp $
 
10
# Copyright:   (c) 1999 - 2007 Riaan Booysen
 
11
# Licence:     GPL
 
12
#----------------------------------------------------------------------
 
13
 
 
14
""" Based on core support preferences this module initialises Companion, Model,
 
15
View and Controller classes. It also executes all active Plug-ins.
 
16
 
 
17
The namespace of this module is used to evalute code at Design-Time with evalCtrl.
 
18
Hence the needed import * and execfile.
 
19
 
 
20
"""
 
21
 
 
22
# XXX This module should be renamed it's function has changed over time
 
23
# XXX Maybe: BoaNamespace/DesignTimeNamespace
 
24
 
 
25
import os
 
26
 
 
27
import Preferences, Utils, Plugins
 
28
from Preferences import IS
 
29
from Utils import _
 
30
 
 
31
import PaletteStore
 
32
 
 
33
# keep until 2.5 upgrade complete
 
34
#from wxPython.wx import *
 
35
 
 
36
import wx
 
37
 
 
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 *
 
42
 
 
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 *
 
61
 
 
62
# Zope requires spesific support
 
63
if Plugins.transportInstalled('ZopeLib.ZopeExplorer'):
 
64
    from ZopeLib.ZopeCompanions import *
 
65
 
 
66
#-Controller imports which auto-registers themselves on the Palette-------------
 
67
 
 
68
from Models import EditorHelper
 
69
 
 
70
if Preferences.csPythonSupport:
 
71
    import Models.PythonControllers
 
72
 
 
73
if Preferences.csWxPythonSupport:
 
74
    import Models.wxPythonControllers
 
75
 
 
76
if Preferences.csPythonSupport and not Preferences.csWxPythonSupport:
 
77
    # useful hack to alias wx.App modules to PyApp modules when wxPython support
 
78
    # is not loaded
 
79
    from Models.PythonEditorModels import PyAppModel
 
80
    EditorHelper.modelReg['App'] = PyAppModel
 
81
 
 
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')
 
87
 
 
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
 
93
 
 
94
if Plugins.transportInstalled('ZopeLib.ZopeExplorer'):
 
95
    import ZopeLib.ZopeEditorModels
 
96
 
 
97
if Utils.IsComEnabled():
 
98
    PaletteStore.newControllers['MakePy-Dialog'] = Controllers.MakePyController
 
99
    PaletteStore.paletteLists['New'].append('MakePy-Dialog')
 
100
 
 
101
#-Plug-ins initialisation-------------------------------------------------------
 
102
if Preferences.pluginPaths:
 
103
    print 'executing plug-ins...'
 
104
    fails = Preferences.failedPlugins
 
105
    succeeded = Preferences.installedPlugins
 
106
 
 
107
    for pluginFilename, ordered, enabled in Plugins.buildPluginExecList():
 
108
        if not enabled:
 
109
            continue
 
110
 
 
111
        pluginBasename = os.path.basename(pluginFilename)
 
112
        
 
113
        print 'executing %s'% os.path.splitext(pluginBasename)[0]
 
114
        
 
115
        filename = pluginFilename.lower()
 
116
        try:
 
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':
 
127
                raise
 
128
            elif Preferences.pluginErrorHandling == 'report':
 
129
                wx.LogError(_('Problem executing plug-in %s:\n%s') %\
 
130
                    (pluginBasename, str(error)) )
 
131
            # else ignore
 
132
 
 
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
 
140
 
 
141
class DesignTimeExpressionError(Exception): pass
 
142
 
 
143
_NB = None
 
144
def evalCtrl(expr, localsDct=None, preserveExc=True):
 
145
    """ Function usually used to evaluate source snippets.
 
146
 
 
147
    Uses the namespace of this module which contain all the wxPython libs
 
148
    and also adds param localDct.
 
149
    """
 
150
    global _NB
 
151
    if not _NB:
 
152
        _NB = IS.load('Images/Inspector/wxNullBitmap.png')
 
153
    if localsDct is None:
 
154
        localsDct = {}
 
155
    localsDct['_'] = lambda x: x
 
156
    wx.NullBitmap = _NB
 
157
    try:
 
158
        return eval(expr, globals(), localsDct)
 
159
    except Exception, err:
 
160
        if preserveExc:
 
161
            raise
 
162
        else:
 
163
            clsName = err.__class__.__name__
 
164
            raise DesignTimeExpressionError, clsName+': '+str(err)