Changeset 2732
- Timestamp:
- 01/21/2007 09:42:35 PM (2 years ago)
- Files:
-
- branches/paul_sandbox/dabo/lib/datanav/Form.py (modified) (18 diffs)
- branches/paul_sandbox/dabo/lib/datanav/Grid.py (modified) (5 diffs)
- branches/paul_sandbox/dabo/lib/datanav/Page.py (modified) (8 diffs)
- branches/paul_sandbox/dabo/lib/datanav/PageFrame.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/paul_sandbox/dabo/lib/datanav/Form.py
r2710 r2732 1 1 import os 2 import random3 2 import traceback 4 3 import wx 5 4 import dabo.dEvents as dEvents 6 5 import dabo.ui 7 from dabo.lib.specParser import importRelationSpecs, importFieldSpecs8 6 from dabo.dLocalize import _, n_ 9 7 import dabo.lib.reportUtils as reportUtils … … 24 22 + Edit : Edit the current record in the result set. 25 23 """ 26 def beforeInit(self): 27 super(Form, self).beforeInit() 28 # Determines if we are actually running the form, or just 29 # previewing it 30 self._fieldSpecs = {} 31 self._relationSpecs = {} 32 self._childBehavior = {} 33 self._requeried = False 34 # When Save/Cancel/Requery are called, do we check the 35 # current primary bizobj, or do we use the main bizobj for 36 # the form? Default is to only affect the current bizobj 37 self.saveCancelRequeryAll = False 38 # What sort of pageframe style do we want? 39 # Choices are "tabs", "list" or "select" 40 self.pageFrameStyle = "tabs" 41 # Where do the pageframe tabs/selector go? 42 # Choices = Top (default), Bottom, Left or Right 43 self.tabPosition = "Top" 44 # We want a toolbar 24 def initProperties(self): 45 25 self.ShowToolBar = True 46 # We want the status bar showing record information47 self._autoUpdateStatusText = True48 # The list of _tempfiles will be deleted when the form is destroyed:49 self._tempFiles = []50 # Do we automatically add edit pages for child bizobjs?51 self._addChildEditPages = True52 53 54 def _initEvents(self):55 self.bindEvent(dEvents.Close, self._onClose)56 self.super()57 58 59 def __init__(self, parent=None, previewMode=False, tbl="", *args, **kwargs):60 self.preview = previewMode61 self.previewDataSource = tbl62 super(Form, self).__init__(parent, *args, **kwargs)63 # We will need to set these separated if in Preview mode.64 self.rowNumber = 065 self.rowCount = 066 # Set a default size67 26 self.Size = (640, 480) 68 69 70 def _afterInit(self): 71 super(Form, self)._afterInit() 27 28 29 def afterInit(self): 72 30 if self.FormType == 'PickList': 73 31 # The form is a picklist, which pops up so the user can choose a record, … … 83 41 self.bindEvent(dEvents.Deactivate, _onHide) 84 42 85 86 def _onClose(self, evt): 87 for f in self._tempFiles: 88 try: 89 os.remove(f) 90 except: 91 # perhaps it is already gone, removed explicitly. 92 pass 93 94 43 # Create the various elements: 44 self.setupPageFrame() 45 46 if not self.Testing: 47 self.setupToolBar() 48 self.setupMenu() 49 50 95 51 def save(self, dataSource=None): 96 if dataSource is None:97 if self.saveCancelRequeryAll:98 dataSource = self._mainTable99 52 ## The bizobj may have made some changes to the data during the save, so 100 53 ## make sure it is reflected on screen by calling update() afterwards. … … 103 56 return ret 104 57 105 106 def cancel(self, dataSource=None):107 if dataSource is None:108 if self.saveCancelRequeryAll:109 dataSource = self._mainTable110 return self.super(dataSource)111 112 def requery(self, dataSource=None):113 if dataSource is None:114 if self.saveCancelRequeryAll:115 dataSource = self._mainTable116 return self.super(dataSource)117 118 def confirmChanges(self):119 if self.preview:120 # Nothing to check121 return True122 else:123 return self.super()124 125 def afterSetPrimaryBizobj(self):126 pass127 128 129 def afterSetFieldSpecs(self):130 self.childViews = []131 for child in self.getBizobj().getChildren():132 self.childViews.append({"dataSource": child.DataSource,133 "caption": child.Caption,134 "menuId": wx.NewId()})135 self.setupPageFrame()136 self.setupToolBar()137 self.setupMenu()138 58 139 59 def setupToolBar(self): … … 283 203 """ Set up the action menu for this frame. 284 204 285 Called when the form is created and also when the fieldspecs are set.205 Called when the form is created. 286 206 """ 287 207 mb = self.MenuBar … … 310 230 """ 311 231 currPage = 0 232 ds = None 312 233 biz = self.getBizobj() 234 if biz is not None: 235 ds = biz.DataSource 313 236 314 237 try: … … 320 243 321 244 if self.beforeSetupPageFrame(): 322 self.pageFrame = PageFrame.PageFrame(self, tabStyle=self. pageFrameStyle,323 TabPosition=self. tabPosition)245 self.pageFrame = PageFrame.PageFrame(self, tabStyle=self.PageFrameStyle, 246 TabPosition=self.PageTabPosition) 324 247 self.Sizer.append(self.pageFrame, "expand", 1) 325 248 self.pageFrame.addSelectPage() 326 249 self.pageFrame.addBrowsePage() 327 if self.preview:328 ds = self.previewDataSource329 else:330 ds = biz.DataSource331 250 if self.FormType != "PickList": 332 251 self.addEditPages(ds) … … 340 259 341 260 def addEditPages(self, ds): 342 biz = self.getBizobj(ds) 261 """Called when it is time to add the edit page(s).""" 262 biz = self.getBizobj() 343 263 if biz: 344 title= _("Edit") + " " + _(biz.Caption)264 caption = _("Edit") + " " + _(biz.Caption) 345 265 else: 346 title = _("Edit") 347 self.addEditPage(ds, title) 348 if biz and self.AddChildEditPages: 349 for child in biz.getChildren(): 350 self.addEditPages(child.DataSource) 351 352 353 def addEditPage(self, ds, title, pageClass=None): 354 """Called when it is time to add the edit page for the passed datasource. 355 356 Subclasses may override, or send their own pageClass. 357 """ 358 self.pageFrame.addEditPage(ds, title, pageClass) 266 caption = _("Edit") 267 self.addEditPage(ds, caption) 268 269 270 def addEditPage(self, ds, title): 271 """Called when it is time to add the edit page for the passed datasource.""" 272 self.pageFrame.addEditPage(ds, title) 273 274 359 275 360 276 361 277 def onSetSelectionCriteria(self, evt): 362 """ Occurs when the user chooses to set the selection criteria. 363 """ 278 """ Occurs when the user chooses to set the selection criteria.""" 364 279 self.pageFrame.SelectedPage = 0 365 280 366 281 367 282 def onBrowseRecords(self, evt): 368 """ Occurs when the user chooses to browse the record set. 369 """ 283 """ Occurs when the user chooses to browse the record set.""" 370 284 self.pageFrame.SelectedPage = 1 371 285 372 286 373 287 def onEditCurrentRecord(self, evt): 374 """ Occurs when the user chooses to edit the current record. 375 """ 288 """ Occurs when the user chooses to edit the current record.""" 376 289 # We stored the datasource in the menu item's Tag property when 377 290 # the menu was created. … … 395 308 if not self.enableQuickReport(): 396 309 dabo.ui.exclaim(_("Sorry, there are no records to report on."), title=_("No Records")) 397 return398 if self.preview:399 # Just previewing400 dabo.ui.info(message="Not available in preview mode",401 title = "Preview Mode")402 310 return 403 311 … … 506 414 507 415 508 def setFieldSpecs(self, xml, tbl):509 """ Reads in the field spec file and creates the appropriate510 controls in the form.511 """512 self._allFieldSpecs = self.parseXML(xml, "Field")513 self._mainTable = tbl514 515 516 def setRelationSpecs(self, xml, bizModule):517 """ Creates any child bizobjs used by the form, and establishes518 the relations with the parent bizobj519 """520 self.RelationSpecs = self.parseXML(xml, "Relation")521 primaryBizobj = self.PrimaryBizobj522 # This will make sure all relations and sub-relations are set.523 newBizobjs = primaryBizobj.addChildByRelationDict(self.RelationSpecs,524 bizModule)525 # If we added any bizobjs, add them to the form's collection, too526 for biz in newBizobjs:527 self.addBizobj(biz)528 529 530 def parseXML(self, xml, specType):531 """ Accepts either a file or raw XML, and handles talking with the532 specParser class. Since that class requires a file, this method will533 create a temp file if raw XML is passed.534 """535 if specType.lower() == "relation":536 ret = importRelationSpecs(xml)537 else:538 ret = importFieldSpecs(xml)539 return ret540 541 542 def creation(self):543 """ Creates the menu, toolbar, and pageframe for the form.544 545 This must be called by the subclass, probably at the end of afterInit(),546 after the fieldSpecs and relationSpecs have been set.547 """548 errMsg = self.beforeCreation()549 if errMsg:550 raise dException.dException, errMsg551 552 self.setupPageFrame()553 self.setupToolBar()554 if not self.preview:555 self.setupMenu()556 else:557 self.ToolBar.Enabled = False558 self.afterCreation()559 560 561 416 def setPrimaryBizobjToDefault(self, ds): 562 417 """ This method is called when we leave an editing page. The … … 567 422 to the one for the form's main table. 568 423 """ 424 bizDS = None 569 425 biz = self.getBizobj() 570 bizDS = biz.DataSource 426 if biz: 427 bizDS = biz.DataSource 571 428 if bizDS == ds: 572 429 # We didn't switch to another editing page, so reset it back … … 593 450 594 451 595 def beforeCreation(self):596 """ Hook method available to customize form creation settings597 before anything on the form, its toolbar, or its menu is created.598 Returning any string from this method will prevent form creation599 from happening, and raise an error.600 """601 pass602 603 def afterCreation(self):604 """ Hook method available to customize the form after all its605 components have been created.606 """607 pass608 609 610 def getFieldSpecsForTable(self, tbl):611 """ Returns the field specs for the given table. If there is no entry612 for the requested table, it returns None.613 """614 ret = None615 try:616 ret = self._allFieldSpecs[tbl]617 except: pass618 return ret619 620 621 452 def onRequery(self, evt): 622 453 """ Override the dForm behavior by running the requery through the select page. 623 454 """ 624 self.pageFrame.GetPage(0).requery() 455 self.requery() 456 457 458 def requery(self, dataSource=None, _fromSelectPage=False): 459 if not _fromSelectPage: 460 # re-route the form's requery through the select page's requery. 461 self.pageFrame.GetPage(0).requery() 462 else: 463 # After the select page does its thing, it calls frm.requery(): 464 return self.super(dataSource) 625 465 626 466 … … 971 811 ## Property get/set code below 972 812 def _getAddChildEditPages(self): 973 return self._addChildEditPages 813 val = getattr(self, "_addChildEditPages", None) 814 if val is None: 815 val = self._addChildEditPages = False 816 return val 974 817 975 818 def _setAddChildEditPages(self, val): … … 1031 874 def _setEditPageClass(self, val): 1032 875 self._editPageClass = val 1033 1034 1035 def _getFieldSpecs(self):1036 try:1037 return self._allFieldSpecs[self._mainTable]1038 except AttributeError:1039 return None1040 1041 def _setFieldSpecs(self, val):1042 self._allFieldSpecs[self._mainTable] = val1043 876 1044 877 … … 1061 894 1062 895 1063 def _getRelationSpecs(self): 1064 return self._relationSpecs 1065 1066 def _setRelationSpecs(self, val): 1067 self._relationSpecs = val 1068 896 def _getPageFrameStyle(self): 897 if hasattr(self, "_pageFrameStyle"): 898 v = self._pageFrameStyle 899 else: 900 v = self._pageFrameStyle = "Tabs" 901 return v 902 903 def _setPageFrameStyle(self, val): 904 assert val.lower() in ("tabs", "list", "select") 905 self._setPageFrameStyle = val 906 907 908 def _getPageTabPosition(self): 909 if hasattr(self, "_pageTabPosition"): 910 v = self._pageTabPosition 911 else: 912 v = self._pageTabPosition = "Top" 913 return v 914 915 def _setPageTabPosition(self, val): 916 assert val.lower() in ("top", "left", "right", "bottom") 917 self._setPageTabPosition = val 918 1069 919 1070 920 def _getSetFocusToBrowseGrid(self): … … 1079 929 1080 930 931 def _getTesting(self): 932 return getattr(self, "_testing", False) 933 934 def _setTesting(self, val): 935 self._testing = bool(val) 936 937 938 1081 939 # Property definitions: 1082 940 AddChildEditPages = property(_getAddChildEditPages, _setAddChildEditPages, None, 1083 _("""Should the form automatically add edit pages for 1084 child bizobjs? (default=True) (bool)""")) 941 _("""Should the form automatically add edit pages for child bizobjs? 942 943 The default is False, and this property may be removed soon.""")) 1085 944 1086 945 BrowseGridClass = property(_getBrowseGridClass, _setBrowseGridClass, None, … … 1096 955 _("""Specifies the class to use for the edit page.""")) 1097 956 1098 FieldSpecs = property(_getFieldSpecs, _setFieldSpecs, None,1099 _("""Reference to the dictionary containing field behavior specs"""))1100 1101 957 FormType = property(_getFormType, _setFormType, None, 1102 958 _("""Specifies the type of form this is. 1103 959 1104 The type of form determines the runtime behavior. FormType can be one of:1105 Normal:1106 A normal dataNav form. The default.1107 1108 PickList:1109 Only select/browse pages shown, and the form is modal, returning the1110 Primary Key of the picked record.1111 1112 Edit:1113 Modal version of normal, with no Select/Browse pages. User code sends1114 the Primary Key of the record to edit.960 The type of form determines the runtime behavior. FormType can be one of: 961 Normal: 962 A normal dataNav form. The default. 963 964 PickList: 965 Only select/browse pages shown, and the form is modal, returning the 966 Primary Key of the picked record. 967 968 Edit: 969 Modal version of normal, with no Select/Browse pages. User code sends 970 the Primary Key of the record to edit. 1115 971 """)) 1116 972 1117 RelationSpecs = property(_getRelationSpecs, _setRelationSpecs, None, 1118 _("""Reference to the dictionary containing table relation specs""")) 973 PageFrameStyle = property(_getPageFrameStyle, _setPageFrameStyle, None, 974 _("""Specifies the style of pageframe to set up. Valid values are: 975 976 Tabs (default) 977 List (down the side) 978 Select""")) 979 980 PageTabPosition = property(_getPageTabPosition, _setPageTabPosition, None, 981 _("""Specifies the location of the pageframe tabs. Valid values are: 982 983 Top (default) 984 Left 985 Right 986 Bottom 987 988 This only applies when PageFrameStyle is set to "Tabs".""")) 1119 989 1120 990 SelectPageClass = property(_getSelectPageClass, _setSelectPageClass, None, … … 1122 992 1123 993 SetFocusToBrowseGrid = property(_getSetFocusToBrowseGrid, 1124 None, _setSetFocusToBrowseGrid,994 _setSetFocusToBrowseGrid, None, 1125 995 _("""Does the focus go to the browse grid when the browse page is entered?""")) 1126 996 997 Testing = property(_getTesting, _setTesting, None, 998 "Flag for use when testing elements of the form.") 999 branches/paul_sandbox/dabo/lib/datanav/Grid.py
r2633 r2732 1 """ Grid.py2 3 This is a grid designed to browse records of a bizobj. It is part of the4 dabo.lib.datanav subframework. It does not descend from dControlMixin at this5 time, but is self-contained. There is a dGridDataTable definition here as6 well, that defines the 'data' that gets displayed in the grid.7 """8 1 import dabo 9 2 import dabo.ui … … 15 8 class Grid(dabo.ui.dGrid): 16 9 def _beforeInit(self, pre): 17 self._fldSpecs = None18 self.includeFields = []19 self.fieldCaptions = {}20 self.colOrders = {}21 self.built = False22 10 self.customSort = True 23 11 super(Grid, self)._beforeInit(pre) … … 35 23 self.bindKey("f2", self._onSortKey) 36 24 self.bindKey("delete", self._onDeleteKey) 37 ## enter/esc don't seem to work as bindKey's in grids:38 #self.bindKey("enter", self._onEnterKey)39 #self.bindKey("escape", self._onEscapeKey)40 25 41 26 if hasattr(self.Form, "preview") and self.Form.preview: … … 57 42 # raw DataSet. This is true in minesweeper, for example. 58 43 ds = self.DataSet 59 60 if not self.built and ds: 61 if self.FieldSpecs is not None: 62 self.buildFromDataSet(ds, 63 keyCaption=self.fieldCaptions, 64 includeFields=self.includeFields, 65 colOrder=self.colOrders, 66 colWidths=self.colWidths, 67 colTypes=self.colTypes, 68 autoSizeCols=False) 69 self.built = True 70 else: 71 self.refresh() 44 self.refresh() 72 45 73 46 … … 179 152 180 153 181 def _getFldSpecs(self):182 return self._fldSpecs183 184 def _setFldSpecs(self, val):185 self._fldSpecs = val186 187 if val is None:188 return189 190 # Update the props191 self.includeFields = [kk for kk in val192 if val[kk]["listInclude"] == "1" ]193 194 self.fieldCaptions = {}195 for kk in val.keys():196 if kk not in self.includeFields:197 continue198 self.fieldCaptions[kk] = val[kk]["caption"]199 200 self.colOrders = {}201 for kk in val.keys():202 if kk not in self.includeFields:203 continue204 self.colOrders[kk] = int(val[kk]["listOrder"])205 206 self.colWidths = {}207 for kk in val.keys():208 if kk not in self.includeFields:209 continue210 self.colWidths[kk] = int(val[kk]["listColWidth"])211 212 self.colTypes = {}213 for kk in val.keys():214 if kk not in self.includeFields:215 continue216 self.colTypes[kk] = val[kk]["type"]217 218 219 FieldSpecs = property(_getFldSpecs, _setFldSpecs, None,220 _("Holds the fields specs for this form (dict)") )221 branches/paul_sandbox/dabo/lib/datanav/Page.py
r2700 r2732 1 1 import os 2 2 import sys 3 import wx4 3 import dabo 5 4 import dabo.dException as dException … … 8 7 from dabo.lib.utils import padl 9 8 from dabo.dObject import dObject 10 11 dabo.ui.loadUI("wx")12 9 13 10 from dabo.ui import dPanel … … 194 191 195 192 def createItems(self): 193 if not self.Sizer: 194 self.Sizer = dabo.ui.dSizer("v") 196 195 self.selectOptionsPanel = self.getSelectOptionsPanel() 197 self. GetSizer().append(self.selectOptionsPanel, "expand", 1, border=20)196 self.Sizer.append(self.selectOptionsPanel, "expand", 1, border=20) 198 197 self.selectOptionsPanel.setFocus() 199 198 super(SelectPage, self).createItems() 200 if self.Form.RequeryOnLoad:201 dabo.ui.callAfter(self.requery)202 199 203 200 … … 361 358 bizobj.setSQL(sql) 362 359 363 ret = frm.requery( )360 ret = frm.requery(_fromSelectPage=True) 364 361 365 362 if ret: … … 405 402 406 403 def getSelectOptionsPanel(self): 407 if not self.Form.preview: 408 dataSource = self.Form.getBizobj().DataSource 409 else: 410 dataSource = self.Form.previewDataSource 411 fs = self.Form.FieldSpecs 412 panel = dPanel(self) 413 gsz = dabo.ui.dGridSizer(vgap=5, hgap=10) 414 gsz.MaxCols = 3 415 label = dabo.ui.dLabel(panel) 416 label.Caption = _("Please enter your record selection criteria:") 417 label.FontSize = label.FontSize + 2 418 label.FontBold = True 419 gsz.append(label, colSpan=3, alignment="center") 420 421 if fs is not None: 422 # Get all the fields that should be included into a list. Order them 423 # into the order specified in the specs. 424 fldList = [] 425 for fld in fs.keys(): 426 if int(fs[fld]["searchInclude"]): 427 fldList.append( (fld, int(fs[fld]["searchOrder"])) ) 428 fldList.sort(lambda x, y: cmp(x[1], y[1])) 429 430 for fldOrd in fldList: 431 fld = fldOrd[0] 432 fldInfo = fs[fld] 433 lbl = SortLabel(panel) 434 lbl.Caption = "%s:" % fldInfo["caption"] 435 lbl.relatedDataField = fld 436 437 # First try getting the selector options from the user hook: 438 opt = self.Form.getSelectOptionsForField(fld) 439 440 if opt is None: 441 # Automatically get the selector options based on the field type: 442 opt = self.getSelectorOptions(fldInfo["type"], fldInfo["wordSearch"]) 443 444 # Add the blank choice and create the dropdown: 445 opt = (IGNORE_STRING,) + tuple(opt) 446 opList = SelectionOpDropdown(panel, choices=opt) 447 448 # First try getting the control class from the user hook: 449 ctrlClass = self.Form.getSelectControlClassForField(fld) 450 451 if ctrlClass is None: 452 # Automatically get the control class based on the field type: 453 ctrlClass = self.getSearchCtrlClass(fldInfo["type"]) 454 455 if ctrlClass is not None: 456 ctrl = ctrlClass(panel) 457 if not opList.StringValue: 458 opList.StringValue = opList.GetString(0) 459 opList.Target = ctrl 460 461 gsz.append(lbl, halign="right") 462 gsz.append(opList, halign="left") 463 gsz.append(ctrl, "expand") 464 465 # Store the info for later use when constructing the query 466 self.selectFields[fld] = { 467 "ctrl" : ctrl, 468 "op" : opList, 469 "type": fldInfo["type"] 470 } 471 else: 472 dabo.errorLog.write("No control class found for field '%s'." % fld) 473 lbl.release() 474 opList.release() 475 476 477 # Now add the limit field 478 lbl = dabo.ui.dLabel(panel) 479 lbl.Caption = _("&Limit") 480 limTxt = SelectTextBox(panel) 481 if len(limTxt.Value) == 0: 482 limTxt.Value = "1000" 483 self.selectFields["limit"] = {"ctrl" : limTxt } 484 gsz.append(lbl, alignment="right") 485 gsz.append(limTxt) 486 487 # Custom SQL checkbox: 488 chkCustomSQL = panel.addObject(dabo.ui.dCheckBox, Caption="Use Custom SQL") 489 chkCustomSQL.bindEvent(dEvents.Hit, self.onCustomSQL) 490 gsz.append(chkCustomSQL) 491 492 # Requery button: 493 requeryButton = dabo.ui.dButton(panel) 494 requeryButton.Caption = _("&Requery") 495 requeryButton.DefaultButton = True 496 requeryButton.bindEvent(dEvents.Hit, self.onRequery) 497 btnRow = gsz.findFirstEmptyCell()[0] + 1 498 gsz.append(requeryButton, row=btnRow, col=1, 499 halign="right", border=3) 500 501 # Make the last column growable 502 gsz.setColExpand(True, 2) 503 panel.SetSizerAndFit(gsz) 504 505 vsz = dabo.ui.dSizer("v") 506 vsz.append(gsz, 1, "expand") 507 508 return panel 509 404 """Subclass hook. Return the panel instance to display on the select page.""" 405 510 406 511 407 def onCustomSQL(self, evt): … … 576 472 if not self.itemsCreated: 577 473 self.createItems() 474 if bizobj and bizobj.RowCount >= 0: 578 475 self.fillGrid(False) 579 if self.Form.preview: 580 self.fillGrid(False) 581 else: 582 if bizobj and bizobj.RowCount >= 0: 583 self.fillGrid(False) 584 self.BrowseGrid.update() 476 self.BrowseGrid.update() 585 477 586 478 587 479 def createItems(self): 588 biz obj= self.Form.getBizobj()480 biz = self.Form.getBizobj() 589 481 grid = self.Form.BrowseGridClass(self, NameBase="BrowseGrid", Size=(10,10)) 590 grid.FieldSpecs = self.Form.FieldSpecs 591 if not self.Form.preview: 592 pass 593 #grid.setBizobj(bizobj) 594 grid.DataSource = bizobj.DataSource 595 else: 596 grid.DataSource = self.Form.previewDataSource 482 if biz: 483 grid.DataSource = biz.DataSource 597 484 self.Sizer.append(grid, 2, "expand") 598 485 self.itemsCreated = True … … 626 513 if not self.DataSource: 627 514 return 628 self.fieldSpecs = self.Form.getFieldSpecsForTable(self.DataSource)629 515 self.createItems() 630 516 … … 651 537 652 538 def createItems(self): 653 fs = self.fieldSpecs 654 relationSpecs = self.Form.RelationSpecs 655 if fs is None: 656 return 657 showEdit = [ (fld, int(fs[fld]["editOrder"])) 658 for fld in fs 659 if (fs[fld]["editInclude"] == "1")] 660 showEdit.sort(lambda x, y: cmp(x[1], y[1])) 661 mainSizer = self.GetSizer() 662 firstControl = None 663 gs = dabo.ui.dGridSizer(vgap=5, maxCols=3) 664 665 for fld in showEdit: 666 fieldName = fld[0] 667 fldInfo = fs[fieldName] 668 fieldType = fldInfo["type"] 669 cap = fldInfo["caption"] 670 fieldEnabled = (fldInfo["editReadOnly"] != "1") 671 672 label = dabo.ui.dLabel(self) #, style=labelStyle) 673 label.NameBase="lbl%s" % fieldName 674 675 # Hook into user's code in case they want to control the object displaying 676 # the data: 677 classRef = self.Form.getEditClassForField(fieldName) 678 if classRef is None: 679 # User didn't supply a class, so derive it based on field type: 680 if fieldType in ["memo",]: 681 classRef = dabo.ui.dEditBox 682 elif fieldType in ["bool",]: 683 classRef = dabo.ui.dCheckBox 684 elif fieldType in ["date",]: 685 #pkm: temporary: dDateTextBox is misbehaving still. So, until we get 686 # it figured out, change the type of control used for date editing 687 # to a raw dTextBox, which can handle viewing/setting dates but 688 # doesn't have all the extra features of dDateTextBox. (2005/08/28) 689 #classRef = dabo.ui.dDateTextBox 690 classRef = dabo.ui.dTextBox 691 else: 692 classRef = dabo.ui.dTextBox 693 694 objectRef = classRef(self) 695 objectRef.NameBase = fieldName 696 objectRef.DataSource = self.DataSource 697 objectRef.DataField = fieldName 698 objectRef.enabled = fieldEnabled 699 700 if fieldEnabled and firstControl is None: 701 firstControl = objectRef 702 703 if classRef == dabo.ui.dCheckBox: 704 # Use the label for a spacer, but don't set the 705 # caption because checkboxes have their own caption. 706 label.Caption = "" 707 objectRef.Caption = cap 708 else: 709 label.Caption = "%s:" % cap 710 711 if not self.Form.preview: 712 if self.Form.getBizobj().RowCount >= 0: 713 pass 714 715 gs.append(label, alignment=("top", "right") ) 716 if fieldType in ["memo",]: 717 # Get the row that these will be added 718 currRow = gs.findFirstEmptyCell()[0] 719 gs.setRowExpand(True, currRow) 720 gs.append(objectRef, "expand") 721 gs.append( (25, 1) ) 722 gs.setColExpand(True, 1) 723 724 childGridCount = 0 725 726 if not self.childrenAdded: 727 self.childrenAdded = True 728 # If there is a child table, add it 729 for rkey in relationSpecs.keys(): 730 rs = relationSpecs[rkey] 731 if rs["source"].lower() == self.DataSource.lower(): 732 childGridCount += 1 733 child = rs["target"] 734 childBiz = self.Form.getBizobj(child) 735 grdLabel = self.addObject(dabo.ui.dLabel, "lblChild" + child) 736 grdLabel.Caption = _(self.Form.getBizobj(child).Caption) 737 grdLabel.FontSize = 14 738 grdLabel.FontBold = True 739 #mainSizer.append( (10, -1) ) 740 mainSizer.append(grdLabel, 0, "expand", alignment="center", 741 border=10, borderSides=("left", "right") ) 742 grid = self.addObject(Grid.Grid, "BrowseGrid" + child) 743 grid.FieldSpecs = self.Form.getFieldSpecsForTable(child) 744 grid.DataSource = child 745 self.childGrids.append(grid) 746 grid.populate() 747 #grid.Height = 100 748 749 mainSizer.append(grid, 1, "expand", border=10, 750 borderSides=("left", "right") ) 751 752 if childGridCount == 0: 753 # Let the edit fields expand normally. 754 gsProportion = 1 755 else: 756 # Each of the child grids got proportions of 1 in the above block, 757 # so they'll size equally. Because the presence of even one child grid 758 # is going to likely push the grid off the bottom, requiring a scroll, 759 # minimize that as much as possible by not allowing the non-grid controls 760 # to expand. 761 ### For some reason, this is preventing the scroll panels from display 762 ### the grids properly. So set this back to one for now. 763 gsProportion = 2 #0 764 mainSizer.insert(0, gs, "expand", gsProportion, border=20) 765 766 # Add top and bottom margins 767 mainSizer.insert( 0, (-1, 10), 0) 768 mainSizer.append( (-1, 20), 0) 769 539 """Subclass hook. Create your items and then call self.super()""" 770 540 self.Sizer.layout() 771 541 self.itemsCreated = True 772 self._focusToControl = firstControl773 542 774 543 def _getDS(self): branches/paul_sandbox/dabo/lib/datanav/PageFrame.py
r2543 r2732 1 import wx2 1 import dabo.ui 3 2 import dabo.dEvents as dEvents … … 5 4 from dabo.dLocalize import _, n_ 6 5 7 dabo.ui.loadUI("wx")8 9 6 10 7 class PageFrameMixin(object): 11 def __init__(self, parent, Name="PageFrame", defaultPages=False, 12 *args, **kwargs): 13 self._defaultPagesOnLoad = defaultPages 14 #super(self.__class__, self).__init__(parent, Name=Name) 8 def __init__(self, parent, Name="PageFrame", *args, **kwargs): 15 9 self._pageStyleClass.__init__(self, parent, Name=Name, *args, **kwargs) 16 10 # Add the images for the various pages. … … 20 14 self.addImage("childview") 21 15 16 self.dsEditPages = {} 22 17 23 def initProperties(self):24 self.PageCount = 025 # Dict to track the edit page for each data source26 self.dsEditPages = {}27 if self.DefaultPagesOnLoad:28 self.addDefaultPages()29 30 #super(self.__class__, self).initProperties()31 self._pageStyleClass.initProperties(self)32 33 18 34 19 def beforePageChange(self, fromPage, toPage): 35 20 """If there are no records, don't let them go to Pages 1 or 2.""" 36 21 if toPage != 0: 37 if self.Form.PrimaryBizobj.RowCount == 0: 22 biz = self.Form.PrimaryBizobj 23 if biz and biz.RowCount == 0: 38 24 self.SelectedPageNumber = 0 39 25 self.Form.StatusText = "No records available" 40 return False 26 return False 41 27 42 28 43 def addDefaultPages(self): 44 """ Add the standard pages to the pageframe. 29 def addPage(self, pageClass, caption="", imgKey=None): 30 page = self.appendPage(pageClass, imgKey=imgKey) 31 if not page.Caption and caption: 32 # Only set the caption to the default if the page class didn't define it. 33 page.Caption = caption 34 return page 35 45 36 46 Subclasses may override or extend. 47 """ 48 if self.Form.FormType != "Edit": 49 self.addSelectPage() 50 self.addBrowsePage() 51 52 if self.Form.FormType != "PickList": 53 self.addEditPage() 37 def addSelectPage(self, caption=_("Select")): 38 self.addPage(self.Form.SelectPageClass, caption, "checkMark") 54 39 55 if not self.Parent.preview: 56 bizobj = self.Parent.getBizobj() 57 for child in bizobj.getChildren(): 58 self.appendPage(self.ChildPageClass(self, child.DataSource), 59 child.Caption, imgKey="childview") 40 def addBrowsePage(self, caption=_("Browse")): 41 self.addPage(self.Form.BrowsePageClass, caption, "browse") 60 42 61 62 def addSelectPage(self, title=_("Select")): 63 self.appendPage(self.Form.SelectPageClass, caption=title, imgKey="checkMark") 43 def addEditPage(self, ds=None, caption=_("Edit")): 44 page = self.addPage(self.Form.EditPageClass, caption, "edit") 45 page.DataSource = ds &n
