Python Reference Guide
 
Loading...
Searching...
No Matches
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
12from pyfbsdk import *
13from pyfbsdk_additions import *
14
15def 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
18def 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
38def 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.GetColumn(0).Caption = "Integer"
51 s.GetColumn(0).Style = FBCellStyle.kFBCellStyleInteger
52
53 s.ColumnAdd("Col 2")
54 s.GetColumn(1).Caption = "Float"
55 s.GetColumn(1).Style = FBCellStyle.kFBCellStyleDouble
56
57 s.ColumnAdd("Col 3")
58 s.GetColumn(2).Caption = "Description"
59
60 s.RowAdd("Pi", 0)
61 s.RowAdd("Infinite", 1)
62 s.RowAdd("Zero", 2)
63
64 s.OnCellChange.Add(OnSpreadEvent)
65 s.OnRowClick.Add(OnSpreadEvent)
66 s.OnColumnClick.Add(OnSpreadEvent)
67 s.OnDragAndDrop.Add(OnDragAndDrop)
68
69 # set some initial values:
70 s.SetCellValue(0, 0, 3)
71 s.SetCellValue(0, 1, 3.1416)
72 s.SetCellValue(0, 2, "Pi = 3.1416")
73
74
75 # For this particular cell, set it as a string cell, even if the column is for ints
76 c = s.GetSpreadCell(1,0)
77 c.Style = FBCellStyle.kFBCellStyleString
78 c.Justify = FBTextJustify.kFBTextJustifyCenter
79 s.SetCellValue(1, 0, "N/A")
80
81 # For this particular cell, set it as a string cell, even if the column is for floats
82 c = s.GetSpreadCell(1,1)
83 c.Style = FBCellStyle.kFBCellStyleString
84 c.Justify = FBTextJustify.kFBTextJustifyCenter
85 s.SetCellValue(1, 1, "N/A")
86
87 s.SetCellValue(1, 2, "Infinite")
88
89
90 s.SetCellValue(2, 2, "Zero = 0")
91
92
93def CreateTool():
94 # Tool creation will serve as the hub for all other controls
95 t = FBCreateUniqueTool("Spread Example")
96 t.StartSizeX = 900
97 t.StartSizeY = 400
98 PopulateLayout(t)
99 ShowTool(t)
100
101
102CreateTool()
Base spreadsheet class.
Definition: pyfbsdk_generated.h:17486
Python built-in string class.
Definition: pyfbsdk.h:77