WIP restructuring fig_dict to be created inside Qt Main Thread

This commit is contained in:
2017-05-11 17:15:20 +02:00
parent d1354a33b1
commit f58d17be14
8 changed files with 156 additions and 89 deletions

View File

@@ -12,41 +12,44 @@ from pylot.core.util.widgets import PickDlg
plt.interactive(False)
class map_projection(QtGui.QWidget):
def __init__(self, mainwindow, figure=None):
def __init__(self, parent, figure=None):
'''
:param: picked, can be False, auto, manual
:value: str
'''
QtGui.QWidget.__init__(self)
self.pyl_mainwindow = mainwindow
self.parser = mainwindow.metadata[1]
self._parent = parent
self.parser = parent.metadata[1]
self.picks = None
self.picks_dict = None
self.figure = figure
self.init_graphics()
self.init_basemap(projection='mill', resolution='l')
self.init_map()
#self.show()
def init_map(self):
self.init_stations()
self.init_lat_lon_dimensions()
self.init_lat_lon_grid()
self.init_basemap(projection='mill', resolution='l')
self.init_x_y_dimensions()
self.connectSignals()
self.draw_everything()
#self.show()
def onpick(self, event):
ind = event.ind
if ind == []:
return
data = self.pyl_mainwindow.get_data().getWFData()
data = self._parent.get_data().getWFData()
for index in ind:
station=str(self.station_names[index])
try:
pickDlg = PickDlg(self, infile=self.pyl_mainwindow.getinfile(),
pickDlg = PickDlg(self, infile=self._parent.getinfile(),
data=data.select(station=station),
station=station,
picks=self.pyl_mainwindow.getPicksOnStation(station, 'manual'),
autopicks=self.pyl_mainwindow.getPicksOnStation(station, 'auto'))
pyl_mw = self.pyl_mainwindow
picks=self._parent.getPicksOnStation(station, 'manual'),
autopicks=self._parent.getPicksOnStation(station, 'auto'))
pyl_mw = self._parent
if pickDlg.exec_():
pyl_mw.setDirty(True)
pyl_mw.update_status('picks accepted ({0})'.format(station))
@@ -67,6 +70,17 @@ class map_projection(QtGui.QWidget):
self.comboBox_phase.currentIndexChanged.connect(self._refresh_drawings)
def init_graphics(self):
if not self.figure:
if not hasattr(self._parent, 'am_figure'):
self.figure = plt.figure()
self.toolbar = NavigationToolbar(self.figure.canvas, self)
else:
self.figure = self._parent.am_figure
self.toolbar = self._parent.am_toolbar
self.main_ax = self.figure.add_subplot(111)
self.canvas = self.figure.canvas
self.main_box = QtGui.QVBoxLayout()
self.setLayout(self.main_box)
@@ -85,18 +99,9 @@ class map_projection(QtGui.QWidget):
self.top_row.addWidget(self.comboBox_phase)
self.top_row.setStretch(1,1) #set stretch of item 1 to 1
if not self.figure:
fig = plt.figure()
else:
fig = self.figure
self.main_ax = fig.add_subplot(111)
self.canvas = fig.canvas
self.main_box.addWidget(self.canvas)
self.toolbar = NavigationToolbar(self.canvas, self)
self.main_box.addWidget(self.toolbar)
self.figure = fig
def init_stations(self):
def get_station_names_lat_lon(parser):
station_names=[]
@@ -186,7 +191,6 @@ class map_projection(QtGui.QWidget):
basemap.drawcoastlines()
self.basemap = basemap
self.figure.tight_layout()
def init_lat_lon_grid(self):
def get_lat_lon_axis(lat, lon):

View File

@@ -1,4 +1,4 @@
[]# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 19 11:27:35 2014
@@ -39,6 +39,7 @@ from pylot.core.util.defaults import OUTPUTFORMATS, FILTERDEFAULTS, LOCTOOLS, \
from pylot.core.util.utils import prepTimeAxis, full_range, scaleWFData, \
demeanTrace, isSorted, findComboBoxIndex, clims
from autoPyLoT import autoPyLoT
from pylot.core.util.thread import Thread
import icons_rc
def getDataType(parent):
@@ -1270,11 +1271,12 @@ class PickDlg(QDialog):
class TuneAutopicker(QWidget):
def __init__(self, ap, parent=None):
QtGui.QWidget.__init__(self, parent)
def __init__(self, ap, fig_dict, parent=None):
QtGui.QWidget.__init__(self, parent, 1)
self.ap = ap
self.station = 'AH11'
self.fd = None
self.parent = parent
self.station = 'AH11' ############# justs for testing
self.fig_dict = fig_dict
self.layout = QtGui.QHBoxLayout()
self.parameter_layout = QtGui.QVBoxLayout()
self.setLayout(self.layout)
@@ -1282,6 +1284,9 @@ class TuneAutopicker(QWidget):
self.add_parameter()
self.add_buttons()
self.set_stretch()
self.resize(1280, 720)
self.setWindowModality(QtCore.Qt.WindowModality.ApplicationModal)
self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
def init_figure_tabs(self):
self.main_tabs = QtGui.QTabWidget()
@@ -1302,13 +1307,20 @@ class TuneAutopicker(QWidget):
self.parameter_layout.addWidget(self.pick_button)
def call_picker(self):
self.parameters.update_params()
picks, fig_dict = autoPyLoT(self.ap, fnames='None', iplot=2)
self.pb_thread = Thread(self, self._hover, arg=None, progressText='Picking trace...')
self.pb_thread.start()
self.ap = self.update_params()
picks = autoPyLoT(self.ap, fnames='None', iplot=2, self.fig_dict)
self.main_tabs.setParent(None)
self.fd = fig_dict[self.station]
self.init_figure_tabs()
self.set_stretch()
def update_params(self):
ap = self.parameters.update_params()
if self.parent:
self.parent._inputs = ap
return ap
def set_stretch(self):
self.layout.setStretch(0, 3)
self.layout.setStretch(1, 1)
@@ -1788,6 +1800,7 @@ class AutoPickParaBox(QtGui.QWidget):
value = self.getValue(box)
self.ap.checkValue(param, value)
self.ap.setParam(param, value)
return self.ap
def getValue(self, box):
if type(box) == QtGui.QLineEdit: