1 |
# |
# |
|
# Copyright 2001 Free Software Foundation |
|
|
# |
|
2 |
# This file is part of GNU Enterprise. |
# This file is part of GNU Enterprise. |
3 |
# |
# |
4 |
# GNU Enterprise is free software; you can redistribute it |
# GNU Enterprise is free software; you can redistribute it |
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 |
20 |
|
# |
21 |
# FILE: |
# FILE: |
22 |
# Simple.py |
# Simple.py |
23 |
# |
# |
29 |
# as a "learning-by-example" tool. |
# as a "learning-by-example" tool. |
30 |
|
|
31 |
|
|
32 |
from gnue.designer.TemplateBase import * |
from gnue.designer.forms.TemplateSupport import * |
33 |
import string |
import string |
34 |
|
|
35 |
|
|
47 |
# |
# |
48 |
# Initialize any runtime variables |
# Initialize any runtime variables |
49 |
# |
# |
50 |
def Start(self, form): |
def Start(self, form, current): |
51 |
self.form = form |
self.form = form |
52 |
|
|
53 |
|
|
64 |
if stepCode == '0': |
if stepCode == '0': |
65 |
return { 'title': 'Basic Form Information', |
return { 'title': 'Basic Form Information', |
66 |
'content': (WizardText('Welcome to the sample form wizard.'), |
'content': (WizardText('Welcome to the sample form wizard.'), |
67 |
WizardText('To create your form, I need to know some basic information. \n' |
WizardText('To create your form, I need to know some basic information.\n\n' |
68 |
'First, what shall I call your form? This name will appear in \n' |
'First, what shall I call your form? This name will appear in ' |
69 |
'the title bar.'), |
'the title bar.'), |
70 |
WizardInput('title', label='Form Title:', required=1, |
WizardInput('title', label='Form Title:', required=1, |
71 |
size=40), |
size=40), |
72 |
WizardText('What connection should this form use to connect to the \ndatabase?'), |
WizardText('What connection should this form use to connect to the database?'), |
73 |
WizardInput('connection',label='Connection:', required=1, |
WizardInput('connection',label='Connection:', required=1, |
74 |
set=self.GetAvailableConnections()), |
set=self.GetAvailableConnections()), |
75 |
WizardText('You may be asked to login to this connection.'), |
WizardText('You may be asked to login to this connection.'), |
246 |
leftlabels = self.variables['masterarrangement'] == 'left' |
leftlabels = self.variables['masterarrangement'] == 'left' |
247 |
|
|
248 |
# Set the basic attributes of the form |
# Set the basic attributes of the form |
249 |
self.form.title = self.variables['title'] |
self.ModifyElement(self.form, title=self.variables['title']) |
250 |
|
|
251 |
# Create a single datasource based on user's input |
# Create a single datasource based on user's input |
252 |
datasource = self.AddElement('datasource', self.form, |
datasource = self.AddElement('datasource', self.form, |
354 |
# Grid/multirecord layout |
# Grid/multirecord layout |
355 |
if multirecord: |
if multirecord: |
356 |
|
|
357 |
self.form.height = 13 |
height = 13 |
358 |
self.form.width = 1 |
width = 1 |
359 |
x = 1 |
x = 1 |
360 |
|
|
361 |
for i in range(len(entryQueue)): |
for i in range(len(entryQueue)): |
362 |
labelQueue[i].x = x |
self.ModifyElement(labelQueue[i],x=x,y=1) |
363 |
labelQueue[i].y = 1 |
self.ModifyElement(entryQueue[i],x=x,y=2) |
|
entryQueue[i].x = x |
|
|
entryQueue[i].y = 2 |
|
364 |
|
|
365 |
# If label width is larger than entry width, center the entry |
# If label width is larger than entry width, center the entry |
366 |
if entryQueue[i].width < labelQueue[i].width: |
if entryQueue[i].width < labelQueue[i].width: |
367 |
entryQueue[i].x = entryQueue[i].x + \ |
self.ModifyElement(entryQueue[i],x=entryQueue[i].x + \ |
368 |
int((labelQueue[i].width - entryQueue[i].width)/2) |
int((labelQueue[i].width - entryQueue[i].width)/2)) |
369 |
|
|
370 |
|
|
371 |
# Calculate the starting x for the next label/entry |
# Calculate the starting x for the next label/entry |
373 |
labelQueue[i].width or entryQueue[i].width) + 1 |
labelQueue[i].width or entryQueue[i].width) + 1 |
374 |
|
|
375 |
# Increase the form width accordingly |
# Increase the form width accordingly |
376 |
self.form.width = self.form.width + dx |
width += dx |
377 |
x = x + dx |
x = x + dx |
378 |
|
|
379 |
# Single Record layout (regardless of label location) |
# Single Record layout (regardless of label location) |
387 |
fx, fy, fdx, fdy = (largestLabel + 2, 1, 0, 1) |
fx, fy, fdx, fdy = (largestLabel + 2, 1, 0, 1) |
388 |
|
|
389 |
# Set form width |
# Set form width |
390 |
self.form.width = largestField + largestLabel + 3 |
width = largestField + largestLabel + 3 |
391 |
|
|
392 |
else: |
else: |
393 |
# Labels above the entries |
# Labels above the entries |
395 |
fx, fy, fdx, fdy = (1, 2, 0, 3) |
fx, fy, fdx, fdy = (1, 2, 0, 3) |
396 |
|
|
397 |
# Set the form width |
# Set the form width |
398 |
self.form.width = 2 + (largestField > largestLabel and largestField \ |
width = 2 + (largestField > largestLabel and largestField \ |
399 |
or largestLabel) |
or largestLabel) |
400 |
|
|
401 |
# Rearrange |
# Rearrange |
402 |
self.form.height = fy+2-fdy |
height = fy+2-fdy |
403 |
for i in range(len(entryQueue)): |
for i in range(len(entryQueue)): |
404 |
entryQueue[i].x = fx |
self.ModifyElement(labelQueue[i],x=lx,y=ly) |
405 |
entryQueue[i].y = fy |
self.ModifyElement(entryQueue[i],x=fx,y=fy) |
|
labelQueue[i].x = lx |
|
|
labelQueue[i].y = ly |
|
406 |
ly = ly + ldy |
ly = ly + ldy |
407 |
lx = lx + ldx |
lx = lx + ldx |
408 |
fy = fy + fdy |
fy = fy + fdy |
409 |
fx = fx + fdx |
fx = fx + fdx |
410 |
self.form.height = self.form.height + fdy |
height = height + fdy |
411 |
|
|
412 |
|
|
413 |
masterDataSource = datasource |
masterDataSource = datasource |
417 |
#### Detail block |
#### Detail block |
418 |
#### |
#### |
419 |
|
|
420 |
basey = self.form.height - 1 |
basey = height - 1 |
421 |
|
|
422 |
# We will use the table name as the basis for all our |
# We will use the table name as the basis for all our |
423 |
# object names. We will add a prefix based on the object |
# object names. We will add a prefix based on the object |
538 |
# Grid/multirecord layout |
# Grid/multirecord layout |
539 |
if multirecord: |
if multirecord: |
540 |
|
|
541 |
self.form.height += 12 |
height += 12 |
542 |
form_width = 1 |
form_width = 1 |
543 |
|
|
544 |
x = 1 |
x = 1 |
563 |
form_width = form_width + dx |
form_width = form_width + dx |
564 |
x = x + dx |
x = x + dx |
565 |
|
|
566 |
self.form.width = max(self.form.width, form_width) |
width = max(width, form_width) |
567 |
|
|
568 |
# Single Record layout (regardless of label location) |
# Single Record layout (regardless of label location) |
569 |
else: |
else: |
576 |
fx, fy, fdx, fdy = (largestLabel + 2, basey + 1, 0, 1) |
fx, fy, fdx, fdy = (largestLabel + 2, basey + 1, 0, 1) |
577 |
|
|
578 |
# Set form width |
# Set form width |
579 |
self.form.width = max(self.form.width,largestField + largestLabel + 3) |
width = max(width,largestField + largestLabel + 3) |
580 |
|
|
581 |
else: |
else: |
582 |
# Labels above the entries |
# Labels above the entries |
584 |
fx, fy, fdx, fdy = (1, basey + 2, 0, 3) |
fx, fy, fdx, fdy = (1, basey + 2, 0, 3) |
585 |
|
|
586 |
# Set the form width |
# Set the form width |
587 |
self.form.width = max(self.form.width, 2 + max(largestField, largestLabel)) |
width = max(width, 2 + max(largestField, largestLabel)) |
588 |
|
|
589 |
# Rearrange |
# Rearrange |
590 |
self.form.height += 1 |
height += 1 |
591 |
for i in range(len(entryQueue)): |
for i in range(len(entryQueue)): |
592 |
entryQueue[i].x = fx |
entryQueue[i].x = fx |
593 |
entryQueue[i].y = fy |
entryQueue[i].y = fy |
597 |
lx = lx + ldx |
lx = lx + ldx |
598 |
fy = fy + fdy |
fy = fy + fdy |
599 |
fx = fx + fdx |
fx = fx + fdx |
600 |
self.form.height = self.form.height + fdy |
height += fdy |
601 |
|
|
602 |
|
|
603 |
#### |
#### |
604 |
#### Set detail datasource to point towards master |
#### Set detail datasource to point towards master |
605 |
#### |
#### |
606 |
|
|
607 |
datasource.master = masterDataSource.name |
self.ModifyElement(datasource, master=masterDataSource.name, |
608 |
datasource.masterlink = string.join(self.variables['masterkeys'],',') |
masterlink=string.join(self.variables['masterkeys'],','), |
609 |
datasource.detaillink = string.join(self.variables['detailkeys'],',') |
detaillink=string.join(self.variables['detailkeys'],',')) |
610 |
|
|
611 |
|
|
612 |
|
#### |
613 |
|
#### Set form width & height |
614 |
|
#### |
615 |
|
|
616 |
|
self.ModifyElement(self.form, height=height, width=width) |
617 |
|
|
618 |
# That's it... we're done. |
# That's it... we're done. |
619 |
return 1 |
return 1 |