[new] missing parents added, some preperations
This commit is contained in:
parent
bf36e5e6a5
commit
7f0d3c2ab4
74
QtPyLoT.py
74
QtPyLoT.py
@ -109,6 +109,7 @@ class MainWindow(QMainWindow):
|
|||||||
print('Using default input file {}'.format(infile))
|
print('Using default input file {}'.format(infile))
|
||||||
if os.path.isfile(infile) == False:
|
if os.path.isfile(infile) == False:
|
||||||
infile = QFileDialog().getOpenFileName(caption='Choose PyLoT-input file')
|
infile = QFileDialog().getOpenFileName(caption='Choose PyLoT-input file')
|
||||||
|
|
||||||
if not os.path.exists(infile[0]):
|
if not os.path.exists(infile[0]):
|
||||||
QMessageBox.warning(self, "PyLoT Warning",
|
QMessageBox.warning(self, "PyLoT Warning",
|
||||||
"No PyLoT-input file declared!")
|
"No PyLoT-input file declared!")
|
||||||
@ -209,6 +210,8 @@ class MainWindow(QMainWindow):
|
|||||||
except:
|
except:
|
||||||
self.startTime = UTCDateTime()
|
self.startTime = UTCDateTime()
|
||||||
|
|
||||||
|
self.init_styles()
|
||||||
|
|
||||||
pylot_icon = QIcon()
|
pylot_icon = QIcon()
|
||||||
pylot_icon.addPixmap(QPixmap(':/icons/pylot.png'))
|
pylot_icon.addPixmap(QPixmap(':/icons/pylot.png'))
|
||||||
|
|
||||||
@ -566,21 +569,22 @@ class MainWindow(QMainWindow):
|
|||||||
self.eventBox.activated.connect(self.refreshEvents)
|
self.eventBox.activated.connect(self.refreshEvents)
|
||||||
|
|
||||||
# add main tab widget
|
# add main tab widget
|
||||||
self.tabs = QTabWidget()
|
self.tabs = QTabWidget(self)
|
||||||
self._main_layout.addWidget(self.tabs)
|
self._main_layout.addWidget(self.tabs)
|
||||||
self.tabs.currentChanged.connect(self.refreshTabs)
|
self.tabs.currentChanged.connect(self.refreshTabs)
|
||||||
|
|
||||||
# add scroll area used in case number of traces gets too high
|
# add scroll area used in case number of traces gets too high
|
||||||
self.wf_scroll_area = QtGui.QScrollArea()
|
self.wf_scroll_area = QtGui.QScrollArea(self)
|
||||||
|
|
||||||
# create central matplotlib figure canvas widget
|
# create central matplotlib figure canvas widget
|
||||||
self.pg = pg
|
self.pg = pg
|
||||||
|
#self.set_style('custom')
|
||||||
self.init_wfWidget()
|
self.init_wfWidget()
|
||||||
|
|
||||||
# init main widgets for main tabs
|
# init main widgets for main tabs
|
||||||
wf_tab = QtGui.QWidget()
|
wf_tab = QtGui.QWidget(self)
|
||||||
array_tab = QtGui.QWidget()
|
array_tab = QtGui.QWidget(self)
|
||||||
events_tab = QtGui.QWidget()
|
events_tab = QtGui.QWidget(self)
|
||||||
|
|
||||||
# init main widgets layouts
|
# init main widgets layouts
|
||||||
self.wf_layout = QtGui.QVBoxLayout()
|
self.wf_layout = QtGui.QVBoxLayout()
|
||||||
@ -623,8 +627,8 @@ class MainWindow(QMainWindow):
|
|||||||
self.dataPlot = PylotCanvas(parent=self, connect_events=False, multicursor=True)
|
self.dataPlot = PylotCanvas(parent=self, connect_events=False, multicursor=True)
|
||||||
self.dataPlot.updateWidget(xlab, None, plottitle)
|
self.dataPlot.updateWidget(xlab, None, plottitle)
|
||||||
else:
|
else:
|
||||||
self.pg = True
|
self.pg = pg
|
||||||
self.dataPlot = WaveformWidgetPG(parent=self, xlabel=xlab, ylabel=None,
|
self.dataPlot = WaveformWidgetPG(parent=self,
|
||||||
title=plottitle)
|
title=plottitle)
|
||||||
self.dataPlot.setCursor(Qt.CrossCursor)
|
self.dataPlot.setCursor(Qt.CrossCursor)
|
||||||
self.wf_scroll_area.setWidget(self.dataPlot)
|
self.wf_scroll_area.setWidget(self.dataPlot)
|
||||||
@ -662,6 +666,53 @@ class MainWindow(QMainWindow):
|
|||||||
if event.key() == QtCore.Qt.Key.Key_Shift:
|
if event.key() == QtCore.Qt.Key.Key_Shift:
|
||||||
self._shift = False
|
self._shift = False
|
||||||
|
|
||||||
|
def init_styles(self):
|
||||||
|
self._styles = {}
|
||||||
|
styles = ['default', 'dark', 'custom']
|
||||||
|
for style in styles:
|
||||||
|
self._styles[style] = {}
|
||||||
|
|
||||||
|
self._styles['default']['stylesheet'] = ("QMainWindow {background-color: rgba(200, 200, 200, 255)}")
|
||||||
|
# ;"
|
||||||
|
# "alternate-background-color: rgba(255, 0, 255, 255);"
|
||||||
|
# "color: rgba(0, 0, 0, 255);"
|
||||||
|
# "gridline-color: rgba(0, 0, 0, 255);"
|
||||||
|
# "selection-background-color: rgba(50, 50, 150, 255)};"
|
||||||
|
# "QMainWindow {background-color: red}")
|
||||||
|
self._styles['default']['background'] = 'w'
|
||||||
|
self._styles['default']['foreground'] = 'k'
|
||||||
|
|
||||||
|
self._styles['dark']['stylesheet'] = ("QWidget {background-color: rgba(50, 50, 60, 255);"
|
||||||
|
"alternate-background-color: rgba(100, 100, 150, 255);"
|
||||||
|
"border-color: rgba(200, 200, 200, 255);"
|
||||||
|
"color: rgba(255, 255, 255, 255);"
|
||||||
|
"gridline-color: rgba(255, 255, 255, 255);"
|
||||||
|
"selection-background-color: rgba(50, 50, 150, 255)}")
|
||||||
|
self._styles['dark']['background'] = QtGui.QColor(50, 50, 65, 255)
|
||||||
|
self._styles['dark']['foreground'] = 'w'
|
||||||
|
|
||||||
|
infile = open('./pylot/core/util/stylesheet.qss', 'r')
|
||||||
|
stylesheet = infile.read()
|
||||||
|
infile.close()
|
||||||
|
self._styles['custom']['stylesheet'] = stylesheet
|
||||||
|
self._styles['custom']['background'] = QtGui.QColor(50, 50, 65, 255)
|
||||||
|
self._styles['custom']['foreground'] = 'w'
|
||||||
|
|
||||||
|
|
||||||
|
def set_style(self, stylename):
|
||||||
|
if not stylename in self._styles:
|
||||||
|
qmb = QMessageBox.warning(self, 'Could not find style',
|
||||||
|
'Could not find style with name {}.'.format(stylename))
|
||||||
|
return
|
||||||
|
self._style = stylename
|
||||||
|
style = self._styles[stylename]
|
||||||
|
self.setStyleSheet(style['stylesheet'])
|
||||||
|
|
||||||
|
if self.pg:
|
||||||
|
pg.setConfigOption('background', style['background'])
|
||||||
|
pg.setConfigOption('foreground', style['foreground'])
|
||||||
|
pg.setConfigOptions(antialias=True)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def metadata(self):
|
def metadata(self):
|
||||||
return self._metadata
|
return self._metadata
|
||||||
@ -1521,7 +1572,7 @@ class MainWindow(QMainWindow):
|
|||||||
self.getPlotWidget().updateWidget()
|
self.getPlotWidget().updateWidget()
|
||||||
plots = self.wfp_thread.data
|
plots = self.wfp_thread.data
|
||||||
for times, data in plots:
|
for times, data in plots:
|
||||||
self.dataPlot.plotWidget.getPlotItem().plot(times, data, pen='k')
|
self.dataPlot.plotWidget.getPlotItem().plot(times, data)#, pen='k')
|
||||||
self.dataPlot.reinitMoveProxy()
|
self.dataPlot.reinitMoveProxy()
|
||||||
self.dataPlot.plotWidget.showAxis('left')
|
self.dataPlot.plotWidget.showAxis('left')
|
||||||
self.dataPlot.plotWidget.showAxis('bottom')
|
self.dataPlot.plotWidget.showAxis('bottom')
|
||||||
@ -2498,7 +2549,7 @@ class MainWindow(QMainWindow):
|
|||||||
self.events_layout.removeWidget(self.event_table)
|
self.events_layout.removeWidget(self.event_table)
|
||||||
|
|
||||||
# init new qtable
|
# init new qtable
|
||||||
self.event_table = QtGui.QTableWidget()
|
self.event_table = QtGui.QTableWidget(self)
|
||||||
self.event_table.setColumnCount(12)
|
self.event_table.setColumnCount(12)
|
||||||
self.event_table.setRowCount(len(eventlist))
|
self.event_table.setRowCount(len(eventlist))
|
||||||
self.event_table.setHorizontalHeaderLabels(['',
|
self.event_table.setHorizontalHeaderLabels(['',
|
||||||
@ -2775,7 +2826,7 @@ class MainWindow(QMainWindow):
|
|||||||
if not self.okToContinue():
|
if not self.okToContinue():
|
||||||
return
|
return
|
||||||
if not fnm:
|
if not fnm:
|
||||||
dlg = QFileDialog()
|
dlg = QFileDialog(parent=self)
|
||||||
fnm = dlg.getOpenFileName(self, 'Open project file...', filter='Pylot project (*.plp)')
|
fnm = dlg.getOpenFileName(self, 'Open project file...', filter='Pylot project (*.plp)')
|
||||||
if not fnm:
|
if not fnm:
|
||||||
return
|
return
|
||||||
@ -2802,7 +2853,7 @@ class MainWindow(QMainWindow):
|
|||||||
'''
|
'''
|
||||||
Save back project to new pickle file.
|
Save back project to new pickle file.
|
||||||
'''
|
'''
|
||||||
dlg = QFileDialog()
|
dlg = QFileDialog(self)
|
||||||
fnm = dlg.getSaveFileName(self, 'Create a new project file...', filter='Pylot project (*.plp)')
|
fnm = dlg.getSaveFileName(self, 'Create a new project file...', filter='Pylot project (*.plp)')
|
||||||
filename = fnm[0]
|
filename = fnm[0]
|
||||||
if not len(fnm[0]):
|
if not len(fnm[0]):
|
||||||
@ -3084,7 +3135,6 @@ def create_window():
|
|||||||
# window.show()
|
# window.show()
|
||||||
return app, app_created
|
return app, app_created
|
||||||
|
|
||||||
|
|
||||||
def main(args=None):
|
def main(args=None):
|
||||||
project_filename = None
|
project_filename = None
|
||||||
pylot_infile = None
|
pylot_infile = None
|
||||||
|
@ -16,11 +16,6 @@ import time
|
|||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
try:
|
|
||||||
import pyqtgraph as pg
|
|
||||||
except:
|
|
||||||
pg = None
|
|
||||||
|
|
||||||
from matplotlib.figure import Figure
|
from matplotlib.figure import Figure
|
||||||
from pylot.core.util.utils import find_horizontals, identifyPhase, loopIdentifyPhase, trim_station_components, \
|
from pylot.core.util.utils import find_horizontals, identifyPhase, loopIdentifyPhase, trim_station_components, \
|
||||||
identifyPhaseID, check4rotated
|
identifyPhaseID, check4rotated
|
||||||
@ -64,12 +59,6 @@ elif sys.version_info.major == 2:
|
|||||||
else:
|
else:
|
||||||
raise ImportError('Could not determine python version.')
|
raise ImportError('Could not determine python version.')
|
||||||
|
|
||||||
if pg:
|
|
||||||
pg.setConfigOption('background', 'w')
|
|
||||||
pg.setConfigOption('foreground', 'k')
|
|
||||||
pg.setConfigOptions(antialias=True)
|
|
||||||
# pg.setConfigOption('leftButtonPan', False)
|
|
||||||
|
|
||||||
|
|
||||||
def getDataType(parent):
|
def getDataType(parent):
|
||||||
type = QInputDialog().getItem(parent, "Select phases type", "Type:",
|
type = QInputDialog().getItem(parent, "Select phases type", "Type:",
|
||||||
@ -435,29 +424,30 @@ class PlotWidget(FigureCanvas):
|
|||||||
|
|
||||||
|
|
||||||
class WaveformWidgetPG(QtGui.QWidget):
|
class WaveformWidgetPG(QtGui.QWidget):
|
||||||
def __init__(self, parent=None, xlabel='x', ylabel='y', title='Title'):
|
def __init__(self, parent, title='Title'):
|
||||||
QtGui.QWidget.__init__(self, parent) # , 1)
|
QtGui.QWidget.__init__(self, parent=parent)
|
||||||
self.setParent(parent)
|
self.pg = self.parent().pg
|
||||||
self._parent = parent
|
# added because adding widget to scrollArea will set scrollArea to parent
|
||||||
|
self.orig_parent = parent
|
||||||
# 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()
|
||||||
# create plot
|
# create plot
|
||||||
self.main_layout = QtGui.QVBoxLayout()
|
self.main_layout = QtGui.QVBoxLayout()
|
||||||
self.label = QtGui.QLabel()
|
self.label = QtGui.QLabel()
|
||||||
self.setLayout(self.main_layout)
|
self.setLayout(self.main_layout)
|
||||||
self.plotWidget = pg.PlotWidget(title=title, autoDownsample=True)
|
self.plotWidget = self.pg.PlotWidget(self.parent(), title=title, autoDownsample=True)
|
||||||
self.main_layout.addWidget(self.plotWidget)
|
self.main_layout.addWidget(self.plotWidget)
|
||||||
self.main_layout.addWidget(self.label)
|
self.main_layout.addWidget(self.label)
|
||||||
self.plotWidget.showGrid(x=False, y=True, alpha=0.2)
|
self.plotWidget.showGrid(x=False, y=True, alpha=0.3)
|
||||||
self.plotWidget.hideAxis('bottom')
|
self.plotWidget.hideAxis('bottom')
|
||||||
self.plotWidget.hideAxis('left')
|
self.plotWidget.hideAxis('left')
|
||||||
self.wfstart, self.wfend = 0, 0
|
self.wfstart, self.wfend = 0, 0
|
||||||
self.reinitMoveProxy()
|
self.reinitMoveProxy()
|
||||||
self._proxy = pg.SignalProxy(self.plotWidget.scene().sigMouseMoved, rateLimit=60, slot=self.mouseMoved)
|
self._proxy = self.pg.SignalProxy(self.plotWidget.scene().sigMouseMoved, rateLimit=60, slot=self.mouseMoved)
|
||||||
|
|
||||||
def reinitMoveProxy(self):
|
def reinitMoveProxy(self):
|
||||||
self.vLine = pg.InfiniteLine(angle=90, movable=False)
|
self.vLine = self.pg.InfiniteLine(angle=90, movable=False)
|
||||||
self.hLine = pg.InfiniteLine(angle=0, movable=False)
|
self.hLine = self.pg.InfiniteLine(angle=0, movable=False)
|
||||||
self.plotWidget.addItem(self.vLine, ignoreBounds=True)
|
self.plotWidget.addItem(self.vLine, ignoreBounds=True)
|
||||||
self.plotWidget.addItem(self.hLine, ignoreBounds=True)
|
self.plotWidget.addItem(self.hLine, ignoreBounds=True)
|
||||||
|
|
||||||
@ -467,10 +457,10 @@ class WaveformWidgetPG(QtGui.QWidget):
|
|||||||
mousePoint = self.plotWidget.getPlotItem().vb.mapSceneToView(pos)
|
mousePoint = self.plotWidget.getPlotItem().vb.mapSceneToView(pos)
|
||||||
x, y, = (mousePoint.x(), mousePoint.y())
|
x, y, = (mousePoint.x(), mousePoint.y())
|
||||||
# if x > 0:# and index < len(data1):
|
# if x > 0:# and index < len(data1):
|
||||||
wfID = self._parent.getWFID(y)
|
wfID = self.orig_parent.getWFID(y)
|
||||||
station = self._parent.getStationName(wfID)
|
station = self.orig_parent.getStationName(wfID)
|
||||||
abstime = self.wfstart + x
|
abstime = self.wfstart + x
|
||||||
if self._parent.get_current_event():
|
if self.orig_parent.get_current_event():
|
||||||
self.label.setText("station = {}, T = {}, t = {} [s]".format(station, abstime, x))
|
self.label.setText("station = {}, T = {}, t = {} [s]".format(station, abstime, x))
|
||||||
self.vLine.setPos(mousePoint.x())
|
self.vLine.setPos(mousePoint.x())
|
||||||
self.hLine.setPos(mousePoint.y())
|
self.hLine.setPos(mousePoint.y())
|
||||||
@ -484,12 +474,6 @@ class WaveformWidgetPG(QtGui.QWidget):
|
|||||||
def clearPlotDict(self):
|
def clearPlotDict(self):
|
||||||
self.plotdict = dict()
|
self.plotdict = dict()
|
||||||
|
|
||||||
def getParent(self):
|
|
||||||
return self._parent
|
|
||||||
|
|
||||||
def setParent(self, parent):
|
|
||||||
self._parent = parent
|
|
||||||
|
|
||||||
def plotWFData(self, wfdata, title=None, zoomx=None, zoomy=None,
|
def plotWFData(self, wfdata, title=None, zoomx=None, zoomy=None,
|
||||||
noiselevel=None, scaleddata=False, mapping=True,
|
noiselevel=None, scaleddata=False, mapping=True,
|
||||||
component='*', nth_sample=1, iniPick=None, verbosity=0):
|
component='*', nth_sample=1, iniPick=None, verbosity=0):
|
||||||
@ -3747,6 +3731,12 @@ class GraphicsTab(PropTab):
|
|||||||
self.main_layout.addWidget(self.spinbox_nth_sample, 1, 1)
|
self.main_layout.addWidget(self.spinbox_nth_sample, 1, 1)
|
||||||
|
|
||||||
def add_pg_cb(self):
|
def add_pg_cb(self):
|
||||||
|
try:
|
||||||
|
import pyqtgraph as pg
|
||||||
|
pg = True
|
||||||
|
except:
|
||||||
|
pg = False
|
||||||
|
|
||||||
text = {True: 'Use pyqtgraphic library for plotting',
|
text = {True: 'Use pyqtgraphic library for plotting',
|
||||||
False: 'Cannot use library: pyqtgraphic not found on system'}
|
False: 'Cannot use library: pyqtgraphic not found on system'}
|
||||||
label = QLabel('PyQt graphic')
|
label = QLabel('PyQt graphic')
|
||||||
|
Loading…
Reference in New Issue
Block a user