-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
make wx backends compatible with wxPython-Phoenix #3421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
758f826
91c4296
ba2fce5
ad6a712
12cf540
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
wx backend has been updated | ||
--------------------------- | ||
The wx backend can now be used with both wxPython classic and | ||
`Phoenix <http://wxpython.org/Phoenix/docs/html/main.html>`__. | ||
|
||
wxPython classic has to be at least version 2.8.12 and works on Python 2.x. As | ||
of May 2015 no official release of wxPython Phoenix is available but a | ||
current snapshot will work on Python 2.7+ and 3.4+. | ||
|
||
If you have multiple versions of wxPython installed, then the user code is | ||
responsible setting the wxPython version. How to do this is | ||
explained in the comment at the beginning of the example | ||
`examples\user_interfaces\embedding_in_wx2.py`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,11 @@ | |
toolbar - comment out the setA_toolbar line for no toolbar | ||
""" | ||
|
||
# Used to guarantee to use at least Wx2.8 | ||
import wxversion | ||
wxversion.ensureMinimal('2.8') | ||
# matplotlib requires wxPython 2.8+ | ||
# set the wxPython version in lib\site-packages\wx.pth file | ||
# or if you have wxversion installed un-comment the lines below | ||
#import wxversion | ||
#wxversion.ensureMinimal('2.8') | ||
|
||
from numpy import arange, sin, pi | ||
|
||
|
@@ -25,25 +27,24 @@ | |
from matplotlib.figure import Figure | ||
|
||
import wx | ||
import wx.lib.mixins.inspection as WIT | ||
|
||
|
||
class CanvasFrame(wx.Frame): | ||
def __init__(self): | ||
wx.Frame.__init__(self, None, -1, | ||
'CanvasFrame', size=(550, 350)) | ||
|
||
self.SetBackgroundColour(wx.NamedColour("WHITE")) | ||
|
||
self.figure = Figure() | ||
self.axes = self.figure.add_subplot(111) | ||
t = arange(0.0, 3.0, 0.01) | ||
s = sin(2*pi*t) | ||
s = sin(2 * pi * t) | ||
|
||
self.axes.plot(t, s) | ||
self.canvas = FigureCanvas(self, -1, self.figure) | ||
|
||
self.sizer = wx.BoxSizer(wx.VERTICAL) | ||
self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) | ||
self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.EXPAND) | ||
self.SetSizer(self.sizer) | ||
self.Fit() | ||
|
||
|
@@ -52,31 +53,19 @@ def __init__(self): | |
def add_toolbar(self): | ||
self.toolbar = NavigationToolbar2Wx(self.canvas) | ||
self.toolbar.Realize() | ||
if wx.Platform == '__WXMAC__': | ||
# Mac platform (OSX 10.3, MacPython) does not seem to cope with | ||
# having a toolbar in a sizer. This work-around gets the buttons | ||
# back, but at the expense of having the toolbar at the top | ||
self.SetToolBar(self.toolbar) | ||
else: | ||
# On Windows platform, default window size is incorrect, so set | ||
# toolbar width to figure width. | ||
tw, th = self.toolbar.GetSizeTuple() | ||
fw, fh = self.canvas.GetSizeTuple() | ||
# By adding toolbar in sizer, we are able to put it at the bottom | ||
# of the frame - so appearance is closer to GTK version. | ||
# As noted above, doesn't work for Mac. | ||
self.toolbar.SetSize(wx.Size(fw, th)) | ||
self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND) | ||
# By adding toolbar in sizer, we are able to put it at the bottom | ||
# of the frame - so appearance is closer to GTK version. | ||
self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND) | ||
# update the axes menu on the toolbar | ||
self.toolbar.update() | ||
|
||
def OnPaint(self, event): | ||
self.canvas.draw() | ||
|
||
|
||
class App(wx.App): | ||
# alternatively you could use | ||
#class App(wx.App): | ||
class App(WIT.InspectableApp): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is new to me. Is this what wx users are supposed to use now? I want to make sure I get this right for my book that I am about to publish. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On 12/5/2014 16:42, Benjamin Root wrote:
so it should be the above or: class App(wx.App): but no longer use wx.PySimpleApp. Werner |
||
def OnInit(self): | ||
'Create the main window and insert the custom frame' | ||
self.Init() | ||
frame = CanvasFrame() | ||
frame.Show(True) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
# Used to guarantee to use at least Wx2.8 | ||
import wxversion | ||
wxversion.ensureMinimal('2.8') | ||
#!/usr/bin/env python | ||
|
||
# matplotlib requires wxPython 2.8+ | ||
# set the wxPython version in lib\site-packages\wx.pth file | ||
# or if you have wxversion installed un-comment the lines below | ||
#import wxversion | ||
#wxversion.ensureMinimal('2.8') | ||
|
||
import wx | ||
import wx.aui | ||
import wx.lib.mixins.inspection as wit | ||
|
||
if 'phoenix' in wx.PlatformInfo: | ||
import wx.lib.agw.aui as aui | ||
else: | ||
import wx.aui as aui | ||
|
||
import matplotlib as mpl | ||
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas | ||
from matplotlib.backends.backend_wxagg import NavigationToolbar2Wx as Toolbar | ||
|
@@ -26,7 +36,7 @@ def __init__(self, parent, id=-1, dpi=None, **kwargs): | |
class PlotNotebook(wx.Panel): | ||
def __init__(self, parent, id=-1): | ||
wx.Panel.__init__(self, parent, id=id) | ||
self.nb = wx.aui.AuiNotebook(self) | ||
self.nb = aui.AuiNotebook(self) | ||
sizer = wx.BoxSizer() | ||
sizer.Add(self.nb, 1, wx.EXPAND) | ||
self.SetSizer(sizer) | ||
|
@@ -38,15 +48,17 @@ def add(self, name="plot"): | |
|
||
|
||
def demo(): | ||
app = wx.PySimpleApp() | ||
# alternatively you could use | ||
#app = wx.App() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment might need more explanation. As it stands, the user is left wondering what the difference is. |
||
# InspectableApp is a great debug tool, see: | ||
# http://wiki.wxpython.org/Widget%20Inspection%20Tool | ||
app = wit.InspectableApp() | ||
frame = wx.Frame(None, -1, 'Plotter') | ||
plotter = PlotNotebook(frame) | ||
axes1 = plotter.add('figure 1').gca() | ||
axes1.plot([1, 2, 3], [2, 1, 4]) | ||
axes2 = plotter.add('figure 2').gca() | ||
axes2.plot([1, 2, 3, 4, 5], [2, 1, 4, 2, 3]) | ||
#axes1.figure.canvas.draw() | ||
#axes2.figure.canvas.draw() | ||
frame.Show() | ||
app.MainLoop() | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By removing these checks, are you saying that the bug they work around are no longer in effect for wx v2.8 and above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On 12/5/2014 16:40, Benjamin Root wrote:
Werner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will test this again, but yes this is no longer relevant.