daboide Commit
Revision 228
Date: 2005-11-09 14:07:57 -0800 (Wed, 09 Nov 2005)
Author: ed
Changed:
D trunk/DataEnvWizard.py
U trunk/Designer.py
U trunk/DesignerComponents.py
U trunk/DesignerFormMixin.py
U trunk/DesignerMenu.py
U trunk/wizards/AppWizard/AppWizard.py
A trunk/wizards/QuickLayoutWizard.py
A trunk/wizards/__init__.py
Log:
Update to all the Designer classes. I wish I could detail everything that's
been changed, but for now I can say that the integration of pageframe-type
controls is working well, including the saving of the design. One quirk noted,
though, is that the contents of pages when saved on OS X are ignored, while
other platforms save correctly. I will be looking into that soon.
Renamed the DataEnvWizard to QuickLayoutWizard, since that was really what it
was meant to do: take fields from the DE in the Designer (note to self: DE is
not persisted in the .cdxml file!), and lay them out in a simple presentation,
instead of making the developer add the label/textbox one at a time. Moved it
into the wizards subdirectory, and added an __init__.py to wizards so that I
could import the QuickLayoutWizard from the Designer.
The rest of the Designer files have whatever incremental changes I've made
since the last commit. Sorry, I was working so sporadically on this that I
don't remember everything. I hope the diffs are enlightening.
Diff:
Deleted: trunk/DataEnvWizard.py
Modified: trunk/Designer.py
===================================================================
--- trunk/Designer.py 2005-11-09 18:11:54 UTC (rev 227)
+++ trunk/Designer.py 2005-11-09 22:07:57 UTC (rev 228)
@@ -339,17 +339,12 @@
information from the sizer/ sizer item that controls the
panel.
"""
-# dabo.trace()
-
if pnl is None:
pnl = self._srcObj
if pnl is None:
pnl = self._selection[0]
# Handle the odd behavior of pages
if isinstance(pnl, dui.dPage):
-
- dabo.trace()
-
pnl = self.getMainLayoutPanel(pnl)
if pnl is None:
# Nothing to add to!
Modified: trunk/DesignerComponents.py
===================================================================
--- trunk/DesignerComponents.py 2005-11-09 18:11:54 UTC (rev 227)
+++ trunk/DesignerComponents.py 2005-11-09 22:07:57 UTC (rev 228)
@@ -50,10 +50,6 @@
# Add the child objects. This will vary depending on the
# class of the item
-
- if isinstance(self, dabo.ui.dPage):
- dabo.trace()
-
ret["children"] = self.getChildrenPropDict()
return ret
Modified: trunk/DesignerFormMixin.py
===================================================================
--- trunk/DesignerFormMixin.py 2005-11-09 18:11:54 UTC (rev 227)
+++ trunk/DesignerFormMixin.py 2005-11-09 22:07:57 UTC (rev 228)
@@ -9,7 +9,7 @@
import dabo.lib.utils as utils
from DesignerControlMixin import DesignerControlMixin as dcm
import DesignerMenu
-from DataEnvWizard import DataEnvWizard
+from wizards.QuickLayoutWizard import QuickLayoutWizard
from DesignerComponents import LayoutPanel
from DesignerComponents import LayoutSizer
from DesignerComponents import LayoutGridSizer
@@ -338,7 +338,7 @@
f.close()
- def onOpenDE(self, evt):
+ def onRunLayoutWiz(self, evt):
if not self._dataEnv:
f = self._cxnFile
if not f:
@@ -364,12 +364,43 @@
x["pk"] = fld[2]
self._dataEnv[tb] = fldDict
- wiz = DataEnvWizard(self)
+ wiz = QuickLayoutWizard(self)
wiz.DE = self._dataEnv
+ wiz.callback = self.onQuickLayoutWizardFinish
wiz.start()
+ wiz.release()
- ## TODO: add the result of the wizard to the form.
-
+
+ def onQuickLayoutWizardFinish(self, controlInfo):
+ print "INFO:", controlInfo
+ ### TODO: use that info to create the controls
+ # as described on the design surface.
+# INFO: {u'country': {'control': <dabo.ui.uiwx.dTextBox.dTextBox;
proxy
+# of C++ wxTextCtrl instance at _01ae5e00_p_wxTextCtrl>,
'caption':
+# u'country', 'controlClass': <class
'dabo.ui.uiwx.dTextBox.dTextBox'>,
+# 'label': <wizards.QuickLayoutWizard.EditLabel; proxy of C++
+# wxStaticText instance at _06cff010_p_wxStaticText>}, u'fax':
+# {'control': <dabo.ui.uiwx.dTextBox.dTextBox; proxy of C++
wxTextCtrl
+# instance at _01b40c00_p_wxTextCtrl>, 'caption': u'fax',
+# 'controlClass': <class 'dabo.ui.uiwx.dTextBox.dTextBox'>,
'label':
+# <wizards.QuickLayoutWizard.EditLabel; proxy of C++ wxStaticText
+# instance at _075061c0_p_wxStaticText>}, u'contact': {'control':
+# <dabo.ui.uiwx.dTextBox.dTextBox; proxy of C++ wxTextCtrl
instance at
+# _01b37c00_p_wxTextCtrl>, 'caption': u'contact', 'controlClass':
<class
+# 'dabo.ui.uiwx.dTextBox.dTextBox'>, 'label':
+# <wizards.QuickLayoutWizard.EditLabel; proxy of C++ wxStaticText
+# instance at _06c648d0_p_wxStaticText>}, u'cust_id': {'control':
+# <dabo.ui.uiwx.dTextBox.dTextBox; proxy of C++ wxTextCtrl
instance at
+# _01b3e200_p_wxTextCtrl>, 'caption': u'cust_id', 'controlClass':
<class
+# 'dabo.ui.uiwx.dTextBox.dTextBox'>, 'label':
+# <wizards.QuickLayoutWizard.EditLabel; proxy of C++ wxStaticText
+# instance at _075028c0_p_wxStaticText>}, u'maxordamt':
{'control':
+# <dabo.ui.uiwx.dTextBox.dTextBox; proxy of C++ wxTextCtrl
instance at
+# _01b42e00_p_wxTextCtrl>, 'caption': u'Spend no more than this:',
+# 'controlClass': <class 'dabo.ui.uiwx.dTextBox.dTextBox'>,
'label':
+# <wizards.QuickLayoutWizard.EditLabel; proxy of C++ wxStaticText
+# instance at _07509af0_p_wxStaticText>}}
+
def onAddControl(self, evt):
self.Application.onAddControl(evt)
Modified: trunk/DesignerMenu.py
===================================================================
--- trunk/DesignerMenu.py 2005-11-09 18:11:54 UTC (rev 227)
+++ trunk/DesignerMenu.py 2005-11-09 22:07:57 UTC (rev 228)
@@ -40,6 +40,6 @@
cm.append(ctl[1], parent.onAddControl)
# Add the DE menuitem
- vm.append("Open Data Environment",
bindfunc=target.onOpenDE,
- help="Open the DE window")
+ vm.append("Quick Layout Wizard",
bindfunc=target.onRunLayoutWiz,
+ help="Quickly create a page layout for
a table")
Modified: trunk/wizards/AppWizard/AppWizard.py
===================================================================
--- trunk/wizards/AppWizard/AppWizard.py 2005-11-09 18:11:54 UTC (rev
227)
+++ trunk/wizards/AppWizard/AppWizard.py 2005-11-09 22:07:57 UTC (rev
228)
@@ -988,6 +988,10 @@
app = dabo.dApp()
app.setAppInfo("appName", "Dabo Application Wizard")
app.setAppInfo("appName", "AppWizard")
- app.MainFormClass = AppWizard
+ app.MainFormClass = None
app.setup()
- app.start()
+ wiz = AppWizard(None)
+
+ # No need to start the app; when the wizard exits, so
+ # will the app.
+
Added: trunk/wizards/QuickLayoutWizard.py
===================================================================
--- trunk/wizards/QuickLayoutWizard.py 2005-11-09 18:11:54 UTC (rev 227)
+++ trunk/wizards/QuickLayoutWizard.py 2005-11-09 22:07:57 UTC (rev 228)
@@ -0,0 +1,387 @@
+import os
+import dabo
+from dabo.lib.ListSorter import ListSorter
+dabo.ui.loadUI("wx")
+import dabo.dEvents as dEvents
+import dabo.dConstants as k
+from dabo.dLocalize import _
+
+import dabo.ui.dialogs.Wizard as Wizard
+import dabo.ui.dialogs.WizardPage as WizardPage
+
+class PgSelect(WizardPage):
+ def createBody(self):
+ self.Title = "Select Fields to Add"
+ self._currTable = None
+
+ sz = self.Sizer
+ sz.appendSpacer(16)
+ lbl = dabo.ui.dLabel(self, Caption="Select Table:")
+ tb = self.tblSelector = dabo.ui.dDropdownList(self)
+ tbls = self.Form.DE.keys()
+ tbls.sort()
+ tb.Choices = tbls
+ tb.PositionValue = 0
+ tb.bindEvent(dabo.dEvents.Hit, self.onTableSelection)
+
+ hsz = dabo.ui.dSizer("h", Spacing=12)
+ hsz.append(lbl)
+ hsz.append(tb)
+ sz.append(hsz, alignment="center")
+ sz.appendSpacer(16)
+
+ # Now create the field list, and populate it with the
+ # selected table's fields
+ lbl = dabo.ui.dLabel(self, Caption="Fields:")
+ sz.append(lbl, 0, alignment="left")
+ lst = self.lstFields = dabo.ui.dListControl(self,
MultipleSelect=True)
+ lst.ValueColumn=2
+ lst.setColumns( ("PK", "Type", "Name") )
+ lst.setColumnWidth(0, 30)
+ sz.append(lst, 1, "x")
+ sz.appendSpacer(16)
+ btnSz = dabo.ui.dSizer("h")
+ btnSz.Spacing = 10
+ btnAll = dabo.ui.dButton(self, Caption="Select All")
+ btnAll.bindEvent(dEvents.Hit, self.onSelectAll)
+ btnSz.append(btnAll, 1, "x")
+ btnNone = dabo.ui.dButton(self, Caption="Select None")
+ btnNone.bindEvent(dEvents.Hit, self.onSelectNone)
+ btnSz.append(btnNone, 1, "x")
+ sz.append(btnSz, 0, "x")
+ sz.appendSpacer(20)
+
+ self.onTableSelection(None)
+
+
+ def onEnterPage(self, dir):
+ dd = self.tblSelector
+ chc = dd.Choices
+ keys = self.Form.DE.keys()
+ if chc != keys:
+ # DE has changed
+ dd.Choices = keys
+ dd.PositionValue = 0
+ self.onTableSelection(None)
+
+
+ def onTableSelection(self, evt):
+ """Populate the field list control with a list of the fields in
the
+ selected table.
+ """
+ self._currTable = self.tblSelector.Value
+ if not self._currTable:
+ return
+ self.lstFields.clear()
+ # Create the items for the list
+ fldDict = self.Form.DE[self._currTable]
+ flds = fldDict.keys()
+ flds.sort()
+ pktext={True:"X", False:""}
+ typeText = {"C" : "char", "I": "int", "M" : "text", "D" :
"date",
+ "T" : "datetime", "B" : "bool", "N" : "float",
"E" : "enum"}
+ fldInfo = [ (pktext[fldDict[p]["pk"]],
typeText[fldDict[p]["type"]], p ) for p in flds]
+ self.lstFields.appendRows(fldInfo)
+
+
+ def onSelectAll(self, evt):
+ self.lstFields.selectAll()
+
+ def onSelectNone(self, evt):
+ self.lstFields.unselectAll()
+
+ def onLeavePage(self, dir):
+ selFlds = self.lstFields.Values
+ selTbl = self._currTable
+ if dir == "forward":
+ # Make sure that they selected something
+ if not(selFlds) or not (selTbl):
+ dabo.ui.info("Please select something first.")
+ return False
+ self.Form.flds = selFlds
+ self.Form.tbl = selTbl
+
+
+class PgLayout(WizardPage):
+ def createBody(self):
+ self.Title = "Layout Selection"
+ self.layouts = []
+ # select a layout type
+ lt = self.layoutType = dabo.ui.dListBox(self,
+ Height=160, ValueMode="Position")
+ lt.bindEvent(dEvents.Hit, self.onLayoutSelect)
+
+ # Define images for each layout. They will be
+ # accessed by position relative to the choices
+ # in the dripdown list
+ self.imgs = ("layoutLblLeft.jpg", "layoutLblTop.jpg",
"layoutGrid.jpg")
+ img = self.layoutImg = dabo.ui.dImage(self, Width=200)
+
+ sz = self.Sizer
+ sz.append(lt, 0, "x")
+ sz.appendSpacer(20)
+ sz.append(img, 1, alignment="center")
+
+
+ def onLayoutSelect(self, evt=None):
+ self.Form.layoutType =
self.Form.availableLayouts[self.layoutType.Value]
+ self.layoutImg.Picture = self.imgs[self.layoutType.Value]
+ self.layout()
+
+
+ def onEnterPage(self, dir):
+ layouts = self.Form.availableLayouts
+ if len(self.Form.flds) == 1:
+ layouts.remove("Grid")
+ self.layoutType.Choices = layouts
+ if dir == "forward":
+ self.layoutType.Value = 0
+ self.onLayoutSelect()
+
+
+
+
+class PgOrdering(WizardPage):
+ def createBody(self):
+ self.Title = "Order Fields"
+
+ lbl = dabo.ui.dLabel(self, Caption="""Select a field, and then
use the buttons
+to change its order""")
+ fs = self.fldSorter = ListSorter(self)
+ fs.Height = 300
+ self.Sizer.append(lbl, 0, "x", alignment="right")
+ self.Sizer.append(fs, 0, "x")
+
+
+ def onEnterPage(self, dir):
+ self.fldSorter.Choices = self.Form.flds
+
+
+ def onLeavePage(self, dir):
+ if dir == "forward":
+ self.Form.flds = self.fldSorter.Choices
+
+
+
+class PgSample(WizardPage):
+ def createBody(self):
+ self.Title = "Sample"
+ self.lastStyle = ""
+ self.lastFldList = []
+ self.controls = {}
+ self.controlSizer = self.samplePanel = self.editText = None
+
+
+ def onEnterPage(self, dir):
+ if dir != "forward":
+ return
+ layType = self.Form.layoutType
+ flds = self.Form.flds
+ if (layType == self.lastStyle) and (flds == self.lastFldList):
+ # Nothing has changed
+ return
+
+ try:
+ self.controlSizer.release()
+ except: pass
+ try:
+ self.samplePanel.release()
+ except: pass
+ self.samplePanel = self.controlSizer = None
+
+ # Create the new controls
+ sp = self.samplePanel = dabo.ui.dScrollPanel(self,
BackColor="papayawhip")
+ self.Sizer.append(sp, 1, "x")
+ sp.Sizer = dabo.ui.dSizer("v")
+ if layType.lower() == "grid":
+ self.makeGrid()
+ return
+
+ # Update the lastX props
+ goneFlds = [fld for fld in self.lastFldList if fld not in flds]
+ for gf in goneFlds:
+ # Delete the controls
+ self.controls[gf]["label"].release()
+ self.controls[gf]["control"].release()
+ del self.controls[gf]
+ self.lastFldList = flds
+ self.lastStyle = layType
+
+ # Define an editable label class
+ class EditLabel(dabo.ui.dLabel):
+ def afterInit(self):
+ # The label will be on the sample panel, which
is on the page
+ # that contains the actual event code.
+ self.bindEvent(dEvents.MouseLeftDoubleClick,
self.Parent.Parent.onLblEdit)
+ # Store the original caption for later reference
+ dabo.ui.callAfter(self._storeCaption)
+
+ def _storeCaption(self):
+ # Save the Caption as an editing reference
+ self.origCap = self.Caption
+
+ # See if it is label-left or label-above
+ if layType.lower().find("above") > -1:
+ style = "above"
+ cs = self.controlSizer = dabo.ui.dSizer("v")
+ else:
+ style = "left"
+ cs = self.controlSizer = dabo.ui.dGridSizer()
+ cs.setColExpand(True, 1)
+ # Go through the list, and add the items to the sizer in order.
Any
+ # field which was previously created will be restored
+ for fld in flds:
+ if self.controls.has_key(fld):
+ cs.append(self.controls[fld]["label"])
+ cs.append(self.controls[fld]["control"],
"expand")
+ else:
+ # Create it
+ lbl = EditLabel(sp, Caption=fld)
+ cls = dabo.ui.dTextBox
+ ctl = cls(sp)
+ cs.append(lbl)
+ cs.append(ctl, "expand")
+ fdc = self.controls[fld] = {}
+ fdc["caption"] = fld
+ fdc["label"] = lbl
+ fdc["control"] = ctl
+ fdc["controlClass"] = cls
+ sp.Sizer.append(cs, 1, "x", border=20, borderFlags="all")
+ self.layout()
+
+
+ def onLblEdit(self, evt):
+ lbl = self.editLabel = evt.EventObject
+ oldCap = lbl.Caption
+
+ et = self.editText
+ if et is None:
+ et = self.editText = dabo.ui.dTextBox(self.samplePanel,
SelectOnEntry=True)
+ et.bindEvent(dEvents.LostFocus, self.onEndLblEdit)
+ et.bindEvent(dEvents.KeyChar, self.onTextKey)
+ et.Visible = False
+ et.Value = oldCap
+
+ et.Position = lbl.Position
+ et.Width = lbl.Width + 100
+ et.Visible = True
+ et.SetFocus()
+ dabo.ui.callAfter(et.selectAll)
+
+
+ def onTextKey(self, evt):
+ keyCode = evt.EventData["keyCode"]
+ keys = dabo.ui.dKeys
+ exit = False
+ if keyCode == keys.key_Escape:
+ exit = True
+ elif keyCode == keys.key_Return:
+ self.onEndLblEdit(evt)
+ if exit:
+ self.editText.Visible = False
+ self.editText.Position = (-50, -50)
+
+
+ def onEndLblEdit(self, evt):
+ tx = self.editText.Value
+ if tx:
+ #### ALSO: need to update the form's fields
+ self.editLabel.Caption = tx
+ self.controls[self.editLabel.origCap]["caption"] = tx
+ self.layout()
+ self.editText.Visible = False
+ self.editText.Position = (-50, -50)
+
+
+ def makeGrid(self):
+ frm = self.Form
+ flds = frm.flds
+ tblInfo = frm.DE[frm.tbl]
+ sp = self.samplePanel
+ cs = self.controlSizer
+ if cs is None:
+ cs = self.controlSizer = dabo.ui.dSizer("v")
+ # Go through the list, and add the items to the grid as columns
+ grd = dabo.uidGrid(sp)
+
+ class sampleCol(dabo.ui.dColumn):
+ def afterInit(self):
+ self.Width=40
+
+ frm.lockScreen()
+ dummyRec = {}
+ for fld in flds:
+ c = sampleCol(grd)
+ c.Caption = fld
+ c.Field = fld
+ typ = tblInfo[fld]["type"]
+ if typ in ("I", "N", "F"):
+ dummyRec[fld] = 99
+ c.DataType = int
+ elif typ in ("C", "M"):
+ dummyRec[fld] = "dummy"
+ c.DataType = str
+ else:
+ dummyRec[fld] = "dummy"
+ c.DataType = str
+
+ grd.addColumn(c)
+ # Make some dummy data
+ for ii in range(10):
+ grd.dataSet.append(dummyRec)
+ grd.fillGrid(True)
+ grd.setRowHeight(0, 18)
+ frm.unlockScreen()
+
+ cs.append(grd, 1, "x")
+ sp.Sizer.append(cs, 1, "x", border=20, borderFlags="all")
+ self.layout()
+
+
+ def onLeavePage(self, dir):
+ if dir == "forward":
+ self.wizard.controlInfo = self.controls
+ return True
+
+
+class QuickLayoutWizard(Wizard):
+ def __init__(self, parent=None):
+ super(QuickLayoutWizard, self).__init__(parent=parent)
+ self.Modal = True
+ self.Caption = "Add From Data Environment"
+ self.Image = "daboIcon128"
+ self.Size = (520, 560)
+ self._dataEnv = {}
+ self.callback = None
+ self.controlInfo = None
+ self.flds = []
+ self.tbl = ""
+ self.availableLayouts = ["Column; labels on Left", "Column;
labels above", "Grid"]
+ self.layoutType = ""
+ pgs = [PgSelect, PgOrdering, PgLayout, PgSample]
+ self.append(pgs)
+
+
+ def finish(self):
+ if callable(self.callback):
+ self.callback(self.controlInfo)
+ return True
+
+
+ def _getDE(self):
+ return self._dataEnv
+
+ def _setDE(self, deDict):
+ self._dataEnv = deDict
+
+
+ DE = property(_getDE, _setDE, None,
+ _("Reference to the data env dictionary (dict)") )
+
+
+if __name__ == "__main__":
+ app = dabo.dApp()
+ app.MainFormClass = None
+ wiz = QuickLayoutWizard()
+ app.setup()
+ wiz.start()
Property changes on: trunk/wizards/QuickLayoutWizard.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/wizards/__init__.py
===================================================================
--- trunk/wizards/__init__.py 2005-11-09 18:11:54 UTC (rev 227)
+++ trunk/wizards/__init__.py 2005-11-09 22:07:57 UTC (rev 228)
@@ -0,0 +1 @@
+from QuickLayoutWizard import QuickLayoutWizard
Property changes on: trunk/wizards/__init__.py
___________________________________________________________________
Name: svn:eol-style
+ native
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev