Esempio n. 1
0
 def _save_select_detect(self, *args, filename=None):
     """Export selected detection."""
     channel, method = self._get_current_chan_type()
     # Read Table
     row_count = self._DetectLocations.rowCount()
     sta_ind = [channel, '', 'Time index (s)']
     end_ind = [method, '', 'Time index (s)']
     duration = ['', '', 'Duration (s)']
     stage = ['', '', 'Sleep stage']
     for row in np.arange(row_count):
         sta_ind.append(str(self._DetectLocations.item(row, 0).text()))
         end_ind.append(str(self._DetectLocations.item(row, 1).text()))
         duration.append(str(self._DetectLocations.item(row, 2).text()))
         stage.append(str(self._DetectLocations.item(row, 3).text()))
     # Get file name :
     saveas = "locinfo" + '_' + channel + '-' + method
     if filename is None:
         filename = dialog_save(self, 'Save ' + method + ' detection',
                                saveas, "CSV file (*.csv);;Text file"
                                " (*.txt);;All files (*.*)")
     if filename:
         file, ext = os.path.splitext(filename)
         file += '_' + channel + '-' + method
         zp = zip(sta_ind, end_ind, duration, stage)
         if ext.find('csv') + 1:
             write_csv(file + '.csv', zp)
         elif ext.find('txt') + 1:
             write_txt(file + '.txt', zp)
Esempio n. 2
0
 def _save_select_detect(self, *args, filename=None):
     """Export selected detection."""
     channel, method = self._get_current_chan_type()
     # Read Table
     row_count = self._DetectLocations.rowCount()
     sta_ind = [channel, '', 'Time index (s)']
     end_ind = [method, '', 'Time index (s)']
     duration = ['', '', 'Duration (s)']
     stage = ['', '', 'Sleep stage']
     for row in np.arange(row_count):
         sta_ind.append(str(self._DetectLocations.item(row, 0).text()))
         end_ind.append(str(self._DetectLocations.item(row, 1).text()))
         duration.append(str(self._DetectLocations.item(row, 2).text()))
         stage.append(str(self._DetectLocations.item(row, 3).text()))
     # Get file name :
     saveas = "locinfo" + '_' + channel + '-' + method
     if filename is None:
         filename = dialog_save(
             self, 'Save ' + method + ' detection', saveas,
             "CSV file (*.csv);;Text file"
             " (*.txt);;All files (*.*)")
     if filename:
         file, ext = os.path.splitext(filename)
         file += '_' + channel + '-' + method
         zp = zip(sta_ind, end_ind, duration, stage)
         if ext.find('csv') + 1:
             write_csv(file + '.csv', zp)
         elif ext.find('txt') + 1:
             write_txt(file + '.txt', zp)
Esempio n. 3
0
 def _save_all_detect(self, *args, filename=None):
     """Export all detections."""
     # Get file name :
     if filename is None:
         filename = dialog_save(self, 'Save all detections', 'detections',
                                "NumPy (*.npy);;All files (*.*)")
     if filename:
         file = os.path.splitext(str(filename))[0]
         np.save(file + '.npy', self._detect.dict)
Esempio n. 4
0
 def _save_all_detect(self, *args, filename=None):
     """Export all detections."""
     # Get file name :
     if filename is None:
         filename = dialog_save(self, 'Save all detections', 'detections',
                                "NumPy (*.npy);;All files (*.*)")
     if filename:
         file = os.path.splitext(str(filename))[0]
         np.save(file + '.npy', self._detect.dict)
Esempio n. 5
0
 def _save_hyp_fig(self, *args, filename=None, **kwargs):
     """Save a 600 dpi .png figure of the hypnogram."""
     if filename is None:
         filename = dialog_save(self, 'Save Hypnogram figure', 'hypno',
                                "PNG (*.png);;All files (*.*)")
     if filename:
         hypno = self._hypno.copy()
         grid = self._slGrid.isChecked()
         ascolor = self._PanHypnoColor.isChecked()
         write_fig_hyp(hypno, self._sf, file=filename,
                       start_s=self._toffset, grid=grid, ascolor=ascolor)
Esempio n. 6
0
 def _save_config(self, *args, filename=None):
     """Save a config file (*.txt) containing several display parameters."""
     if filename is None:
         filename = dialog_save(self, 'Save config File', 'config',
                                "JSON file (*.json);;Text file (*.txt)")
     if filename:
         config = {}
         # Get channels visibility / amplitude :
         viz, amp = [], []
         for i, k in enumerate(self._chanChecks):
             viz.append(k.isChecked())
             amp.append(self._ymaxSpin[i].value())
         config['Channel_Names'] = self._channels
         config['Channel_Visible'] = viz
         config['Channel_Amplitude'] = amp
         # config['AllAmpMin'] = self._PanAllAmpMin.value()
         # config['AllAmpMax'] = self._PanAllAmpMax.value()
         config['SymAmp'] = self._PanAmpSym.isChecked()
         config['AutoAmp'] = self._PanAmpAuto.isChecked()
         # Spectrogram :
         config['Spec_Visible'] = self.menuDispSpec.isChecked()
         config['Spec_Method'] = self._PanSpecMethod.currentIndex()
         config['Spec_Length'] = self._PanSpecNfft.value()
         config['Spec_Overlap'] = self._PanSpecStep.value()
         config['Spec_Cmap'] = self._PanSpecCmap.currentIndex()
         config['Spec_CmapInv'] = self._PanSpecCmapInv.isChecked()
         config['Spec_Chan'] = self._PanSpecChan.currentIndex()
         config['Spec_Fstart'] = self._PanSpecFstart.value()
         config['Spec_Fend'] = self._PanSpecFend.value()
         config['Spec_Con'] = self._PanSpecCon.value()
         config['Spec_Interp'] = self._PanSpecInterp.currentIndex()
         # Hypnogram/time axis/navigation/topo/indic/zoom :
         config['Hyp_Visible'] = self.menuDispHypno.isChecked()
         config['Time_Visible'] = self.menuDispTimeax.isChecked()
         config['Topo_Visible'] = self.menuDispTopo.isChecked()
         config['Nav_Visible'] = self.menuDispNavbar.isChecked()
         config['Indic_Visible'] = self.menuDispIndic.isChecked()
         config['Zoom_Visible'] = self.menuDispZoom.isChecked()
         config['Hyp_Lw'] = self._PanHypnoLw.value()
         config['Hyp_Color'] = self._PanHypnoColor.isChecked()
         # Navigation bar properties :
         config['Slider'] = self._SlVal.value()
         config['Step'] = self._SigSlStep.value()
         config['Display_Window'] = self._SigWin.value()
         config['Scoring_Window'] = self._ScorWin.value()
         config['Goto'] = self._SlGoto.value()
         config['Magnify'] = self._slMagnify.isChecked()
         config['AbsTime'] = self._slAbsTime.isChecked()
         config['Display_Scoring_Window'] = self._ScorWinVisible.isChecked()
         config['Grid'] = self._slGrid.isChecked()
         config['Unit'] = self._slRules.currentIndex()
         save_config_json(filename, config)
Esempio n. 7
0
 def _save_info_table(self, *args, filename=None):
     """Export stat info."""
     # Get file name :
     if filename is None:
         filename = dialog_save(self, 'Save file', 'statsinfo',
                                "CSV file (*.csv);;Text file (*.txt);;"
                                "All files (*.*)")
     if filename:
         file, ext = os.path.splitext(filename)
         if ext.find('csv') + 1:
             write_csv(file + '.csv', zip(self._keysInfo, self._valInfo))
         elif ext.find('txt') + 1:
             write_txt(file + '.txt', zip(self._keysInfo, self._valInfo))
