def BindEvents(self):
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_ERASE_BACKGROUND, lambda e: None)
self.Bind(wx.EVT_RIGHT_DOWN, self.OnButtonDown)
self.Bind(wx.EVT_LEFT_DOWN, self.OnButtonDown)
self.Bind(wx.EVT_MIDDLE_DOWN, self.OnButtonDown)
self.Bind(wx.EVT_RIGHT_UP, self.OnButtonUp)
self.Bind(wx.EVT_LEFT_UP, self.OnButtonUp)
self.Bind(wx.EVT_MIDDLE_UP, self.OnButtonUp)
self.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheel)
self.Bind(wx.EVT_MOTION, self.OnMotion)
self.Bind(wx.EVT_ENTER_WINDOW, self.OnEnter)
self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave)
self.Bind(wx.EVT_CHAR, self.OnKeyDown)
self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
if wx.Platform == "__WXGTK__":
# wxGTK requires that the window be created before you can
# set its shape, so delay the call to SetWindowShape until
# this event.
self.Bind(wx.EVT_WINDOW_CREATE, self.OnWindowCreate)
else:
# On wxMSW and wxMac the window has already been created.
self.Bind(wx.EVT_SIZE, self.OnSize)
if _useCapture and hasattr(wx, 'EVT_MOUSE_CAPTURE_LOST'):
self.Bind(wx.EVT_MOUSE_CAPTURE_LOST, self.OnMouseCaptureLost)
python类EVT_SIZE的实例源码
wxPython_Wallpaper.py 文件源码
项目:Python-GUI-Programming-Cookbook-Second-Edition
作者: PacktPublishing
项目源码
文件源码
阅读 19
收藏 0
点赞 0
评论 0
def __init__(self, parent):
wx.Panel.__init__(self, parent)
imageFile = 'Tile.bmp'
self.bmp = wx.Bitmap(imageFile)
# react to a resize event and redraw image
parent.Bind(wx.EVT_SIZE, self.canvasCallback)
menu = wx.Menu()
menu.Append(wx.ID_ABOUT, "About", "wxPython GUI")
menu.AppendSeparator()
menu.Append(wx.ID_EXIT, "Exit", " Exit the GUI")
menuBar = wx.MenuBar()
menuBar.Append(menu, "File")
parent.SetMenuBar(menuBar)
self.textWidget = wx.TextCtrl(self, size=(280, 80), style=wx.TE_MULTILINE)
button = wx.Button(self, label="Create OpenGL 3D Cube", pos=(60, 100))
self.Bind(wx.EVT_BUTTON, self.buttonCallback, button)
parent.CreateStatusBar()
def createWidgets(self):
self.listCtrl = wxskinListCtrl(self, ID_LISTCTRL, style=wx.LC_REPORT|wx.SUNKEN_BORDER|wx.LC_SINGLE_SEL|wx.LC_VRULES|wx.LC_HRULES)
self.listCtrl.InsertColumn(0, "Name")
self.listCtrl.InsertColumn(1, "Number")
ColumnSorterMixin.__init__(self, 2)
self.currentItem = 0
wx.EVT_SIZE(self, self.OnSize)
wx.EVT_LIST_ITEM_SELECTED(self, ID_LISTCTRL, self.OnItemSelected)
wx.EVT_LIST_ITEM_ACTIVATED(self, ID_LISTCTRL, self.OnItemActivated)
wx.EVT_CLOSE(self, self.closeWindow)
wx.EVT_LEFT_DCLICK(self.listCtrl, self.OnPopupEdit)
wx.EVT_RIGHT_DOWN(self.listCtrl, self.OnRightDown)
# for wxMSW and wxGTK respectively
wx.EVT_COMMAND_RIGHT_CLICK(self.listCtrl, ID_LISTCTRL, self.OnRightClick)
wx.EVT_RIGHT_UP(self.listCtrl, self.OnRightClick)
def createWidgets(self):
self.listCtrl = wxskinListCtrl(self, ID_LISTCTRL, style=wx.LC_REPORT|wx.SUNKEN_BORDER|wx.LC_SINGLE_SEL|wx.LC_VRULES|wx.LC_HRULES)
self.listCtrl.InsertColumn(0, "Name")
self.listCtrl.InsertColumn(1, "Number")
ColumnSorterMixin.__init__(self, 2)
self.currentItem = 0
wx.EVT_SIZE(self, self.OnSize)
wx.EVT_LIST_ITEM_SELECTED(self, ID_LISTCTRL, self.OnItemSelected)
wx.EVT_LIST_ITEM_ACTIVATED(self, ID_LISTCTRL, self.OnItemActivated)
wx.EVT_CLOSE(self, self.closeWindow)
wx.EVT_LEFT_DCLICK(self.listCtrl, self.OnPopupEdit)
wx.EVT_RIGHT_DOWN(self.listCtrl, self.OnRightDown)
# for wxMSW and wxGTK respectively
wx.EVT_COMMAND_RIGHT_CLICK(self.listCtrl, ID_LISTCTRL, self.OnRightClick)
wx.EVT_RIGHT_UP(self.listCtrl, self.OnRightClick)
def createWidgets(self):
self.listCtrl = wxskinListCtrl(self, ID_LISTCTRL, style=wx.LC_REPORT|wx.SUNKEN_BORDER|wx.LC_SINGLE_SEL|wx.LC_VRULES|wx.LC_HRULES)
self.listCtrl.InsertColumn(COL_STATUS, "Status")
self.listCtrl.InsertColumn(COL_DATE, "Date")
self.listCtrl.InsertColumn(COL_FROM, "From")
self.listCtrl.InsertColumn(COL_MESSAGE, "Message")
ColumnSorterMixin.__init__(self, 4)
self.currentItem = 0
wx.EVT_SIZE(self, self.OnSize)
wx.EVT_LIST_ITEM_SELECTED(self, ID_LISTCTRL, self.OnItemSelected)
wx.EVT_LIST_ITEM_ACTIVATED(self, ID_LISTCTRL, self.OnItemActivated)
wx.EVT_RIGHT_DOWN(self.listCtrl, self.OnRightDown)
wx.EVT_LEFT_DCLICK(self.listCtrl, self.OnPopupEdit)
wx.EVT_CLOSE(self, self.closeWindow)
# for wxMSW and wxGTK respectively
wx.EVT_COMMAND_RIGHT_CLICK(self.listCtrl, ID_LISTCTRL, self.OnRightClick)
wx.EVT_RIGHT_UP(self.listCtrl, self.OnRightClick)
def __init__(self, parent, id=wx.ID_ANY, style=wx.ST_SIZEGRIP,
name="EnhancedStatusBar"):
"""Default Class Constructor.
EnhancedStatusBar.__init__(self, parent, id=wx.ID_ANY,
style=wx.ST_SIZEGRIP,
name="EnhancedStatusBar")
"""
wx.StatusBar.__init__(self, parent, id, style, name)
self._items = {}
self._curPos = 0
self._parent = parent
wx.EVT_SIZE(self, self.OnSize)
wx.CallAfter(self.OnSize, None)
def __init__(self, parent,**kwargs):
wx.Panel.__init__(self,parent,**kwargs)
self.parent = parent
self.figure = matplotlib.figure.Figure()
self.canvas = wxaggb.FigureCanvasWxAgg(self, -1, self.figure)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
self.Bind(wx.EVT_SIZE, self.sizeHandler)
# canvas is your canvas, and root is your parent (Frame, TopLevel, Tk instance etc.)
#self.zoomhandle = wxaggb.NavigationToolbar2WxAgg(self.canvas)
#self.toolbar = wxb.NavigationToolbar2Wx(self.canvas)
#self.toolbar.Realize()
#self.toolbar.update()
self.cmap = matplotlib.cm.RdYlBu_r
def __init__(self,title):
super(Frame,self).__init__(None,-1,title,style=wx.DEFAULT_FRAME_STYLE^wx.MAXIMIZE_BOX^wx.RESIZE_BORDER)
self.colors = {0:(204,192,179),2:(238, 228, 218),4:(237, 224, 200),8:(242, 177, 121),16:(245, 149, 99),32:(246, 124, 95),64:(246, 94, 59),128:(237, 207, 114),256:(237, 207, 114),512:(237, 207, 114),1024:(237, 207, 114),2048:(237, 207, 114),4096:(237, 207, 114),8192:(237, 207, 114),16384:(237, 207, 114),32768:(237, 207, 114),65536:(237, 207, 114),131072:(237, 207, 114),262144:(237, 207, 114),524288:(237, 207, 114),1048576:(237, 207, 114),2097152:(237, 207, 114),4194304:(237, 207, 114),8388608:(237, 207, 114),16777216:(237, 207, 114)}#?????????
self.setIcon()
self.initGame()
self.initBuffer()
panel = wx.Panel(self) #??????
#------????
panel.Bind(wx.EVT_KEY_DOWN,self.onKeyDown)
panel.SetFocus() #?????
self.Bind(wx.EVT_SIZE,self.onSize) #use wx.BufferedPaintDC
self.Bind(wx.EVT_PAINT,self.onPaint)
self.Bind(wx.EVT_CLOSE,self.onClose) #????
#------
self.SetClientSize((505,720)) #??????
self.Center() #?????
self.Show()
def __init__(self, parent):
wx.Control.__init__(self, parent)
main_sizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=0)
main_sizer.AddGrowableCol(0)
main_sizer.AddGrowableRow(0)
# create location text control
self.Location = wx.TextCtrl(self, size=wx.Size(0, -1),
style=wx.TE_PROCESS_ENTER)
self.Location.Bind(wx.EVT_KEY_DOWN, self.OnLocationChar)
main_sizer.AddWindow(self.Location, flag=wx.GROW)
# create browse button
self.BrowseButton = wx.Button(self, label='...', size=wx.Size(30, -1))
self.BrowseButton.Bind(wx.EVT_BUTTON, self.OnBrowseButtonClick)
main_sizer.AddWindow(self.BrowseButton, flag=wx.GROW)
self.Bind(wx.EVT_SIZE, self.OnSize)
self.SetSizer(main_sizer)
self.Controller = None
self.VarType = None
self.Default = False
def __init__(self, parent):
wx.Control.__init__(self, parent)
main_sizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=0)
main_sizer.AddGrowableCol(0)
main_sizer.AddGrowableRow(0)
# create location text control
self.Duration = wx.TextCtrl(self, size=wx.Size(0, -1),
style=wx.TE_PROCESS_ENTER)
self.Duration.Bind(wx.EVT_KEY_DOWN, self.OnDurationChar)
main_sizer.AddWindow(self.Duration, flag=wx.GROW)
# create browse button
self.EditButton = wx.Button(self, label='...', size=wx.Size(30, -1))
self.Bind(wx.EVT_BUTTON, self.OnEditButtonClick, self.EditButton)
main_sizer.AddWindow(self.EditButton, flag=wx.GROW)
self.Bind(wx.EVT_SIZE, self.OnSize)
self.SetSizer(main_sizer)
self.Default = None
def __init__(self, parent, id=wx.ID_ANY, style=wx.ST_SIZEGRIP,
name="EnhancedStatusBar"):
"""Default Class Constructor.
EnhancedStatusBar.__init__(self, parent, id=wx.ID_ANY,
style=wx.ST_SIZEGRIP,
name="EnhancedStatusBar")
"""
wx.StatusBar.__init__(self, parent, id, style, name)
self._items = {}
self._curPos = 0
self._parent = parent
wx.EVT_SIZE(self, self.OnSize)
wx.CallAfter(self.OnSize, None)
def __init__(self, parent, manager=None):
attribList = attribs = (glcanvas.WX_GL_RGBA, glcanvas.WX_GL_DOUBLEBUFFER, glcanvas.WX_GL_DEPTH_SIZE, 24)
glcanvas.GLCanvas.__init__(self, parent, -1, attribList=attribList)
self.init = False
self.context = glcanvas.GLContext(self)
self.manager = self.manager = Manager() if manager is None else manager
self.size = None
self.SetBackgroundStyle(wx.BG_STYLE_PAINT)
self.Bind(wx.EVT_SIZE, self.OnSize)
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_LEFT_DOWN, self.OnMouseDown)
self.Bind(wx.EVT_LEFT_UP, self.OnMouseUp)
self.Bind(wx.EVT_MOTION, self.OnMouseMotion)
self.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheel)
self.lastx, self.lasty = None, None
self.update = True
#print('init===========')
def __init__(self, *args, **kwds):
# begin wxGlade: help_window.__init__
kwds["style"] = wx.MAXIMIZE | wx.CLOSE_BOX | wx.THICK_FRAME|wx.CAPTION
wx.Dialog.__init__(self, *args, **kwds)
self.window_1 = wx.SplitterWindow(self, wx.ID_ANY, style=wx.SP_3D | wx.SP_BORDER)
self.window_1_pane_left = wx.Panel(self.window_1, wx.ID_ANY)
self.html_left = html.HtmlWindow(self.window_1_pane_left, wx.ID_ANY, size=(1, 1))
self.window_1_pane_right = wx.Panel(self.window_1, wx.ID_ANY)
self.html_right = html.HtmlWindow(self.window_1_pane_right, wx.ID_ANY, size=(1, 1))
#self.Bind(wx.EVT_COself.on_hyperlink,self.html_left)
self.Bind(wx.html.EVT_HTML_LINK_CLICKED,self.on_hyperlink,self.html_left)
#self.Bind(wx.EVT_SIZE,self.on_resize)
self.__set_properties()
self.__do_layout()
#self.on_resize(None)
self.load_htmlpage()
# end wxGlade
def __init__(self):
wx.ScrolledWindow.__init__(self)
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_SIZE, self.OnResized)
self.Bind(wx.EVT_SCROLLWIN, self.OnScrolled)
# OnCreate required to avoid crashing wx in xrc creation
self.Bind(wx.EVT_WINDOW_CREATE, self.OnCreate)
# Disable physical scrolling - refresh entire display on each scroll event.
self.EnableScrolling(False, False)
# This line enables double-buffered painting for reduced flicker.
self.SetBackgroundStyle(wx.BG_STYLE_PAINT)
# The previous scroll action (for maintaining viewport during resizes).
self.prev_scroll = None
self.layout = HexViewLayout()
def __init__(self, controller_uid):
TopLevel.__init__(self, controller_uid)
UIM = UIManager()
controller = UIM.get(self._controller_uid)
wx.Dialog.__init__(self, None, wx.ID_ANY, controller.model.title,
pos=controller.model.pos, size=controller.model.size,
style=controller.model.style
)
self._objects = {}
if controller.model.icon:
self.icon = wx.Icon(controller.model.icon, wx.BITMAP_TYPE_ICO)
self.SetIcon(self.icon)
if controller.model.maximized:
self.Maximize()
self.Bind(wx.EVT_MAXIMIZE, self.on_maximize)
self.Bind(wx.EVT_SIZE, self.on_size)
self.Bind(wx.EVT_MOVE, self.on_move)
dialog_box = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(dialog_box)
self.mainpanel = self.AddCreateContainer('BoxSizer', self, proportion=1,
flag=wx.TOP|wx.LEFT|wx.RIGHT|wx.EXPAND, border=10
)
button_sizer = self.CreateButtonSizer(controller.model.flags)
dialog_box.Add(button_sizer, flag=wx.ALIGN_CENTER|wx.TOP|wx.BOTTOM, border=10)
dialog_box.Layout()
def _SizeComponent(self):
#print '_SizeComponent'
if not self._windows:
self.SetSize([0, self.GetSize().GetHeight()])
# #print ' self.SetSize([{}, {}])'.format(0, self.GetSize().GetHeight())
#self.Unbind(wx.EVT_SIZE)
elif self._GetFit():
self.SetSize([self.GetParent().GetClientSize().GetWidth(),
self.GetSize().GetHeight()])
else:
soma = self._LarguraUtil()
soma += self._border_size
soma += len(self.get_windows_shown()) * self._sash_size
self.SetSize([soma, self.GetSize().GetHeight()])
# #print ' self.SetSize([{}, {}])'.format(soma, self.GetSize().GetHeight())
#self.Bind(wx.EVT_SIZE, self._OnSize)
self._SizeWindows()
wxPython_Wallpaper.py 文件源码
项目:Python-GUI-Programming-Cookbook-Second-Edition
作者: PacktPublishing
项目源码
文件源码
阅读 21
收藏 0
点赞 0
评论 0
def __init__(self, parent):
glcanvas.GLCanvas.__init__(self, parent, -1)
self.context = glcanvas.GLContext(self)
self.init = False
# Cube 3D start rotation
self.last_X = self.x = 30
self.last_Y = self.y = 30
self.Bind(wx.EVT_SIZE, self.sizeCallback)
self.Bind(wx.EVT_PAINT, self.paintCallback)
self.Bind(wx.EVT_LEFT_DOWN, self.mouseDownCallback)
self.Bind(wx.EVT_LEFT_UP, self.mouseUpCallback)
self.Bind(wx.EVT_MOTION, self.mouseMotionCallback)
wxPython_OpenGL_GUI.py 文件源码
项目:Python-GUI-Programming-Cookbook-Second-Edition
作者: PacktPublishing
项目源码
文件源码
阅读 21
收藏 0
点赞 0
评论 0
def __init__(self, parent):
glcanvas.GLCanvas.__init__(self, parent, -1)
self.context = glcanvas.GLContext(self)
self.init = False
# Cube 3D start rotation
self.last_X = self.x = 30
self.last_Y = self.y = 30
self.Bind(wx.EVT_SIZE, self.sizeCallback)
self.Bind(wx.EVT_PAINT, self.paintCallback)
self.Bind(wx.EVT_LEFT_DOWN, self.mouseDownCallback)
self.Bind(wx.EVT_LEFT_UP, self.mouseUpCallback)
self.Bind(wx.EVT_MOTION, self.mouseMotionCallback)
import_OpenGL_cube_and_cone.py 文件源码
项目:Python-GUI-Programming-Cookbook-Second-Edition
作者: PacktPublishing
项目源码
文件源码
阅读 19
收藏 0
点赞 0
评论 0
def __init__(self, parent):
glcanvas.GLCanvas.__init__(self, parent, -1)
self.init = False
self.context = glcanvas.GLContext(self) # <== this was missing when I wrote the book in 2015...
# initial mouse position
self.lastx = self.x = 30
self.lasty = self.y = 30
self.size = None
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
self.Bind(wx.EVT_SIZE, self.OnSize)
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_LEFT_DOWN, self.OnMouseDown)
self.Bind(wx.EVT_LEFT_UP, self.OnMouseUp)
self.Bind(wx.EVT_MOTION, self.OnMouseMotion)
wxPython_Wallpaper_simple.py 文件源码
项目:Python-GUI-Programming-Cookbook-Second-Edition
作者: PacktPublishing
项目源码
文件源码
阅读 24
收藏 0
点赞 0
评论 0
def __init__(self, parent):
glcanvas.GLCanvas.__init__(self, parent, -1)
self.context = glcanvas.GLContext(self)
self.init = False
# Cube 3D start rotation
self.last_X = self.x = 30
self.last_Y = self.y = 30
self.Bind(wx.EVT_SIZE, self.sizeCallback)
self.Bind(wx.EVT_PAINT, self.paintCallback)
self.Bind(wx.EVT_LEFT_DOWN, self.mouseDownCallback)
self.Bind(wx.EVT_LEFT_UP, self.mouseUpCallback)
self.Bind(wx.EVT_MOTION, self.mouseMotionCallback)
def __init__(self, parent, obj=None, mouse_callback=None, select_callback=None):
wx.Panel.__init__(self, parent)
self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_LEFT_DOWN, self.OnMouseDown)
self.Bind(wx.EVT_LEFT_UP, self.OnMouseUp)
self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
self.Bind(wx.EVT_RIGHT_UP, self.OnMouseUp)
self.Bind(wx.EVT_MOTION, self.OnMotion)
self.Bind(wx.EVT_SIZE, self.OnSize)
self.refresh_from_selection = False
self.background_bitmap = None
self.obj = obj
self.selstart = self.selend = self.movepos = None
self.moveSelection = False
self.createSelection = False
self.begin = 0
if self.obj is not None:
self.chnls = len(self.obj)
self.end = self.obj.getDur(False)
else:
self.chnls = 1
self.end = 1.0
self.img = [[]]
self.mouse_callback = mouse_callback
self.select_callback = select_callback
if sys.platform == "win32" or sys.platform.startswith("linux"):
self.dcref = wx.BufferedPaintDC
else:
self.dcref = wx.PaintDC
self.setImage()
#FL 02/10/2017
self.playCursorPos = 0
def init_gl(self):
print('creating Frame')
self.window = wx.Frame ( parent=None, id=wx.ID_ANY, title=self.title,
style=wx.DEFAULT_FRAME_STYLE|wx.WS_EX_PROCESS_IDLE )
print('creating GLCanvas')
self.canvas = glcanvas.GLCanvas ( self.window, glcanvas.WX_GL_RGBA )
print('creating GLContext')
self.context = glcanvas.GLContext(self.canvas)
self.canvas.SetFocus()
self.window.SetSize ( (self.renderer.window_size[0], self.renderer.window_size[1]) )
print('showing Frame')
self.window.Show(True)
print('calling SetTopWindow')
self.SetTopWindow(self.window)
self.Bind ( wx.EVT_CHAR, self.OnChar )
self.canvas.Bind ( wx.EVT_SIZE, self.OnCanvasSize )
self.canvas.Bind ( wx.EVT_PAINT, self.OnCanvasPaint )
wx.IdleEvent.SetMode ( wx.IDLE_PROCESS_SPECIFIED )
self.Bind ( wx.EVT_IDLE, self.OnIdle )
print('making context current')
self.canvas.SetCurrent ( self.context )
self.renderer.init_gl()
def OnSize(self, event):
"""
Handles the ``wx.EVT_SIZE`` event for :class:`ImageContainerBase`.
:param `event`: a :class:`SizeEvent` event to be processed.
"""
self.Refresh() # Call on paint
event.Skip()
def OnSize(self, event):
"""
Handles the ``wx.EVT_SIZE`` event for :class:`ImageContainer`.
:param `event`: a :class:`SizeEvent` event to be processed.
"""
ImageContainerBase.OnSize(self, event)
event.Skip()
def _unbindfuncs(self):
# I would need a list of the functions that been bound to unbind them
while True:
try:
widget, event, dynboundmethod = self._dynbindings.pop()
except IndexError:
break # no more items in the list
else:
if event in [wx.EVT_MENU, wx.EVT_TOOL]:
self.Unbind(event, handler=dynboundmethod, id=widget.GetId())
elif event in [wx.EVT_SIZE]:
self.Unbind(event, handler=dynboundmethod)
else:
widget.Unbind(event, handler=dynboundmethod)
def _bindfuncs(self):
# wx classes throw exception if getmember is applied to the instance (self)
methods = inspect.getmembers(self.__class__, inspect.ismethod)
for mname, method in methods:
dynbindings = getattr(method, '_dynbinding', None)
if dynbindings is None:
continue
for dynbinding in dynbindings:
if dynbinding:
eventname, widgetprefix, widgetname = dynbinding
event = getattr(wx, eventname, None)
if event is None:
print 'Method', mname
print 'Failed to find eventname', eventname
continue
name = 'm_' + widgetprefix.lower() + widgetname.lower()
widget = None
for attrname in dir(self):
if attrname.lower() == name:
widget = getattr(self, attrname)
break
if not widget:
print 'Method', mname
print 'Failed to find widget', name
continue
boundmethod = method.__get__(self, self.__class__)
self._dynbindings.append((widget, event, boundmethod))
if event in [wx.EVT_MENU, wx.EVT_TOOL]:
self.Bind(event, boundmethod, id=widget.GetId())
elif event in [wx.EVT_SIZE]:
self.Bind(event, boundmethod)
else:
widget.Bind(event, boundmethod)
def initCanvas(self):
"""Initialize a new matplotlib canvas, figure and axis.
"""
self.plotPanel = wx.Panel(self)
self.plotPanel.SetBackgroundColour('white')
plotSizer = wx.BoxSizer(orient=wx.VERTICAL)
self.plotPanel.SetSizer(plotSizer)
self.fig = plt.Figure(facecolor='white')
#self.canvas = FigureCanvas(parent=self, id=wx.ID_ANY, figure=self.fig)
self.canvas = FigureCanvas(parent=self.plotPanel, id=wx.ID_ANY, figure=self.fig)
self.ax = self.fig.add_subplot(1,1,1)
self.ax.set_xlabel('Time (s)')
self.ax.set_ylabel('Frequency (Hz)')
self.cbAx = self.fig.add_axes([0.91, 0.05, 0.03, 0.93])
#self.fig.subplots_adjust(hspace=0.0, wspace=0.0,
# left=0.035, right=0.92, top=0.98, bottom=0.05)
self.adjustMargins()
self.firstPlot()
self.lastSize = (0,0)
self.needsResizePlot = True
self.canvas.Bind(wx.EVT_SIZE, self.resizePlot)
self.canvas.Bind(wx.EVT_IDLE, self.idleResizePlot)
##self.plotToolbar = widgets.PyPlotNavbar(self.canvas)
##plotSizer.Add(self.plotToolbar, proportion=0, flag=wx.EXPAND)
plotSizer.Add(self.canvas, proportion=1, flag=wx.EXPAND)
#self.plotToolbar.Hide()
def initResponse(self):
self.freqResponseFig = plt.Figure()
self.freqResponseCanvas = FigureCanvas(parent=self,
id=wx.ID_ANY, figure=self.freqResponseFig)
self.freqResponseAx = self.freqResponseFig.add_subplot(1,1,1)
#self.freqResponseFig.tight_layout()
self.phaseResponseFig = plt.Figure()
self.phaseResponseCanvas = FigureCanvas(parent=self,
id=wx.ID_ANY, figure=self.phaseResponseFig)
self.phaseResponseAx = self.phaseResponseFig.add_subplot(1,1,1)
#self.freqResponseFig.tight_layout()
responseSizer = wx.BoxSizer(wx.VERTICAL)
freqResponseControlBox = widgets.ControlBox(self,
label='Freqency Response', orient=wx.VERTICAL)
freqResponseControlBox.Add(self.freqResponseCanvas, proportion=1,
flag=wx.ALL | wx.EXPAND, border=8)
responseSizer.Add(freqResponseControlBox, proportion=1,
flag=wx.TOP | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=10)
phaseResponseControlBox = widgets.ControlBox(self,
label='Phase Response', orient=wx.VERTICAL)
phaseResponseControlBox.Add(self.phaseResponseCanvas, proportion=1,
flag=wx.ALL | wx.EXPAND, border=8)
responseSizer.Add(phaseResponseControlBox, proportion=1,
flag=wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=10)
self.bottomSizer.Add(responseSizer, proportion=1, flag=wx.EXPAND)
self.freqResponseCanvas.SetMinSize((0,0))
self.phaseResponseCanvas.SetMinSize((0,0))
# could we prevent resize when panel is not visible? XXX - idfah
self.freqResponseLastSize = (0,0)
self.freqResponseCanvas.Bind(wx.EVT_SIZE, self.freqResponseResize)
self.phaseResponseLastSize = (0,0)
self.phaseResponseCanvas.Bind(wx.EVT_SIZE, self.phaseResponseResize)
self.updateResponse()
def initResponse(self):
self.freqResponseFig = plt.Figure()
self.freqResponseCanvas = FigureCanvas(parent=self,
id=wx.ID_ANY, figure=self.freqResponseFig)
self.freqResponseAx = self.freqResponseFig.add_subplot(1,1,1)
#self.freqResponseFig.tight_layout()
self.phaseResponseFig = plt.Figure()
self.phaseResponseCanvas = FigureCanvas(parent=self,
id=wx.ID_ANY, figure=self.phaseResponseFig)
self.phaseResponseAx = self.phaseResponseFig.add_subplot(1,1,1)
#self.freqResponseFig.tight_layout()
responseSizer = wx.BoxSizer(wx.VERTICAL)
freqResponseControlBox = widgets.ControlBox(self,
label='Freqency Response', orient=wx.VERTICAL)
freqResponseControlBox.Add(self.freqResponseCanvas, proportion=1,
flag=wx.ALL | wx.EXPAND, border=8)
responseSizer.Add(freqResponseControlBox, proportion=1,
flag=wx.TOP | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=10)
phaseResponseControlBox = widgets.ControlBox(self,
label='Phase Response', orient=wx.VERTICAL)
phaseResponseControlBox.Add(self.phaseResponseCanvas, proportion=1,
flag=wx.ALL | wx.EXPAND, border=8)
responseSizer.Add(phaseResponseControlBox, proportion=1,
flag=wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=10)
self.bottomSizer.Add(responseSizer, proportion=1, flag=wx.EXPAND)
self.freqResponseCanvas.SetMinSize((0,0))
self.phaseResponseCanvas.SetMinSize((0,0))
# could we prevent resize when panel is not visible? XXX - idfah
self.freqResponseLastSize = (0,0)
self.freqResponseCanvas.Bind(wx.EVT_SIZE, self.freqResponseResize)
self.phaseResponseLastSize = (0,0)
self.phaseResponseCanvas.Bind(wx.EVT_SIZE, self.phaseResponseResize)
self.updateResponse()
def __init__(self, parent, background='black', style=0, *args, **kwargs):
"""Initialize a new DrawablePanel.
Args:
parent: wx parent object.
style: Style arguments passed the the wx.Panel base class.
The wx.NO_FULL_REPAINT_ON_RESIZE argument is added
to the given style arguments.
args, kwargs: Additional arguments passed to the wx.Panel
base class.
"""
wx.Panel.__init__(self, parent=parent, style=style | wx.NO_FULL_REPAINT_ON_RESIZE,
*args, **kwargs)
self.background = background
self.lastSize = (0,0)
# initial resize creates initial drawing
# buffer and triggers first draw
self.resize()
self.Bind(wx.EVT_PAINT, self.repaint)
self.Bind(wx.EVT_SIZE, self.resize)