[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))
|
||||
if os.path.isfile(infile) == False:
|
||||
infile = QFileDialog().getOpenFileName(caption='Choose PyLoT-input file')
|
||||
|
||||
if not os.path.exists(infile[0]):
|
||||
QMessageBox.warning(self, "PyLoT Warning",
|
||||
"No PyLoT-input file declared!")
|
||||
@ -209,6 +210,8 @@ class MainWindow(QMainWindow):
|
||||
except:
|
||||
self.startTime = UTCDateTime()
|
||||
|
||||
self.init_styles()
|
||||
|
||||
pylot_icon = QIcon()
|
||||
pylot_icon.addPixmap(QPixmap(':/icons/pylot.png'))
|
||||
|
||||
@ -566,21 +569,22 @@ class MainWindow(QMainWindow):
|
||||
self.eventBox.activated.connect(self.refreshEvents)
|
||||
|
||||
# add main tab widget
|
||||
self.tabs = QTabWidget()
|
||||
self.tabs = QTabWidget(self)
|
||||
self._main_layout.addWidget(self.tabs)
|
||||
self.tabs.currentChanged.connect(self.refreshTabs)
|
||||
|
||||
# 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
|
||||
self.pg = pg
|
||||
#self.set_style('custom')
|
||||
self.init_wfWidget()
|
||||
|
||||
# init main widgets for main tabs
|
||||
wf_tab = QtGui.QWidget()
|
||||
array_tab = QtGui.QWidget()
|
||||
events_tab = QtGui.QWidget()
|
||||
wf_tab = QtGui.QWidget(self)
|
||||
array_tab = QtGui.QWidget(self)
|
||||
events_tab = QtGui.QWidget(self)
|
||||
|
||||
# init main widgets layouts
|
||||
self.wf_layout = QtGui.QVBoxLayout()
|
||||
@ -623,8 +627,8 @@ class MainWindow(QMainWindow):
|
||||
self.dataPlot = PylotCanvas(parent=self, connect_events=False, multicursor=True)
|
||||
self.dataPlot.updateWidget(xlab, None, plottitle)
|
||||
else:
|
||||
self.pg = True
|
||||
self.dataPlot = WaveformWidgetPG(parent=self, xlabel=xlab, ylabel=None,
|
||||
self.pg = pg
|
||||
self.dataPlot = WaveformWidgetPG(parent=self,
|
||||
title=plottitle)
|
||||
self.dataPlot.setCursor(Qt.CrossCursor)
|
||||
self.wf_scroll_area.setWidget(self.dataPlot)
|
||||
@ -662,6 +666,53 @@ class MainWindow(QMainWindow):
|
||||
if event.key() == QtCore.Qt.Key.Key_Shift:
|
||||
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
|
||||
def metadata(self):
|
||||
return self._metadata
|
||||
@ -1521,7 +1572,7 @@ class MainWindow(QMainWindow):
|
||||
self.getPlotWidget().updateWidget()
|
||||
plots = self.wfp_thread.data
|
||||
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.plotWidget.showAxis('left')
|
||||
self.dataPlot.plotWidget.showAxis('bottom')
|
||||
@ -2498,7 +2549,7 @@ class MainWindow(QMainWindow):
|
||||
self.events_layout.removeWidget(self.event_table)
|
||||
|
||||
# init new qtable
|
||||
self.event_table = QtGui.QTableWidget()
|
||||
self.event_table = QtGui.QTableWidget(self)
|
||||
self.event_table.setColumnCount(12)
|
||||
self.event_table.setRowCount(len(eventlist))
|
||||
self.event_table.setHorizontalHeaderLabels(['',
|
||||
@ -2775,7 +2826,7 @@ class MainWindow(QMainWindow):
|
||||
if not self.okToContinue():
|
||||
return
|
||||
if not fnm:
|
||||
dlg = QFileDialog()
|
||||
dlg = QFileDialog(parent=self)
|
||||
fnm = dlg.getOpenFileName(self, 'Open project file...', filter='Pylot project (*.plp)')
|
||||
if not fnm:
|
||||
return
|
||||
@ -2802,7 +2853,7 @@ class MainWindow(QMainWindow):
|
||||
'''
|
||||
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)')
|
||||
filename = fnm[0]
|
||||
if not len(fnm[0]):
|
||||
@ -3084,7 +3135,6 @@ def create_window():
|
||||
# window.show()
|
||||
return app, app_created
|
||||
|
||||
|
||||
def main(args=None):
|
||||
project_filename = None
|
||||
pylot_infile = None
|
||||
|
@ -16,11 +16,6 @@ import time
|
||||
|
||||
import numpy as np
|
||||
|
||||
try:
|
||||
import pyqtgraph as pg
|
||||
except:
|
||||
pg = None
|
||||
|
||||
from matplotlib.figure import Figure
|
||||
from pylot.core.util.utils import find_horizontals, identifyPhase, loopIdentifyPhase, trim_station_components, \
|
||||
identifyPhaseID, check4rotated
|
||||
@ -64,12 +59,6 @@ elif sys.version_info.major == 2:
|
||||
else:
|
||||
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):
|
||||
type = QInputDialog().getItem(parent, "Select phases type", "Type:",
|
||||
@ -435,29 +424,30 @@ class PlotWidget(FigureCanvas):
|
||||
|
||||
|
||||
class WaveformWidgetPG(QtGui.QWidget):
|
||||
def __init__(self, parent=None, xlabel='x', ylabel='y', title='Title'):
|
||||
QtGui.QWidget.__init__(self, parent) # , 1)
|
||||
self.setParent(parent)
|
||||
self._parent = parent
|
||||
def __init__(self, parent, title='Title'):
|
||||
QtGui.QWidget.__init__(self, parent=parent)
|
||||
self.pg = self.parent().pg
|
||||
# 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
|
||||
self.plotdict = dict()
|
||||
# create plot
|
||||
self.main_layout = QtGui.QVBoxLayout()
|
||||
self.label = QtGui.QLabel()
|
||||
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.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('left')
|
||||
self.wfstart, self.wfend = 0, 0
|
||||
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):
|
||||
self.vLine = pg.InfiniteLine(angle=90, movable=False)
|
||||
self.hLine = pg.InfiniteLine(angle=0, movable=False)
|
||||
self.vLine = self.pg.InfiniteLine(angle=90, movable=False)
|
||||
self.hLine = self.pg.InfiniteLine(angle=0, movable=False)
|
||||
self.plotWidget.addItem(self.vLine, ignoreBounds=True)
|
||||
self.plotWidget.addItem(self.hLine, ignoreBounds=True)
|
||||
|
||||
@ -467,10 +457,10 @@ class WaveformWidgetPG(QtGui.QWidget):
|
||||
mousePoint = self.plotWidget.getPlotItem().vb.mapSceneToView(pos)
|
||||
x, y, = (mousePoint.x(), mousePoint.y())
|
||||
# if x > 0:# and index < len(data1):
|
||||
wfID = self._parent.getWFID(y)
|
||||
station = self._parent.getStationName(wfID)
|
||||
wfID = self.orig_parent.getWFID(y)
|
||||
station = self.orig_parent.getStationName(wfID)
|
||||
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.vLine.setPos(mousePoint.x())
|
||||
self.hLine.setPos(mousePoint.y())
|
||||
@ -484,12 +474,6 @@ class WaveformWidgetPG(QtGui.QWidget):
|
||||
def clearPlotDict(self):
|
||||
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,
|
||||
noiselevel=None, scaleddata=False, mapping=True,
|
||||
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)
|
||||
|
||||
def add_pg_cb(self):
|
||||
try:
|
||||
import pyqtgraph as pg
|
||||
pg = True
|
||||
except:
|
||||
pg = False
|
||||
|
||||
text = {True: 'Use pyqtgraphic library for plotting',
|
||||
False: 'Cannot use library: pyqtgraphic not found on system'}
|
||||
label = QLabel('PyQt graphic')
|
||||
|
Loading…
Reference in New Issue
Block a user