Esempio n. 8
0
 def _save_config(self, *args, filename=None):
     """Save a config file (*.txt) containing several display parameters."""
     if filename is None:
         filename = dialog_save(self, 'Save config File', 'config',
                                "JSON file (*.json);;Text file (*.txt)")
     if filename:
         config = {}
         # Get channels visibility / amplitude :
         viz, amp = [], []
         for i, k in enumerate(self._chanChecks):
             viz.append(k.isChecked())
             amp.append(self._ymaxSpin[i].value())
         config['Channel_Names'] = self._channels
         config['Channel_Visible'] = viz
         config['Channel_Amplitude'] = amp
         # config['AllAmpMin'] = self._PanAllAmpMin.value()
         # config['AllAmpMax'] = self._PanAllAmpMax.value()
         config['SymAmp'] = self._PanAmpSym.isChecked()
         config['AutoAmp'] = self._PanAmpAuto.isChecked()
         # Spectrogram :
         config['Spec_Visible'] = self.menuDispSpec.isChecked()
         config['Spec_Method'] = self._PanSpecMethod.currentIndex()
         config['Spec_Length'] = self._PanSpecNfft.value()
         config['Spec_Overlap'] = self._PanSpecStep.value()
         config['Spec_Cmap'] = self._PanSpecCmap.currentIndex()
         config['Spec_CmapInv'] = self._PanSpecCmapInv.isChecked()
         config['Spec_Chan'] = self._PanSpecChan.currentIndex()
         config['Spec_Fstart'] = self._PanSpecFstart.value()
         config['Spec_Fend'] = self._PanSpecFend.value()
         config['Spec_Con'] = self._PanSpecCon.value()
         config['Spec_Interp'] = self._PanSpecInterp.currentIndex()
         # Hypnogram/time axis/navigation/topo/indic/zoom :
         config['Hyp_Visible'] = self.menuDispHypno.isChecked()
         config['Time_Visible'] = self.menuDispTimeax.isChecked()
         config['Topo_Visible'] = self.menuDispTopo.isChecked()
         config['Nav_Visible'] = self.menuDispNavbar.isChecked()
         config['Indic_Visible'] = self.menuDispIndic.isChecked()
         config['Zoom_Visible'] = self.menuDispZoom.isChecked()
         config['Hyp_Lw'] = self._PanHypnoLw.value()
         config['Hyp_Color'] = self._PanHypnoColor.isChecked()
         # Navigation bar properties :
         config['Slider'] = self._SlVal.value()
         config['Step'] = self._SigSlStep.value()
         config['Window'] = self._SigWin.value()
         config['Goto'] = self._SlGoto.value()
         config['Magnify'] = self._slMagnify.isChecked()
         config['AbsTime'] = self._slAbsTime.isChecked()
         config['Grid'] = self._slGrid.isChecked()
         config['Unit'] = self._slRules.currentIndex()
         save_config_json(filename, config)
Esempio n. 9
0
 def _save_info_table(self, *args, filename=None):
     """Export stat info."""
     # Get file name :
     if filename is None:
         filename = dialog_save(
             self, 'Save file', 'statsinfo',
             "CSV file (*.csv);;Text file (*.txt);;"
             "All files (*.*)")
     if filename:
         file, ext = os.path.splitext(filename)
         if ext.find('csv') + 1:
             write_csv(file + '.csv', zip(self._keysInfo, self._valInfo))
         elif ext.find('txt') + 1:
             write_txt(file + '.txt', zip(self._keysInfo, self._valInfo))
Esempio n. 10
0
 def _save_hyp_fig(self, *args, filename=None, **kwargs):
     """Save a 600 dpi .png figure of the hypnogram."""
     if filename is None:
         filename = dialog_save(self, 'Save Hypnogram figure', 'hypno',
                                "PNG (*.png);;All files (*.*)")
     if filename:
         hypno = self._hypno.copy()
         grid = self._slGrid.isChecked()
         ascolor = self._PanHypnoColor.isChecked()
         write_fig_hyp(hypno,
                       self._sf,
                       file=filename,
                       start_s=self._toffset,
                       grid=grid,
                       ascolor=ascolor)
