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
- additional changes in backend_wx
- additional updates to examples and set them to default to 2.8
  • Loading branch information
wernerfb committed Jan 6, 2014
commit 2751eb98d3c6181bd965ae50091868da8d2035fb
15 changes: 7 additions & 8 deletions examples/user_interfaces/embedding_in_wx2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +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
#wxversion.select('2.9.6-msw-phoenix') # 2.9.x phoenix

from numpy import arange, sin, pi

Expand Down Expand Up @@ -55,7 +55,11 @@ def __init__(self):
self.Fit()

self.add_toolbar() # comment this out for no toolbar

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

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

def add_toolbar(self):
self.toolbar = NavigationToolbar2Wx(self.canvas)
Expand All @@ -81,11 +85,6 @@ def add_toolbar(self):
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
11 changes: 8 additions & 3 deletions examples/user_interfaces/embedding_in_wx3.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +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
#wxversion.select('2.9.6-msw-phoenix') # 2.9.x phoenix

import sys, time, os, gc
import matplotlib
Expand Down Expand Up @@ -67,7 +67,12 @@ def __init__(self, parent):
sizer.Add(self.toolbar, 0, wx.GROW)
self.SetSizer(sizer)
self.Fit()

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

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

def init_plot_data(self):
a = self.fig.add_subplot(111)

Expand Down
4 changes: 2 additions & 2 deletions examples/user_interfaces/embedding_in_wx4.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +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
#wxversion.select('2.9.6-msw-phoenix') # 2.9.x phoenix


from numpy import arange, sin, pi
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
20 changes: 18 additions & 2 deletions examples/user_interfaces/fourier_demo_wx.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import numpy as np
import 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 wx
print wx.VERSION_STRING
import matplotlib
matplotlib.interactive(False)
matplotlib.use('WXAgg')
Expand Down Expand Up @@ -64,7 +73,8 @@ def __init__(self, parent, label, param):
self.sliderLabel = wx.StaticText(parent, label=label)
self.sliderText = wx.TextCtrl(parent, -1, style=wx.TE_PROCESS_ENTER)
self.slider = wx.Slider(parent, -1)
self.slider.SetMax(param.maximum*1000)
#self.slider.SetMax(param.maximum*1000)
self.slider.SetRange(0, param.maximum*1000)
self.setKnob(param.value)

sizer = wx.BoxSizer(wx.HORIZONTAL)
Expand Down Expand Up @@ -133,6 +143,12 @@ def __init__(self, *args, **kwargs):
self.f0.attach(self)
self.A.attach(self)
self.Bind(wx.EVT_SIZE, self.sizeHandler)

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

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

def sizeHandler(self, *args, **kwargs):
self.canvas.SetSize(self.GetSize())
Expand Down
5 changes: 3 additions & 2 deletions examples/user_interfaces/wxcursor_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,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
#wxversion.select('2.9.6-msw-phoenix') # 2.9.x phoenix

import matplotlib
matplotlib.use('WXAgg')
Expand Down Expand Up @@ -50,6 +50,7 @@ def __init__(self, ):

self.statusBar = wx.StatusBar(self, -1)
self.statusBar.SetFieldsCount(1)
self.statusBar.SetStatusWidths([-1])
self.SetStatusBar(self.statusBar)

self.toolbar = NavigationToolbar2Wx(self.figure_canvas)
Expand Down
130 changes: 97 additions & 33 deletions lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,10 @@ def Printer_Setup(self, event=None):
sizerAll.Add(wx.StaticText(dlg,-1,dmsg),
0, wx.ALL | wx.EXPAND, 5)

sizer = wx.FlexGridSizer(0,3)
if 'phoenix' in wx.PlatformInfo:
sizer = wx.FlexGridSizer(rows=0, cols=3, hgap=0, vgap=0)
else:
sizer = wx.FlexGridSizer(0,3)
sizerAll.Add(sizer, 0, wx.ALL | wx.EXPAND, 5)

