moved function createAction to the widgets module (reused in additional widget)

bugfix: on Linux systems os.getlogin raises an exception (reimplementation: getLogin)
This commit is contained in:
Sebastian Wehling 2015-03-04 11:52:04 +01:00
parent b23c9d1104
commit 0dbcca1c6f
4 changed files with 30 additions and 27 deletions

View File

@ -23,7 +23,6 @@ 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 QCoreApplication, QSettings, Signal, QFile, QFileInfo from PySide.QtCore import QCoreApplication, QSettings, Signal, QFile, QFileInfo
@ -36,7 +35,7 @@ from pylot.core.read import Data, FilterOptions
from pylot.core.util import _getVersionString, FILTERDEFAULTS, fnConstructor, \ from pylot.core.util import _getVersionString, FILTERDEFAULTS, fnConstructor, \
checkurl, FormatError, FilterOptionsDialog, \ checkurl, FormatError, FilterOptionsDialog, \
NewEventDlg, createEvent, MPLWidget, PropertiesDlg, HelpForm, \ NewEventDlg, createEvent, MPLWidget, PropertiesDlg, HelpForm, \
DatastructureError DatastructureError, createAction, getLogin
from pylot.core.util.structure import DATASTRUCTURE from pylot.core.util.structure import DATASTRUCTURE
@ -51,17 +50,19 @@ class MainWindow(QMainWindow):
def __init__(self, parent=None): def __init__(self, parent=None):
super(MainWindow, self).__init__(parent) super(MainWindow, self).__init__(parent)
self.createAction = createAction
self.dirty = False self.dirty = False
settings = QSettings() settings = QSettings()
if settings.value("user/FullName", None) is None: if settings.value("user/FullName", None) is None:
fulluser = QInputDialog.getText(self, "Enter Name:", "Full name") fulluser = QInputDialog.getText(self, "Enter Name:", "Full name")
settings.setValue("user/FullName", fulluser) settings.setValue("user/FullName", fulluser)
settings.setValue("user/Login", os.getlogin()) settings.setValue("user/Login", getLogin())
settings.sync() settings.sync()
self.recentEvents = settings.value("data/recentEvents", []) self.recentEvents = settings.value("data/recentEvents", [])
self.fnames = None self.fnames = None
self.dataStructure = DATASTRUCTURE[ self.dataStructure = DATASTRUCTURE[
settings.value("data/Structure", None)]() settings.value("data/Structure", "PILOT")]()
self.seismicPhase = str(settings.value("phase", "P")) self.seismicPhase = str(settings.value("phase", "P"))
self.dispComponent = str(settings.value("plotting/dispComponent", "Z")) self.dispComponent = str(settings.value("plotting/dispComponent", "Z"))
if settings.value("data/dataRoot", None) is None: if settings.value("data/dataRoot", None) is None:
@ -89,7 +90,6 @@ class MainWindow(QMainWindow):
self.updateFilterOptions() self.updateFilterOptions()
def setupUi(self): def setupUi(self):
try: try:
@ -205,23 +205,6 @@ class MainWindow(QMainWindow):
_widget.setLayout(_layout) _widget.setLayout(_layout)
self.setCentralWidget(_widget) self.setCentralWidget(_widget)
def createAction(self, text, slot=None, shortcut=None, icon=None,
tip=None, checkable=False):
"""
:rtype : ~PySide.QtGui.QAction
"""
action = QAction(text, self)
if icon is not None:
action.setIcon(icon)
if shortcut is not None:
action.setShortcut(shortcut)
if tip is not None:
action.setToolTip(tip)
if slot is not None:
action.triggered.connect(slot)
if checkable:
action.setCheckable(True)
return action
def updateFileMenu(self): def updateFileMenu(self):
@ -335,7 +318,7 @@ class MainWindow(QMainWindow):
def getData(self): def getData(self):
return self.data return self.data
def getDataWidget(self): def getPlotWidget(self):
return self.DataPlot return self.DataPlot
def addActions(self, target, actions): def addActions(self, target, actions):
@ -359,7 +342,7 @@ class MainWindow(QMainWindow):
self.plotWaveformData() self.plotWaveformData()
def plotWaveformData(self): def plotWaveformData(self):
self.getData().plotWFData(self.getDataWidget()) self.getData().plotWFData(self.getPlotWidget())
def filterWaveformData(self): def filterWaveformData(self):
if self.getData(): if self.getData():

View File

@ -4,9 +4,9 @@ from pylot.core.util.errors import OptionsError, FormatError, DatastructureError
from pylot.core.util.layouts import layoutStationButtons from pylot.core.util.layouts import layoutStationButtons
from pylot.core.util.utils import fnConstructor, createArrival, createEvent,\ from pylot.core.util.utils import fnConstructor, createArrival, createEvent,\
createPick, createAmplitude, createOrigin, createMagnitude, getOwner, \ createPick, createAmplitude, createOrigin, createMagnitude, getOwner, \
getHash getHash, getLogin
from pylot.core.util.widgets import PickDlg, HelpForm, FilterOptionsDialog,\ from pylot.core.util.widgets import PickDlg, HelpForm, FilterOptionsDialog,\
PropertiesDlg, NewEventDlg, MPLWidget PropertiesDlg, NewEventDlg, MPLWidget, createAction
from pylot.core.util.version import get_git_version as _getVersionString from pylot.core.util.version import get_git_version as _getVersionString

View File

@ -23,9 +23,11 @@ def fnConstructor(s):
return fn return fn
def getLogin():
return pwd.getpwuid(os.getuid())[0]
def getHash(time): def getHash(time):
''' '''
:param time: time object for which a hash should be calculated :param time: time object for which a hash should be calculated
:type time: :class: `~obspy.core.utcdatetime.UTCDateTime` object :type time: :class: `~obspy.core.utcdatetime.UTCDateTime` object
:return: str :return: str

View File

@ -43,6 +43,24 @@ from pylot.core.read import FilterOptions
from pylot.core.util.defaults import OUTPUTFORMATS from pylot.core.util.defaults import OUTPUTFORMATS
def createAction(parent, text, slot=None, shortcut=None, icon=None,
tip=None, checkable=False):
"""
:rtype : ~PySide.QtGui.QAction
"""
action = QAction(text, parent)
if icon is not None:
action.setIcon(icon)
if shortcut is not None:
action.setShortcut(shortcut)
if tip is not None:
action.setToolTip(tip)
if slot is not None:
action.triggered.connect(slot)
if checkable:
action.setCheckable(True)
return action
class MPLWidget(FigureCanvas): class MPLWidget(FigureCanvas):
def __init__(self, parent=None, xlabel='x', ylabel='y', title='Title'): def __init__(self, parent=None, xlabel='x', ylabel='y', title='Title'):