Changeset 325

Show
Ignore:
Timestamp:
Wed Aug 22 14:46:24 2007
Author:
Brian
Message:

Scripts updated to use object api

Files:

Legend:

Unmodified
Added
Removed
Modified
  • scripts/trunk/ORM/Install ORM Tables.py

    r318 r325  
    20 20 # 070806 - first draft of program based on Install Assignment Hours  
    21 21 #       Included draft of tables and objects  
      22 # 070807 - added object and report_object  
    22 23  
    23 24 # These design notes are intended to explore the problem. They include more than will be  
    24 25 #   implemented in the initial version.  
    25 26  
      27 def DoAdd():  
      28     # Specified all required Report Types and Column Types  
      29     # It will either add them or update them if they already exist.  
      30  
    26 31 #       Report  
      32 #           set it so that data.py won't manage the rows  
      33  
      34 #       Row  
      35 #       - PosX  
      36 #       - PosY  
      37 #       - Moveable # can this object be moved with the mouse  
      38 #       - FollowID  # if this ID is moved, follow it  
      39 #       - EndAID    # this line connects these two objects, follow each end if it is moved  
      40 #       - EndBID  
    27 41  
    28 42 #       ORMObject  
    29 43 #       - ID  
    30 44 #       - ProjectID (Schema)  
    31   #       - Type ['Entry', 'Value']  
      45 #       - Name  
      46 #       - RefMode = identifier used to refer to instances of object  
      47 #       - Type ['Entity', 'Value']  
      48 #       - Independent [None, '!']  
    32 49 #       - Derived [None, '*', '+']  
    33 50 #       - DerivationRule  
    34   #       - Independent [None, '!']  
    35 51  
    36   #       ReportORMObject  
    37   #       - ORMObjectID  # many may point to same  
    38   #       - ReportID  
    39   #       - PosX  
    40   #       - PosY  
      52     rt = { 'Name': 'ORM Diagram', 'TableA': 'ORMObject', 'TableB': None, 'Also': None, 'AllOrEach': 'each',  
      53            'SuggestedColumns': ',ID;,Name' }  
      54     ct = [  
      55     { 'Name': 'ID',           'Label': None,             'DataType': 'i', 'AccessType': 'd', 'T': 'A', 'Edit': False, 'Width': 35  },  
      56     { 'Name': 'Name',         'Label': None,             'DataType': 't', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 100  },  
      57         ]  
      58     Data.AddReportType(rt, ct)  
      59  
      60  
      61     rt = { 'Name': 'ORM Objects', 'TableA': 'ORMObject', 'TableB': None, 'Also': None, 'AllOrEach': 'each',  
      62            'SuggestedColumns': ',ID;,Name;,RefMode;,Type;,Independent;,Derived;,DerivationRule;,DateAdded' }  
      63     ct = [  
      64     { 'Name': 'ProjectID',    'Label': 'Project\nID',    'DataType': 'i', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 50  },  
      65     { 'Name': 'Project/Name', 'Label': 'Project\nName',  'DataType': 't', 'AccessType': 'i', 'T': 'A', 'Edit': False, 'Width': 100  },  
      66     { 'Name': 'ID',           'Label': None,             'DataType': 'i', 'AccessType': 'd', 'T': 'A', 'Edit': False, 'Width': 35  },  
      67     { 'Name': 'Name',         'Label': None,             'DataType': 't', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 100  },  
      68     { 'Name': 'RefMode',      'Label': None,             'DataType': 't', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 100  },  
      69     { 'Name': 'Type',         'Label': None,             'DataType': 't', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 35  },  
      70     { 'Name': 'Independent',  'Label': None,             'DataType': 't', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 75  },  
      71     { 'Name': 'Derived',      'Label': None,             'DataType': 't', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 50  },  
      72     { 'Name': 'DerivationRule',  'Label': None,          'DataType': 't', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 180  },  
      73     { 'Name': 'DateAdded',    'Label': 'Date\nAdded',    'DataType': 'd', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 80  },  
      74         ]  
      75     Data.AddReportType(rt, ct)  
    41 76  
    42 77 #       ORMFact  
     
    49 84 #       - DerivationRule  
    50 85  
    51   #       ReportORMFact  
    52   #       - ORMFactID  # many may point to same  
    53   #       - ReportID  
    54   #       - PosX  
    55   #       - PosY  
      86     rt = { 'Name': 'ORM Facts', 'TableA': 'ORMFact', 'TableB': None, 'Also': None, 'AllOrEach': 'each',  
      87            'SuggestedColumns': ',ID;,Name;,RefMode;,Type;,Independent;,Derived;,DerivationRule;,DateAdded' }  
      88     ct = [  
      89     { 'Name': 'ProjectID',    'Label': 'Project\nID',    'DataType': 'i', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 50  },  
      90     { 'Name': 'Project/Name', 'Label': 'Project\nName',  'DataType': 't', 'AccessType': 'i', 'T': 'A', 'Edit': False, 'Width': 100  },  
      91     { 'Name': 'ID',           'Label': None,             'DataType': 'i', 'AccessType': 'd', 'T': 'A', 'Edit': False, 'Width': 35  },  
      92     { 'Name': 'Name',         'Label': None,             'DataType': 't', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 100  },  
      93     { 'Name': 'Nary',          'Label': None,             'DataType': 'i', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 100  },  
      94     { 'Name': 'ReadingID',     'Label': None,             'DataType': 't', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 35  },  
      95     { 'Name': 'ReadingAltID',  'Label': None,             'DataType': 't', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 75  },  
      96     { 'Name': 'Derived',       'Label': None,             'DataType': 't', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 50  },  
      97     { 'Name': 'DerivationRule',  'Label': None,          'DataType': 't', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 180  },  
      98     { 'Name': 'DateAdded',     'Label': 'Date\nAdded',    'DataType': 'd', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 80  },  
      99         ]  
      100     Data.AddReportType(rt, ct)  
    56 101  
    57   #       ORMRole  
      102 #       ORMReading  (follows the fact, but has it's own X&Y  
      103 #       - ID  
      104 #       - ProjectID (Schema)  
      105 #       - ORMFactID  
      106 #       - Reading  
      107  
      108     rt = { 'Name': 'ORM Reading', 'TableA': 'ORMReading', 'TableB': None, 'Also': None, 'AllOrEach': 'each',  
      109            'SuggestedColumns': ',ID;,FactID;,Reading;,DateAdded' }  
      110     ct = [  
      111     { 'Name': 'ProjectID',     'Label': 'Project\nID',    'DataType': 'i', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 50  },  
      112     { 'Name': 'Project/Name',  'Label': 'Project\nName',  'DataType': 't', 'AccessType': 'i', 'T': 'A', 'Edit': False, 'Width': 100  },  
      113     { 'Name': 'ID',            'Label': None,             'DataType': 'i', 'AccessType': 'd', 'T': 'A', 'Edit': False, 'Width': 35  },  
      114     { 'Name': 'FactID',        'Label': None,             'DataType': 'i', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 100  },  
      115     { 'Name': 'Reading',       'Label': None,             'DataType': 't', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 35  },  
      116     { 'Name': 'DateAdded',     'Label': 'Date\nAdded',    'DataType': 'd', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 80  },  
      117         ]  
      118     Data.AddReportType(rt, ct)  
      119  
      120 #       ORMRole  (the role name can be positioned, but the line end points follow the entities and facts  
    58 121 #       - ID  
    59 122 #       - ProjectID (Schema)  
     
    62 125 #       - Unique ['a', 'd']  
    63 126  
    64   #       ReportORMRole  
    65   #       - ORMRoleID  # many may point to same  
    66   #       - ReportID  
    67   #       - ReportORMFactID       # these determine where to draw the role  
    68   #       - ReportORMObjectID     #  
      127     rt = { 'Name': 'ORM Role', 'TableA': 'ORMRole', 'TableB': None, 'Also': None, 'AllOrEach': 'each',  
      128            'SuggestedColumns': ',ID;,FactID;,Seq;,Name;,DateAdded' }  
      129     ct = [  
      130     { 'Name': 'ProjectID',     'Label': 'Project\nID',    'DataType': 'i', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 50  },  
      131     { 'Name': 'Project/Name',  'Label': 'Project\nName',  'DataType': 't', 'AccessType': 'i', 'T': 'A', 'Edit': False, 'Width': 100  },  
      132     { 'Name': 'ID',            'Label': None,             'DataType': 'i', 'AccessType': 'd', 'T': 'A', 'Edit': False, 'Width': 35  },  
      133     { 'Name': 'FactID',        'Label': None,             'DataType': 'i', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 100  },  
      134     { 'Name': 'Seq',           'Label': None,             'DataType': 'i', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 100  },  
      135     { 'Name': 'Name',          'Label': None,             'DataType': 't', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 35  },  
      136     { 'Name': 'DateAdded',     'Label': 'Date\nAdded',    'DataType': 'd', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 80  },  
      137         ]  
      138     Data.AddReportType(rt, ct)  
    69 139  
    70 140 #       ORMConstraint  
     
    77 147 #       - ORMPathAltID  
    78 148  
    79   #       ReportORMConstraint  
    80   #       - ORMConstraintID  # many may point to same  
    81   #       - ReportID  
    82   #       - PosX  
    83   #       - PosY  
      149     rt = { 'Name': 'ORM Constraint', 'TableA': 'ORMConstraint', 'TableB': None, 'Also': None, 'AllOrEach': 'each',  
      150            'SuggestedColumns': ',ID;,FactID;,Seq;,Name;,DateAdded' }  
      151     ct = [  
      152     { 'Name': 'ProjectID',     'Label': 'Project\nID',    'DataType': 'i', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 50  },  
      153     { 'Name': 'Project/Name',  'Label': 'Project\nName',  'DataType': 't', 'AccessType': 'i', 'T': 'A', 'Edit': False, 'Width': 100  },  
      154     { 'Name': 'ID',            'Label': None,             'DataType': 'i', 'AccessType': 'd', 'T': 'A', 'Edit': False, 'Width': 35  },  
      155     { 'Name': 'Type',          'Label': None,             'DataType': 't', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 35  },  
      156     { 'Name': 'Alethic',       'Label': None,             'DataType': 't', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 35  },  
      157     { 'Name': 'DateAdded',     'Label': 'Date\nAdded',    'DataType': 'd', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 80  },  
      158         ]  
      159     Data.AddReportType(rt, ct)  
    84 160  
    85 161 #       ORMPath  
     
    99 175 #       - Text  
    100 176  
      177 # --------------------------  
      178 #       ReportORMObject  
      179 #       - ORMObjectID  # many may point to same  
      180 #       - ReportID  
      181 #       - PosX  
      182 #       - PosY  
      183  
      184 ### instead of a report object, it might be better just to use the good old report row?  
      185 ##    rt = { 'Name': 'ORM Report Objects', 'TableA': 'ORMReportObject', 'TableB': None, 'Also': None, 'AllOrEach': 'each',  
      186 ##           'SuggestedColumns': ',ReportID;,Report/Name;,ID;,ORMObjectID;,ORMObject/Name;,PosX;,PosY;,DateAdded' }  
      187 ##    ct = [  
      188 ##    { 'Name': 'ProjectID',    'Label': 'Project\nID',    'DataType': 'i', 'AccessType': 'd', 'T': 'A', 'Edit': False, 'Width': 50  },  
      189 ##    { 'Name': 'Project/Name', 'Label': 'Project\nName',  'DataType': 't', 'AccessType': 'i', 'T': 'A', 'Edit': False, 'Width': 100  },  
      190 ##    { 'Name': 'ReportID',     'Label': None,             'DataType': 'i', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 35  },  
      191 ##    { 'Name': 'Report/Name',  'Label': 'Report\nName',   'DataType': 't', 'AccessType': 'i', 'T': 'A', 'Edit': False, 'Width': 100  },  
      192 ##    { 'Name': 'ID',           'Label': None,             'DataType': 'i', 'AccessType': 'd', 'T': 'A', 'Edit': False, 'Width': 35  },  
      193 ##    { 'Name': 'ORMObjectID',  'Label': None,             'DataType': 'i', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 80  },  
      194 ##    { 'Name': 'ORMObject/Name', 'Label': 'ORMObject\nName', 'DataType': 't', 'AccessType': 'i', 'T': 'A', 'Edit': False, 'Width': 100  },  
      195 ##    { 'Name': 'PosX',         'Label': None,             'DataType': 'i', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 35  },  
      196 ##    { 'Name': 'PosY',         'Label': None,             'DataType': 'i', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 35  },  
      197 ##    { 'Name': 'DateAdded',    'Label': 'Date\nAdded',    'DataType': 'd', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 80  },  
      198 ##        ]  
      199 ##    Data.AddReportType(rt, ct)  
      200  
      201 #       ReportORMFact  
      202 #       - ORMFactID  # many may point to same  
      203 #       - ReportID  
      204 #       - PosX  
      205 #       - PosY  
      206  
      207 #       ReportORMRole  
      208 #       - ORMRoleID  # many may point to same  
      209 #       - ReportID  
      210 #       - ReportORMFactID       # these determine where to draw the role  
      211 #       - ReportORMObjectID     #  
      212  
      213 #       ReportORMConstraint  
      214 #       - ORMConstraintID  # many may point to same  
      215 #       - ReportID  
      216 #       - PosX  
      217 #       - PosY  
      218  
    101 219 #       ReportORMNote  
    102 220 #       - ORMNoteID  # many may point to same  
     
    113 231 #    example: "xxDocument", "xxOwner", "xxURL", etc.  
    114 232  
    115   def DoAdd():  
    116   #    global AddReportType, AddTable, AddRow  
    117    
    118       # Specified all required Report Types and Column Types  
    119       # It will either add them or update them if they already exist.  
    120    
    121       rt = { 'Name': 'Project', 'TableA': 'Project', 'TableB': None, 'Also': None, 'AllOrEach': 'all',  
    122              'SuggestedColumns': ',Name;,StartDate;,TargetEndDate;,Week/EffortHours,,13' }  
    123       ct = [  
    124       { 'Name': 'ActualEndDate',       'Label': 'Actual\nEnd Date',   'DataType': 'd', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 80  },  
    125       { 'Name': 'Week/EffortHours',     'Label': 'Week/Effort',       'DataType': 'i', 'AccessType': 's', 'T': 'X', 'Edit': True,  'Width': 40  },  
    126   #    { 'Name': 'Day/EffortHours',      'Label': 'Day/Effort',        'DataType': 'i', 'AccessType': 's', 'T': 'X', 'Edit': True,  'Width': 40  },  
    127           ]  
    128       Data.AddReportType(rt, ct)  
    129    
    130       rt = { 'Name': 'Task', 'TableA': 'Task', 'TableB': None, 'Also': None, 'AllOrEach': 'both',  
    131              'SuggestedColumns': ',Name;,StartDate;,DurationHours;,EffortHours;,CalculatedStartDate;,ResourceNames;,Day/Gantt,,21' }  
    132       ct = [  
    133       { 'Name': 'Project/Name',        'Label': "Project\nName",      'DataType': 'y', 'AccessType': 'i', 'T': 'A', 'Edit': False,  'Width': 140 },  
    134       { 'Name': 'EffortHours',         'Label': 'Effort',             'DataType': 'i', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 60  },  
    135       { 'Name': 'ResourceNames',       'Label': 'Resource\nNames', 'Path': 'ID/Assignment/TaskID/ResourceID/Resource/Name', 'DataType': 't', 'AccessType': 'list', 'T': 'A', 'Edit': False,  'Width': 80  },  
    136       { 'Name': 'ResourcesShortNames', 'Label': 'Resource\nShort Names', 'Path': 'ID/Assignment/TaskID/ResourceID/Resource/ShortName', 'DataType': 't', 'AccessType': 'list', 'T': 'A', 'Edit': False,  'Width': 80  },  
    137       { 'Name': 'ActualEndDate',       'Label': 'Actual\nEnd Date',   'DataType': 'd', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 80  },  
    138       { 'Name': 'Week/EffortHours',     'Label': 'Week/Effort',       'DataType': 'i', 'AccessType': 's', 'T': 'X', 'Edit': True,  'Width': 40  },  
    139       { 'Name': 'Day/EffortHours',      'Label': 'Day/Effort',        'DataType': 'i', 'AccessType': 's', 'T': 'X', 'Edit': True,  'Width': 40  },  
    140           ]  
    141       Data.AddReportType(rt, ct)  
    142    
    143       rt = { 'Name': 'Task/Assignment', 'TableA': 'Task', 'TableB': 'Assignment', 'Also': 'Task', 'AllOrEach': 'each',  
    144              'SuggestedColumns': 'Task,Name;Task,DurationHours;Task,EffortHours;,Resource/Name;,Role;,EffortHours;Task,Day/EffortHours,,21' }  
    145       ct = [  
    146       { 'Name': 'Role',                'Label': 'Role',               'DataType': 't', 'AccessType': 'd', 'T': 'B', 'Edit': True,  'Width': 80  },  
    147       { 'Name': 'EffortHours',         'Label': 'Assignment\nEffort', 'DataType': 'i', 'AccessType': 'd', 'T': 'B', 'Edit': True,  'Width': 80  },  
    148           ]  
    149       Data.AddReportType(rt, ct)  
    150    
    151       rt = { 'Name': 'Resource', 'TableA': 'Resource', 'TableB': None, 'Also': None,  
    152              'SuggestedColumns': ',Name;,Day/EffortHours,,21' }  
    153       ct = [  
    154       { 'Name': 'Week/EffortHours',     'Label': 'Week/Effort',                'DataType': 'i', 'AccessType': 's', 'T': 'X', 'Edit': True,  'Width': 40 },  
    155       { 'Name': 'Day/EffortHours',      'Label': 'Day/Effort',                'DataType': 'i', 'AccessType': 's', 'T': 'X', 'Edit': True,  'Width': 40 },  
    156           ]  
    157       Data.AddReportType(rt, ct)  
    158    
    159       rt = { 'Name': 'Resource/Assignment', 'TableA': 'Resource', 'TableB': 'Assignment', 'Also': 'Resource', 'AllOrEach': 'all',  
    160              'SuggestedColumns': 'Resource,Name;,Task/Name;,Role;,EffortHours;Resource,Day/EffortHours,,21' }   
    161       ct = [  
    162       { 'Name': 'Task/ProjectID',  'Label': 'Project\nID',    'DataType': 'i',  'AccessType': 'i', 'T': 'B', 'Edit': False, 'Width': 60 },  
    163       { 'Name': 'EffortHours',     'Label': 'Assignment\nEffort',         'DataType': 'i', 'AccessType': 'd', 'T': 'B', 'Edit': True,  'Width': 80  },  
    164           ]  
    165       Data.AddReportType(rt, ct)  
    166    
    167   #    rt = { 'Name': 'ProjectResource', 'Label': 'Project Resource', 'TableA': 'ProjectResource', 'TableB': None, 'Also': None, 'AllOrEach': 'both' }  
    168   #    ct = [  
    169   #        { 'Name': 'ID',             'Label': None, 'DataType': 'i',  'AccessType': 'd', 'T': 'A', 'Edit': False, 'Width': 40  },  
    170   #        { 'Name': 'ProjectID',      'Label': 'Project\nID', 'DataType': 'i',  'AccessType': 'd', 'T': 'A', 'Edit': False, 'Width': 80 },  
    171   #        { 'Name': 'Project/Name',   'Label': None, 'DataType': 't',  'AccessType': 'i', 'T': 'A', 'Edit': False, 'Width': 140 },  
    172   #        { 'Name': 'ResourceID',     'Label': 'Resource\nID', 'DataType': 'i',  'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 80 },  
    173   #        { 'Name': 'Resource/Name',  'Label': None, 'DataType': 't',  'AccessType': 'i', 'T': 'A', 'Edit': False, 'Width': 140 },  
    174   #        { 'Name': 'HourlyRate',     'Label': 'Hourly Rate', 'DataType': 'f',  'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 80 },  
    175   #        { 'Name': 'Week/ActualEffortHours',    'Label': 'Week/ActualEffort', 'DataType': 'i',  'AccessType': 's', 'T': 'A', 'Edit': True,  'Width': 80 },  
    176   #        { 'Name': 'Day/ActualEffortHours',     'Label': 'Week/ActualEffort', 'DataType': 'i',  'AccessType': 's', 'T': 'A', 'Edit': True,  'Width': 80 },  
    177   #        ]  
    178   #    Data.AddReportType(rt, ct)  
    179    
    180 233     # add required data tables  
    181       Data.AddTable('ProjectWeek')  
    182       # Data.AddTable('ProjectDay')  
    183       Data.AddTable('TaskWeek')  
    184       Data.AddTable('TaskDay')  
    185       Data.AddTable('ResourceWeek')  
    186       Data.AddTable('ResourceDay')  
    187       Data.AddTable('AssignmentWeek')  
    188       Data.AddTable('AssignmentDay')  
      234 #    Data.AddTable('ProjectWeek')  
    189 235  
    190 236  
    191       Data.SetUndo("Install Assignment Effort Tables")  
      237     Data.SetUndo("Install ORM Tables")  
    191 237  
    192 238 # do only if GanttPV version 0.2 or greater  
  • scripts/trunk/ORM/Open ORM Window.py

    r318 r325  
    3 3 # uses FlagNotebook to control placement of the notebook pages on the screen  
    4 4  
    5   # add a menu bar to the window - change content depending on which pane is active?  
    6   # put a toolbar at the top of each page in the notebooks  
      5 # higher priority  
      6 # 1) add a menu bar to the window - change content depending on which pane is active?  
      7 # 2))put a toolbar at the top of each page in the notebooks  
    7 8 #  steal it from the demo  
    8   # put a status bar at the bottom  
    9   # put popupmenus on the orm drawing canvas - to select different types of objects  
      9 # 3) put a status bar at the bottom  
      10 # 4) put popupmenus on the orm drawing canvas - to select different types of objects  
      11 #       -- partly DONE working for pseudo dc canvas  
      12 # 5) add a pseudo dc window -- DONE  
      13 # 6) put all of the notebook windows into a dynamic sash window??  
      14 #   but there may be problems with the scroll bars??  
      15 #   also, I can't see how to save and restore the subwindow layout  
    10 16  
    11 17 # lower priority  
     
    17 23  
    18 24 # 070806 - First experiments with combining FlatNoteBook and OGL  
      25 # 070807 - Added pseudo dc window  
    19 26  
    20 27 import wx  
     
    22 29 import random  
    23 30 # import images  
      31 import sys  
    24 32  
      33 #  
    25 34 import wx.lib.ogl as ogl  
    26 35 ogl.OGLInitialize()  # affter app object, but before OGL is used  
      36 db = Data._dbDatabase(Data.Database)  # will get objects from this database  
      37  
      38 #---------------------------------------------------------------------------  
      39 # Below here it is OGL  
      40 #---------------------------------------------------------------------------  
    27 41  
    28 42 class DrawnShape(ogl.DrawnShape):  
     
    55 69         # Make sure to call CalculateSize when all drawing is done  
    56 70         self.CalculateSize()  
    57            
      71  
      72  
    58 73 #----------------------------------------------------------------------  
    59 74  
     
    80 95     def __init__(self, w=0.0, h=0.0):  
    81 96         ogl.RectangleShape.__init__(self, w, h)  
    82           self.SetCornerRadius(-0.3)  
      97         self.SetCornerRadius(-0.1)  
    82 97  
    83 98  
     
    361 376             line.Show(True)  
    362 377  
      378 # -- code for popup menu on canvas??? -- This isn't working  
      379         self.Bind(wx.EVT_CONTEXT_MENU, self.OnContextMenu)  
      380  
      381     def OnContextMenu(self, event):  
      382         self.log.WriteText("OnContextMenu\n")  
      383  
      384         # only do this part the first time so the events are only bound once  
      385         #  
      386         # Yet another anternate way to do IDs. Some prefer them up top to  
      387         # avoid clutter, some prefer them close to the object of interest  
      388         # for clarity.  
      389         if not hasattr(self, "popupID1"):  
      390             self.popupID1 = wx.NewId()  
      391             self.popupID2 = wx.NewId()  
      392             self.popupID3 = wx.NewId()  
      393             self.popupID4 = wx.NewId()  
      394             self.popupID5 = wx.NewId()  
      395             self.popupID6 = wx.NewId()  
      396             self.popupID7 = wx.NewId()  
      397             self.popupID8 = wx.NewId()  
      398             self.popupID9 = wx.NewId()  
      399  
      400             self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)  
      401             self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)  
      402             self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)  
      403             self.Bind(wx.EVT_MENU, self.OnPopupFour, id=self.popupID4)  
      404             self.Bind(wx.EVT_MENU, self.OnPopupFive, id=self.popupID5)  
      405             self.Bind(wx.EVT_MENU, self.OnPopupSix, id=self.popupID6)  
      406             self.Bind(wx.EVT_MENU, self.OnPopupSeven, id=self.popupID7)  
      407             self.Bind(wx.EVT_MENU, self.OnPopupEight, id=self.popupID8)  
      408             self.Bind(wx.EVT_MENU, self.OnPopupNine, id=self.popupID9)  
      409  
      410         # make a menu  
      411         menu = wx.Menu()  
      412         # Show how to put an icon in the menu  
      413         item = wx.MenuItem(menu, self.popupID1,"One")  
      414         bmp = images.getSmilesBitmap()  
      415         item.SetBitmap(bmp)  
      416         menu.AppendItem(item)  
      417         # add some other items  
      418         menu.Append(self.popupID2, "Two")  
      419         menu.Append(self.popupID3, "Three")  
      420         menu.Append(self.popupID4, "Four")  
      421         menu.Append(self.popupID5, "Five")  
      422         menu.Append(self.popupID6, "Six")  
      423         # make a submenu  
      424         sm = wx.Menu()  
      425         sm.Append(self.popupID8, "sub item 1")  
      426         sm.Append(self.popupID9, "sub item 1")  
      427         menu.AppendMenu(self.popupID7, "Test Submenu", sm)  
      428  
      429  
      430         # Popup the menu.  If an item is selected then its handler  
      431         # will be called before PopupMenu returns.  
      432         self.PopupMenu(menu)  
      433         menu.Destroy()  
      434  
      435  
      436     def OnPopupOne(self, event):  
      437         self.log.WriteText("Popup one\n")  
      438  
      439     def OnPopupTwo(self, event):  
      440         self.log.WriteText("Popup two\n")  
      441  
      442     def OnPopupThree(self, event):  
      443         self.log.WriteText("Popup three\n")  
      444  
      445     def OnPopupFour(self, event):  
      446         self.log.WriteText("Popup four\n")  
      447  
      448     def OnPopupFive(self, event):  
      449         self.log.WriteText("Popup five\n")  
      450  
      451     def OnPopupSix(self, event):  
      452         self.log.WriteText("Popup six\n")  
      453  
      454     def OnPopupSeven(self, event):  
      455         self.log.WriteText("Popup seven\n")  
      456  
      457     def OnPopupEight(self, event):  
      458         self.log.WriteText("Popup eight\n")  
      459  
      460     def OnPopupNine(self, event):  
      461         self.log.WriteText("Popup nine\n")  
      462 # -- end code for popup menu on canvas??? --  
    363 463  
    364 464     def MyAddShape(self, shape, x, y, pen, brush, text):  
     
    397 497         self.log.write("OnEndDragLeft: %s, %s, %s\n" % (x, y, keys))  
    398 498  
      499 #---------------------------------------------------------------------------  
      500 # Below here it is pseudo dc  
      501 #---------------------------------------------------------------------------  
      502  
      503 W = 2000  
      504 H = 2000  
      505 SW = 150  
      506 SH = 150  
      507 SHAPE_COUNT = 2500  
      508 hitradius = 5  
      509  
      510 #---------------------------------------------------------------------------  
      511  
      512 colours = [  
      513     "BLACK",  
      514     "BLUE",  
      515     "BLUE VIOLET",  
      516     "BROWN",  
      517     "CYAN",  
      518     "DARK GREY",  
      519     "DARK GREEN",  
      520     "GOLD",  
      521     "GREY",  
      522     "GREEN",  
      523     "MAGENTA",  
      524     "NAVY",  
      525     "PINK",  
      526     "RED",  
      527     "SKY BLUE",  
      528     "VIOLET",  
      529     "YELLOW",  
      530     ]  
      531  
      532  
      533  
      534 class MyCanvas(wx.ScrolledWindow):  
      535     def __init__(self, parent, id, log, size = wx.DefaultSize):  
      536         wx.ScrolledWindow.__init__(self, parent, id, (0, 0), size=size, style=wx.SUNKEN_BORDER)  
      537  
      538         self.ReportID = None  
      539         pid = 2  # need to create this  
      540         if not self.ReportID:  
      541             rtid = Data.SearchByColumn(Data.Database['ReportType'], {'Name': 'ORM Diagram'}, unique=True)  
      542             columns = Data.GetSuggestedColumns(rtid)  
      543             report = {'Table': 'Report', 'ReportTypeID': rtid, 'AdjustRowOption': 'ORM Diagram'}  
      544             self.ReportID = Data.AddReport(pid, report, columns)  
      545  
      546         self.lines = []  
      547         self.maxWidth  = W  
      548         self.maxHeight = H  
      549         self.x = self.y = 0  
      550         self.curLine = []  
      551         self.drawing = False  
      552  
      553         self.SetBackgroundColour("WHITE")  
      554         # bmp = images.getTest2Bitmap()  
      555         bmp = Menu.Bitmap("icons/New Project.bmp", wx.BITMAP_TYPE_ANY)  
      556         mask = wx.Mask(bmp, wx.BLUE)  
      557         bmp.SetMask(mask)  
      558         self.bmp = bmp  
      559  
      560         self.SetVirtualSize((self.maxWidth, self.maxHeight))  
      561         self.SetScrollRate(20,20)  
      562          
      563         # create a PseudoDC to record our drawing  
      564         self.pdc = wx.PseudoDC()  
      565         self.pen_cache = {}  
      566         self.brush_cache = {}  
      567         self.DoDrawing(self.pdc)  
      568 #        log.write('Created PseudoDC draw list with %d operations!'%self.pdc.GetLen())  
      569         self.log = log  
      570         self.log.write('Created PseudoDC draw list with %d operations!'%self.pdc.GetLen())  
      571  
      572         self.Bind(wx.EVT_PAINT, self.OnPaint)  
      573         self.Bind(wx.EVT_ERASE_BACKGROUND, lambda x:None)  
      574         self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse)  
      575          
      576         # vars for handling mouse clicks  
      577         self.dragid = -1  
      578         self.lastpos = (0,0)  
      579      
      580 # -- code for popup menu on canvas??? -- This isn't working  
      581         self.Bind(wx.EVT_CONTEXT_MENU, self.OnContextMenu)  
      582  
      583     def OnContextMenu(self, event):  
      584         #self.log = sys.stdout  
      585         #self.log.WriteText("OnContextMenu\n")  
      586  
      587         # only do this part the first time so the events are only bound once  
      588         #  
      589         # Yet another anternate way to do IDs. Some prefer them up top to  
      590         # avoid clutter, some prefer them close to the object of interest  
      591         # for clarity.  
      592         if not hasattr(self, "popupID1"):  
      593             self.popupID1 = wx.NewId()  
      594             self.popupID2 = wx.NewId()  
      595             self.popupID3 = wx.NewId()  
      596             self.popupID4 = wx.NewId()  
      597             self.popupID5 = wx.NewId()  
      598             self.popupID6 = wx.NewId()  
      599             self.popupID7 = wx.NewId()  
      600             self.popupID8 = wx.NewId()  
      601             self.popupID9 = wx.NewId()  
      602  
      603             self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)  
      604             self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)  
      605             self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)  
      606             self.Bind(wx.EVT_MENU, self.OnPopupFour, id=self.popupID4)  
      607             self.Bind(wx.EVT_MENU, self.OnPopupFive, id=self.popupID5)  
      608             self.Bind(wx.EVT_MENU, self.OnPopupSix, id=self.popupID6)  
      609             self.Bind(wx.EVT_MENU, self.OnPopupSeven, id=self.popupID7)  
      610             self.Bind(wx.EVT_MENU, self.OnPopupEight, id=self.popupID8)  
      611             self.Bind(wx.EVT_MENU, self.OnPopupNine, id=self.popupID9)  
      612  
      613         # make a menu  
      614         menu = wx.Menu()  
      615         # Show how to put an icon in the menu  
      616         item = wx.MenuItem(menu, self.popupID1,"One")  
      617 #        bmp = images.getSmilesBitmap()  
      618         bmp = Menu.Bitmap("icons/New Project.bmp", wx.BITMAP_TYPE_ANY)  
      619         item.SetBitmap(bmp)  
      620         menu.AppendItem(item)  
      621         # add some other items  
      622         menu.Append(self.popupID2, "Two")  
      623         menu.Append(self.popupID3, "Three")  
      624         menu.Append(self.popupID4, "Four")  
      625         menu.Append(self.popupID5, "Five")  
      626         menu.Append(self.popupID6, "Six")  
      627         # make a submenu  
      628         sm = wx.Menu()  
      629         sm.Append(self.popupID8, "sub item 1")  
      630         sm.Append(self.popupID9, "sub item 1")  
      631         menu.AppendMenu(self.popupID7, "Test Submenu", sm)  
      632  
      633  
      634         # Popup the menu.  If an item is selected then its handler  
      635         # will be called before PopupMenu returns.  
      636         self.PopupMenu(menu)  
      637         menu.Destroy()  
      638  
      639  
      640     def OnPopupOne(self, event):  
      641         self.log.WriteText("Popup one\n")  
      642  
      643     def OnPopupTwo(self, event):  
      644         self.log.WriteText("Popup two\n")  
      645  
      646     def OnPopupThree(self, event):  
      647         self.log.WriteText("Popup three\n")  
      648  
      649     def OnPopupFour(self, event):  
      650         self.log.WriteText("Popup four\n")  
      651  
      652     def OnPopupFive(self, event):  
      653         self.log.WriteText("Popup five\n")  
      654  
      655     def OnPopupSix(self, event):  
      656         self.log.WriteText("Popup six\n")  
      657  
      658     def OnPopupSeven(self, event):  
      659         self.log.WriteText("Popup seven\n")  
      660  
      661     def OnPopupEight(self, event):  
      662         self.log.WriteText("Popup eight\n")  
      663  
      664     def OnPopupNine(self, event):  
      665         self.log.WriteText("Popup nine\n")  
      666 # -- end code for popup menu on canvas??? --  
      667  
      668     def ConvertEventCoords(self, event):  
      669         xView, yView = self.GetViewStart()  
      670         xDelta, yDelta = self.GetScrollPixelsPerUnit()  
      671         return (event.GetX() + (xView * xDelta),  
      672             event.GetY() + (yView * yDelta))  
      673  
      674     def OffsetRect(self, r):  
      675         xView, yView = self.GetViewStart()  
      676         xDelta, yDelta = self.GetScrollPixelsPerUnit()  
      677         r.OffsetXY(-(xView*xDelta),-(yView*yDelta))  
      678  
      679     def AddEntity(self, x, y):  
      680         # self.ReportID = 5 # get this report's ID from self.something  
      681         projectid = 2 # get this from the report  
      682         today = Data.TodayString()  
      683  
      684         object_type = 'ORMObject'  
      685         model = {'Table': object_type, 'ProjectID': projectid, 'DateAdded': today}  
      686         object_id = Data.Update(model)['ID']  
      687         graphic = {'Table': 'ReportRow', 'ProjectID': projectid, 'Re