Attachment 'OWC_test.py'
Download 1 #PTB: All true and false were changed to True and False
2 #PTB: was from wxPython.wx import *
3 import wx
4 if wx.Platform == '__WXMSW__':
5 #PTB: from wxPython.lib.activexwrapper import MakeActiveXClass
6 from wx.lib.activexwrapper import MakeActiveXClass
7 import _OfficeWebComp11
8
9 try:
10 OWCModule = _OfficeWebComp11
11 except:
12 raise ImportError("Could not import Office Web Components")
13
14
15 """
16 OWCChartWrapper provides a means to relatively straightforwardly display
17 plotted information by using the chart ActiveX control which forms part of
18 the Microsoft Office Web Controls to display chart data.
19
20 This file imports a wrapper generated by makepy.py, a tools for generating
21 Python wrappers to COM objects. The wrapper was copied from
22 c:\Python22\Lib\site-packages\win32com\gen_py (which is where makepy puts it,
23 under the name of the COM object class ID) and given a more sensible name.
24
25 DO NOT edit _OfficeWebComponents.py - it's a generated file.
26
27 This module was tested against Office 2000 Web Components, but should probably
28 work with newer versions of the components. You will need a license for Office
29 which matches the version of the Web Components you are using, or this won't
30 work.
31 """
32
33 class lineChartPanel(wx.Panel): #PTB: was wxPanel
34 def __init__(self, parent):
35 #PTB: was wxPanel.__init__(self, parent, -1, style=wxCLIP_CHILDREN|wxNO_FULL_REPAINT_ON_RESIZE)
36 wx.Panel.__init__(self, parent, -1, style=wx.CLIP_CHILDREN|wx.NO_FULL_REPAINT_ON_RESIZE)
37
38 # Create a class encapsulating the Office Web Components chart control
39 cChart = MakeActiveXClass(OWCModule.ChartSpace, eventObj = self)
40
41 # Create a local instance of the Chart Class
42 self.oChart = cChart(self, -1)
43
44 # Create an alias for the control properties
45 self.c = self.oChart.Constants
46 self.oChart.Charts.Add()
47 #oChart.Charts[0].Type = c.chChartTypeSmoothLine
48 self.series_data = {}
49
50 # Sizer and so on...
51 """
52 PTB: was
53 sizer = wxBoxSizer(wxVERTICAL)
54 sizer.Add(self.oChart, 1, wxEXPAND)
55 """
56 sizer = wx.BoxSizer(wx.VERTICAL)
57 sizer.Add(self.oChart, 1, wx.EXPAND)
58 self.SetSizer(sizer)
59 self.SetAutoLayout(True)
60 """
61 PTB: was
62 EVT_SIZE(self, self.onSize)
63 EVT_WINDOW_DESTROY(self, self.onDestroy)
64 """
65 wx.EVT_SIZE(self, self.onSize)
66 wx.EVT_WINDOW_DESTROY(self, self.onDestroy)
67
68 def onDestroy(self, evt):
69 if self.oChart:
70 self.oChart.Cleanup()
71 self.oChart = None
72
73 def onSize(self, evt):
74 self.Layout()
75
76 def setCaption(self, chart_type, caption):
77 """Set the chart caption"""
78 self.oChart.Charts[0].Type = chart_type
79 self.oChart.Charts[0].HasTitle = True
80 self.oChart.Charts[0].Title.Caption = caption
81 self.oChart.Charts[0].Title.Font.Name = "Helvetica"
82 self.oChart.Charts[0].Title.Font.Size = 12
83 self.oChart.Charts[0].Title.Font.Bold = True
84
85 def setAxis(self, axis, text, major, minor):
86 if axis == 'X':
87 position = self.c.chAxisPositionBottom
88 else:
89 position = self.c.chAxisPositionLeft
90 self.oChart.Charts[0].Axes(position).HasTitle = True
91 self.oChart.Charts[0].Axes(position).Title.Caption = text
92 self.oChart.Charts[0].Axes(position).Title.Font.Size = 8
93 self.oChart.Charts[0].Axes(position).MajorUnit = major
94 self.oChart.Charts[0].Axes(position).MinorUnit = minor
95
96 def addDataSet(self, set_name, data_list):
97 """Add a category, with its data, to the chart."""
98 self.series_data[set_name] = data_list
99
100 def finaliseChartData(self):
101 """Once all data has been defined, insert all of the data sets."""
102 ordered_keys = self.series_data.keys()
103 ordered_keys.sort()
104 self.oChart.Charts[0].SeriesCollection.Add()
105 self.oChart.Charts[0].SeriesCollection[0].SetData(self.c.chDimCategories,
106 self.c.chDataLiteral,
107 ordered_keys)
108 b = [self.series_data[k] for k in ordered_keys]
109 self.oChart.Charts[0].SeriesCollection[0].SetData(self.c.chDimValues,
110 self.c.chDataLiteral,
111 b)
112
113 #----------------------------------------------------------------------
114
115
116 if __name__ == '__main__':
117 class TestFrame(wx.Frame): #PTB: was wxFrame
118 def __init__(self):
119 #PTB was wxFrame
120 wx.Frame.__init__(self, None, -1, "ActiveX test -- Internet Explorer",
121 size=(640, 480),style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
122 #PTB was style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
123 self.CreateStatusBar()
124 self.tp = lineChartPanel(self)
125 self.tp.setCaption(self.tp.c.chChartTypeSmoothLine, 'Test')
126 self.tp.addDataSet(1, 6)
127 self.tp.addDataSet(2, 8)
128 self.tp.addDataSet(3, 10)
129 self.tp.addDataSet(4, 12)
130 self.tp.addDataSet(5, 14)
131 self.tp.addDataSet(6, 16)
132 self.tp.finaliseChartData()
133 #PTB was EVT_CLOSE(self, self.OnCloseWindow)
134 wx.EVT_CLOSE(self, self.OnCloseWindow)
135
136 def OnCloseWindow(self, evt):
137 self.tp.Destroy()
138 self.Destroy()
139
140 app = wx.PySimpleApp() #PTB: was app = wxPySimpleApp
141 frame = TestFrame()
142 frame.Show(True)
143 app.MainLoop()
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.