sizer.Add(wx.StaticText(dlg,-1,'Figure Width'),
Expand Down Expand Up @@ -923,7 +926,10 @@ def Printer_Preview(self, event=None):
po2 = PrintoutWx(self, width=self.printer_width,
margin=self.printer_margin)
self.preview = wx.PrintPreview(po1,po2,self.printerData)
if not self.preview.Ok(): print("error with preview")
if 'phoenix' in wx.PlatformInfo:
if not self.preview.IsOk(): print("error with preview")
else:
if not self.preview.Ok(): print("error with preview")

self.preview.SetZoom(50)
frameInst= self
Expand Down Expand Up @@ -1052,7 +1058,7 @@ def start_event_loop(self, timeout=0):

# Event loop handler for start/stop event loop
if 'phoenix' in wx.PlatformInfo:
self.event_loop = wx.GUIEventLoop()
self._event_loop = wx.GUIEventLoop()
else:
self._event_loop = wx.EventLoop()
self._event_loop.Run()
Expand Down Expand Up @@ -1712,10 +1718,20 @@ def Destroy(self):

def _onMenuButton(self, evt):
"""Handle menu button pressed."""
x, y = self.GetPositionTuple()
w, h = self.GetSizeTuple()
self.PopupMenuXY(self._menu, x, y+h-4)
# When menu returned, indicate selection in button

if 'phoenix' in wx.PlatformInfo:
x, y = self.GetPosition()
w, h = self.GetSize()
else:
x, y = self.GetPositionTuple()
w, h = self.GetSizeTuple()

if 'phoenix' in wx.PlatformInfo:
self.PopupMenu(self._menu, x, y+h-4)
else:
self.PopupMenuXY(self._menu, x, y+h-4)
# When menu returned, indicate selection in button

evt.Skip()

def _handleSelectAllAxes(self, evt):
Expand Down Expand Up @@ -1869,27 +1885,39 @@ def configure_subplots(self, evt):
frame = wx.Frame(None, -1, "Configure subplots")

toolfig = Figure((6,3))
canvas = self.get_canvas(frame, toolfig)
self.canvas = self.get_canvas(frame, toolfig)

# Create a figure manager to manage things
figmgr = FigureManager(canvas, 1, frame)
figmgr = FigureManager(self.canvas, 1, frame)

# Now put all into a sizer
sizer = wx.BoxSizer(wx.VERTICAL)
# This way of adding to sizer allows resizing
sizer.Add(canvas, 1, wx.LEFT|wx.TOP|wx.GROW)
sizer.Add(self.canvas, 1, wx.LEFT|wx.TOP|wx.GROW)
frame.SetSizer(sizer)
frame.Fit()
tool = SubplotTool(self.canvas.figure, toolfig)
frame.Bind(wx.EVT_PAINT, self.OnPaint)

frame.Show()

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

def save_figure(self, *args):
# Fetch the required filename and file type.
filetypes, exts, filter_index = self.canvas._get_imagesave_wildcards()
default_file = self.canvas.get_default_filename()
if 'phoenix' in wx.PlatformInfo:
fdStyle = wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT
else:
fdStyle = wx.SAVE|wx.OVERWRITE_PROMPT

dlg = wx.FileDialog(self._parent, "Save to file", "", default_file,
filetypes,
wx.SAVE|wx.OVERWRITE_PROMPT)
fdStyle)

dlg.SetFilterIndex(filter_index)
if dlg.ShowModal() == wx.ID_OK:
dirname = dlg.GetDirectory()
Expand Down Expand Up @@ -2025,27 +2053,60 @@ def _create_controls(self, can_kill):
# Need the following line as Windows toolbars default to 15x16

