Skip to content

- wxPython Phoenix #1995

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

Closed
wants to merge 10 commits into from
Prev Previous commit
Next Next commit
- adapt other wx backend demos to support classic and phoenix
  • Loading branch information
wernerfb committed Jan 6, 2014
commit 96b5654f528056a5a140baca46e3efceb735e9e5
24 changes: 18 additions & 6 deletions examples/user_interfaces/embedding_in_wx2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

# Used to guarantee to use at least Wx2.8
import wxversion
wxversion.ensureMinimal('2.8')
#wxversion.ensureMinimal('2.8')
#wxversion.select('2.8')
#wxversion.select('2.9.5') # 2.9.x classic
wxversion.select('2.9.6-msw-phoenix') # 2.9.x phoenix

from numpy import arange, sin, pi

Expand All @@ -25,14 +28,18 @@
from matplotlib.figure import Figure

import wx
print wx.VERSION_STRING

class CanvasFrame(wx.Frame):

def __init__(self):
wx.Frame.__init__(self,None,-1,
'CanvasFrame',size=(550,350))

self.SetBackgroundColour(wx.NamedColour("WHITE"))
if 'phoenix' in wx.PlatformInfo:
self.SetBackgroundColour(wx.Colour("WHITE"))
else:
self.SetBackgroundColour(wx.NamedColour("WHITE"))

self.figure = Figure()
self.axes = self.figure.add_subplot(111)
Expand Down Expand Up @@ -61,19 +68,24 @@ def add_toolbar(self):
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()
if 'phoenix' in wx.PlatformInfo:
tw, th = self.toolbar.GetSize()
fw, fh = self.canvas.GetSize()
else:
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)
# update the axes menu on the toolbar
self.toolbar.update()


self.Bind(wx.EVT_PAINT, self.OnPaint)
def OnPaint(self, event):
self.canvas.draw()
event.Skip()

class App(wx.App):

Expand Down
24 changes: 19 additions & 5 deletions examples/user_interfaces/embedding_in_wx3.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@

# Used to guarantee to use at least Wx2.8
import wxversion
wxversion.ensureMinimal('2.8')
#wxversion.ensureMinimal('2.8')
#wxversion.select('2.8')
#wxversion.select('2.9.5') # 2.9.x classic
wxversion.select('2.9.6-msw-phoenix') # 2.9.x phoenix

import sys, time, os, gc
import matplotlib
Expand All @@ -35,6 +38,9 @@
import numpy as np

import wx

print(wx.VERSION_STRING)

import wx.xrc as xrc

ERR_TOL = 1e-5 # floating point slop for peak-detection
Expand Down Expand Up @@ -132,14 +138,22 @@ def OnInit(self):
# whiz button ------------------

whiz_button = xrc.XRCCTRL(self.frame,"whiz_button")
wx.EVT_BUTTON(whiz_button, whiz_button.GetId(),
self.plotpanel.OnWhiz)

if 'phoenix' in wx.PlatformInfo:
whiz_button.Bind(wx.EVT_BUTTON, self.plotpanel.OnWhiz)
else:
wx.EVT_BUTTON(whiz_button, whiz_button.GetId(),
self.plotpanel.OnWhiz)

# bang button ------------------

bang_button = xrc.XRCCTRL(self.frame,"bang_button")
wx.EVT_BUTTON(bang_button, bang_button.GetId(),
self.OnBang)
if 'phoenix' in wx.PlatformInfo:
bang_button.Bind(wx.EVT_BUTTON, self.OnBang)

else:
wx.EVT_BUTTON(bang_button, bang_button.GetId(),
self.OnBang)

# final setup ------------------

Expand Down
33 changes: 25 additions & 8 deletions examples/user_interfaces/embedding_in_wx4.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

# Used to guarantee to use at least Wx2.8
import wxversion
wxversion.ensureMinimal('2.8')
#wxversion.ensureMinimal('2.8')
#wxversion.select('2.8')
#wxversion.select('2.9.5') # 2.9.x classic
wxversion.select('2.9.6-msw-phoenix') # 2.9.x phoenix


from numpy import arange, sin, pi

Expand All @@ -32,9 +36,15 @@ def __init__(self, canvas, cankill):

