Commit 6ebdf3fb authored by DN's avatar DN

Added open/create actions.

parent 00185a8f
......@@ -29,28 +29,44 @@ import os
from silx.gui import qt as Qt
from .Utils import nextFileName
from .icons import getQIcon as getXsocsIcon
from .widgets.Wizard import XsocsWizard
from .process.RecipSpaceWidget import RecipSpaceWidget
from .process.FitWidget import FitWidget
from .view.IntensityView import IntensityView
from .view.QspaceView import QSpaceView
from .widgets.ProjectChooser import ProjectChooserDialog
from .view.FitView import FitView
from .project.XsocsProject import XsocsProject
from .view.QspaceView import QSpaceView
from .view.IntensityView import IntensityView
from .model.TreeView import TreeView
from .model.Model import Model
from .project.IntensityGroup import IntensityGroup
from .project.QSpaceGroup import QSpaceItem
from .model.ModelDef import ModelRoles
from .model.Model import Model, RootNode
from .process.FitWidget import FitWidget
from .process.RecipSpaceWidget import RecipSpaceWidget
from .project.FitGroup import FitItem
from .project.XsocsH5Factory import XsocsH5Factory, h5NodeToProjectItem
from .project.QSpaceGroup import QSpaceItem
from .project.XsocsProject import XsocsProject
from .project.IntensityGroup import IntensityGroup
from .project.Hdf5Nodes import setH5NodeFactory, H5File
from .Utils import nextFileName
from .model.ModelDef import ModelRoles
from .project.XsocsH5Factory import XsocsH5Factory, h5NodeToProjectItem
_COMPANY_NAME = 'ESRF'
_APP_NAME = 'XSOCS'
class ProjectRoot(RootNode):
ColumnNames = ['Item', '']
class ProjectModel(Model):
RootNode = ProjectRoot
class ProjectTree(TreeView):
sigDelegateEvent = Qt.Signal(object, object)
......@@ -61,17 +77,20 @@ class ProjectTree(TreeView):
class XsocsGui(Qt.QMainWindow):
__sigQueuedClose = Qt.Signal()
def __init__(self,
parent=None,
projectH5File=None):
super(XsocsGui, self).__init__(parent)
self.statusBar()
setH5NodeFactory(XsocsH5Factory)
self.move(0, 0)
self.resize(300, 600)
self.__project = None
self.__intensityView = None
self.__qspaceViews = {}
self.__fitViews = {}
......@@ -79,22 +98,20 @@ class XsocsGui(Qt.QMainWindow):
self.__createViews()
self.__createActions()
self.__createMenus()
# self.__createToolBars()
self.__createToolBars()
self.__startupprojectH5File = projectH5File
self.__widget_setup = False
self.__sigQueuedClose.connect(self.__close, Qt.Qt.QueuedConnection)
self.__readSettings()
def __close(self):
self.deleteLater()
self.__setupProject(projectFile=projectH5File)
def __createViews(self):
tree = ProjectTree()
tree.setShowUniqueGroup(False)
tree.sigDelegateEvent.connect(self.__viewEvent)
model = Model(parent=tree)
model = ProjectModel(parent=tree)
model.startModel()
tree.setModel(model)
self.setCentralWidget(tree)
......@@ -119,6 +136,8 @@ class XsocsGui(Qt.QMainWindow):
''.format(projectItem, event))
def __showIntensity(self, node=None):
if self.__project is None:
return
view = self.__intensityView
if not view:
if node is None:
......@@ -213,16 +232,6 @@ class XsocsGui(Qt.QMainWindow):
def model(self):
return self.tree.model()
def showEvent(self, event):
super(XsocsGui, self).showEvent(event)
if not self.__widget_setup:
# self.__firstInitSig.emit()
if not self.__showWizard():
self.__sigQueuedClose.emit()
return
self.__widget_setup = True
self.__showIntensity()
def closeEvent(self, event):
self.__writeSettings()
super(XsocsGui, self).closeEvent(event)
......@@ -243,34 +252,44 @@ class XsocsGui(Qt.QMainWindow):
self.restoreState(settings.value("MainWindow/state", Qt.QByteArray()))
settings.endGroup()
def __showWizard(self):
projectFile = self.__startupprojectH5File
def __setupProject(self, projectFile=None):
if projectFile is None:
wizard = XsocsWizard(parent=self)
if wizard.exec_() == Qt.QDialog.Accepted:
# TODO : we suppose that we get a valid file... maybe we should
# perform some checks...
projectFile = wizard.projectFile
wizard.deleteLater()
else:
wizard.deleteLater()
return False
self.__setupProject(projectFile=projectFile)
return True
self.__project = None
return
def __setupProject(self, projectFile=None):
mode = 'r+'
project = XsocsProject(projectFile, mode=mode)
rootNode = H5File(h5File=projectFile)
self.tree.model().appendGroup(rootNode)
model = self.tree.model()
model.removeRow(0)
model.appendGroup(rootNode)
self.__project = project
self.__showIntensity()
return True
def __createActions(self):
style = Qt.QApplication.style()
self.__actions = actions = {}
# load
icon = style.standardIcon(Qt.QStyle.SP_DialogOpenButton)
openAct = Qt.QAction(icon, '&Open project', self)
openAct.setShortcuts(Qt.QKeySequence.Open)
openAct.setStatusTip('Open an existing project')
openAct.triggered.connect(self.__openProject)
actions['open'] = openAct
# create
icon = getXsocsIcon('create_project')
createAct = Qt.QAction(icon, '&Create project', self)
createAct.setShortcuts(Qt.QKeySequence.New)
createAct.setStatusTip('Create a new project')
createAct.triggered.connect(self.__createProject)
actions['create'] = createAct
# exit the application
icon = style.standardIcon(Qt.QStyle.SP_DialogCancelButton)
quitAct = Qt.QAction(icon, 'E&xit', self)
......@@ -291,6 +310,8 @@ class XsocsGui(Qt.QMainWindow):
menuBar = self.menuBar()
fileMenu = menuBar.addMenu('&File')
fileMenu.addAction(actions['open'])
fileMenu.addAction(actions['create'])
fileMenu.addSeparator()
fileMenu.addAction(actions['quit'])
......@@ -302,6 +323,39 @@ class XsocsGui(Qt.QMainWindow):
menus['file'] = fileMenu
menus['help'] = helpMenu
def __createToolBars(self):
actions = self.__actions
toolBar = self.addToolBar('File')
toolBar.setObjectName('Toolbar/File')
toolBar.addAction(actions['open'])
toolBar.addAction(actions['create'])
def __openProject(self):
dialog = ProjectChooserDialog(self)
dialog.setFixedWidth(500)
rc = dialog.exec_()
if rc == Qt.QDialog.Accepted:
projectFile = dialog.projectFile
dialog.deleteLater()
else:
dialog.deleteLater()
return
self.__setupProject(projectFile)
def __createProject(self):
wizard = XsocsWizard(parent=self)
if wizard.exec_() == Qt.QDialog.Accepted:
# TODO : we suppose that we get a valid file... maybe we should
# perform some checks...
projectFile = wizard.projectFile
wizard.deleteLater()
else:
wizard.deleteLater()
return False
self.__setupProject(projectFile=projectFile)
return True
# ####################################################################
# ####################################################################
......
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2015-2016 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/
from __future__ import absolute_import
__authors__ = ["D. Naudet"]
__license__ = "MIT"
__date__ = "15/09/2016"
import os
from silx.gui import qt as Qt
from ...io.XsocsH5 import XsocsH5
from .FileChooser import FileChooser
from ..widgets.Containers import GroupBox
from ..project.XsocsProject import XsocsProject
class ProjectChooserDialog(Qt.QDialog):
projectFile = property(lambda self: self.__projectFile)
def __init__(self, parent=None):
super(ProjectChooserDialog, self).__init__(parent)
self.__projectFile = None
layout = Qt.QVBoxLayout(self)
prjChooser = ProjectChooser()
layout.addWidget(prjChooser)
prjChooser.sigProjectPicked.connect(self.__prjPicked)
self.__bnBox = bnBox = Qt.QDialogButtonBox(Qt.QDialogButtonBox.Open |
Qt.QDialogButtonBox.Cancel)
bnBox.rejected.connect(self.reject)
bnBox.accepted.connect(self.accept)
bnBox.button(Qt.QDialogButtonBox.Open).setEnabled(False)
layout.addWidget(bnBox)
def __prjPicked(self, filename):
if filename:
self.__projectFile = filename
enabled = True
else:
self.__projectFile = None
enabled = False
self.__bnBox.button(Qt.QDialogButtonBox.Open).setEnabled(enabled)
class ProjectChooser(Qt.QWidget):
sigProjectPicked = Qt.Signal(object)
projectSummary = property(lambda self:
self.findChild(ProjectSummaryWidget))
def __init__(self, parent=None):
super(ProjectChooser, self).__init__(parent)
layout = Qt.QVBoxLayout(self)
self.__isValid = False
self.__selectedPath = None
group = GroupBox('Please select the project file to open.')
layout.addWidget(group)
grpLayout = Qt.QHBoxLayout(group)
filePicker = FileChooser(fileMode=Qt.QFileDialog.ExistingFile)
filePicker.setObjectName('PROJ_FILEPICKER')
grpLayout.addWidget(filePicker)
filePicker.sigSelectionChanged.connect(self.__filePicked)
fileDialog = filePicker.fileDialog
fileDialog.setNameFilters(['Xsocs project files (*.prj)',
'Any files (*)'])
group = GroupBox('Project Summary')
layout.addWidget(group)
grpLayout = Qt.QVBoxLayout(group)
view = ProjectSummaryWidget()
grpLayout.addWidget(view)
def __filePicked(self, selectedPath):
self.__selectedPath = selectedPath
view = self.projectSummary
view.setProjectFile(selectedPath)
valid = view.isValidProject()
self.__isValid = valid
if valid:
self.sigProjectPicked.emit(selectedPath)
else:
self.sigProjectPicked.emit('')
def isValid(self):
return self.__isValid
class ProjectSummaryWidget(Qt.QWidget):
def __init__(self, projectFile=None, parent=None):
super(ProjectSummaryWidget, self).__init__(parent)
self.__valid = False
layout = Qt.QVBoxLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
view = Qt.QTreeWidget()
view.setColumnCount(2)
view.setHeaderLabels(['Name', 'Value'])
view.header().setResizeMode(Qt.QHeaderView.ResizeToContents)
layout.addWidget(view)
self.setProjectFile(projectFile)
def isValidProject(self):
return self.__valid
def setProjectFile(self, projectFile):
view = self.findChild(Qt.QTreeWidget)
view.clear()
self.__valid = False
if projectFile is None:
return
errMsg = ''
try:
# reading project file
errMsg = 'Failed to open X-Socs project file.'
projectH5 = XsocsProject(projectFile, mode='r')
# reading XSOCS data file
errMsg = 'Failed to open X-Socs data file.'
xsocsFile = projectH5.xsocsFile
xsocsH5 = XsocsH5(xsocsFile, mode='r')
# getting entries
errMsg = 'Failed to read entries from data file.'
entries = xsocsH5.entries()
# getting entries
errMsg = 'Failed to read scan parameters.'
params = xsocsH5.scan_params(entries[0])
inputItem = Qt.QTreeWidgetItem(
['Data file', os.path.basename(xsocsFile)])
inputItem.setToolTip(0, xsocsFile)
inputItem.setToolTip(1, xsocsFile)
inputItem.addChild(Qt.QTreeWidgetItem(['Full path', xsocsFile]))
view.addTopLevelItem(inputItem)
# getting scan angles
errMsg = 'Failed to read scan angles.'
# TODO : check that there are at least 2 angles
text = '{0} [{1} -> {2}]'.format(
str(len(entries)),
str(xsocsH5.scan_angle(entries[0])),
str(xsocsH5.scan_angle(entries[-1])))
entriesItem = Qt.QTreeWidgetItem(['Angles', text])
for entryIdx, entry in enumerate(entries):
text = 'eta = {0}'.format(str(xsocsH5.scan_angle(entry)))
entryItem = Qt.QTreeWidgetItem([str(entryIdx), text])
entriesItem.addChild(entryItem)
view.addTopLevelItem(entriesItem)
# getting acquisition params
errMsg = 'Failed to read Acquisition parameters.'
title = ' '.join(str(value) for value in params.values())
commandItem = Qt.QTreeWidgetItem(['Scan', title])
commandItem.setToolTip(0, title)
commandItem.setToolTip(1, title)
for key, value in params.items():
commandItem.addChild(Qt.QTreeWidgetItem([key, str(value)]))
view.addTopLevelItem(commandItem)
for key, value in xsocsH5.acquisition_params(entries[0]).items():
view.addTopLevelItem(Qt.QTreeWidgetItem([key, str(value)]))
except Exception as ex:
style = Qt.QApplication.style()
errorItem = Qt.QTreeWidgetItem(['', errMsg])
icon = style.standardIcon(Qt.QStyle.SP_MessageBoxCritical)
errorItem.setIcon(0, icon)
errorItem.setBackground(1, Qt.QBrush(Qt.Qt.red))
exItem = Qt.QTreeWidgetItem([ex.__class__.__name__, str(ex)])
errorItem.addChild(exItem)
view.addTopLevelItem(errorItem)
errorItem.setExpanded(True)
return
self.__valid = True
\ No newline at end of file
......@@ -25,6 +25,7 @@
from __future__ import absolute_import
__authors__ = ["D. Naudet"]
__license__ = "MIT"
__date__ = "15/09/2016"
......@@ -35,12 +36,12 @@ from functools import partial
from silx.gui import qt as Qt
from ...io.XsocsH5 import XsocsH5
from .. import icons as XsocsIcons
from .FileChooser import FileChooser
from ..widgets.Containers import GroupBox
from ..process.MergeWidget import MergeWidget
from ..project.XsocsProject import XsocsProject
from .ProjectChooser import ProjectSummaryWidget
class XsocsWizard(Qt.QWizard):
......@@ -199,104 +200,6 @@ class SelectDataPage(Qt.QWizardPage):
self.wizard().next()
class ProjectSummaryWidget(Qt.QWidget):
def __init__(self, projectFile=None, parent=None):
super(ProjectSummaryWidget, self).__init__(parent)
self.__valid = False
layout = Qt.QVBoxLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
view = Qt.QTreeWidget()
view.setColumnCount(2)
view.setHeaderLabels(['Name', 'Value'])
view.header().setResizeMode(Qt.QHeaderView.ResizeToContents)
layout.addWidget(view)
self.setProjectFile(projectFile)
def isValidProject(self):
return self.__valid
def setProjectFile(self, projectFile):
view = self.findChild(Qt.QTreeWidget)
view.clear()
self.__valid = False
if projectFile is None:
return
errMsg = ''
try:
# reading project file
errMsg = 'Failed to open X-Socs project file.'
projectH5 = XsocsProject(projectFile, mode='r')
# reading XSOCS data file
errMsg = 'Failed to open X-Socs data file.'
xsocsFile = projectH5.xsocsFile
xsocsH5 = XsocsH5(xsocsFile, mode='r')
# getting entries
errMsg = 'Failed to read entries from data file.'
entries = xsocsH5.entries()
# getting entries
errMsg = 'Failed to read scan parameters.'
params = xsocsH5.scan_params(entries[0])
inputItem = Qt.QTreeWidgetItem(
['Data file', os.path.basename(xsocsFile)])
inputItem.setToolTip(0, xsocsFile)
inputItem.setToolTip(1, xsocsFile)
inputItem.addChild(Qt.QTreeWidgetItem(['Full path', xsocsFile]))
view.addTopLevelItem(inputItem)
# getting scan angles
errMsg = 'Failed to read scan angles.'
# TODO : check that there are at least 2 angles
text = '{0} [{1} -> {2}]'.format(
str(len(entries)),
str(xsocsH5.scan_angle(entries[0])),
str(xsocsH5.scan_angle(entries[-1])))
entriesItem = Qt.QTreeWidgetItem(['Angles', text])
for entryIdx, entry in enumerate(entries):
text = 'eta = {0}'.format(str(xsocsH5.scan_angle(entry)))
entryItem = Qt.QTreeWidgetItem([str(entryIdx), text])
entriesItem.addChild(entryItem)
view.addTopLevelItem(entriesItem)
# getting acquisition params
errMsg = 'Failed to read Acquisition parameters.'
title = ' '.join(str(value) for value in params.values())
commandItem = Qt.QTreeWidgetItem(['Scan', title])
commandItem.setToolTip(0, title)
commandItem.setToolTip(1, title)
for key, value in params.items():
commandItem.addChild(Qt.QTreeWidgetItem([key, str(value)]))
view.addTopLevelItem(commandItem)
for key, value in xsocsH5.acquisition_params(entries[0]).items():
view.addTopLevelItem(Qt.QTreeWidgetItem([key, str(value)]))
except Exception as ex:
style = Qt.QApplication.style()
errorItem = Qt.QTreeWidgetItem(['', errMsg])
icon = style.standardIcon(Qt.QStyle.SP_MessageBoxCritical)
errorItem.setIcon(0, icon)
errorItem.setBackground(1, Qt.QBrush(Qt.Qt.red))
exItem = Qt.QTreeWidgetItem([ex.__class__.__name__, str(ex)])
errorItem.addChild(exItem)
view.addTopLevelItem(errorItem)
errorItem.setExpanded(True)
return
self.__valid = True
class ReviewProjectPage(Qt.QWizardPage):
def __init__(self, parent=None):
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="32"
height="32"
viewBox="0 0 32 32.000001"
id="svg2"
version="1.1"
inkscape:version="0.91 r13725"
sodipodi:docname="create_project.svg"
inkscape:export-filename="/home/erlaak/work/devs/kmap/kmap/resources/gui/icons/create_project.png"
inkscape:export-xdpi="90"
inkscape:export-ydpi="90">
<defs
id="defs4" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="2.8"
inkscape:cx="72.34011"
inkscape:cy="-2.013837"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
units="px"
inkscape:window-width="1855"
inkscape:window-height="1176"
inkscape:window-x="65"
inkscape:window-y="24"
inkscape:window-maximized="1" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>