bugfix: zooming with scroll wheel now working properly

task: panning now available while in exploration mode, if a phase is selected initial pick can be set and afterwards the onset itself (procedure questionable as two picks are needed)
panning not tested yet!
This commit is contained in:
Sebastian Wehling-Benatelli 2015-04-09 08:49:11 +02:00
parent c15716388d
commit 67dd66535a

View File

@ -243,6 +243,11 @@ class PickDlg(QDialog):
self.components = 'ZNE' self.components = 'ZNE'
self.picks = {} self.picks = {}
# initialize panning attributes
self.press = None
self.xpress = None
self.ypress = None
# set attribute holding data # set attribute holding data
if data is None: if data is None:
try: try:
@ -269,12 +274,14 @@ class PickDlg(QDialog):
self.apd = self.getWFData() self.apd = self.getWFData()
# set plot labels # set plot labels
self.setPlotLabels() self.setPlotLabels()
# connect button press event to an action # connect button press event to an action
self.cidpress = self.connectPressEvent(self.setIniPick) self.cidpress = self.connectPressEvent(self.panPress)
self.cidscroll = self.getPlotWidget().mpl_connect('scroll_event', self.cidmotion = self.connectMotionEvent()
self.scrollZoom) self.cidrelease = self.connectReleaseEvent()
self.cidscroll = self.connectScrollEvent()
def setupUi(self): def setupUi(self):
@ -315,7 +322,6 @@ class PickDlg(QDialog):
_dialtoolbar.addAction(self.filterAction) _dialtoolbar.addAction(self.filterAction)
_dialtoolbar.addWidget(self.selectPhase) _dialtoolbar.addWidget(self.selectPhase)
#_dialtoolbar.addAction(self.zoomAction)
_innerlayout = QVBoxLayout() _innerlayout = QVBoxLayout()
@ -328,6 +334,9 @@ class PickDlg(QDialog):
_outerlayout.addWidget(_dialtoolbar) _outerlayout.addWidget(_dialtoolbar)
_outerlayout.addLayout(_innerlayout) _outerlayout.addLayout(_innerlayout)
self.selectPhase.currentIndexChanged.connect(self.verifyPhaseSelection)
self.setLayout(_outerlayout) self.setLayout(_outerlayout)
def disconnectPressEvent(self): def disconnectPressEvent(self):
@ -335,11 +344,43 @@ class PickDlg(QDialog):
def connectPressEvent(self, slot): def connectPressEvent(self, slot):
widget = self.getPlotWidget() widget = self.getPlotWidget()
self.cidpress = widget.mpl_connect('button_press_event', slot) return widget.mpl_connect('button_press_event', slot)
def reconnectPressEvent(self, slot): def reconnectPressEvent(self, slot):
self.disconnectPressEvent() self.disconnectPressEvent()
self.cidpress = self.connectPressEvent(slot) return self.connectPressEvent(slot)
def disconnectScrollEvent(self):
widget = self.getPlotWidget()
widget.mpl_disconnect(self.cidscroll)
def connectScrollEvent(self):
widget = self.getPlotWidget()
return widget.mpl_connect('scroll_event', self.scrollZoom)
def disconnectMotionEvent(self):
widget = self.getPlotWidget()
widget.mpl_disconnect(self.cidmotion)
def connectMotionEvent(self):
widget = self.getPlotWidget()
return widget.mpl_connect('motion_notify_event', self.panMotion)
def disconnectReleaseEvent(self):
widget = self.getPlotWidget()
widget.mpl_disconnect(self.cidrelease)
def connectReleaseEvent(self):
widget = self.getPlotWidget()
return widget.mpl_connect('button_release_event', self.panRelease)
def verifyPhaseSelection(self):
phase = self.selectPhase.currentText()
if phase:
self.disconnectReleaseEvent()
self.disconnectScrollEvent()
self.disconnectMotionEvent()
self.reconnectPressEvent(self.setIniPick)
def getComponents(self): def getComponents(self):
return self.components return self.components
@ -385,7 +426,9 @@ class PickDlg(QDialog):
channel = self.getChannelID(round(gui_event.ydata)) channel = self.getChannelID(round(gui_event.ydata))
wfdata = self.selectWFData(channel) wfdata = self.selectWFData(channel)
self.getPlotWidget().mpl_disconnect(self.cidscroll) self.disconnectScrollEvent()
self.cidpress = self.reconnectPressEvent(self.setPick)
ini_pick = gui_event.xdata ini_pick = gui_event.xdata
@ -394,6 +437,7 @@ class PickDlg(QDialog):
# 3 > SNR >= 2 -> 5 sec MRW # 3 > SNR >= 2 -> 5 sec MRW
# 2 > SNR >= 1.5 -> 10 sec LRW # 2 > SNR >= 1.5 -> 10 sec LRW
# 1.5 > SNR -> 15 sec VLRW # 1.5 > SNR -> 15 sec VLRW
# see also Diehl et al. 2009
res_wins = { res_wins = {
'HRW' : 2., 'HRW' : 2.,
@ -426,13 +470,9 @@ class PickDlg(QDialog):
zoomy=zoomy) zoomy=zoomy)
self.updateAPD(wfdata) self.updateAPD(wfdata)
self.getPlotWidget().axes.plot()
# reset labels # reset labels
self.setPlotLabels() self.setPlotLabels()
self.reconnectPressEvent(self.setPick)
def setPick(self, gui_event): def setPick(self, gui_event):
pick = gui_event.xdata pick = gui_event.xdata
ax = self.getPlotWidget().axes ax = self.getPlotWidget().axes
@ -442,6 +482,32 @@ class PickDlg(QDialog):
ax.plot([pick, pick], ylims, 'r--') ax.plot([pick, pick], ylims, 'r--')
self.getPlotWidget().draw() self.getPlotWidget().draw()
def panPress(self, gui_event):
ax = self.getPlotWidget().axes
if gui_event.inaxes != ax: return
self.cur_xlim = ax.get_xlim()
self.cur_ylim = ax.get_ylim()
self.press = gui_event.xdata, gui_event.ydata
self.xpress, self.ypress = self.press
def panRelease(self, gui_event):
ax = self.getPlotWidget().axes
self.press = None
ax.figure.canvas.draw()
def panMotion(self, gui_event):
ax = self.getPlotWidget().axes
if self.press is None: return
if gui_event.inaxes != ax: return
dx = gui_event.xdata - self.xpress
dy = gui_event.ydata - self.ypress
self.cur_xlim -= dx
self.cur_ylim -= dy
ax.set_xlim(self.cur_xlim)
ax.set_ylim(self.cur_ylim)
ax.figure.canvas.draw()
def filterWFData(self): def filterWFData(self):
ax = self.getPlotWidget().axes ax = self.getPlotWidget().axes
ylims = ax.get_ylim() ylims = ax.get_ylim()
@ -473,7 +539,7 @@ class PickDlg(QDialog):
else: else:
self.connectPressEvent(self.setIniPick) self.connectPressEvent(self.setIniPick)
def scrollZoom(self, gui_event, factor=1.2): def scrollZoom(self, gui_event, factor=2.):
widget = self.getPlotWidget() widget = self.getPlotWidget()
@ -490,16 +556,15 @@ class PickDlg(QDialog):
scale_factor = 1 scale_factor = 1
print gui_event.button print gui_event.button
act_width = (curr_xlim[1]-curr_xlim[0])*.5 new_xlim = gui_event.xdata - scale_factor * (gui_event.xdata - curr_xlim)
act_height = (curr_ylim[1]-curr_ylim[0])*.5 new_ylim = gui_event.ydata - scale_factor * (gui_event.ydata - curr_ylim)
new_width = act_width*scale_factor new_xlim.sort()
new_height= act_height*scale_factor new_xlim[0] = max(new_xlim[0], self.limits['xlims'][0])
new_xlim[1] = min(new_xlim[1], self.limits['xlims'][1])
new_xlim = [max(gui_event.xdata - new_width, self.limits['xlims'][0]), new_ylim.sort()
min(gui_event.xdata + new_width, self.limits['xlims'][1])] new_ylim[0] = max(new_ylim[0], self.limits['ylims'][0])
new_ylim = [max(gui_event.ydata - new_height, self.limits['ylims'][0]), new_ylim[1] = min(new_ylim[1], self.limits['ylims'][1])
min(gui_event.ydata + new_height, self.limits['ylims'][1])]
widget.axes.set_xlim(new_xlim) widget.axes.set_xlim(new_xlim)
widget.axes.set_ylim(new_ylim) widget.axes.set_ylim(new_ylim)