Esempio n. 11
0
    def _fcn_run_screenshot(self):
        """Run the screenshot."""
        # Get filename :
        filename = dialog_save(self, 'Screenshot', 'screenshot', "PNG (*.PNG)"
                               ";;TIFF (*.tiff);;JPG (*.jpg);;"
                               "All files (*.*)")
        # Get screenshot arguments :
        kwargs = self._ssGui.to_kwargs()

        if kwargs['entire']:  # Screenshot of the entire window
            self._ssGui._ss.close()
            write_fig_pyqt(self, filename)
        else:  # Screenshot of selected canvas
            # Remove unsed entries :
            del kwargs['entire']
            self.screenshot(filename, **kwargs)
Esempio n. 12
0
    def _fcn_run_screenshot(self):
        """Run the screenshot."""
        # Get filename :
        filename = dialog_save(self, 'Screenshot', 'screenshot', "PNG (*.PNG)"
                               ";;TIFF (*.tiff);;JPG (*.jpg);;"
                               "All files (*.*)")
        # Get screenshot arguments :
        kwargs = self._ssGui.to_kwargs()

        if kwargs['entire']:  # Screenshot of the entire window
            self._ssGui._ss.close()
            write_fig_pyqt(self, filename)
        else:  # Screenshot of selected canvas
            # Get canvas name :
            name = kwargs['canvas']
            # Remove unsed entries :
            del kwargs['entire'], kwargs['canvas']
            if name == 'spectrogram':
                # Force the spectrogram to be displayed :
                self.menuDispSpec.setChecked(True)
                self._disptog_spec()
                # Get canvas
                canvas = self._specCanvas.canvas
            elif name == 'hypnogram':
                # Force the spectrogram to be displayed :
                self.menuDispHypno.setChecked(True)
                self._disptog_hyp()
                # Get canvas
                canvas = self._hypCanvas.canvas
            elif name == 'topoplot':
                # Force the spectrogram to be displayed :
                self.menuDispTopo.setChecked(True)
                self._disptog_topo()
                # Get canvas :
                canvas = self._topoCanvas.canvas
            else:
                # Get the index of this channel :
                kc = self._channels.index(name)
                # Force the channel to be displayed :
                self._chanChecks[kc].setChecked(True)
                self._fcn_chan_viz()
                canvas = self._chanCanvas[kc].canvas
            # Finally, render the canvas :
            write_fig_canvas(filename, canvas=canvas, **kwargs)
Esempio n. 13
0
 def _save_scoring_table(self, *args, filename=None):
     """Export score info."""
     # Read Table
     row_count = self._scoreTable.rowCount()
     sta_ind, end_ind, stage = [], [], []
     for row in np.arange(row_count):
         sta_ind.append(str(self._scoreTable.item(row, 0).text()))
         end_ind.append(str(self._scoreTable.item(row, 1).text()))
         stage.append(str(self._scoreTable.item(row, 2).text()))
     # Get file name :
     if filename is None:
         filename = dialog_save(self, 'Save file', 'scoring_info',
                                "CSV file (*.csv);;Text file (*.txt);;"
                                "All files (*.*)")
     if filename:
         file, ext = os.path.splitext(filename)
         if ext.find('csv') + 1:
             write_csv(file + '.csv', zip(sta_ind, end_ind, stage))
         elif ext.find('txt') + 1:
             write_txt(file + '.txt', zip(sta_ind, end_ind, stage))
