From ce00fc06a5f778860f6dbb4db2273b54a813e997 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 10 Aug 2016 10:48:54 -0700 Subject: [PATCH] * Slight refactoring in wx/lib/plot/examples/demo.py * Add a __init__.py * Update the PyPlot sample in the main wxPython demo to use the new plot demo --- demo/PyPlot.py | 108 +++++++------------------------ wx/lib/plot/examples/__init__.py | 0 wx/lib/plot/examples/demo.py | 17 +++-- 3 files changed, 31 insertions(+), 94 deletions(-) create mode 100644 wx/lib/plot/examples/__init__.py diff --git a/demo/PyPlot.py b/demo/PyPlot.py index a5758302..442b896e 100644 --- a/demo/PyPlot.py +++ b/demo/PyPlot.py @@ -1,24 +1,23 @@ -#!/usr/bin/env python import wx hadImportError = False try: + import numpy import wx.lib.plot except ImportError: hadImportError = True -################################################################\ -# Where's the code??? | -# | -# wx.lib.plot.py came with its own excellent demo built in, | -# for testing purposes, but it serves quite well to demonstrate | -# the code and classes within, so we are simply borrowing that | -# code for the demo. Please load up wx.lib.plot.py for a review | -# of the code itself. The demo/test is at the bottom of | -# the file, as expected. | -################################################################/ +############################################################################# +# Where's the code??? +# +# The wx.lib.plot package comes with its own excellent demo built in, for +# testing purposes, but it serves quite well to demonstrate the code and +# classes within, so we are simply importing and using that code for this +# sample in the wxPython demo. Please load up wx/lib/plot/examples/demo.py +# for a review of the demo code itself. +############################################################################# #--------------------------------------------------------------------------- @@ -32,7 +31,8 @@ class TestPanel(wx.Panel): def OnButton(self, evt): - win = wx.lib.plot.TestFrame(self, -1, "PlotCanvas Demo") + from wx.lib.plot.examples.demo import PlotDemoMainFrame + win = PlotDemoMainFrame(self, -1, "wx.lib.plot Demo") win.Show() #--------------------------------------------------------------------------- @@ -44,12 +44,10 @@ def runTest(frame, nb, log): else: from wx.lib.msgpanel import MessagePanel win = MessagePanel(nb, """\ -This demo requires the Numeric or numarray module, -which could not be imported. It probably is not installed -(it's not part of the standard Python distribution). See the -Python site (http://www.python.org) for information on -downloading source or binaries.""", - 'Sorry', wx.ICON_WARNING) +This demo requires the numpy module, which could not be imported. +It probably is not installed (it's not part of the standard Python +distribution). See https://pypi.python.org/pypi/numpy for information +about the numpy package.""", 'Sorry', wx.ICON_WARNING) return win @@ -63,79 +61,19 @@ else:

PyPlot

-This demo illustrates the features of the new PyPlot modules, found -in wx.lib.plot.py. All methods and functions are documented clearly -therein; only the overview is included here. +This demo illustrates the features of the PyPlot modules, found +in the wx.lib.plot package.

-PyPlot is an improvement over wxPlotCanvas, which is now deprecated. -If you are using wxPlotCanvas now, please make plans to migrate in -anticipation of the time that wxPlotCanvas disappears completely. - -

-The demo illustrates four different plot styles (with appropriate +The demo illustrates several different plot styles (with appropriate variations on fonts, etc, to show how flexible it is) as well as provides you with a means to tinker with all the features that -come with the class itself. +come with the class itself. Be sure to explore the options in the +Plot and Options menus to explore some of the capabilities of this +plotting package. -

- -
-%s
-""" % wx.lib.plot.__doc__ +""" if __name__ == '__main__': diff --git a/wx/lib/plot/examples/__init__.py b/wx/lib/plot/examples/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/wx/lib/plot/examples/demo.py b/wx/lib/plot/examples/demo.py index bcca212c..b483b157 100644 --- a/wx/lib/plot/examples/demo.py +++ b/wx/lib/plot/examples/demo.py @@ -300,19 +300,15 @@ def _draw10Objects(): # --------------------------------------------------------------------------- ### Demo Application # --------------------------------------------------------------------------- -class DemoApp(object): +class PlotDemoApp(object): def __init__(self): self.app = wx.App() - self.frame = MainFrame(None, -1, "PlotCanvas") + self.frame = PlotDemoMainFrame(None, -1, "PlotCanvas") self.frame.Show(True) - wx.CallAfter(wx.MessageBox, - "Various plot types can be shown using the Plot menu. " + - "Check out the Options menu too.", - "wx.lib.plot Demo") self.app.MainLoop() -class MainFrame(wx.Frame): +class PlotDemoMainFrame(wx.Frame): # ----------------------------------------------------------------------- ### UI Initialization # ----------------------------------------------------------------------- @@ -342,7 +338,10 @@ class MainFrame(wx.Frame): # Show closest point when enabled self.client.canvas.Bind(wx.EVT_MOTION, self.OnMotion) - self.Show(True) + wx.CallAfter(wx.MessageBox, + "Various plot types can be shown using the Plot menu. " + + "Check out the Options menu too.", + "wx.lib.plot Demo") def _init_file_menu(self): @@ -979,7 +978,7 @@ def run_demo(): """ Run the :mod:`wx.lib.plot` demo application. """ - DemoApp() + PlotDemoApp() if __name__ == '__main__':