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

« back to all changes in this revision

Viewing changes to Plug-ins/XRCSupport.plug-in.py

  • Committer: Bazaar Package Importer
  • Author(s): Cédric Delfosse
  • Date: 2007-01-23 21:32:29 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070123213229-1d9lxp9c4dutjwv5
Add a .desktop file (Closes: #349081)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import string
2
 
 
3
 
from wxPython.wx import *
4
 
from wxPython.xrc import *
5
 
 
6
 
from Companions import BaseCompanions
7
 
 
8
 
class XmlResourceDTC(BaseCompanions.UtilityDTC):
9
 
    handledConstrParams = ()
10
 
    def __init__(self, name, designer, objClass):
11
 
        BaseCompanions.UtilityDTC.__init__(self, name, designer, objClass)
12
 
        self.editors['FileMask'] = StrConstrPropEdit
13
 
 
14
 
##    def hideDesignTime(self):
15
 
##        return ['Handle']
16
 
    def constructor(self):
17
 
        return {'FileMask': 'filemask', 'Name': 'name'}
18
 
    def designTimeSource(self, position='wxDefaultPos', size='wxDefaultSize'):
19
 
        return {'filemask': "''"}
20
 
    def writeImports(self):
21
 
        return 'from wxPython.xrc import *'
22
 
 
23
 
    factoryDict = {'LoadPanel'  : 'XrcPanel'}
24
 
    def factory(self, method):
25
 
        return self.factoryDict.get(method, None)
26
 
 
27
 
from Companions import ContainerCompanions
28
 
import methodparse
29
 
 
30
 
class XrcPanelDTC(ContainerCompanions.PanelDTC):
31
 
    suppressWindowId = true
32
 
    def constructor(self):
33
 
        return {'Name': 'name'}
34
 
 
35
 
    def designTimeControl(self, position, size, args = None):
36
 
        """ Create and initialise a design-time control """
37
 
        if args:
38
 
            args['id'] = -1
39
 
            self.control = apply(self.ctrlClass, (), args)
40
 
        else:
41
 
            self.control = apply(self.ctrlClass, (), self.designTimeDefaults(position, size))
42
 
 
43
 
        self.initDesignTimeControl()
44
 
        return self.control
45
 
 
46
 
    def designTimeDefaults(self, position = wxDefaultPosition,
47
 
                                 size = wxDefaultSize):
48
 
        xrcObjs = self.designer.getObjectsOfClass(wxXmlResource)
49
 
        if not xrcObjs:
50
 
            raise 'No wxXmlResource objects found'
51
 
        # factory/LoadPage allows no positional info
52
 
        if not position: posx, posy = 0, 0
53
 
        else:            posx, posy = position.x, position.y
54
 
        return {'parent': self.parent, 'id': -1, 'pos': (posx, posy),
55
 
                'size': (200, 200)}
56
 
 
57
 
    xmlResource = ''
58
 
    def persistConstr(self, className, params):
59
 
        paramStrs = []
60
 
        for param in params.keys():
61
 
            paramStrs.append('%s = %s'%(param, params[param]))
62
 
 
63
 
        if not self.textConstr:
64
 
            xrcObjs = self.designer.getObjectsOfClass(wxXmlResource)
65
 
            names = xrcObjs.keys()
66
 
            if names:
67
 
                dlg = wxSingleChoiceDialog(self.designer, 'Select wxXmlResource to LoadPanel from',
68
 
                      'wxXmlResource.LoadPanel', names)
69
 
                try:
70
 
                    if dlg.ShowModal() == wxID_OK:
71
 
                        xrcObj = dlg.GetStringSelection()
72
 
                        self.xmlResource = string.split(xrcObj, '.')[1]
73
 
                    else:
74
 
                        raise 'Cancelled!'
75
 
                finally:
76
 
                    dlg.Destroy()
77
 
            else:
78
 
                raise 'No wxXmlResource objects found'
79
 
        else:
80
 
            self.xmlResource = self.textConstr.factory[0]
81
 
 
82
 
        self.textConstr = methodparse.ConstructorParse(
83
 
            'self.%s = self.%s.LoadPanel(%s)'%(self.name, self.xmlResource,
84
 
            string.join(paramStrs, ', ')))
85
 
 
86
 
        self.designer.addCtrlToObjectCollection(self.textConstr)
87
 
 
88
 
    def designTimeSource(self, position = 'wxDefaultPosition', size = 'wxDefaultSize'):
89
 
        return {'name':  `self.name`}
90
 
 
91
 
 
92
 
class XrcPanel(wxPanel):
93
 
    pass
94
 
 
95
 
import PaletteStore
96
 
PaletteStore.paletteLists['Utilities (Data)'].append(wxXmlResource)
97
 
PaletteStore.compInfo.update({wxXmlResource: ['wxXmlResource', XmlResourceDTC]})
98
 
PaletteStore.paletteLists['ContainersLayout'].append(XrcPanel)
99
 
PaletteStore.compInfo[XrcPanel] = ['XrcPanel', XrcPanelDTC]
 
1
import wx
 
2
import wx.xrc
 
3
 
 
4
from Companions import BaseCompanions
 
5
 
 
6
class XmlResourceDTC(BaseCompanions.UtilityDTC):
 
7
    handledConstrParams = ()
 
8
    def __init__(self, name, designer, objClass):
 
9
        BaseCompanions.UtilityDTC.__init__(self, name, designer, objClass)
 
10
        self.editors['FileMask'] = StrConstrPropEdit
 
11
 
 
12
##    def hideDesignTime(self):
 
13
##        return ['Handle']
 
14
    def constructor(self):
 
15
        return {'FileMask': 'filemask', 'Name': 'name'}
 
16
    def designTimeSource(self, position='wx.DefaultPos', size='wx.DefaultSize'):
 
17
        return {'filemask': "''"}
 
18
    def writeImports(self):
 
19
        return 'import wx.xrc'
 
20
 
 
21
    factoryDict = {'LoadPanel'  : 'XrcPanel'}
 
22
    def factory(self, method):
 
23
        return self.factoryDict.get(method, None)
 
24
 
 
25
from Companions import ContainerCompanions
 
26
import methodparse
 
27
 
 
28
class XrcPanelDTC(ContainerCompanions.PanelDTC):
 
29
    suppressWindowId = True
 
30
    def constructor(self):
 
31
        return {'Name': 'name'}
 
32
 
 
33
    def designTimeControl(self, position, size, args = None):
 
34
        """ Create and initialise a design-time control """
 
35
        if args:
 
36
            args['id'] = -1
 
37
            self.control = apply(self.ctrlClass, (), args)
 
38
        else:
 
39
            self.control = apply(self.ctrlClass, (), self.designTimeDefaults(position, size))
 
40
 
 
41
        self.initDesignTimeControl()
 
42
        return self.control
 
43
 
 
44
    def designTimeDefaults(self, position = wx.DefaultPosition,
 
45
                                 size = wx.DefaultSize):
 
46
        xrcObjs = self.designer.getObjectsOfClass(wx.xrc.XmlResource)
 
47
        if not xrcObjs:
 
48
            raise 'No wx.xrc.XmlResource objects found'
 
49
        # factory/LoadPage allows no positional info
 
50
        if not position: posx, posy = 0, 0
 
51
        else:            posx, posy = position.x, position.y
 
52
        return {'parent': self.parent, 'id': -1, 'pos': (posx, posy),
 
53
                'size': (200, 200)}
 
54
 
 
55
    xmlResource = ''
 
56
    def persistConstr(self, className, params):
 
57
        paramStrs = []
 
58
        for param in params.keys():
 
59
            paramStrs.append('%s = %s'%(param, params[param]))
 
60
 
 
61
        if not self.textConstr:
 
62
            xrcObjs = self.designer.getObjectsOfClass(wx.xrc.XmlResource)
 
63
            names = xrcObjs.keys()
 
64
            if names:
 
65
                dlg = wx.SingleChoiceDialog(self.designer, 'Select wx.xrc.XmlResource to LoadPanel from',
 
66
                      'wx.xrc.XmlResource.LoadPanel', names)
 
67
                try:
 
68
                    if dlg.ShowModal() == wx.ID_OK:
 
69
                        xrcObj = dlg.GetStringSelection()
 
70
                        self.xmlResource = xrcObj.split('.')[1]
 
71
                    else:
 
72
                        raise 'Cancelled!'
 
73
                finally:
 
74
                    dlg.Destroy()
 
75
            else:
 
76
                raise 'No wx.xrc.XmlResource objects found'
 
77
        else:
 
78
            self.xmlResource = self.textConstr.factory[0]
 
79
 
 
80
        self.textConstr = methodparse.ConstructorParse(
 
81
            'self.%s = self.%s.LoadPanel(%s)'%(self.name, self.xmlResource,
 
82
            ', '.join(paramStrs)))
 
83
 
 
84
        self.designer.addCtrlToObjectCollection(self.textConstr)
 
85
 
 
86
    def designTimeSource(self, position = 'wx.DefaultPosition', size = 'wx.DefaultSize'):
 
87
        return {'name':  `self.name`}
 
88
 
 
89
 
 
90
class XrcPanel(wx.Panel):
 
91
    pass
 
92
 
 
93
#-------------------------------------------------------------------------------
 
94
 
 
95
import Plugins
 
96
 
 
97
Plugins.registerComponent('Utilities (Data)', wx.xrc.XmlResource,
 
98
                          'wx.xrc.XmlResource', XmlResourceDTC)
 
99
Plugins.registerComponent('ContainersLayout', XrcPanel,
 
100
                          'XrcPanel', XrcPanelDTC)