Esempio n. 14
0
    def _fcn_run_screenshot(self):
        """Run the screenshot."""
        # Get filename :
        filename = dialog_save(self, 'Screenshot', 'screenshot', "PNG (*.PNG)"
                               ";;TIFF (*.tiff);;JPG (*.jpg);;"
                               "All files (*.*)")
        # Get screenshot arguments :
        kwargs = self._ssGui.to_kwargs()

        if kwargs['entire']:  # Screenshot of the entire window
            self._ssGui._ss.close()
            write_fig_pyqt(self, filename)
        elif kwargs['canvas'] in ['Grid', 'Signal']:  # Selected canvas
            # Remove unsed entries :
            if kwargs['canvas'] == 'Grid':
                c = self._grid_canvas.canvas
            elif kwargs['canvas'] == 'Signal':
                c = self._signal_canvas.canvas
            del kwargs['entire'], kwargs['canvas']
            write_fig_canvas(filename, c, widget=None, **kwargs)
Esempio n. 15
0
 def _save_annotation_table(self, *args, filename=None):
     """Export annotation table."""
     # Read Table
     row_count = self._AnnotateTable.rowCount()
     sta_ind, end_ind, annot = [], [], []
     for row in np.arange(row_count):
         sta_ind.append(str(self._AnnotateTable.item(row, 0).text()))
         end_ind.append(str(self._AnnotateTable.item(row, 1).text()))
         annot.append(str(self._AnnotateTable.item(row, 2).text()))
     # Get file name :
     if filename is None:
         filename = dialog_save(self, 'Save annotations', 'annotations',
                                "CSV file (*.csv);;Text file (*.txt);;"
                                "All files (*.*)")
     if filename:
         file, ext = os.path.splitext(filename)
         if ext.find('csv') + 1:
             write_csv(file + '.csv', zip(sta_ind, end_ind, annot))
         elif ext.find('txt') + 1:
             write_txt(file + '.txt', zip(sta_ind, end_ind, annot))
Esempio n. 16
0
 def saveHypData(self, *args, filename=None, reply=None):  # noqa
     """Save the hypnogram data either in a hyp or txt file."""
     # Define default filename for the hypnogram :
     if not isinstance(self._file, str):
         hyp_file = 'hypno'
     else:
         hyp_file = os.path.basename(self._file) + '_hypno'
     # Version switch :
     if reply is None:
         msg = ("Since release 0.4, hypnogram are exported using stage "
                "duration rather than point-per-second. This new format "
                "avoids potential errors caused by downsampling and "
                "confusion in the values assigned to each sleep stage. \n\n"
                "Click 'Yes' to use the new format and 'No' to use the old "
                "format. For more information, visit the doc at "
                "visbrain.org/sleep")
         reply = QtWidgets.QMessageBox.question(self, 'Message', msg,
                                                QtWidgets.QMessageBox.Yes,
                                                QtWidgets.QMessageBox.No)
     if reply == QtWidgets.QMessageBox.No:  # v1 = sample
         dialog_ext = "Text file (*.txt);;Elan file (*.hyp)"
         version = 'sample'
     else:  # v2 = time
         dialog_ext = ("Text file (*.txt);;Csv file (*.csv);;Excel file "
                       "(*.xlsx)")
         version = 'time'
     # Open dialog window :
     if filename is None:
         filename = dialog_save(self, 'Save File', hyp_file,
                                dialog_ext + ";;All files (*.*)")
     if filename:
         info = {'Duration_sec': self._N * 1 / self._sfori}
         if isinstance(self._file, str):
             info['Datafile'] = self._file
         write_hypno(filename,
                     self._hypno,
                     version=version,
                     sf=self._sfori,
                     npts=self._N,
                     time=self._time,
                     info=info)
