16 |
# write to the Free Software Foundation, Inc., 59 Temple Place |
# write to the Free Software Foundation, Inc., 59 Temple Place |
17 |
# - Suite 330, Boston, MA 02111-1307, USA. |
# - Suite 330, Boston, MA 02111-1307, USA. |
18 |
# |
# |
19 |
# Copyright 2001-2002 Free Software Foundation |
# Copyright 2001-2003 Free Software Foundation |
20 |
# |
# |
21 |
# FILE: |
# FILE: |
22 |
# form/Instance.py |
# form/Instance.py |
27 |
# NOTES: |
# NOTES: |
28 |
# |
# |
29 |
|
|
30 |
|
from wxPython.wx import * |
31 |
|
|
32 |
from gnue.designer.forms import properties as formProperties |
from gnue.designer.forms import properties as formProperties |
33 |
from gnue.designer.Instance import BaseInstance |
from gnue.designer.base.Instance import BaseInstance |
34 |
from gnue.designer import PopupMenu |
from gnue.designer.base import PopupMenu |
35 |
import Incubator |
from Incubator import Incubator |
36 |
import wizards |
import wizards |
37 |
from WizardRunner import WizardRunner |
from WizardRunner import WizardRunner |
38 |
|
|
39 |
# Tool support... |
# Tool support... |
40 |
from LayoutEditor import LayoutEditor |
from LayoutEditor import LayoutEditor |
41 |
from TreeView import TreeView |
from TreeView import TreeView |
42 |
from gnue.designer.PropertyEditor import PropertyEditor |
from PropertyEditor import PropertyEditor |
43 |
from gnue.designer.TriggerEditor import TriggerEditor |
from EventEditor import EventEditor |
44 |
from gnue.designer.DataSourceEditor import DataSourceEditor |
from gnue.designer.base.tools.TriggerEditor import TriggerEditor |
45 |
from gnue.designer.SchemaViewer import SchemaViewer |
from gnue.designer.base.tools.DataSourceEditor import DataSourceEditor |
46 |
|
from gnue.designer.base.tools.SchemaViewer import SchemaViewer |
47 |
|
|
48 |
from gnue.designer.PopupMenu import ObjectMenu |
from gnue.designer.base.PopupMenu import ObjectMenu |
49 |
|
|
50 |
from gnue.forms import GFInstance |
from gnue.forms import GFInstance |
51 |
from gnue.forms import GFForm, GFParser, GFObjects, GFLibrary |
from gnue.forms import GFForm, GFParser, GFObjects, GFLibrary |
52 |
from gnue.common import GTrigger |
from gnue.common import GTrigger, GDataSource |
53 |
|
|
54 |
class Instance(BaseInstance, GFInstance.GFInstance): |
class Instance(BaseInstance, GFInstance.GFInstance): |
55 |
|
|
56 |
def __init__(self, app, *args, **params): |
def __init__(self, app, *args, **params): |
57 |
|
|
58 |
self.incubator = Incubator |
self.incubator = Incubator(self) |
59 |
self.properties = formProperties |
self.properties = formProperties |
60 |
self.wizardRunner = WizardRunner |
self.wizardRunner = WizardRunner |
61 |
|
|
63 |
# TODO: part of the main Instance class, but an |
# TODO: part of the main Instance class, but an |
64 |
# TODO: attribute such as Instance.formInstance? |
# TODO: attribute such as Instance.formInstance? |
65 |
|
|
66 |
GFInstance.GFInstance.__init__(self, app, -1, |
GFInstance.GFInstance.__init__(self, app, |
67 |
app.connections, |
app.connections, |
68 |
None, disableSplash=1) |
None, disableSplash=1) |
69 |
|
|
70 |
# For GFInstance support, iirc |
# For GFInstance support, iirc |
71 |
self._pages = [] |
self._pages = [] |
72 |
|
|
73 |
|
# Build a list of positionable widgets |
74 |
|
self._positionableList = [] |
75 |
|
elements = self.incubator.elements |
76 |
|
for tag in elements.keys(): |
77 |
|
try: |
78 |
|
if elements['Positionable']: |
79 |
|
self._positionableList.append(tag) |
80 |
|
except KeyError: |
81 |
|
pass |
82 |
|
|
83 |
|
|
84 |
BaseInstance.__init__(self, app, *args, **params) |
BaseInstance.__init__(self, app, *args, **params) |
85 |
|
|
86 |
|
self.registerEventListeners({ |
87 |
|
'ObjectModified' : self.onModifyObject, |
88 |
|
'ObjectDeleted' : self.onDeleteObject, |
89 |
|
}) |
90 |
|
|
91 |
def loadBuffer(self, buffer): |
def loadBuffer(self, buffer): |
92 |
form = GFParser.loadFile (buffer, self, initialize=0) |
form = GFParser.loadFile (buffer, self, initialize=0) |
94 |
return form |
return form |
95 |
|
|
96 |
|
|
97 |
def loadEmpty(self): |
def loadEmpty(self, style=None): |
98 |
form = GFForm.GFForm() |
form = GFForm.GFForm() |
99 |
options = GFObjects.GFOptions(form) |
options = GFObjects.GFOptions(form) |
100 |
form.title = _("Untitled Form") |
form.title = _("Untitled Form") |
101 |
form.height = 12 |
form.height = 12 |
102 |
form.name = 'form' |
form.name = 'form' |
103 |
form.width = 40 |
form.width = 40 |
104 |
GFObjects.GFPage(form) |
GFObjects.GFLogic(form) |
105 |
|
layout = GFObjects.GFLayout(form) |
106 |
|
layout.Char__width = 40 |
107 |
|
layout.Char__height = 12 |
108 |
|
GFObjects.GFPage(layout) |
109 |
return form |
return form |
110 |
|
|
111 |
|
|
112 |
def inventoryObject(self, object): |
def inventoryObject(self, object): |
113 |
if isinstance(object, GFObjects.GFPage) and \ |
if object._type == 'GFForm': |
114 |
|
object._blockMap = {} |
115 |
|
elif object._type == 'GFLogic': |
116 |
|
object._parent._logic = object |
117 |
|
elif object._type == 'GFLayout': |
118 |
|
object._parent._layout = object |
119 |
|
# Yes, you guessed it! More layout mgmt hackery... |
120 |
|
object._xmlchildnamespaces = {'Char':'GNUe:Layout:Char'} |
121 |
|
elif object._type == 'GFBlock': |
122 |
|
if self.rootObject._blockMap.has_key(object.name): |
123 |
|
raise "Warning: Multiple blocks with name %s" % object.name |
124 |
|
self.rootObject._blockMap[object.name] = object |
125 |
|
object._fieldMap = {} |
126 |
|
elif object._type == 'GFField': |
127 |
|
object.findParentOfType('GFBlock')._fieldMap[object.name] = object |
128 |
|
elif object._type == 'GFEntry': |
129 |
|
object._block = self.rootObject._blockMap[object.block] |
130 |
|
object._field = object._block._fieldMap[object.field] |
131 |
|
elif isinstance(object, GFObjects.GFPage) and \ |
132 |
object._parent == self.rootObject: |
object._parent == self.rootObject: |
133 |
self._pages.append(object) |
self._pages.append(object) |
134 |
|
|
135 |
object._popupMenu = ObjectMenu(self, object) |
object._popupMenu = ObjectMenu(self, object) |
136 |
|
|
137 |
|
|
138 |
def createVisualEditor(self): |
def onModifyObject(self, event): |
139 |
return LayoutEditor(self, self) |
object = event.object |
140 |
|
# TODO: Maintain all those fun dicts/lists created in inventoryObject() |
141 |
|
|
142 |
|
|
143 |
|
def onDeleteObject(self, event): |
144 |
|
object = event.object |
145 |
|
if object._type == 'GFPage': |
146 |
|
self._pages.remove(object) |
147 |
|
|
148 |
|
# TODO: Maintain all those fun dicts/lists created in inventoryObject() |
149 |
|
|
150 |
|
|
151 |
def createTools(self): |
def createTools(self): |
152 |
self.addTool('propertyEditor', _('Property Inspector'), PropertyEditor) |
self.addTool('visualEditor', _('Layout Editor'), LayoutEditor, 'F11') |
153 |
self.addTool('treeEditor', _('Object Navigator'), TreeView) |
self.addTool('propertyEditor', _('Property Inspector'), PropertyEditor, 'F10') |
154 |
self.addTool('triggerEditor', _('Event Editor'), TriggerEditor) |
self.addTool('treeEditor', _('Object Navigator'), TreeView, 'F8') |
155 |
self.addTool('datasourceEditor', _('Data Source Editor'), DataSourceEditor) |
self.addTool('schemaViewer', _('Schema Navigator'), SchemaViewer) |
156 |
self.addTool('schemaViewer', _('Schema Navigator'), SchemaViewer) |
self.addToolSeparator() |
157 |
|
self.addTool('datasourceEditor',_('Data Source Editor'), DataSourceEditor) |
158 |
|
#self.addTool('blockEditor', _('Block Editor'), BlockEditor, 'F5') |
159 |
|
#self.addTool('fieldEditor', _('Field Editor'), FieldEditor, 'F6') |
160 |
|
self.addToolSeparator() |
161 |
|
self.addTool('eventEditor', _('Trigger Inspector'), EventEditor, 'F7') |
162 |
|
self.addTool('triggerEditor', _('Code Editor'), TriggerEditor, 'F12') |
163 |
|
|
164 |
|
def createWizards(self): |
165 |
self.loadWizards(wizards) |
self.loadWizards(wizards) |
166 |
|
|
167 |
|
|
|
## def insertDataSourceTool(self, event=None, params=None): |
|
|
## pass |
|
|
## |
|
|
## def insertPageTool(self, event=None, params=None): |
|
|
## pass |
|
|
## |
|
|
## def insertBlockTool(self, event=None, params=None): |
|
|
## pass |
|
|
## |
|
|
## def insertFieldTool(self, event=None, params=None): |
|
|
## pass |
|
|
## |
|
|
## def insertDropdownTool(self, event=None, params=None): |
|
|
## pass |
|
|
|
|
168 |
def preSave(self): |
def preSave(self): |
169 |
|
|
170 |
# Do a little rearranging of objects |
# Do a little rearranging of objects |
174 |
databases = [] |
databases = [] |
175 |
datasources = [] |
datasources = [] |
176 |
triggers = [] |
triggers = [] |
177 |
pages = [] |
logic = [] |
178 |
|
layout = [] |
179 |
other = [] |
other = [] |
180 |
|
|
181 |
for child in self.rootObject._children: |
for child in self.rootObject._children: |
183 |
options.append(child) |
options.append(child) |
184 |
elif isinstance(child, GFLibrary.GFImport): |
elif isinstance(child, GFLibrary.GFImport): |
185 |
imports.append(child) |
imports.append(child) |
186 |
elif isinstance(child, GFObjects.GFDatabase): |
elif isinstance(child, GDataSource.GConnection): |
187 |
databases.append(child) |
databases.append(child) |
188 |
elif isinstance(child, GFObjects.GFDataSource) or \ |
elif isinstance(child, GFObjects.GFDataSource) or \ |
189 |
(isinstance(child, GFLibrary.GFImportItem) and |
(isinstance(child, GFLibrary.GFImportItem) and |
193 |
(isinstance(child, GFLibrary.GFImportItem) and |
(isinstance(child, GFLibrary.GFImportItem) and |
194 |
child._type == 'GFimport-trigger'): |
child._type == 'GFimport-trigger'): |
195 |
triggers.append(child) |
triggers.append(child) |
196 |
elif isinstance(child, GFObjects.GFPage) or \ |
elif isinstance(child, GFObjects.GFLayout) or \ |
197 |
|
(isinstance(child, GFLibrary.GFImportItem) and |
198 |
|
child._type == 'GFimport-layout'): |
199 |
|
layout.append(child) |
200 |
|
elif isinstance(child, GFObjects.GFLogic) or \ |
201 |
(isinstance(child, GFLibrary.GFImportItem) and |
(isinstance(child, GFLibrary.GFImportItem) and |
202 |
child._type == 'GFimport-page'): |
child._type == 'GFimport-logic'): |
203 |
pages.append(child) |
logic.append(child) |
204 |
else: |
else: |
205 |
other.append(child) |
other.append(child) |
206 |
|
|
217 |
self.rootObject._children.append(child) |
self.rootObject._children.append(child) |
218 |
for child in triggers: |
for child in triggers: |
219 |
self.rootObject._children.append(child) |
self.rootObject._children.append(child) |
220 |
for child in pages: |
for child in logic: |
221 |
|
self.rootObject._children.append(child) |
222 |
|
for child in layout: |
223 |
self.rootObject._children.append(child) |
self.rootObject._children.append(child) |
224 |
for child in other: |
for child in other: |
225 |
self.rootObject._children.append(child) |
self.rootObject._children.append(child) |
226 |
|
|
227 |
|
# Used by TemplateParser to build a wizard.current dict |
228 |
# Hack having to do with UIwxpython import |
def buildWizardCurrentDict(self): |
229 |
def uiEventTrap(self, event): |
baseForm = self._currentObject.findParentOfType('GFForm') |
230 |
pass |
return {'form': baseForm, |
231 |
|
'logic': baseForm._logic, |
232 |
|
'layout': baseForm._layout, |
233 |
|
'page': self.visualEditor.page, |
234 |
|
'block': self.visualEditor.block, |
235 |
|
'object': self._currentObject} |
236 |
|
|
237 |
|
# # Hack having to do with UIwxpython import |
238 |
|
# def uiEventTrap(self, event): |
239 |
|
# pass |
240 |
|
|
241 |
|
|