create a working MainWindow

This commit is contained in:
Sebastian Wehling-Benatelli 2014-12-08 10:26:14 +01:00
parent 9603f7127c
commit ef8bd6572e
4 changed files with 55 additions and 30 deletions

View File

@ -23,6 +23,7 @@ https://www.iconfinder.com/iconsets/flavour
(http://www.gnu.org/copyleft/lesser.html) (http://www.gnu.org/copyleft/lesser.html)
""" """
import os
import sys import sys
from PySide.QtCore import * from PySide.QtCore import *
@ -35,6 +36,7 @@ from pylot.core.read import (Data,
from pylot.core.util import FILTERDEFAULTS from pylot.core.util import FILTERDEFAULTS
from pylot.core.util import fnConstructor from pylot.core.util import fnConstructor
from pylot.core.util import checkurl from pylot.core.util import checkurl
from pylot.core.util import layoutStationButtons
from pylot.core.util import (FilterOptionsDialog, from pylot.core.util import (FilterOptionsDialog,
MPLWidget, MPLWidget,
HelpForm) HelpForm)
@ -46,31 +48,39 @@ __version__ = _getVersionString()
class MainWindow(QMainWindow): class MainWindow(QMainWindow):
closing = Signal()
def __init__(self, parent=None): def __init__(self, parent=None):
super(MainWindow, self).__init__(parent) super(MainWindow, self).__init__(parent)
settings = QSettings() settings = QSettings()
self.recentEvents = settings.value("recentEvents", []) if settings.value("user/FullName", None) is None:
self.setWindowTitle("PyLoT - do seismic processing the pythonic way") fulluser = QInputDialog.getText(self, "Enter Name:", "Full name")
settings.setValue("user/FullName", fulluser)
settings.setValue("user/Login", os.getlogin())
settings.sync()
self.recentEvents = settings.value("data/recentEvents", [])
self.setWindowTitle("PyLoT - do seismic processing the python way")
self.setWindowIcon(QIcon(":/icon.ico")) self.setWindowIcon(QIcon(":/icon.ico"))
self.seismicPhase = str(settings.value("phase", "P")) self.seismicPhase = str(settings.value("phase", "P"))
if settings.value("dataRoot", None) is None: if settings.value("data/dataRoot", None) is None:
dirname = QFileDialog().getExistingDirectory() dirname = QFileDialog().getExistingDirectory(caption = 'Choose data root ...')
settings.setValue("dataRoot", dirname) settings.setValue("data/dataRoot", dirname)
settings.sync() settings.sync()
# initialize filter parameter # initialize filter parameter
filterOptionsP = FILTERDEFAULTS['P'] filterOptionsP = FILTERDEFAULTS['P']
filterOptionsS = FILTERDEFAULTS['S'] filterOptionsS = FILTERDEFAULTS['S']
print filterOptionsP, "\n", filterOptionsS # print filterOptionsP, "\n", filterOptionsS
self.filterOptionsP = FilterOptions(**filterOptionsP) self.filterOptionsP = FilterOptions(**filterOptionsP)
self.filterOptionsS = FilterOptions(**filterOptionsS) self.filterOptionsS = FilterOptions(**filterOptionsS)
# initialize data # initialize data
self.data = None self.data = None
self.dirty = False
self.loadData() self.loadData()
self.updateFilterOptions() self.updateFilterOptions()
print self.filteroptions # print self.filteroptions
try: try:
self.startTime = min([tr.stats.starttime for tr in self.data.wfdata]) self.startTime = min([tr.stats.starttime for tr in self.data.wfdata])
except: except:
@ -103,7 +113,7 @@ class MainWindow(QMainWindow):
self.fileMenu.clear() self.fileMenu.clear()
self.addActions(self.fileMenu, self.fileMenuActions[:-1]) self.addActions(self.fileMenu, self.fileMenuActions[:-1])
current = self.data.evtdata.getEventID() current = self.data.evtdata.getID()
recentEvents = [] recentEvents = []
for eventID in self.recentEvents: for eventID in self.recentEvents:
fname = fnConstructor(eventID) fname = fnConstructor(eventID)
@ -141,7 +151,7 @@ class MainWindow(QMainWindow):
self.data = Data(evtdata=fname) self.data = Data(evtdata=fname)
def saveData(self): def saveData(self):
pass return True
def getComponent(self): def getComponent(self):
return self return self
@ -158,13 +168,19 @@ class MainWindow(QMainWindow):
xlab = self.startTime.strftime('seconds since %d %b %Y %H:%M:%S (%Z)') xlab = self.startTime.strftime('seconds since %d %b %Y %H:%M:%S (%Z)')
plottitle = self._getCurrentPlotType() plottitle = self._getCurrentPlotType()
_widget = QWidget()
_layout = QHBoxLayout()
# create central matplotlib figure widget # create central matplotlib figure widget
self.DataPlot = MPLWidget(parent=self, self.DataPlot = MPLWidget(parent=self,
xlabel=xlab, xlabel=xlab,
ylabel=None, ylabel=None,
title=plottitle) title=plottitle)
statsButtons = layoutStationButtons(self.getData(), self.getComponent())
self.setCentralWidget(self.getDataWidget()) _layout.addLayout(statsButtons)
_layout.addWidget(self.DataPlot)
self.setLayout(_layout)
self.setCentralWidget(_widget)
openIcon = self.style().standardIcon(QStyle.SP_DirOpenIcon) openIcon = self.style().standardIcon(QStyle.SP_DirOpenIcon)
quitIcon = self.style().standardIcon(QStyle.SP_MediaStop) quitIcon = self.style().standardIcon(QStyle.SP_MediaStop)
@ -219,15 +235,6 @@ class MainWindow(QMainWindow):
status.addPermanentWidget(self.eventLabel) status.addPermanentWidget(self.eventLabel)
status.showMessage("Ready", 500) status.showMessage("Ready", 500)
# statLayout = layoutStationButtons(self.getData(), self.getComponent())
# dataLayout = self.getDataWidget()
# maingrid = QGridLayout()
# maingrid.setSpacing(10)
# maingrid.addLayout(statLayout, 0, 0)
# maingrid.addWidget(self.getDataWidget(), 0, 1)
# self.setLayout(maingrid)
def okToContinue(self): def okToContinue(self):
if self.dirty: if self.dirty:
return self.saveData() return self.saveData()
@ -283,12 +290,25 @@ class MainWindow(QMainWindow):
def updateStatus(self, message): def updateStatus(self, message):
self.statusBar().showMessage(message, 5000) self.statusBar().showMessage(message, 5000)
if self.getData() is not None:
if not self.getData().isNew():
self.setWindowTitle("PyLoT - processing event %s[*]" % self.getData().getID())
elif self.getData().isNew():
self.setWindowTitle("PyLoT - New event [*]")
else:
self.setWindowTitle("PyLoT - seismic processing the python way[*]")
self.setWindowTitle("PyLoT - seismic processing the python way[*]")
self.setWindowModified(self.dirty)
self.statusBar().showMessage(message, 5000)
def printEvent(self): def printEvent(self):
pass pass
def closeEvent(self): def closeEvent(self, event):
return self.saveData() if self.okToContinue():
self.closing.emit()
QMainWindow.closeEvent(self, event)
def helpHelp(self): def helpHelp(self):
if checkurl(): if checkurl():
@ -313,7 +333,7 @@ def main():
# Show main window and run the app # Show main window and run the app
pylot_form.show() pylot_form.show()
sys.exit(pylot_app.exec_()) pylot_app.exec_()
if __name__ == "__main__": if __name__ == "__main__":
main() sys.exit(main())

View File

@ -1 +1 @@
e6ac-dirty 9603-dirty

View File

@ -44,14 +44,19 @@ class Data(object):
self.wfdata = Stream() self.wfdata = Stream()
else: else:
self.wfdata = Stream() self.wfdata = Stream()
self.newevent = False
if evtdata is not None and isinstance(evtdata, Event): if evtdata is not None and isinstance(evtdata, Event):
self.evtdata = evtdata self.evtdata = evtdata
elif evtdata is not None: elif evtdata is not None:
cat = readEvents(evtdata) cat = readEvents(evtdata)
self.evtdata = cat[0] self.evtdata = cat[0]
else: # create an empty Event object else: # create an empty Event object
self.newevent = True
self.evtdata = Event() self.evtdata = Event()
def isNew(self):
return self.newevent
def exportEvent(self, fnout=None, evtformat='QUAKEML'): def exportEvent(self, fnout=None, evtformat='QUAKEML'):
if fnout is None: if fnout is None:
@ -75,7 +80,7 @@ class Data(object):
pass #axes = widget.axes pass #axes = widget.axes
def getEventID(self): def getID(self):
try: try:
return self.evtdata.get('resource_id').id return self.evtdata.get('resource_id').id
except: except:

File diff suppressed because one or more lines are too long