Esempio n. 17
0
 def _save_scoring_table(self, *args, filename=None):
     """Export score info."""
     # Read Table
     row_count = self._scoreTable.rowCount()
     sta_ind, end_ind, stage = [], [], []
     for row in np.arange(row_count):
         sta_ind.append(str(self._scoreTable.item(row, 0).text()))
         end_ind.append(str(self._scoreTable.item(row, 1).text()))
         stage.append(str(self._scoreTable.item(row, 2).text()))
     # Get file name :
     if filename is None:
         filename = dialog_save(
             self, 'Save file', 'scoring_info',
             "CSV file (*.csv);;Text file (*.txt);;"
             "All files (*.*)")
     if filename:
         file, ext = os.path.splitext(filename)
         if ext.find('csv') + 1:
             write_csv(file + '.csv', zip(sta_ind, end_ind, stage))
         elif ext.find('txt') + 1:
             write_txt(file + '.txt', zip(sta_ind, end_ind, stage))
Esempio n. 18
0
 def _save_annotation_table(self, *args, filename=None):
     """Export annotation table."""
     # Read Table
     row_count = self._AnnotateTable.rowCount()
     sta_ind, end_ind, annot = [], [], []
     for row in np.arange(row_count):
         sta_ind.append(str(self._AnnotateTable.item(row, 0).text()))
         end_ind.append(str(self._AnnotateTable.item(row, 1).text()))
         annot.append(str(self._AnnotateTable.item(row, 2).text()))
     # Get file name :
     if filename is None:
         filename = dialog_save(
             self, 'Save annotations', 'annotations',
             "CSV file (*.csv);;Text file (*.txt);;"
             "All files (*.*)")
     if filename:
         file, ext = os.path.splitext(filename)
         if ext.find('csv') + 1:
             write_csv(file + '.csv', zip(sta_ind, end_ind, annot))
         elif ext.find('txt') + 1:
             write_txt(file + '.txt', zip(sta_ind, end_ind, annot))
Esempio n. 19
0
    def _fcn_run_screenshot(self):
        """Run the screenshot."""
        # Get filename :
        filename = dialog_save(
            self, 'Screenshot', 'screenshot', "PNG (*.PNG)"
            ";;TIFF (*.tiff);;JPG (*.jpg);;"
            "All files (*.*)")
        # Get screenshot arguments :
        kwargs = self._ssGui.to_kwargs()

        if kwargs['entire']:  # Screenshot of the entire window
            self._ssGui._ss.close()
            write_fig_pyqt(self, filename)
        elif kwargs['canvas'] in ['Grid', 'Signal']:  # Selected canvas
            # Remove unsed entries :
            if kwargs['canvas'] == 'Grid':
                c = self._grid_canvas.canvas
            elif kwargs['canvas'] == 'Signal':
                c = self._signal_canvas.canvas
            del kwargs['entire'], kwargs['canvas']
            write_fig_canvas(filename, c, widget=None, **kwargs)
Esempio n. 20
0
 def _fcn_save_annotations(self, *args, filename=None):
     """Save annotations."""
     # Read Table
     row_count = self._annot_table.rowCount()
     time, amp, signal, text = [], [], [], []
     for row in range(row_count):
         time.append(self._annot_table.item(row, 0).text())
         amp.append(self._annot_table.item(row, 1).text())
         signal.append(self._annot_table.item(row, 2).text())
         text.append(self._annot_table.item(row, 3).text())
     # Get file name :
     if filename is None:
         filename = dialog_save(self, 'Save annotations', 'annotations',
                                "CSV file (*.csv);;Text file (*.txt);;"
                                "All files (*.*)")
     if filename:
         kw = {'delimiter': '_'}
         file, ext = os.path.splitext(filename)
         if ext.find('csv') + 1:
             write_csv(file + '.csv', zip(time, amp, signal, text), **kw)
         elif ext.find('txt') + 1:
             write_txt(file + '.txt', zip(time, amp, signal, text), **kw)
