UI/Spread.py

UI/Spread.py
1 # Copyright 2009 Autodesk, Inc. All rights reserved.
2 # Use of this software is subject to the terms of the Autodesk license agreement
3 # provided at the time of installation or download, or which otherwise accompanies
4 # this software in either electronic or hard copy form.
5 #
6 # Script description:
7 # Create a tool with a Spread showing how to modify column name and adding datas.
8 #
9 # Topic: FBSpread,FBDragAndDropState
10 #
11 
12 from pyfbsdk import *
13 from pyfbsdk_additions import *
14 
15 def OnSpreadEvent(control, event):
16  print "Type:%s, Action %d, Row:%d, Column:%d Value: %s" % (event.Type, event.Action, event.Row, event.Column, str(control.GetCellValue(event.Row, event.Column)))
17 
18 def OnDragAndDrop(control, event):
19  """
20  DragAndDropEvent documentation:
21  Accept (): Accept a drag and drop sequence.
22  Add (FBComponent pComponent, int pId=0): Add an item to the drag and drop list.
23  Clear (): Clear drag and drop list.
24  Get (int pIndex): Get the FBComponent specified by pIndex from the Drag and Drop list.
25  GetCount (): Get the number of items in the DragAndDrop list.
26 
27  Data: Property: User specified reference. (for example, FBSpread:row)
28  PosX: Property: X position of mouse.
29  PosY: Property: Y position of mouse.
30  State: Property: Drag and drop sub-event.
31  components: list of dragged components
32  """
33  if event.State == FBDragAndDropState.kFBDragAndDropDrag:
34  event.Accept()
35  print "Type:%s, State%d, PosX:%d, PosY:%d, NbElements:%d" % (event.Type, event.State, event.PosX, event.PosY, event.GetCount())
36 
37 
38 def PopulateLayout(mainLyt):
39  x = FBAddRegionParam(0,FBAttachType.kFBAttachLeft,"")
40  y = FBAddRegionParam(0,FBAttachType.kFBAttachTop,"")
41  w = FBAddRegionParam(0,FBAttachType.kFBAttachRight,"")
42  h = FBAddRegionParam(0,FBAttachType.kFBAttachBottom,"")
43  mainLyt.AddRegion("main","main", x, y, w, h)
44 
45  s = FBSpread()
46  s.Caption = "Spread"
47  mainLyt.SetControl("main",s)
48 
49  s.ColumnAdd("Col 1")
50  s.ColumnAdd("Col 2")
51  s.ColumnAdd("Col 3")
52 
53  s.RowAdd("Row 1", 0)
54  s.RowAdd("Row 2", 1)
55  s.RowAdd("Row 3", 2)
56 
57  s.OnCellChange.Add(OnSpreadEvent)
58  s.OnRowClick.Add(OnSpreadEvent)
59  s.OnColumnClick.Add(OnSpreadEvent)
60  s.OnDragAndDrop.Add(OnDragAndDrop)
61 
62  c = s.GetColumn(0)
63  c.Caption = "first column"
64 
65  # set some initial values:
66  s.SetCellValue(0, 0, 3)
67  s.SetCellValue(0, 1, 3.1416)
68  s.SetCellValue(0, 2, "py = 3.1416")
69 
70 def CreateTool():
71  # Tool creation will serve as the hub for all other controls
72  t = FBCreateUniqueTool("Spread Example")
73  t.StartSizeX = 900
74  t.StartSizeY = 400
75  PopulateLayout(t)
76  ShowTool(t)
77 
78 
79 CreateTool()