📄 wxplotframe.py
字号:
#Boa:Frame:wxPlotFrame
"""
A wxFrame for plots in PyChem that uses wxPyPlot
$Id: wxPlotFrame.py Copyright (C) 2005 Roger Jarvis
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""
import string,tempfile,os,wxPlotPropertiesDialog
from wxPython.wx import *
from wxPyPlot import *
from wx import *
def create(parent):
return wxPlotFrame(parent)
[wxID_WXPLOTFRAME, wxID_WXPLOTFRAMEPLCEXPANDPLOT, wxID_WXPLOTFRAMESTXYCOORDS,
wxID_WXPLOTFRAMEWINDOW1,
] = map(lambda _init_ctrls: wxNewId(), range(4))
[wxID_WXPLOTFRAMEMNUPOPUPITEMS0, wxID_WXPLOTFRAMEMNUPOPUPITEMS1,
wxID_WXPLOTFRAMEMNUPOPUPITEMS2, wxID_WXPLOTFRAMEMNUPOPUPITEMS3,
] = map(lambda _init_coll_mnuPopUp_Items: wxNewId(), range(4))
[wxID_WXPLOTFRAMEXYCOORDSITEMS0] = map(lambda _init_coll_xyCoOrds_Items: wxNewId(), range(1))
class wxPlotFrame(wxFrame):
def _init_coll_mnuPopUp_Items(self, parent):
# generated method, don't edit
parent.Append(helpString='', id=wxID_WXPLOTFRAMEMNUPOPUPITEMS0,
item='Copy', kind=wxITEM_NORMAL)
parent.Append(helpString='', id=wxID_WXPLOTFRAMEMNUPOPUPITEMS1,
item='Print', kind=wxITEM_NORMAL)
parent.Append(helpString='', id=wxID_WXPLOTFRAMEMNUPOPUPITEMS2,
item='Save', kind=wxITEM_NORMAL)
parent.Append(helpString='', id=wxID_WXPLOTFRAMEMNUPOPUPITEMS3,
item='Properties', kind=wxITEM_NORMAL)
EVT_MENU(self, wxID_WXPLOTFRAMEMNUPOPUPITEMS0, self.OnMnuPopUpCopyMenu)
EVT_MENU(self, wxID_WXPLOTFRAMEMNUPOPUPITEMS1, self.OnMnuPopUpPrintMenu)
EVT_MENU(self, wxID_WXPLOTFRAMEMNUPOPUPITEMS2, self.OnMnuPopUpSaveMenu)
EVT_MENU(self, wxID_WXPLOTFRAMEMNUPOPUPITEMS3,
self.OnMnuPopUpPropertiesMenu)
def _init_utils(self):
# generated method, don't edit
self.mnuPopUp = wxMenu(title='')
self._init_coll_mnuPopUp_Items(self.mnuPopUp)
def _init_ctrls(self, prnt):
# generated method, don't edit
wxFrame.__init__(self, id=wxID_WXPLOTFRAME, name='wxPlotFrame',
parent=prnt, pos=wxPoint(284, 125), size=wxSize(440, 410),
style=wxDEFAULT_FRAME_STYLE, title='Expanded Plot')
self._init_utils()
self.SetClientSize(wxSize(432, 376))
self.SetToolTipString('')
EVT_SIZE(self, self.OnWxPlotFrameSize)
self.window1 = wxWindow(id=wxID_WXPLOTFRAMEWINDOW1, name='window1',
parent=self, pos=wxPoint(0, 0), size=wxSize(432, 376), style=0)
self.window1.SetToolTipString('')
self.plcExpandPlot = PlotCanvas(id=wxID_WXPLOTFRAMEPLCEXPANDPLOT,
name='plcExpandPlot', parent=self.window1, pos=wxPoint(0, 0),
size=wxSize(430, 372), style=0)
self.plcExpandPlot.SetFontSizeTitle(12)
self.plcExpandPlot.SetToolTipString('')
self.plcExpandPlot.SetEnableZoom(True)
self.plcExpandPlot.SetEnableLegend(False)
EVT_RIGHT_DOWN(self.plcExpandPlot, self.OnPlcExpandPlotRightDown)
EVT_MOTION(self.plcExpandPlot, self.OnPlcExpandPlotMotion)
self.stXyCoords = wxStaticText(id=wxID_WXPLOTFRAMESTXYCOORDS,
label='xy-coords', name='stXyCoords', parent=self.window1,
pos=wxPoint(144, 80), size=wxSize(59, 16), style=0)
self.stXyCoords.SetToolTipString('')
self.stXyCoords.Show(False)
self.stXyCoords.SetBackgroundColour(wxColour(255, 255, 128))
self.stXyCoords.SetFont(wxFont(10, wxSWISS, wxNORMAL, wxNORMAL, False,
'Microsoft Sans Serif'))
def __init__(self, parent, PlotGraph):
self._init_ctrls(parent)
self.plcExpandPlot.Draw(PlotGraph[0],xAxis=PlotGraph[1],yAxis=PlotGraph[2])
self.TempPath = tempfile.gettempdir()
self.stXyCoords.SetPosition((0,0))
self.PlotGraph = PlotGraph
def OnWxPlotFrameSize(self, event):
size = event.GetSize()
self.window1.SetClientSize(size)
self.plcExpandPlot.SetClientSize((size[0]-8,size[1]-30))
def OnPlcExpandPlotRightDown(self, event):
pt = event.GetPosition()
self.PopupMenu(self.mnuPopUp, pt)
def OnMnuPopUpCopyMenu(self, event):
#This is a hash up to get copy functionality
self.plcExpandPlot.SaveFile(os.path.join(self.TempPath,'temp.bmp'))
bmp = Bitmap(os.path.join(self.TempPath,'temp.bmp'), wxBITMAP_TYPE_BMP)
bmpdo = BitmapDataObject(bmp)
wxTheClipboard.Open()
wxTheClipboard.SetData(bmpdo)
wxTheClipboard.Close()
def OnMnuPopUpPrintMenu(self, event):
self.plcExpandPlot.Printout()
def OnMnuPopUpSaveMenu(self, event):
self.plcExpandPlot.SaveFile()
def OnPlcExpandPlotMotion(self, event):
xy = self.plcExpandPlot.GetXY(event)
self.stXyCoords.SetLabel(string.join(('Coordinates: X(',str('%.2f' %xy[0]),'),Y(',str('%.2f' %xy[1]),')'),''))
self.stXyCoords.Show()
def OnMnuPopUpPropertiesMenu(self, event):
dlg = wxPlotPropertiesDialog.wxPlotPropertiesDialog(self,self.plcExpandPlot,self.PlotGraph)
try:
dlg.ShowModal()
if dlg.GetButtonPress() == 1:
self.plcExpandPlot.Clear()
graph = dlg.GetNewPlotParams()
self.plcExpandPlot.Draw(graph[0],xAxis=graph[1],yAxis=graph[2])
finally:
dlg.Destroy()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -