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 |
# forms/wizards/AddDropdown.py |
# forms/wizards/AddDropdown.py |
25 |
# Add a dropdown entry to a form, creating any datasources if necessary. |
# Add a dropdown entry to a form, creating any datasources if necessary. |
26 |
# |
# |
27 |
# NOTES: |
# NOTES: |
|
# While functional, the primary purpose of this wizard is |
|
|
# as a "learning-by-example" tool. |
|
28 |
|
|
29 |
|
|
30 |
from gnue.designer.forms.TemplateSupport import * |
from gnue.designer.forms.TemplateSupport import * |
60 |
self.y = y |
self.y = y |
61 |
self.width = width |
self.width = width |
62 |
self.height = height |
self.height = height |
63 |
|
|
64 |
|
if not self.current['block']: |
65 |
|
raise InsufficientInformation, _("There are no blocks in this form.") |
66 |
|
|
67 |
self.__getExistingDatasources() |
self.__getExistingDatasources() |
68 |
|
|
69 |
|
|
87 |
if stepCode == '0': |
if stepCode == '0': |
88 |
|
|
89 |
if self.__firstConnection: |
if self.__firstConnection: |
90 |
self.variables['connection'] == self.__firstConnection |
self.variables['connection'] = self.__firstConnection |
91 |
|
|
92 |
if len (self.__datasourceMap): |
if len (self.__datasourceMap): |
93 |
set=((0,'Create a new datasource'), |
set=((0,'Create a new datasource'), |
163 |
# |
# |
164 |
elif stepCode == '1:reuse': |
elif stepCode == '1:reuse': |
165 |
return { 'title': 'Datasource Connection', |
return { 'title': 'Datasource Connection', |
166 |
'content': (WizardText('What connection should this form use to connect to the \ndatabase?'), |
'content': (WizardText('Which existing datasource should be used?'), |
167 |
WizardInput('connection',label='Connection:', required=1, |
WizardInput('source',label='Datasource:', required=1, |
168 |
set=self.__getExistingDatasources()), |
set=self.__getExistingDatasources())), |
|
WizardText('You may be asked to login to this connection.')), |
|
169 |
'prev': '0', |
'prev': '0', |
170 |
'next': '2:reuse' } |
'next': '2:reuse' } |
171 |
|
|
238 |
# Create new datasource |
# Create new datasource |
239 |
if self.variables['datasource'] == 0: |
if self.variables['datasource'] == 0: |
240 |
datasource = self.AddElement('datasource', self.form, |
datasource = self.AddElement('datasource', self.form, |
241 |
{ 'name': "dtsDrp_%s_%s" % (self.variables['table'], |
{ 'name': self.GetUniqueName("dtsDrp_%s_%s" % (self.variables['table'], |
242 |
self.variables['name']), |
self.variables['name'])), |
243 |
'database': self.variables['connection'], |
'connection': self.variables['connection'], |
244 |
'prequery': 1, |
'prequery': 1, |
245 |
'table': self.variables['table'] } ) |
'table': self.variables['table'] } ) |
246 |
keyfield = self.variables['key'] |
keyfield = self.variables['key'] |
255 |
# Create a "static" datasource |
# Create a "static" datasource |
256 |
else: |
else: |
257 |
datasource = self.AddElement('datasource', self.form, |
datasource = self.AddElement('datasource', self.form, |
258 |
{ 'name': "dtsDrpStatic%s" % self.variables['name'], |
{ 'name': self.GetUniqueName("dtsDrpStatic%s" % self.variables['name']), |
259 |
'type': "static" } ) |
'type': "static" } ) |
260 |
keyfield = 'key' |
keyfield = 'key' |
261 |
descrfield = 'descr' |
descrfield = 'descr' |
269 |
except ValueError: |
except ValueError: |
270 |
pass |
pass |
271 |
ssr = self.AddElement('staticsetrow', ss) |
ssr = self.AddElement('staticsetrow', ss) |
272 |
self.AddElement('staticsetfield',ssr,{'name': 'key','value': key}) |
self.AddElement('staticsetfield',ssr,{'name': 'key', 'value': key}) |
273 |
self.AddElement('staticsetfield',ssr,{'name': 'descr','value': descr}) |
self.AddElement('staticsetfield',ssr,{'name': 'descr','value': descr}) |
274 |
|
|
275 |
|
|
278 |
# |
# |
279 |
|
|
280 |
# Make sure we find a Block |
# Make sure we find a Block |
281 |
block = self.current.findParentOfType('GFBlock') |
block = self.current['block'] |
282 |
if not block: |
page = self.current['page'] |
|
block = self.current.findParentOfType('GFPage').findChildOfType('GFBlock') |
|
|
if not block: |
|
|
# Create a block |
|
|
block = self.AddElement('block', self.current.findParentOfType('GFPage')) |
|
283 |
|
|
284 |
self.AddElement('entry', self.current.findChildOfType('GFBlock'), |
field = self.AddElement('field', block, |
285 |
{ 'name': 'fld%s' % self.variables['name'], |
{ 'name': self.GetUniqueName('fld%s' % self.variables['name'], block), |
286 |
'field': self.variables['name'], |
'field': self.variables['name'], |
|
'style': 'dropdown', |
|
|
'x': self.x, |
|
|
'y': self.y, |
|
|
'width': self.width or 10, |
|
|
'height': 1, |
|
287 |
'fk_source': datasource.name, |
'fk_source': datasource.name, |
288 |
'fk_key': keyfield, |
'fk_key': keyfield, |
289 |
'fk_description': descrfield } ) |
'fk_description': descrfield } ) |
290 |
|
|
291 |
|
|
292 |
|
self.AddElement('entry', page, |
293 |
|
{ 'name': self.GetUniqueName('ntry%s' % self.variables['name'], page), |
294 |
|
'field': field.name, |
295 |
|
'block': block.name, |
296 |
|
'style': 'dropdown', |
297 |
|
'Char:x': self.x, |
298 |
|
'Char:y': self.y, |
299 |
|
'Char:width': self.width or 10, |
300 |
|
'Char:height': 1 } ) |
301 |
|
|
302 |
|
|
303 |
return 1 |
return 1 |
304 |
|
|
305 |
|
|
312 |
self.__firstConnection = None |
self.__firstConnection = None |
313 |
self.__datasourceSet = [] |
self.__datasourceSet = [] |
314 |
self.__datasourceMap = {} |
self.__datasourceMap = {} |
315 |
for child in self.form._children: |
for child in self.form.findChildrenOfType('GFDataSource'): |
316 |
if child._type == 'GFDataSource' and hasattr(child,'table'): |
if hasattr(child,'table'): |
317 |
self.__datasourceSet.append((child.name,"%s (%s)" % (child.name, child.table))) |
self.__datasourceSet.append((child.name,"%s (%s)" % (child.name, child.table))) |
318 |
self.__datasourceMap[child.name] = child |
self.__datasourceMap[child.name] = child |
319 |
if not self.__firstConnection: |
if not self.__firstConnection: |
336 |
'Version' : VERSION, |
'Version' : VERSION, |
337 |
'Author' : 'The GNUe Designer Team', |
'Author' : 'The GNUe Designer Team', |
338 |
'Behavior': WIZARD, |
'Behavior': WIZARD, |
339 |
'Location' : 'Tools|Insert|Drop Down Entry' |
'Location' : 'Edit|Insert|Drop Down Entry' |
340 |
} |
} |
341 |
|
|