self.SetToolBitmapSize(wx.Size(16,16))
self.AddSimpleTool(_NTB_X_PAN_LEFT, _load_bitmap('stock_left.xpm'),
'Left', 'Scroll left')
self.AddSimpleTool(_NTB_X_PAN_RIGHT, _load_bitmap('stock_right.xpm'),
'Right', 'Scroll right')
self.AddSimpleTool(_NTB_X_ZOOMIN, _load_bitmap('stock_zoom-in.xpm'),
'Zoom in', 'Increase X axis magnification')
self.AddSimpleTool(_NTB_X_ZOOMOUT, _load_bitmap('stock_zoom-out.xpm'),
'Zoom out', 'Decrease X axis magnification')
self.AddSeparator()
self.AddSimpleTool(_NTB_Y_PAN_UP,_load_bitmap('stock_up.xpm'),
'Up', 'Scroll up')
self.AddSimpleTool(_NTB_Y_PAN_DOWN, _load_bitmap('stock_down.xpm'),
'Down', 'Scroll down')
self.AddSimpleTool(_NTB_Y_ZOOMIN, _load_bitmap('stock_zoom-in.xpm'),
'Zoom in', 'Increase Y axis magnification')
self.AddSimpleTool(_NTB_Y_ZOOMOUT, _load_bitmap('stock_zoom-out.xpm'),
'Zoom out', 'Decrease Y axis magnification')
self.AddSeparator()
self.AddSimpleTool(_NTB_SAVE, _load_bitmap('stock_save_as.xpm'),
'Save', 'Save plot contents as images')
self.AddSeparator()
if 'phoenix' in wx.PlatformInfo:
self.AddTool(_NTB_X_PAN_LEFT, 'Left',
_load_bitmap('stock_left.xpm'),
'Scroll left')
self.AddTool(_NTB_X_PAN_RIGHT, 'Right',
_load_bitmap('stock_right.xpm'),
'Scroll right')
self.AddTool(_NTB_X_ZOOMIN, 'Zoom in',
_load_bitmap('stock_zoom-in.xpm'),
'Increase X axis magnification')
self.AddTool(_NTB_X_ZOOMOUT, 'Zoom out',
_load_bitmap('stock_zoom-out.xpm'),
'Decrease X axis magnification')
self.AddSeparator()
self.AddTool(_NTB_Y_PAN_UP, 'Up',
_load_bitmap('stock_up.xpm'),
'Scroll up')
self.AddTool(_NTB_Y_PAN_DOWN, 'Down',
_load_bitmap('stock_down.xpm'),
'Scroll down')
self.AddTool(_NTB_Y_ZOOMIN, 'Zoom in',
_load_bitmap('stock_zoom-in.xpm'),
'Increase Y axis magnification')
self.AddTool(_NTB_Y_ZOOMOUT, 'Zoom out',
_load_bitmap('stock_zoom-out.xpm'),
'Decrease Y axis magnification')
self.AddSeparator()
self.AddTool(_NTB_SAVE, 'Save',
_load_bitmap('stock_save_as.xpm'),
'Save plot contents as images')
self.AddSeparator()

else:
self.AddSimpleTool(_NTB_X_PAN_LEFT, _load_bitmap('stock_left.xpm'),
'Left', 'Scroll left')
self.AddSimpleTool(_NTB_X_PAN_RIGHT, _load_bitmap('stock_right.xpm'),
'Right', 'Scroll right')
self.AddSimpleTool(_NTB_X_ZOOMIN, _load_bitmap('stock_zoom-in.xpm'),
'Zoom in', 'Increase X axis magnification')
self.AddSimpleTool(_NTB_X_ZOOMOUT, _load_bitmap('stock_zoom-out.xpm'),
'Zoom out', 'Decrease X axis magnification')
self.AddSeparator()
self.AddSimpleTool(_NTB_Y_PAN_UP,_load_bitmap('stock_up.xpm'),
'Up', 'Scroll up')
self.AddSimpleTool(_NTB_Y_PAN_DOWN, _load_bitmap('stock_down.xpm'),
'Down', 'Scroll down')
self.AddSimpleTool(_NTB_Y_ZOOMIN, _load_bitmap('stock_zoom-in.xpm'),
'Zoom in', 'Increase Y axis magnification')
self.AddSimpleTool(_NTB_Y_ZOOMOUT, _load_bitmap('stock_zoom-out.xpm'),
'Zoom out', 'Decrease Y axis magnification')
self.AddSeparator()
self.AddSimpleTool(_NTB_SAVE, _load_bitmap('stock_save_as.xpm'),
'Save', 'Save plot contents as images')
self.AddSeparator()

bind(self, wx.EVT_TOOL, self._onLeftScroll, id=_NTB_X_PAN_LEFT)
bind(self, wx.EVT_TOOL, self._onRightScroll, id=_NTB_X_PAN_RIGHT)
Expand Down Expand Up @@ -2229,7 +2290,10 @@ def OnPrintPage(self, page):
(ppw,pph) = self.GetPPIPrinter() # printer's pixels per in
(pgw,pgh) = self.GetPageSizePixels() # page size in pixels
(dcw,dch) = dc.GetSize()
(grw,grh) = self.canvas.GetSizeTuple()
if 'phoenix' in wx.PlatformInfo:
(grw,grh) = self.canvas.GetSize()
else:
(grw,grh) = self.canvas.GetSizeTuple()

# save current figure dpi resolution and bg color,
# so that we can temporarily set them to the dpi of
Expand Down