#PTB: All true and false were changed to True and False
#PTB: was from wxPython.wx import *
import wx
if wx.Platform == '__WXMSW__':
        #PTB: from wxPython.lib.activexwrapper import MakeActiveXClass
        from wx.lib.activexwrapper import MakeActiveXClass
        import _OfficeWebComp11

        try:
                OWCModule = _OfficeWebComp11
        except:
                raise ImportError("Could not import Office Web Components")


"""
OWCChartWrapper provides a means to relatively straightforwardly display
plotted information by using the chart ActiveX control which forms part of
the Microsoft Office Web Controls to display chart data.

This file imports a wrapper generated by makepy.py, a tools for generating
Python wrappers to COM objects. The wrapper was copied from
c:\Python22\Lib\site-packages\win32com\gen_py (which is where makepy puts it,
under the name of the COM object class ID) and given a more sensible name.

DO NOT edit _OfficeWebComponents.py - it's a generated file.

This module was tested against Office 2000 Web Components, but should probably
work with newer versions of the components. You will need a license for Office
which matches the version of the Web Components you are using, or this won't
work.
"""

class lineChartPanel(wx.Panel): #PTB: was wxPanel
        def __init__(self, parent):
                #PTB: was wxPanel.__init__(self, parent, -1, style=wxCLIP_CHILDREN|wxNO_FULL_REPAINT_ON_RESIZE)
                wx.Panel.__init__(self, parent, -1, style=wx.CLIP_CHILDREN|wx.NO_FULL_REPAINT_ON_RESIZE)

                # Create a class encapsulating the Office Web Components chart control
                cChart = MakeActiveXClass(OWCModule.ChartSpace, eventObj = self)

                # Create a local instance of the Chart Class
                self.oChart = cChart(self, -1)

                # Create an alias for the control properties
                self.c = self.oChart.Constants
                self.oChart.Charts.Add()
                #oChart.Charts[0].Type = c.chChartTypeSmoothLine
                self.series_data = {}

                # Sizer and so on...
                """
                PTB: was
                sizer = wxBoxSizer(wxVERTICAL)
                sizer.Add(self.oChart, 1, wxEXPAND)
                """
                sizer = wx.BoxSizer(wx.VERTICAL)
                sizer.Add(self.oChart, 1, wx.EXPAND)
                self.SetSizer(sizer)
                self.SetAutoLayout(True)
                """
                PTB: was
                EVT_SIZE(self, self.onSize)
                EVT_WINDOW_DESTROY(self, self.onDestroy)
                """
                wx.EVT_SIZE(self, self.onSize)
                wx.EVT_WINDOW_DESTROY(self, self.onDestroy)

        def onDestroy(self, evt):
                if self.oChart:
                        self.oChart.Cleanup()
                        self.oChart = None

        def onSize(self, evt):
                self.Layout()

        def setCaption(self, chart_type, caption):
                """Set the chart caption"""
                self.oChart.Charts[0].Type = chart_type
                self.oChart.Charts[0].HasTitle = True
                self.oChart.Charts[0].Title.Caption   = caption
                self.oChart.Charts[0].Title.Font.Name = "Helvetica"
                self.oChart.Charts[0].Title.Font.Size = 12
                self.oChart.Charts[0].Title.Font.Bold = True

        def setAxis(self, axis, text, major, minor):
                if axis == 'X':
                        position = self.c.chAxisPositionBottom
                else:
                        position = self.c.chAxisPositionLeft
                self.oChart.Charts[0].Axes(position).HasTitle = True
                self.oChart.Charts[0].Axes(position).Title.Caption = text
                self.oChart.Charts[0].Axes(position).Title.Font.Size = 8
                self.oChart.Charts[0].Axes(position).MajorUnit = major
                self.oChart.Charts[0].Axes(position).MinorUnit = minor

        def addDataSet(self, set_name, data_list):
                """Add a category, with its data, to the chart."""
                self.series_data[set_name] = data_list

        def finaliseChartData(self):
                """Once all data has been defined, insert all of the data sets."""
                ordered_keys = self.series_data.keys()
                ordered_keys.sort()
                self.oChart.Charts[0].SeriesCollection.Add()
                self.oChart.Charts[0].SeriesCollection[0].SetData(self.c.chDimCategories,
                                                                      self.c.chDataLiteral,
                                                                                                                  ordered_keys)
                b = [self.series_data[k] for k in ordered_keys]
                self.oChart.Charts[0].SeriesCollection[0].SetData(self.c.chDimValues,
                                                                  self.c.chDataLiteral,
                                                                                                                  b)

#----------------------------------------------------------------------


if __name__ == '__main__':
        class TestFrame(wx.Frame): #PTB: was wxFrame
                def __init__(self):
                        #PTB was wxFrame
                        wx.Frame.__init__(self, None, -1, "ActiveX test -- Internet Explorer",
                             size=(640, 480),style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
                        #PTB was style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
                        self.CreateStatusBar()
                        self.tp = lineChartPanel(self)
                        self.tp.setCaption(self.tp.c.chChartTypeSmoothLine, 'Test')
                        self.tp.addDataSet(1, 6)
                        self.tp.addDataSet(2, 8)
                        self.tp.addDataSet(3, 10)
                        self.tp.addDataSet(4, 12)
                        self.tp.addDataSet(5, 14)
                        self.tp.addDataSet(6, 16)
                        self.tp.finaliseChartData()
                        #PTB was EVT_CLOSE(self, self.OnCloseWindow)
                        wx.EVT_CLOSE(self, self.OnCloseWindow)

                def OnCloseWindow(self, evt):
                        self.tp.Destroy()
                        self.Destroy()

        app = wx.PySimpleApp() #PTB: was app = wxPySimpleApp
        frame = TestFrame()
        frame.Show(True)
        app.MainLoop()
