[add] Ctrl+S to save fig (has to be clicked firsts)
This commit is contained in:
parent
16997ff49b
commit
c6105330e0
@ -31,6 +31,8 @@ except ImportError:
|
|||||||
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
|
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
|
||||||
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT
|
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT
|
||||||
from matplotlib.widgets import MultiCursor
|
from matplotlib.widgets import MultiCursor
|
||||||
|
from matplotlib.tight_layout import get_renderer, get_subplotspec_list, get_tight_layout_figure
|
||||||
|
|
||||||
from PySide import QtCore, QtGui
|
from PySide import QtCore, QtGui
|
||||||
from PySide.QtGui import QAction, QApplication, QCheckBox, QComboBox, \
|
from PySide.QtGui import QAction, QApplication, QCheckBox, QComboBox, \
|
||||||
QDateTimeEdit, QDialog, QDialogButtonBox, QDoubleSpinBox, QGroupBox, \
|
QDateTimeEdit, QDialog, QDialogButtonBox, QDoubleSpinBox, QGroupBox, \
|
||||||
@ -607,7 +609,6 @@ class WaveformWidgetPG(QtGui.QWidget):
|
|||||||
class PylotCanvas(FigureCanvas):
|
class PylotCanvas(FigureCanvas):
|
||||||
def __init__(self, figure=None, parent=None, connect_events=True, multicursor=False,
|
def __init__(self, figure=None, parent=None, connect_events=True, multicursor=False,
|
||||||
panZoomX=True, panZoomY=True):
|
panZoomX=True, panZoomY=True):
|
||||||
|
|
||||||
self._parent = parent
|
self._parent = parent
|
||||||
if not figure:
|
if not figure:
|
||||||
figure = Figure()
|
figure = Figure()
|
||||||
@ -616,11 +617,12 @@ class PylotCanvas(FigureCanvas):
|
|||||||
|
|
||||||
self.axes = figure.axes
|
self.axes = figure.axes
|
||||||
self.figure = figure
|
self.figure = figure
|
||||||
self.figure.set_facecolor((.92, .92, .92))
|
self.figure.set_facecolor((1., 1., 1.))
|
||||||
# attribute plotdict is a dictionary connecting position and a name
|
# attribute plotdict is a dictionary connecting position and a name
|
||||||
self.plotdict = dict()
|
self.plotdict = dict()
|
||||||
# initialize super class
|
# initialize super class
|
||||||
super(PylotCanvas, self).__init__(self.figure)
|
super(PylotCanvas, self).__init__(self.figure)
|
||||||
|
|
||||||
if multicursor:
|
if multicursor:
|
||||||
# add a cursor for station selection
|
# add a cursor for station selection
|
||||||
self.multiCursor = MultiCursor(self.figure.canvas, self.axes,
|
self.multiCursor = MultiCursor(self.figure.canvas, self.axes,
|
||||||
@ -652,6 +654,9 @@ class PylotCanvas(FigureCanvas):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
self.setFocusPolicy(QtCore.Qt.StrongFocus)
|
||||||
|
self.setFocus()
|
||||||
|
|
||||||
def panPress(self, gui_event):
|
def panPress(self, gui_event):
|
||||||
ax_check = False
|
ax_check = False
|
||||||
for ax in self.axes:
|
for ax in self.axes:
|
||||||
@ -734,6 +739,15 @@ class PylotCanvas(FigureCanvas):
|
|||||||
|
|
||||||
self.draw()
|
self.draw()
|
||||||
|
|
||||||
|
def saveFigure(self):
|
||||||
|
if self.figure:
|
||||||
|
fd = QtGui.QFileDialog()
|
||||||
|
fname, filter = fd.getSaveFileName(self._parent, filter='Images (*.png)')
|
||||||
|
if not fname:
|
||||||
|
return
|
||||||
|
if not fname.endswith('.png'):
|
||||||
|
fname += '.png'
|
||||||
|
self.figure.savefig(fname)
|
||||||
|
|
||||||
def calcPanZoom(self, origin, lower_b, upper_b, factor, positive):
|
def calcPanZoom(self, origin, lower_b, upper_b, factor, positive):
|
||||||
d_lower = abs(origin - lower_b)
|
d_lower = abs(origin - lower_b)
|
||||||
@ -806,46 +820,60 @@ class PylotCanvas(FigureCanvas):
|
|||||||
if hasattr(parent, 'refreshPhaseText'):
|
if hasattr(parent, 'refreshPhaseText'):
|
||||||
parent.refreshPhaseText()
|
parent.refreshPhaseText()
|
||||||
|
|
||||||
|
def keyPressHandler(self, gui_event):
|
||||||
|
if gui_event.key == 'ctrl+s':
|
||||||
|
self.saveFigure()
|
||||||
|
|
||||||
def connectEvents(self):
|
def connectEvents(self):
|
||||||
self.cidscroll = self.connectScrollEvent(self.scrollZoom)
|
self.cidscroll = self.connectScrollEvent(self.scrollZoom)
|
||||||
self.cidpress = self.connectPressEvent(self.panPress)
|
self.cidpress = self.connectPressEvent(self.panPress)
|
||||||
self.cidmotion = self.connectMotionEvent(self.pan)
|
self.cidmotion = self.connectMotionEvent(self.pan)
|
||||||
self.cidrelease = self.connectReleaseEvent(self.panRelease)
|
self.cidrelease = self.connectReleaseEvent(self.panRelease)
|
||||||
|
self.cidkpress = self.connectKeyPressEvent(self.keyPressHandler)
|
||||||
|
|
||||||
def disconnectEvents(self):
|
def disconnectEvents(self):
|
||||||
self.disconnectScrollEvent()
|
self.disconnectScrollEvent(self.cidscroll)
|
||||||
self.disconnectMotionEvent()
|
self.disconnectMotionEvent(self.cidmotion)
|
||||||
self.disconnectPressEvent()
|
self.disconnectPressEvent(self.cidpress)
|
||||||
self.disconnectReleaseEvent()
|
self.disconnectReleaseEvent(self.cidrelease)
|
||||||
|
self.disconnectKeyPressEvent(self.cidkpress)
|
||||||
|
|
||||||
def disconnectPressEvent(self):
|
self.cidscroll = None
|
||||||
self.mpl_disconnect(self.cidpress)
|
self.cidrelease = None
|
||||||
self.cidpress = None
|
self.cidpress = None
|
||||||
|
self.cidmotion = None
|
||||||
|
self.cidkpress = None
|
||||||
|
|
||||||
|
def disconnectPressEvent(self, cid):
|
||||||
|
self.mpl_disconnect(cid)
|
||||||
|
|
||||||
def connectPressEvent(self, slot):
|
def connectPressEvent(self, slot):
|
||||||
return self.mpl_connect('button_press_event', slot)
|
return self.mpl_connect('button_press_event', slot)
|
||||||
|
|
||||||
def disconnectMotionEvent(self):
|
def disconnectMotionEvent(self, cid):
|
||||||
self.mpl_disconnect(self.cidmotion)
|
self.mpl_disconnect(cid)
|
||||||
self.cidmotion = None
|
|
||||||
|
|
||||||
def connectMotionEvent(self, slot):
|
def connectMotionEvent(self, slot):
|
||||||
return self.mpl_connect('motion_notify_event', slot)
|
return self.mpl_connect('motion_notify_event', slot)
|
||||||
|
|
||||||
def disconnectReleaseEvent(self):
|
def disconnectReleaseEvent(self, cid):
|
||||||
self.mpl_disconnect(self.cidrelease)
|
self.mpl_disconnect(cid)
|
||||||
self.cidrelease = None
|
|
||||||
|
|
||||||
def connectReleaseEvent(self, slot):
|
def connectReleaseEvent(self, slot):
|
||||||
return self.mpl_connect('button_release_event', slot)
|
return self.mpl_connect('button_release_event', slot)
|
||||||
|
|
||||||
def disconnectScrollEvent(self):
|
def disconnectScrollEvent(self, cid):
|
||||||
self.mpl_disconnect(self.cidscroll)
|
self.mpl_disconnect(cid)
|
||||||
self.cidscroll = None
|
|
||||||
|
|
||||||
def connectScrollEvent(self, slot):
|
def connectScrollEvent(self, slot):
|
||||||
return self.mpl_connect('scroll_event', slot)
|
return self.mpl_connect('scroll_event', slot)
|
||||||
|
|
||||||
|
def disconnectKeyPressEvent(self, cid):
|
||||||
|
self.mpl_disconnect(cid)
|
||||||
|
|
||||||
|
def connectKeyPressEvent(self, slot):
|
||||||
|
return self.mpl_connect('key_press_event', slot)
|
||||||
|
|
||||||
def getPlotDict(self):
|
def getPlotDict(self):
|
||||||
return self.plotdict
|
return self.plotdict
|
||||||
|
|
||||||
@ -1152,6 +1180,8 @@ class PickDlg(QDialog):
|
|||||||
self.multicompfig.setZoomBorders2content()
|
self.multicompfig.setZoomBorders2content()
|
||||||
|
|
||||||
self.multicompfig.updateCurrentLimits()
|
self.multicompfig.updateCurrentLimits()
|
||||||
|
self.multicompfig.draw()
|
||||||
|
self.multicompfig.setFocus()
|
||||||
|
|
||||||
# setup ui
|
# setup ui
|
||||||
self.setupUi()
|
self.setupUi()
|
||||||
|
Loading…
Reference in New Issue
Block a user