Exemple #1
0
    def on_but(self):
        path_old = self.path
        qfdial = QFileDialog(directory=self.path)
        qfdial.setHistory([]) # clear history
        rsp = qfdial.restoreState(qfdial.saveState())
        qfdial.setHistory(self.dirs)
        logger.debug('QFileDialog.history: %s' % str(qfdial.history()))
        resp = qfdial.getSaveFileName(parent=self, caption='Output file', filter=self.fltr)\
               if self.mode == 'w' else \
               qfdial.getOpenFileName(parent=self, caption='Input file', filter=self.fltr)

        logger.debug('response: %s len=%d' % (resp, len(resp)))

        self.path, filter = resp

        dname, fname = os.path.split(self.path)

        if self.mode == 'r' and not os.path.lexists(self.path):
            logger.debug('pass does not exist: %s' % self.path)
            return

        elif dname == '' or fname == '':
            logger.debug('input directiry name "%s" or file name "%s" is empty... use default values'%(dname, fname))
            return

        elif self.path == path_old:
            logger.debug('path has not been changed: %s' % str(self.path))
            return

        else:
            logger.debug('selected file: %s' % self.path)
            self.but.setText(self.but_text())
            self.path_is_changed.emit(self.path)
            self.but.setStyleSheet(self.but_style_selected)
Exemple #2
0
    def selParamFileDialog(self):
        """bring up window to select simulation parameter file"""

        relative_root_path = os.path.join(os.path.dirname(__file__), '..')
        hnn_root_dir = os.path.realpath(relative_root_path)

        qfd = QFileDialog()
        qfd.setHistory([
            os.path.join(get_output_dir(), 'param'),
            os.path.join(hnn_root_dir, 'param')
        ])
        fn = qfd.getOpenFileName(self, 'Open param file',
                                 os.path.join(hnn_root_dir, 'param'),
                                 "Param files (*.param)")
        if len(fn) > 0 and fn[0] == '':
            # no file selected in dialog
            return

        tmpfn = os.path.abspath(fn[0])

        try:
            params = read_params(tmpfn)
        except ValueError:
            QMessageBox.information(
                self, "HNN", "WARNING: could not"
                "retrieve parameters from %s" % tmpfn)
            return

        # check that valid number of trials was given
        if 'N_trials' not in params or params['N_trials'] == 0:
            print("Warning: invalid configured number of trials."
                  " Setting 'N_trials' to 1.")
            params['N_trials'] = 1

        # Now update GUI components
        self.baseparamwin.paramfn = tmpfn

        # now update the GUI components to reflect the param file selected
        self.baseparamwin.updateDispParam(params)
        self.setWindowTitle(self.baseparamwin.paramfn)

        self.initSimCanvas()  # recreate canvas

        # check if param file exists in combo box already
        cb_index = self.cbsim.findText(self.baseparamwin.paramfn)
        self.populateSimCB(cb_index)  # populate the combobox

        if self.sim_data.get_exp_data_size() > 0:
            self.toggleEnableOptimization(True)
Exemple #3
0
    def loadDataFileDialog(self):
        """bring up window to select/load external dipole data"""
        hnn_root_dir = \
            os.path.realpath(os.path.join(os.path.dirname(__file__), '..'))

        qfd = QFileDialog()
        qfd.setHistory([
            os.path.join(get_output_dir(), 'data'),
            os.path.join(hnn_root_dir, 'data')
        ])
        fn = qfd.getOpenFileName(self, 'Open data file',
                                 os.path.join(hnn_root_dir, 'data'),
                                 "Data files (*.txt)")
        if len(fn) > 0 and fn[0] == '':
            # no file selected in dialog
            return

        # use abspath to make sure have right path separators
        self.loadDataFile(os.path.abspath(fn[0]))