Changeset 2713
- Timestamp:
- 01/17/07 22:23:49 (2 years ago)
- Files:
-
- branches/carl2/AUTHORS (modified) (1 diff)
- branches/carl2/dabo/biz/dBizobj.py (modified) (15 diffs)
- branches/carl2/dabo/biz/test/test_dBizobj.py (modified) (1 diff)
- branches/carl2/dabo/db/dCursorMixin.py (modified) (15 diffs)
- branches/carl2/dabo/db/dbFirebird.py (modified) (1 diff)
- branches/carl2/dabo/db/test/test_dCursorMixin.py (modified) (1 diff)
- branches/carl2/dabo/lib/EasyDialogBuilder.py (copied) (copied from trunk/dabo/lib/EasyDialogBuilder.py)
- branches/carl2/dabo/lib/datanav/Form.py (modified) (1 diff)
- branches/carl2/dabo/lib/datanav/Page.py (modified) (2 diffs)
- branches/carl2/dabo/ui/dDataControlMixinBase.py (modified) (1 diff)
- branches/carl2/dabo/ui/uiwx/dFormMixin.py (modified) (2 diffs)
- branches/carl2/dabo/ui/uiwx/dGrid.py (modified) (7 diffs)
- branches/carl2/dabo/ui/uiwx/dMessageBox.py (modified) (1 diff)
- branches/carl2/dabo/ui/uiwx/dPageFrame.py (modified) (4 diffs)
- branches/carl2/dabo/ui/uiwx/dRefactorMixin.py (deleted)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/carl2/AUTHORS
r2412 r2713 11 11 Stefano Masini 12 12 Adi J. Sieker 13 Carl Karsten 14 Nate Lowrie 15 Uwe Grauer 13 16 14 17 branches/carl2/dabo/biz/dBizobj.py
r2666 r2713 187 187 errMsg = self.beforePointerMove() 188 188 if errMsg: 189 raise dException. dException, errMsg189 raise dException.BusinessRuleViolation, errMsg 190 190 191 191 self._CurrentCursor.first() … … 206 206 errMsg = self.beforePointerMove() 207 207 if errMsg: 208 raise dException. dException, errMsg208 raise dException.BusinessRuleViolation, errMsg 209 209 210 210 self._CurrentCursor.prior() … … 225 225 errMsg = self.beforePointerMove() 226 226 if errMsg: 227 raise dException. dException, errMsg227 raise dException.BusinessRuleViolation, errMsg 228 228 229 229 self._CurrentCursor.next() … … 244 244 errMsg = self.beforePointerMove() 245 245 if errMsg: 246 raise dException. dException, errMsg246 raise dException.BusinessRuleViolation, errMsg 247 247 248 248 self._CurrentCursor.last() … … 257 257 258 258 useTransact = startTransaction or topLevel 259 old_pk = getattr(self.Record, self.KeyField, None)260 259 cursor = self._CurrentCursor 260 old_pk = cursor.getPK() 261 261 262 262 if useTransact: … … 301 301 errMsg = self.beforeSave() 302 302 if errMsg: 303 raise dException. dException, errMsg303 raise dException.BusinessRuleViolation, errMsg 304 304 305 305 if self.KeyField is None: 306 raise dException. dException, _("No key field defined for table: ") + self.DataSource306 raise dException.MissingPKException, _("No key field defined for table: ") + self.DataSource 307 307 308 308 # Validate any changes to the data. If there is data that fails … … 328 328 # No need to start another transaction. And since this is a child bizobj, 329 329 # we need to save all rows that have changed. 330 child.saveAll(startTransaction=False, topLevel=False) 330 if child.RowCount > 0: 331 child.saveAll(startTransaction=False, topLevel=False) 331 332 332 333 # Finish the transaction, and requery the children if needed. … … 337 338 338 339 except dException.ConnectionLostException, e: 339 raise dException.ConnectionLostException, e340 raise 340 341 341 342 except dException.NoRecordsException, e: 342 # Nothing to roll back; just throw it back for the form to display 343 raise dException.NoRecordsException, e 343 raise 344 344 345 345 except dException.DBQueryException, e: … … 381 381 errMsg = self.beforeCancel() 382 382 if errMsg: 383 raise dException. dException, errMsg383 raise dException.BusinessRuleViolation, errMsg 384 384 385 385 # Tell the cursor and all children to cancel themselves: … … 398 398 errMsg = self.beforePointerMove() 399 399 if errMsg: 400 raise dException. dException, errMsg400 raise dException.BusinessRuleViolation, errMsg 401 401 402 402 if self.KeyField is None: … … 563 563 old_currentCursorKey = self.__currentCursorKey 564 564 try: 565 old_pk = getattr(self.Record, self.KeyField, None)565 old_pk = self._CurrentCursor.getPK() 566 566 except dException.NoRecordsException: 567 567 # no rows to scan … … 618 618 errMsg = self.beforePointerMove() 619 619 if errMsg: 620 raise dException. dException, errMsg620 raise dException.BusinessRuleViolation, errMsg 621 621 622 622 self._CurrentCursor.new() … … 663 663 errMsg = self.beforeRequery() 664 664 if errMsg: 665 raise dException. dException, errMsg665 raise dException.BusinessRuleViolation, errMsg 666 666 if self.KeyField is None: 667 667 errMsg = _("No Primary Key defined in the Bizobj for %s") % self.DataSource … … 1092 1092 errMsg = self.beforeChildRequery() 1093 1093 if errMsg: 1094 raise dException. dException, errMsg1094 raise dException.BusinessRuleViolation, errMsg 1095 1095 1096 1096 pk = self.getPK() … … 1579 1579 errMsg = self.beforePointerMove() 1580 1580 if errMsg: 1581 raise dException. dException, errMsg1581 raise dException.BusinessRuleViolation, errMsg 1582 1582 self._moveToRowNum(rownum) 1583 1583 self.requeryAllChildren() branches/carl2/dabo/biz/test/test_dBizobj.py
r2653 r2713 293 293 self.assertEqual(bizChild.RowCount, 1) 294 294 self.assertEqual(bizChild.Record.cInvNum, "IN99991") 295 295 296 # Test the case where you add a new parent record but no new children: 297 bizMain.new() 298 self.assertEqual(bizMain.RowCount, 4) 299 bizMain.saveAll() 300 self.assertEqual(bizMain.RowCount, 4) 301 bizMain.requery() 302 self.assertEqual(bizMain.RowCount, 4) 303 296 304 297 305 if __name__ == "__main__": branches/carl2/dabo/db/dCursorMixin.py
r2712 r2713 146 146 def getSortCase(self): 147 147 return self.sortCase 148 148 149 150 def pkExpression(self): 151 """Returns the current PK expression.""" 152 rec = self._records[self.RowNumber] 153 if isinstance(self.KeyField, tuple): 154 pk = tuple([rec[kk] for kk in self.KeyField]) 155 else: 156 pk = rec[self.KeyField] 157 return pk 158 149 159 150 160 def correctFieldType(self, field_val, field_name, _fromRequery=False): … … 628 638 # self.RowNumber doesn't exist (init phase?) Nothing's changed: 629 639 return False 630 631 memento = self._mementos.get(rec [self.KeyField], None)632 new_rec = self._newRecords.has_key(rec [self.KeyField])640 recKey = self.pkExpression() 641 memento = self._mementos.get(recKey, None) 642 new_rec = self._newRecords.has_key(recKey) 633 643 634 644 return not (memento is None and not new_rec) … … 687 697 raise dException.NoRecordsException, _("No records in the data set.") 688 698 rec = self._records[self.RowNumber] 689 if self._newRecords.has_key(rec[self.KeyField]) and self.AutoPopulatePK: 699 recKey = self.pkExpression() 700 if self._newRecords.has_key(recKey) and self.AutoPopulatePK: 690 701 # New, unsaved record 691 702 ret = rec[kons.CURSOR_TMPKEY_FIELD] … … 736 747 if typ: 737 748 try: 738 ret = {"C" : str, "D" : datetime.date, "B" : bool,739 "N" : float, "M" : str, "I" : int, "T": datetime.datetime}[typ]749 ret = {"C": unicode, "D": datetime.date, "B": bool, "G": long, 750 "N": float, "M": unicode, "I": int, "T": datetime.datetime}[typ] 740 751 except KeyError: 741 752 ret = None … … 874 885 875 886 rec = self._records[row] 876 mem = self._mementos.get(rec[self.KeyField], {}) 887 recKey = self.pkExpression() 888 mem = self._mementos.get(recKey, {}) 877 889 878 890 for k, v in mem.items(): … … 1024 1036 saverow(row) 1025 1037 else: 1026 pk = self. _records[self.RowNumber][self.KeyField]1038 pk = self.pkExpression() 1027 1039 if pk in self._mementos.keys() or pk in self._newRecords.keys(): 1028 1040 saverow(self.RowNumber) … … 1033 1045 def __saverow(self, row): 1034 1046 rec = self._records[row] 1035 newrec = self._newRecords.has_key(rec[self.KeyField]) 1047 recKey = self.pkExpression() 1048 newrec = self._newRecords.has_key(recKey) 1036 1049 diff = self.getRecordStatus(row) 1037 1050 if diff or newrec: … … 1088 1101 # sql = "update %s set %s where %s" % (self.BackendObject.encloseSpaces(self.Table), 1089 1102 # updClause, pkWhere) 1090 oldPKVal = rec[self.KeyField]1103 oldPKVal = self.pkExpression() 1091 1104 newPKVal = None 1092 1105 if newrec and self.AutoPopulatePK: … … 1099 1112 if newPKVal and not self._compoundKey: 1100 1113 self.setFieldVal(self.KeyField, newPKVal, row) 1101 1114 1102 1115 #run the update 1103 1116 aux = self.AuxCursor … … 1209 1222 row = self.RowNumber 1210 1223 rec = self._records[row] 1211 if self._newRecords.has_key(rec[self.KeyField]): 1224 recKey = self.pkExpression() 1225 if self._newRecords.has_key(recKey): 1212 1226 # We simply need to remove the row, and clear the memento and newrec flag. 1213 1227 self._clearMemento(row) … … 1219 1233 1220 1234 # Not a new record: need to manually replace the old values: 1221 mem = self._mementos.get(rec [self.KeyField], {})1235 mem = self._mementos.get(recKey, {}) 1222 1236 for fld, val in mem.items(): 1223 1237 self._records[row][fld] = val … … 1235 1249 1236 1250 rec = self._records[delRowNum] 1237 if self._newRecords.has_key( rec[self.KeyField]):1251 if self._newRecords.has_key(self.pkExpression()): 1238 1252 res = True 1239 1253 else: … … 1515 1529 row = self.RowNumber 1516 1530 rec = self._records[row] 1531 recKey = self.pkExpression() 1517 1532 1518 1533 if self._compoundKey: … … 1520 1535 else: 1521 1536 keyFields = [self.KeyField] 1522 mem = self._mementos.get(rec[self.KeyField], {}) 1537 recKey = self.pkExpression() 1538 mem = self._mementos.get(recKey, {}) 1523 1539 1524 1540 def getPkVal(fld): … … 1992 2008 if self.RowCount <= 0: 1993 2009 return False 1994 return self._newRecords.has_key(self._records[self.RowNumber][self.KeyField]) 2010 recKey = self.pkExpression() 2011 return self._newRecords.has_key(recKey) 1995 2012 1996 2013 branches/carl2/dabo/db/dbFirebird.py
r2712 r2713 12 12 self.fieldPat = re.compile("([A-Za-z_][A-Za-z0-9-_]+)\.([A-Za-z_][A-Za-z0-9-_]+)") 13 13 import kinterbasdb 14 if not kinterbasdb.initialized: 15 kinterbasdb.init(type_conv=200) 14 initialized = getattr(kinterbasdb, "initialized", None) 15 if not initialized: 16 if initialized is None: 17 # type_conv=200 KeyError with the older versions. User will need 18 # mxDateTime installed as well: 19 kinterbasdb.init() 20 else: 21 # Use Python's Decimal and datetime types: 22 kinterbasdb.init(type_conv=200) 23 if initialized is None: 24 # Older versions of kinterbasedb didn't have this attribute, so we write 25 # it ourselves: 26 kinterbasdb.initialized = True 27 16 28 self.dbapi = kinterbasdb 17 29 branches/carl2/dabo/db/test/test_dCursorMixin.py
r2667 r2713 290 290 ## actually occur. 291 291 def setUp(self): 292 con = dabo.db.dConnection(DbType="Firebird", User="dabo _unittest",293 password=" T30T35DB4K30Z45I67N60", Database="dabo_unittest",294 Host=" paulmcnett.com")292 con = dabo.db.dConnection(DbType="Firebird", User="dabotester", 293 password="Y57W8EN6CB06KBCCDCX01D6B", Database="dabo_unittest", 294 Host="dabodev.com") 295 295 self.cur = con.getDaboCursor() 296 296 self.temp_table_name = "dabo_unittest_tbl" branches/carl2/dabo/lib/datanav/Form.py
r2657 r2713 194 194 help=_("Browse the records in the current recordset.")) 195 195 196 # Add one edit menu item for every edit page (every page past the second) 196 def onActivatePage(evt): 197 self.pageFrame.SelectedPage = evt.EventObject.Tag 198 199 # Add an edit menu item, and an activation menu for every subsequent page 197 200 if self.FormType != "PickList": 198 201 for index in range(2, self.pageFrame.PageCount): 199 200 202 if index == 2: 201 202 203 title = "&%s\tAlt+3" % (_(self.pageFrame.Pages[index].Caption)) 203 204 onHit = self.onEditCurrentRecord 205 tag = self.pageFrame.Pages[index].DataSource 206 help = _("Edit the fields of the currently selected record.") 204 207 else: 205 206 title = "%s\tAlt+%d" % (_(self.pageFrame.Pages[index].Caption), 207 208 index+1) 209 210 menu.append(title, OnHit=self.onEditCurrentRecord, bmp="edit", 211 help=_("Edit the fields of the currently selected record."), 212 Tag=self.pageFrame.Pages[index].DataSource) 213 menu.appendSeparator() 208 title = "%s\tAlt+%d" % (_(self.pageFrame.Pages[index].Caption), index + 1) 209 onHit = onActivatePage 210 tag = self.pageFrame.Pages[index] 211 help = "" 212 213 menu.append(title, OnHit=onHit, bmp="edit", help=help, Tag=tag) 214 menu.appendSeparator() 214 215 215 216 if self.FormType != "Edit": branches/carl2/dabo/lib/datanav/Page.py
r2633 r2713 206 206 pass 207 207 208 def setGroupBy(self, biz): 209 """Subclass hook.""" 210 pass 211 208 212 209 213 def setOrderBy(self, biz): … … 351 355 self.setWhere(bizobj) 352 356 self.setOrderBy(bizobj) 357 self.setGroupBy(bizobj) 353 358 self.setLimit(bizobj) 354 359 branches/carl2/dabo/ui/dDataControlMixinBase.py
r2531 r2713 160 160 # can store the oldval, so always flush 'em. 161 161 oldVal = None 162 if curVal is None or curVal != oldVal: 162 if curVal is None: 163 isChanged = True 164 else: 165 if isinstance(curVal, float) and isinstance(oldVal, float): 166 # If it is a float, make sure that it has changed by more than the 167 # rounding error. 168 isChanged = (abs(curVal - oldVal) > 0.0000001) 169 else: 170 isChanged = (curVal != oldVal) 171 if isChanged: 163 172 if not self._DesignerMode: 164 173 if self.DataSource and self.DataField: branches/carl2/dabo/ui/uiwx/dFormMixin.py
r2639 r2713 138 138 self._skipActivate = False 139 139 else: 140 # Restore the saved size and position, which can't happen 141 # in __init__ because we may not have our name yet. 142 try: 143 restoredSP = self.restoredSP 144 except: 145 restoredSP = False 146 if not restoredSP: 147 if self.SaveRestorePosition: 148 self.restoreSizeAndPosition() 149 140 150 self.raiseEvent(dEvents.Activate, evt) 141 151 self._skipActivate = (self.Application.Platform == "Win") … … 146 156 147 157 def __onActivate(self, evt): 148 # Restore the saved size and position, which can't happen149 # in __init__ because we may not have our name yet.150 try:151 restoredSP = self.restoredSP152 except:153 restoredSP = False154 if not restoredSP:155 if self.SaveRestorePosition:156 self.restoreSizeAndPosition()157 158 158 # If the ShowStatusBar property was set to True, this will create it 159 159 sb = self.StatusBar branches/carl2/dabo/ui/uiwx/dGrid.py
r2657 r2713 1 1 # -*- coding: utf-8 -*- 2 import copy 2 3 import sys 3 4 import datetime … … 109 110 def setColumns(self, colDefs): 110 111 """Create columns based on passed list of column definitions.""" 111 # Column order should already be in the definition. If there is a custom112 # setting by the user, override it.113 114 # See if the defs have changed. If not, update any column info,115 # and return. If so, clear the data to force a re-draw of the table.116 112 if colDefs == self.colDefs: 117 self.setColumnInfo()113 # Already done, no need to take the time. 118 114 return 115 116 app = self.grid.Application 117 form = self.grid.Form 119 118 120 119 for idx, col in enumerate(colDefs): … … 126 125 nm = "" 127 126 colName = "Column_%s" % nm 128 app = self.grid.Application129 form = self.grid.Form130 127 131 128 pos = col._getUserSetting("Order") … … 167 164 col.Order = num 168 165 colDefs.sort(self.orderSort) 169 self.colDefs = colDefs 170 self.setColumnInfo() 166 self.colDefs = copy.copy(colDefs) 171 167 172 168 def orderSort(self, col1, col2): … … 174 170 175 171 176 def setColumnInfo(self):177 self.colDefs.sort(self.orderSort)178 179 180 172 def convertType(self, typ): 181 173 """Convert common types, names and abbreviations for … … 1781 1773 def fillGrid(self, force=False): 1782 1774 """ Refresh the grid to match the data in the data set.""" 1783 # Save the focus, if any1784 currFocus = self.FindFocus()1785 currDataField = None1786 # if the current focus is data-aware, we must temporarily remove it's binding1787 # or the value of the control will flow to other records in the bizobj, but1788 # I admit that I'm not entirely sure why.1789 if currFocus:1790 try:1791 currDataField = currFocus.DataField1792 currFocus.DataField = ""1793 except AttributeError:1794 pass1795 1775 1796 1776 # Get the default row size from dApp's user settings … … 1805 1785 tbl.setColumns(self.Columns) 1806 1786 tbl.fillTable(force) 1807 1808 ## pkm: I've disabled the following block, because setting the focus1809 ## can steal focus from the active form. It also doesn't seem1810 ## right to have this code here...1811 if False and force:1812 row = max(0, self.CurrentRow)1813 col = max(0, self.CurrentColumn)1814 if "linux" in sys.platform:1815 # Needed on Linux to get the grid to have the focus,1816 # but on windows this is deadly:1817 for window in self.Children:1818 window.SetFocus()1819 # Needed on win and mac to get the grid to have the focus:1820 self.GetGridWindow().SetFocus()1821 if not self.IsVisible(row, col):1822 self.MakeCellVisible(row, col)1823 self.MakeCellVisible(row, col)1824 self.SetGridCursor(row, col)1825 1826 if currFocus is not None:1827 # put the data binding back and re-set the focus:1828 try:1829 currFocus.setFocus()1830 currFocus.DataField = currDataField1831 currFocus.refresh()1832 except: pass1833 1787 1834 1788 if not self._sortRestored: branches/carl2/dabo/ui/uiwx/dMessageBox.py
r2351 r2713 93 93 94 94 if __name__ == "__main__": 95 app = wx.PySimpleApp() 95 app = dabo.dApp() 96 app.showMainFormOnStart = False 97 app.setup() 96 98 print areYouSure("Are you happy?") 97 99 print areYouSure("Are you sure?", cancelButton=True) branches/carl2/dabo/ui/uiwx/dPageFrame.py
r2541 r2713 125 125 dd.SetSelection(pos) 126 126 127 128 129 127 128 import random 130 129 class _dPageFrame_test(dPageFrame): 131 130 def initProperties(self): 132 131 self.Width = 400 133 132 self.Height = 175 133 self.TabPosition = random.choice(("Top", "Bottom", "Left", "Right")) 134 134 135 135 def afterInit(self): 136 136 self.appendPage(caption="Introduction") 137 137 self.appendPage(caption="Chapter I") 138 self.appendPage(caption="Chapter 2") 139 140 def beforePageChange(self, fromPage, toPage): 141 # Don't allow the user to go from page 0 to page 2 142 if fromPage == 0 and toPage == 2: 143 return False 144 else: 145 return True 138 self.Pages[0].BackColor = "darkred" 139 self.Pages[1].BackColor = "darkblue" 146 140 147 141 def onPageChanged(self, evt): … … 153 147 self.Width = 400 154 148 self.Height = 175 149 self.TabPosition = random.choice(("Top", "Bottom", "Left", "Right")) 155 150 156 151 def afterInit(self): 157 152 self.appendPage(caption="Introduction") 158 153 self.appendPage(caption="Chapter I") 159 self.appendPage(caption="Chapter 2") 154 self.Pages[0].BackColor = "darkred" 155 self.Pages[1].BackColor = "darkblue" 160 156 161 157 def onPageChanged(self, evt): … … 167 163 self.Width = 400 168 164 self.Height = 175 165 self.TabPosition = random.choice(("Top", "Bottom", "Left", "Right")) 169 166 170 167 def afterInit(self): 171 168 self.appendPage(caption="Introduction") 172 169 self.appendPage(caption="Chapter I") 173 self.appendPage(caption="Chapter 2") 170 self.Pages[0].BackColor = "darkred" 171 self.Pages[1].BackColor = "darkblue" 174 172 175 173 def onPageChanged(self, evt): … … 177 175 178 176 177 179 178 if __name__ == "__main__": 180 179 import test
