Changeset 2732

Show
Ignore:
Timestamp:
01/21/2007 09:42:35 PM (2 years ago)
Author:
paul
Message:

Here's my first machete swipe at datanav. To test this you'll also need
my appwizard changes in daboide/paul_sandbox, which is forthcoming.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/paul_sandbox/dabo/lib/datanav/Form.py

    r2710 r2732  
    11import os 
    2 import random 
    32import traceback 
    43import wx 
    54import dabo.dEvents as dEvents 
    65import dabo.ui 
    7 from dabo.lib.specParser import importRelationSpecs, importFieldSpecs 
    86from dabo.dLocalize import _, n_ 
    97import dabo.lib.reportUtils as reportUtils 
     
    2422            + Edit   : Edit the current record in the result set. 
    2523    """ 
    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): 
    4525        self.ShowToolBar = True 
    46         # We want the status bar showing record information 
    47         self._autoUpdateStatusText = True 
    48         # 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 = True 
    52      
    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 = previewMode 
    61         self.previewDataSource = tbl 
    62         super(Form, self).__init__(parent, *args, **kwargs) 
    63         # We will need to set these separated if in Preview mode. 
    64         self.rowNumber = 0 
    65         self.rowCount = 0 
    66         # Set a default size 
    6726        self.Size = (640, 480) 
    68  
    69  
    70     def _afterInit(self): 
    71         super(Form, self)._afterInit() 
     27     
     28 
     29    def afterInit(self): 
    7230        if self.FormType == 'PickList': 
    7331            # The form is a picklist, which pops up so the user can choose a record, 
     
    8341            self.bindEvent(dEvents.Deactivate, _onHide) 
    8442 
    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 
    9551    def save(self, dataSource=None): 
    96         if dataSource is None: 
    97             if self.saveCancelRequeryAll: 
    98                 dataSource = self._mainTable 
    9952        ## The bizobj may have made some changes to the data during the save, so  
    10053        ## make sure it is reflected on screen by calling update() afterwards. 
     
    10356        return ret 
    10457     
    105      
    106     def cancel(self, dataSource=None): 
    107         if dataSource is None: 
    108             if self.saveCancelRequeryAll: 
    109                 dataSource = self._mainTable 
    110         return self.super(dataSource) 
    111      
    112     def requery(self, dataSource=None): 
    113         if dataSource is None: 
    114             if self.saveCancelRequeryAll: 
    115                 dataSource = self._mainTable 
    116         return self.super(dataSource) 
    117      
    118     def confirmChanges(self): 
    119         if self.preview: 
    120             # Nothing to check 
    121             return True 
    122         else: 
    123             return self.super() 
    124      
    125     def afterSetPrimaryBizobj(self):         
    126         pass 
    127          
    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() 
    13858     
    13959    def setupToolBar(self): 
     
    283203        """ Set up the action menu for this frame. 
    284204 
    285         Called when the form is created and also when the fieldspecs are set
     205        Called when the form is created
    286206        """ 
    287207        mb = self.MenuBar 
     
    310230        """ 
    311231        currPage = 0 
     232        ds = None 
    312233        biz = self.getBizobj() 
     234        if biz is not None: 
     235            ds = biz.DataSource 
    313236 
    314237        try: 
     
    320243         
    321244        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) 
    324247            self.Sizer.append(self.pageFrame, "expand", 1) 
    325248            self.pageFrame.addSelectPage() 
    326249            self.pageFrame.addBrowsePage() 
    327             if self.preview: 
    328                 ds = self.previewDataSource 
    329             else: 
    330                 ds = biz.DataSource 
    331250            if self.FormType != "PickList": 
    332251                self.addEditPages(ds) 
     
    340259     
    341260    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() 
    343263        if biz: 
    344             title = _("Edit") + " " + _(biz.Caption) 
     264            caption = _("Edit") + " " + _(biz.Caption) 
    345265        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 
    359275 
    360276 
    361277    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.""" 
    364279        self.pageFrame.SelectedPage = 0 
    365280 
    366281         
    367282    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.""" 
    370284        self.pageFrame.SelectedPage = 1 
    371285 
    372286         
    373287    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.""" 
    376289        # We stored the datasource in the menu item's Tag property when 
    377290        # the menu was created. 
     
    395308        if not self.enableQuickReport(): 
    396309            dabo.ui.exclaim(_("Sorry, there are no records to report on."), title=_("No Records")) 
    397             return 
    398         if self.preview: 
    399             # Just previewing  
    400             dabo.ui.info(message="Not available in preview mode",  
    401                     title = "Preview Mode") 
    402310            return 
    403311 
     
    506414 
    507415 
    508     def setFieldSpecs(self, xml, tbl): 
    509         """ Reads in the field spec file and creates the appropriate 
    510         controls in the form.  
    511         """ 
    512         self._allFieldSpecs = self.parseXML(xml, "Field") 
    513         self._mainTable = tbl 
    514  
    515  
    516     def setRelationSpecs(self, xml, bizModule): 
    517         """ Creates any child bizobjs used by the form, and establishes 
    518         the relations with the parent bizobj 
    519         """ 
    520         self.RelationSpecs = self.parseXML(xml, "Relation") 
    521         primaryBizobj = self.PrimaryBizobj 
    522         # 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, too 
    526         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 the  
    532         specParser class. Since that class requires a file, this method will 
    533         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 ret 
    540          
    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, errMsg 
    551  
    552         self.setupPageFrame() 
    553         self.setupToolBar() 
    554         if not self.preview: 
    555             self.setupMenu() 
    556         else: 
    557             self.ToolBar.Enabled = False 
    558         self.afterCreation() 
    559          
    560      
    561416    def setPrimaryBizobjToDefault(self, ds): 
    562417        """ This method is called when we leave an editing page. The 
     
    567422        to the one for the form's main table. 
    568423        """ 
     424        bizDS = None 
    569425        biz = self.getBizobj() 
    570         bizDS = biz.DataSource 
     426        if biz: 
     427            bizDS = biz.DataSource 
    571428        if bizDS == ds: 
    572429            # We didn't switch to another editing page, so reset it back 
     
    593450         
    594451     
    595     def beforeCreation(self): 
    596         """ Hook method available to customize form creation settings 
    597         before anything on the form, its toolbar, or its menu is created. 
    598         Returning any string from this method will prevent form creation 
    599         from happening, and raise an error. 
    600         """ 
    601         pass 
    602          
    603     def afterCreation(self): 
    604         """ Hook method available to customize the form after all its 
    605         components have been created. 
    606         """ 
    607         pass 
    608      
    609      
    610     def getFieldSpecsForTable(self, tbl): 
    611         """ Returns the field specs for the given table. If there is no entry 
    612         for the requested table, it returns None. 
    613         """ 
    614         ret = None 
    615         try: 
    616             ret = self._allFieldSpecs[tbl] 
    617         except: pass 
    618         return ret 
    619          
    620      
    621452    def onRequery(self, evt): 
    622453        """ Override the dForm behavior by running the requery through the select page. 
    623454        """ 
    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) 
    625465 
    626466 
     
    971811    ## Property get/set code below 
    972812    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 
    974817 
    975818    def _setAddChildEditPages(self, val): 
     
    1031874    def _setEditPageClass(self, val): 
    1032875        self._editPageClass = val        
    1033  
    1034  
    1035     def _getFieldSpecs(self): 
    1036         try: 
    1037             return self._allFieldSpecs[self._mainTable] 
    1038         except AttributeError: 
    1039             return None 
    1040  
    1041     def _setFieldSpecs(self, val): 
    1042         self._allFieldSpecs[self._mainTable] = val 
    1043876 
    1044877 
     
    1061894             
    1062895 
    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 
    1069919 
    1070920    def _getSetFocusToBrowseGrid(self): 
     
    1079929 
    1080930 
     931    def _getTesting(self): 
     932        return getattr(self, "_testing", False) 
     933 
     934    def _setTesting(self, val): 
     935        self._testing = bool(val) 
     936 
     937 
     938 
    1081939    # Property definitions: 
    1082940    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.""")) 
    1085944     
    1086945    BrowseGridClass = property(_getBrowseGridClass, _setBrowseGridClass, None, 
     
    1096955            _("""Specifies the class to use for the edit page.""")) 
    1097956 
    1098     FieldSpecs = property(_getFieldSpecs, _setFieldSpecs, None,  
    1099             _("""Reference to the dictionary containing field behavior specs""")) 
    1100  
    1101957    FormType = property(_getFormType, _setFormType, None, 
    1102958            _("""Specifies the type of form this is. 
    1103959 
    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 the  
    1110         Primary Key of the picked record. 
    1111  
    1112     Edit: 
    1113         Modal version of normal, with no Select/Browse pages. User code sends 
    1114         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. 
    1115971""")) 
    1116972 
    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".""")) 
    1119989 
    1120990    SelectPageClass = property(_getSelectPageClass, _setSelectPageClass, None, 
     
    1122992 
    1123993    SetFocusToBrowseGrid = property(_getSetFocusToBrowseGrid,  
    1124             None, _setSetFocusToBrowseGrid
     994            _setSetFocusToBrowseGrid, None
    1125995            _("""Does the focus go to the browse grid when the browse page is entered?""")) 
    1126996         
     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.py 
    2  
    3 This is a grid designed to browse records of a bizobj. It is part of the  
    4 dabo.lib.datanav subframework. It does not descend from dControlMixin at this  
    5 time, but is self-contained. There is a dGridDataTable definition here as  
    6 well, that defines the 'data' that gets displayed in the grid. 
    7 """ 
    81import dabo 
    92import dabo.ui 
     
    158class Grid(dabo.ui.dGrid): 
    169    def _beforeInit(self, pre): 
    17         self._fldSpecs = None 
    18         self.includeFields = [] 
    19         self.fieldCaptions = {} 
    20         self.colOrders = {} 
    21         self.built = False 
    2210        self.customSort = True 
    2311        super(Grid, self)._beforeInit(pre) 
     
    3523        self.bindKey("f2", self._onSortKey) 
    3624        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) 
    4025 
    4126        if hasattr(self.Form, "preview") and self.Form.preview: 
     
    5742            # raw DataSet. This is true in minesweeper, for example. 
    5843            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() 
    7245 
    7346 
     
    179152 
    180153 
    181     def _getFldSpecs(self): 
    182         return self._fldSpecs 
    183  
    184     def _setFldSpecs(self, val): 
    185         self._fldSpecs = val 
    186  
    187         if val is None: 
    188             return 
    189  
    190         # Update the props 
    191         self.includeFields = [kk for kk in val 
    192                 if val[kk]["listInclude"] == "1" ] 
    193  
    194         self.fieldCaptions = {} 
    195         for kk in val.keys(): 
    196             if kk not in self.includeFields: 
    197                 continue 
    198             self.fieldCaptions[kk] = val[kk]["caption"] 
    199  
    200         self.colOrders = {} 
    201         for kk in val.keys(): 
    202             if kk not in self.includeFields: 
    203                 continue 
    204             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                 continue 
    210             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                 continue 
    216             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  
    11import os 
    22import sys 
    3 import wx 
    43import dabo 
    54import dabo.dException as dException 
     
    87from dabo.lib.utils import padl 
    98from dabo.dObject import dObject 
    10  
    11 dabo.ui.loadUI("wx") 
    129 
    1310from dabo.ui import dPanel 
     
    194191         
    195192    def createItems(self): 
     193        if not self.Sizer: 
     194            self.Sizer = dabo.ui.dSizer("v") 
    196195        self.selectOptionsPanel = self.getSelectOptionsPanel() 
    197         self.GetSizer().append(self.selectOptionsPanel, "expand", 1, border=20) 
     196        self.Sizer.append(self.selectOptionsPanel, "expand", 1, border=20) 
    198197        self.selectOptionsPanel.setFocus() 
    199198        super(SelectPage, self).createItems() 
    200         if self.Form.RequeryOnLoad: 
    201             dabo.ui.callAfter(self.requery) 
    202199             
    203200 
     
    361358                bizobj.setSQL(sql) 
    362359     
    363             ret = frm.requery(
     360            ret = frm.requery(_fromSelectPage=True
    364361 
    365362        if ret: 
     
    405402 
    406403    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         
    510406 
    511407    def onCustomSQL(self, evt): 
     
    576472        if not self.itemsCreated: 
    577473            self.createItems() 
     474        if bizobj and bizobj.RowCount >= 0: 
    578475            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() 
    585477 
    586478         
    587479    def createItems(self): 
    588         bizobj = self.Form.getBizobj() 
     480        biz = self.Form.getBizobj() 
    589481        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 
    597484        self.Sizer.append(grid, 2, "expand") 
    598485        self.itemsCreated = True 
     
    626513        if not self.DataSource: 
    627514            return 
    628         self.fieldSpecs = self.Form.getFieldSpecsForTable(self.DataSource) 
    629515        self.createItems() 
    630516 
     
    651537 
    652538    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()""" 
    770540        self.Sizer.layout() 
    771541        self.itemsCreated = True 
    772         self._focusToControl = firstControl 
    773542 
    774543    def _getDS(self): 
  • branches/paul_sandbox/dabo/lib/datanav/PageFrame.py

    r2543 r2732  
    1 import wx 
    21import dabo.ui 
    32import dabo.dEvents as dEvents 
     
    54from dabo.dLocalize import _, n_ 
    65 
    7 dabo.ui.loadUI("wx") 
    8  
    96 
    107class 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): 
    159        self._pageStyleClass.__init__(self, parent, Name=Name, *args, **kwargs) 
    1610        # Add the images for the various pages. 
     
    2014        self.addImage("childview") 
    2115 
     16        self.dsEditPages = {} 
    2217 
    23     def initProperties(self): 
    24         self.PageCount = 0 
    25         # Dict to track the edit page for each data source 
    26         self.dsEditPages = {} 
    27         if self.DefaultPagesOnLoad: 
    28             self.addDefaultPages() 
    29  
    30         #super(self.__class__, self).initProperties() 
    31         self._pageStyleClass.initProperties(self) 
    32          
    3318     
    3419    def beforePageChange(self, fromPage, toPage): 
    3520        """If there are no records, don't let them go to Pages 1 or 2.""" 
    3621        if toPage != 0: 
    37             if self.Form.PrimaryBizobj.RowCount == 0: 
     22            biz = self.Form.PrimaryBizobj 
     23            if biz and biz.RowCount == 0: 
    3824                self.SelectedPageNumber = 0 
    3925                self.Form.StatusText = "No records available" 
    40                 return False        
     26                return False 
    4127         
    4228         
    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         
    4536 
    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") 
    5439 
    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") 
    6042 
    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