Skip to content

Commit

Permalink
add possibility to save the default config to a new file.
Browse files Browse the repository at this point in the history
  • Loading branch information
cwiede committed Oct 18, 2020
1 parent c6a9d23 commit 8ba091a
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
11 changes: 11 additions & 0 deletions nexxT/core/Configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,17 @@ def save(self, file=None):
self.setDirty(False)
return cfg

def filename(self):
"""
Get the configuration file name or None if it is not set.
:return:
"""
try:
return self._propertyCollection.getProperty("CFGFILE")
except PropertyCollectionPropertyNotFound:
return None


def propertyCollection(self):
"""
Get the (root) property collection.
Expand Down
2 changes: 1 addition & 1 deletion nexxT/interface/Filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def environment(self):
"""
return self._environment

def onSuggestDynamicPorts(self):
def onSuggestDynamicPorts(self): # pylint: disable=no-self-use
"""
Shall return the suggested dynamic ports of this filter. Prominent example is to return the streams
contained in a HDF5 file. Note that it is safe to assume that the instance lives in the GUI thread,
Expand Down
13 changes: 13 additions & 0 deletions nexxT/services/SrvConfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,19 @@ def execute():
ConfigFileLoader.save(self._configuration)
execute()

@Slot(str)
def saveConfigAs(self, filename):
"""
Call this slot to save the configuration
:return:
"""
@handleException
def execute():
assertMainThread()
logger.debug("Saving config file")
ConfigFileLoader.save(self._configuration, filename)
execute()

@Slot(str)
def newConfig(self, cfgFileName):
"""
Expand Down
20 changes: 18 additions & 2 deletions nexxT/services/gui/Configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, configuration):
self.actLoad = QAction(QApplication.style().standardIcon(QStyle.SP_DialogOpenButton), "Open config", self)
self.actLoad.triggered.connect(self._execLoad)
self.actSave = QAction(QApplication.style().standardIcon(QStyle.SP_DialogSaveButton), "Save config", self)
self.actSave.triggered.connect(self.saveConfig)
self.actSave.triggered.connect(self._execSaveConfig)
self.actNew = QAction(QApplication.style().standardIcon(QStyle.SP_FileIcon), "New config", self)
self.actNew.triggered.connect(self._execNew)

Expand Down Expand Up @@ -149,11 +149,27 @@ def _execNew(self):
assertMainThread()
if self._checkDirty():
return
fn, _ = QFileDialog.getSaveFileName(self.mainWidget, "Save configuration", filer="*.json")
fn, _ = QFileDialog.getSaveFileName(self.mainWidget, "New configuration", ".", filter="*.json")
if fn is not None and fn != "":
logger.debug("Creating config file %s", fn)
self.newConfig(fn)

def _execSaveConfig(self):
if self.configuration().filename() is None:
self._execSaveConfigAs()
else:
self.saveConfig()

def _execSaveConfigAs(self):
"""
Opens a file dialog to get the save file name and calls saveConfig.
:return:
"""
assertMainThread()
fn, _ = QFileDialog.getSaveFileName(self.mainWidget, "Save configuration as", ".", "*.json")
if fn is not None and fn != "":
self.saveConfigAs(fn)

def _addGraphView(self, subConfig):
g = subConfig.getGraph()
# remove already deleted graph views from internal list
Expand Down
5 changes: 3 additions & 2 deletions nexxT/services/gui/GraphEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ def accept(self):
self.selectedInputPorts = [cb.text() for cb in self.inputCheckBoxes if cb.isChecked() and cb.isEnabled()]
self.selectedOutputPorts = [cb.text() for cb in self.outputCheckBoxes if cb.isChecked() and cb.isEnabled()]
return super().accept()

def reject(self):
"""
Rejects user selection.
Expand Down Expand Up @@ -1203,7 +1203,8 @@ def onSuggestDynamicPorts(self):
with mockup.createFilter() as env:
inputPorts, outputPorts = env.getPlugin().onSuggestDynamicPorts()
if len(inputPorts) > 0 or len(outputPorts) > 0:
inputPorts, outputPorts = PortSelectorDialog.getSelectedPorts(self.views()[0], inputPorts, outputPorts, self.graph, item.name)
inputPorts, outputPorts = PortSelectorDialog.getSelectedPorts(self.views()[0], inputPorts, outputPorts,
self.graph, item.name)
for ip in inputPorts:
self.graph.addDynamicInputPort(item.name, ip)
for op in outputPorts:
Expand Down

0 comments on commit 8ba091a

Please sign in to comment.