Esempio n. 21
0
 def _fcn_save_annotations(self, *args, filename=None):
     """Save annotations."""
     # Read Table
     row_count = self._annot_table.rowCount()
     time, amp, signal, text = [], [], [], []
     for row in range(row_count):
         time.append(self._annot_table.item(row, 0).text())
         amp.append(self._annot_table.item(row, 1).text())
         signal.append(self._annot_table.item(row, 2).text())
         text.append(self._annot_table.item(row, 3).text())
     # Get file name :
     if filename is None:
         filename = dialog_save(
             self, 'Save annotations', 'annotations',
             "CSV file (*.csv);;Text file (*.txt);;"
             "All files (*.*)")
     if filename:
         kw = {'delimiter': '_'}
         file, ext = os.path.splitext(filename)
         if ext.find('csv') + 1:
             write_csv(file + '.csv', zip(time, amp, signal, text), **kw)
         elif ext.find('txt') + 1:
             write_txt(file + '.txt', zip(time, amp, signal, text), **kw)
Esempio n. 22
0
 def saveHypData(self, *args, filename=None, reply=None):  # noqa
     """Save the hypnogram data either in a hyp or txt file."""
     # Define default filename for the hypnogram :
     if not isinstance(self._file, str):
         hyp_file = 'hypno'
     else:
         hyp_file = os.path.basename(self._file) + '_hypno'
     # Version switch :
     if reply is None:
         msg = ("Since release 0.4, hypnogram are exported using stage "
                "duration rather than point-per-second. This new format "
                "avoids potential errors caused by downsampling and "
                "confusion in the values assigned to each sleep stage. \n\n"
                "Click 'Yes' to use the new format and 'No' to use the old "
                "format. For more information, visit the doc at "
                "visbrain.org/sleep")
         reply = QtWidgets.QMessageBox.question(self, 'Message', msg,
                                                QtWidgets.QMessageBox.Yes,
                                                QtWidgets.QMessageBox.No)
     if reply == QtWidgets.QMessageBox.No:  # v1 = sample
         dialog_ext = "Text file (*.txt);;Elan file (*.hyp)"
         version = 'sample'
     else:  # v2 = time
         dialog_ext = ("Text file (*.txt);;Csv file (*.csv);;Excel file "
                       "(*.xlsx)")
         version = 'time'
     # Open dialog window :
     if filename is None:
         filename = dialog_save(self, 'Save File', hyp_file, dialog_ext +
                                ";;All files (*.*)")
     if filename:
         info = {'Duration_sec': self._N * 1 / self._sfori}
         if isinstance(self._file, str):
             info['Datafile'] = self._file
         write_hypno(filename, self._hypno, version=version, sf=self._sfori,
                     npts=self._N, time=self._time, info=info)