# for simplicity I'm going to reuse a bitmap from wx, you'll
# probably want to add your own.
self.AddSimpleTool(self.ON_CUSTOM, _load_bitmap('stock_left.xpm'),
'Click me', 'Activate custom contol')
wx.EVT_TOOL(self, self.ON_CUSTOM, self._on_custom)
if 'phoenix' in wx.PlatformInfo:
self.AddTool(self.ON_CUSTOM, 'Click me',
_load_bitmap('stock_left.xpm'),
'Activate custom contol')
self.Bind(wx.EVT_TOOL, self._on_custom, id=self.ON_CUSTOM)
else:
self.AddSimpleTool(self.ON_CUSTOM, _load_bitmap('stock_left.xpm'),
'Click me', 'Activate custom contol')
wx.EVT_TOOL(self, self.ON_CUSTOM, self._on_custom)

def _on_custom(self, evt):
# add some text to the axes in a random location in axes (0,1)
Expand All @@ -61,7 +71,10 @@ def __init__(self):
wx.Frame.__init__(self,None,-1,
'CanvasFrame',size=(550,350))

self.SetBackgroundColour(wx.NamedColour("WHITE"))
if 'phoenix' in wx.PlatformInfo:
self.SetBackgroundColour(wx.Colour("WHITE"))
else:
self.SetBackgroundColour(wx.NamedColour("WHITE"))

self.figure = Figure(figsize=(5,4), dpi=100)
self.axes = self.figure.add_subplot(111)
Expand All @@ -75,7 +88,7 @@ def __init__(self):
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.canvas, 1, wx.TOP | wx.LEFT | wx.EXPAND)
# Capture the paint message
wx.EVT_PAINT(self, self.OnPaint)
self.Bind(wx.EVT_PAINT, self.OnPaint)

self.toolbar = MyNavigationToolbar(self.canvas, True)
self.toolbar.Realize()
Expand All @@ -87,8 +100,12 @@ def __init__(self):
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()
if 'phoenix' in wx.PlatformInfo:
tw, th = self.toolbar.GetSize()
fw, fh = self.canvas.GetSize()
else:
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.
Expand Down
4 changes: 2 additions & 2 deletions examples/user_interfaces/embedding_in_wx5.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Used to guarantee to use at least Wx2.8
import wxversion
wxversion.ensureMinimal('2.8')
#wxversion.ensureMinimal('2.8')
#wxversion.select('2.8')
#wxversion.select('2.9.5') # 2.9.x classic
#wxversion.select('2.9.6-msw-phoenix') # 2.9.x phoenix
wxversion.select('2.9.6-msw-phoenix') # 2.9.x phoenix


import wx
Expand Down
25 changes: 21 additions & 4 deletions examples/user_interfaces/wxcursor_demo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
"""
Example to draw a cursor and report the data coords in wx
"""
# Used to guarantee to use at least Wx2.8
import wxversion
#wxversion.ensureMinimal('2.8')
#wxversion.select('2.8')
#wxversion.select('2.9.5') # 2.9.x classic
wxversion.select('2.9.6-msw-phoenix') # 2.9.x phoenix

import matplotlib
matplotlib.use('WXAgg')
Expand All @@ -11,14 +17,17 @@
from numpy import arange, sin, pi

import wx
print wx.VERSION_STRING

class CanvasFrame(wx.Frame):

def __init__(self, ):
wx.Frame.__init__(self,None,-1,
'CanvasFrame',size=(550,350))

self.SetBackgroundColour(wx.NamedColour("WHITE"))
if 'phoenix' in wx.PlatformInfo:
self.SetBackgroundColour(wx.Colour("WHITE"))
else:
self.SetBackgroundColour(wx.NamedColour("WHITE"))

self.figure = Figure()
self.axes = self.figure.add_subplot(111)
Expand Down Expand Up @@ -46,9 +55,17 @@ def __init__(self, ):
self.toolbar = NavigationToolbar2Wx(self.figure_canvas)
self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
self.toolbar.Show()

self.Bind(wx.EVT_PAINT, self.OnPaint)

def OnPaint(self, event):
self.figure_canvas.draw()
event.Skip()

def ChangeCursor(self, event):
self.figure_canvas.SetCursor(wx.StockCursor(wx.CURSOR_BULLSEYE))
if 'phoenix' in wx.PlatformInfo:
self.figure_canvas.SetCursor(wx.Cursor(wx.CURSOR_BULLSEYE))
else:
self.figure_canvas.SetCursor(wx.StockCursor(wx.CURSOR_BULLSEYE))

def UpdateStatusBar(self, event):
if event.inaxes:
Expand Down