Changeset 445

Show
Ignore:
Timestamp:
Fri Jun 13 23:35:00 2008
Author:
Brian
Message:

Improved object api in Data.py to simplify setting of object pointers. Fixed some bugs I discovered in ORM.py while working on Rmap. Alex fixed an insert column bug in GanttReport?.py.

Files:

Legend:

Unmodified
Added
Removed
Modified
  • ganttpv/trunk/ORM.py

    r443 r445  
    1286 1286 ##        model['Seq'] = fact.Nary  
    1287 1287         object_type = 'ORMRole'  
      1288         model['ORMObjectTypeID'] = nodeb.TableID  
    1288 1289     elif shape_type == 'ORMSubtypeConnectorShape':  # what should this be called?  
    1289 1290         model['ORMSubtypeID'] = nodeb.TableID  
     
    2555 2556 def AddRole(fact_object, add_role):  # in a separate function "just in case"  
    2556 2557     readings = fact_object.GetList('ORMFactReading')  
      2558     today = Data.TodayString()  
    2557 2559     for reading in readings:  
    2558 2560         roles = reading.ORMRoleSequence.GetList('ORMRolePosition')  
     
    2561 2563         newpos.Seq = len(roles) + 1  
    2562 2564         newpos.ORMRoleID = add_role.ID  
      2565         newpos.DateAdded = today  
    2563 2566  
    2564 2567 ##    if not add_role.ORMFactType == fact_object:  # if it hasn't already been added  
     
    3875 3878         clist.ORMConstraintID = target.ID  
    3876 3879         clist.Seq = len(priorlists)+1  # next number  
      3880         today = Data.TodayString()  
      3881         clist.DateAdded = today  
    3877 3882         fact_type_ids = {}  
    3878 3883         for i, role in enumerate(self.rolelist):  
     
    3881 3886             crole.ORMRoleID = role.ID  
    3882 3887             crole.Seq = i + 1  
      3888             crole.DateAdded = today  
    3883 3889             fact_type_ids[role.ORMFactTypeID] = None  
    3884 3890  
     
    4120 4126  
    4121 4127     def RedrawAll(self):  # this should be called after undo and redo -- IMPORTANT  
      4128         '''Redo and undo are problems. Need to remove graphis of all undos.  
      4129             Need to add graphis for all redos. This code still doesn't work.  
      4130             Maybe I should just rebuild everything?'''  
      4131  
    4122 4132 ##        for dcid in self.objids:  
    4123 4133 ##            shape = self.dcid_to_shape_xref.get(dcid)  
      4134  
      4135         # identify un-added objects  
      4136         dcids = {}  
      4137         for dcid in self.objids:  
      4138             dcids[dcid] = None  
      4139  
    4124 4140         # undelete objects will be in this list, but shouldn't be in self.objids  
    4125 4141         for shape in self.Report.GetList('GraphicObject'):  
     
    4134 4150  
    4135 4151             self.RedrawID(shape.dcid)  
      4152              
      4153             if shape.dcid in dcids:  # identify obsolete dcids  
      4154                 del dcids[shape.dcid]  
      4155  
      4156         for dcid in dcids.keys():  # undo of adds, delete dcids  
      4157             self.pdc.RemoveId(dcid)  
      4158             self.objids.remove(dcid)  
      4159             if debug: print 'removing dcid', dcid  
    4136 4160  
    4137 4161     def _ConnectEm(self, source, target):  
  • ganttpv/trunk/GanttReport.py

    r440 r445  
    824 824  
    825 825     def onSearch(self, event):  
      826         # return a transformed list where every item is a unique tuple  
      827         # identically-named choices are always shown at the same time,  
      828         # in the same order, so we can tell them apart by their order  
      829         def deDupper(oldlist):  
      830             newlist = []  
      831             count = dict.fromkeys(oldlist, 0)  
      832             for x in oldlist:  
      833                 newlist.append((x, count[x]))  
      834                 count[x] += 1  
      835             return newlist  
      836  
      837         def reDupper(newlist):  
      838             return [x[0] for x in newlist]  
      839  
    826 840         # get the visible selection set  
    827           choices = self.SelectionListBox.GetStrings()  
      841         choices = deDupper(self.SelectionListBox.GetStrings())  
    827 841         sel_numbers = self.SelectionListBox.GetSelections()  
    828 842         selections = dict.fromkeys([choices[n] for n in sel_numbers])  
     
    845 859             choices = [x for x in self.choices if x in self.selections]  
    846 860         else:  
    847               choices = [x for x in self.choices if re.search(search, x, re.I)]  
    848           self.SelectionListBox.Set(choices)  
      861             choices = [x for x in self.choices if re.search(search, x[0], re.I)]  
      862                 # x[0] is equivalent to reDupping  
      863         self.SelectionListBox.Set(reDupper(choices))  
    849 864         for i, choice in enumerate(choices):  
    850 865             if choice in self.selections:  
  • ganttpv/trunk/Data.py

    r437 r445  
    104 104 # 080602 - Brian - add subtypes to object api  
    105 105 # 080604 - Brian - simplify return of objects via object api (don't require 'get')  
      106 # 080609 - Brian - simplify setting of object pointer values via object api  
    106 107  
    107 108 import datetime, calendar  
     
    637 638     def __setattr__(self, name, value):  
    638 639         # edits  
    639           if name in ('Table', 'ID', 'db', 'Valid', 'Get', 'GetList'):  
      640         if name in ('Table', 'ID', 'db', 'Valid', 'Get', 'GetList', 'GetGraphicList'):  
    639 640             return  # silently ignore attempts to change these?  
    640 641         if not self.Valid():  
    641 642             return  
    642           change = {'Table': self.Table, 'ID': self.ID, name: value }  
      643         if isinstance(value, Object):  # make it easier to do foreign keys  
      644             if name == 'Target':  
      645                 change = {'Table': self.Table, 'ID': self.ID,  
      646                           'TableName': value.Table, 'TableID': value.ID }  
      647             elif self.db._ConvertAlias(name) == value.Table:  
      648                 change = {'Table': self.Table, 'ID': self.ID,  
      649                           name + 'ID': value.ID }  
      650             else:  # silently ignore object vs. name mismatches  
      651                 return  
      652         else:     
      653             change = {'Table': self.Table, 'ID': self.ID, name: value }  
    643 654         Update(change)  # can only update the active database -- IMPORTANT  
    644 655         return  
     
    677 688         if not self.Valid(): return None  
    678 689  
    679           if self.Table in ('ReportRow', 'GraphicObject') and name == 'Target':  
      690 ##        if self.Table in ('ReportRow', 'GraphicObject') and name == 'Target':  
      691         if name == 'Target':  
    680 692             if self.TableName and self.TableID:  # don't create new  
    681 693                 return self.db.GetObject(self.TableName, self.TableID)