Esempio n. 23
0
    def _fcn_save_config(self, _, filename=None):
        """Save the configuration."""
        # Get the name of the file to be saved :
        if filename is None:
            filename = dialog_save(self, 'Save config File', 'config',
                                   "Text file (*.txt);;All files (*.*)")
        if filename:
            config = {}

            # ----------------- VISIBLE OBJECTS -----------------
            config['SettingViz'] = self.menuDispQuickSettings.isChecked()
            config['EngramViz'] = self.menuDispEngram.isChecked()
            config['SourcesViz'] = self.menuDispSources.isChecked()
            config['ConnectViz'] = self.menuDispConnect.isChecked()
            config['ROIViz'] = self.menuDispROI.isChecked()
            config['CbarViz'] = self.menuDispCbar.isChecked()

            # ----------------- CAMERAS -----------------
            config['CamState'] = self.view.wc.camera.get_state()
            rect = self.cbqt.cbviz._wc.camera.rect
            config['CamCbState'] = list(rect.pos) + list(rect.size)

            # ----------------- GUI SETTINGS -----------------
            # Background color :
            bgd = (self.bgd_red.value(), self.bgd_green.value(),
                   self.bgd_blue.value())
            config['BcgColor'] = bgd
            # Tab :
            config['CurrentTab'] = self.QuickSettings.currentIndex()

            # ----------------- ENGRAM -----------------
            # Surroundings :
            config['EngramTransp'] = self._engram_translucent.isChecked()
            config['EngramHemi'] = self._engramPickHemi.currentIndex()
            config['EngramTemplate'] = self._engramTemplate.currentIndex()
            # ROI :
            config['RoiTransp'] = self._roiTransp.isChecked()
            config['RoiAnat'] = self._roiDiv.currentIndex()
            config['RoiSmooth'] = self._roiSmooth.value()
            config['RoiStruct'] = self._fcn_get_selected_rois()
            # Cross-sections :
            config['CsSagit'] = self._csSagit.value()
            config['CsCoron'] = self._csCoron.value()
            config['CsAxial'] = self._csAxial.value()
            config['CsDiv'] = self._csDiv.currentIndex()
            config['CsCmap'] = self._csCmap.currentIndex()
            config['CsTransp'] = self._csTransp.isChecked()
            config['CsSplit'] = self._csSplit.isChecked()
            config['CsGrp'] = self.grpSec.isChecked()
            # Volume :
            config['VolDiv'] = self._volDiv.currentIndex()
            config['VolRendering'] = self._volRendering.currentIndex()
            config['VolCmap'] = self._volCmap.currentIndex()
            config['VolTh'] = self._volIsoTh.value()
            config['VolGrp'] = self.grpVol.isChecked()

            # ----------------- SOURCES -----------------
            # Sources object :
            config['SourcesDisp'] = self._sourcesPickdisp.currentIndex()
            config['SourcesSym'] = self.s_Symbol.currentIndex()
            config['SourcesRm'] = self.s_radiusMin.value()
            config['SourcesRM'] = self.s_radiusMax.value()
            config['SourcesEcol'] = color2json(self.s_EdgeColor, False)
            config['SourcesEw'] = self.s_EdgeWidth.value()
            config['SourcesScale'] = self.s_Scaling.isChecked()
            # Source's text :
            config['StextShow'] = self.grpText.isChecked()
            config['StextSz'] = self.q_stextsize.value()
            config['StextCol'] = color2json(self.q_stextcolor)
            config['StextXYZ'] = (self.x_text.value(), self.y_text.value(),
                                  self.z_text.value())
            # Source's projection settings :
            config['SprojRad'] = self._uitRadius.value()
            config['SprojType'] = self._uitPickProj.currentIndex()
            config['SprojOn'] = self._uitProjectOn.currentIndex()
            config['SprojCon'] = self._uitContribute.isChecked()
            # Source's time-series :
            config['StsWidth'] = self._tsWidth.value()
            config['StsAmp'] = self._tsAmp.value()
            config['StsLw'] = self._tsLw.value()
            config['StsDxyz'] = (self._tsDx.value(), self._tsDy.value(),
                                 self._tsDz.value())
            config['StsColor'] = color2json(self._tsColor)

            # ----------------- CONNECTIVITY -----------------
            config['ConnectCby'] = self.uiConnect_colorby.currentIndex()
            config['ConnectAlp'] = self._connectStaDynTransp.currentIndex()
            config['ConnectMin'] = self.uiConnect_dynMin.value()
            config['ConnectMax'] = self.uiConnect_dynMax.value()
            config['ConnectRad'] = self._densityRadius.value()
            config['ConnectLw'] = self.uiConnect_lw.value()
            config['ConnectBun'] = self._conBlEnable.isChecked()
            config['ConnectBunRad'] = self._conBlRadius.value()
            config['ConnectBunDxyz'] = self._conBlDxyz.value()

            # ----------------- CBAR -----------------
            # Visual:
            config['Cbar'] = self.cbqt.cbobjs.to_dict(alldicts=True)
            config['CbarIdx'] = self.cbqt.cbui.object.currentIndex()

            # Write the configuration into a json file :
            save_config_json(filename, config)