Exemplo n.º 1
0
 def julia_kernel_editor_closed(self, ret_code):
     """Catches the selected Julia kernel name when the editor is closed."""
     previous_julia_kernel = self.ui.comboBox_julia_kernel.currentText()
     self.ui.comboBox_julia_kernel.clear()
     julia_kernel_cb_items = ["Select Julia kernel spec..."
                              ] + [*find_julia_kernels().keys()]
     self.ui.comboBox_julia_kernel.addItems(julia_kernel_cb_items)
     if ret_code != 1:  # Editor closed with something else than clicking Ok.
         # Set previous kernel selected in combobox if it still exists
         previous_kernel_index = self.ui.comboBox_julia_kernel.findText(
             previous_julia_kernel)
         if previous_kernel_index == -1:
             self.ui.comboBox_julia_kernel.setCurrentIndex(0)
         else:
             self.ui.comboBox_julia_kernel.setCurrentIndex(
                 previous_kernel_index)
         return
     new_kernel = self._kernel_editor.selected_kernel
     index = self.ui.comboBox_julia_kernel.findText(new_kernel)
     if index == -1:
         notification = Notification(
             self, f"Julia kernel spec {new_kernel} not found")
         notification.show()
         self.ui.comboBox_julia_kernel.setCurrentIndex(0)
     else:
         self.ui.comboBox_julia_kernel.setCurrentIndex(index)
Exemplo n.º 2
0
 def python_kernel_editor_closed(self, ret_code):
     """Catches the selected Python kernel name when the editor is closed."""
     previous_python_kernel = self.ui.comboBox_python_kernel.currentText()
     self.ui.comboBox_python_kernel.clear()
     python_kernel_cb_items = ["Select Python kernel spec..."
                               ] + [*find_python_kernels().keys()]
     self.ui.comboBox_python_kernel.addItems(python_kernel_cb_items)
     if ret_code != 1:  # Editor closed with something else than clicking Ok.
         # Set previous kernel selected in Python kernel combobox if it still exists
         python_kernel_index = self.ui.comboBox_python_kernel.findText(
             previous_python_kernel)
         if python_kernel_index == -1:
             self.ui.comboBox_python_kernel.setCurrentIndex(
                 0)  # Previous not found
         else:
             self.ui.comboBox_python_kernel.setCurrentIndex(
                 python_kernel_index)
         return
     new_kernel = self._kernel_editor.selected_kernel
     index = self.ui.comboBox_python_kernel.findText(new_kernel)
     if index == -1:  # New kernel not found, should be quite exceptional
         notification = Notification(
             self, f"Python kernel spec {new_kernel} not found")
         notification.show()
         self.ui.comboBox_python_kernel.setCurrentIndex(0)
     else:
         self.ui.comboBox_python_kernel.setCurrentIndex(index)
    def done(self, r):
        """Checks that selected path exists and is a valid
        Spine Toolbox directory when ok button is clicked or
        when enter is pressed without the combobox being in focus.

        Args:
            r (int) Return code
        """
        if r == QDialog.Accepted:
            if not os.path.isdir(self.selection()):
                notification = Notification(self, "Path does not exist")
                notification.show()
                return
            project_json_fp = os.path.abspath(
                os.path.join(self.selection(), ".spinetoolbox",
                             "project.json"))
            if not os.path.isfile(project_json_fp):
                notification = Notification(
                    self, "Not a valid Spine Toolbox project")
                notification.show()
                return
            # self.selection() now contains a valid Spine Toolbox project directory.
            # Add the parent directory of selected directory to qsettings
            self.update_recents(
                os.path.abspath(os.path.join(self.selection(),
                                             os.path.pardir)),
                self._toolbox.qsettings())
        super().done(r)
Exemplo n.º 4
0
    def combobox_key_press_event(self, e):
        """Interrupts Enter and Return key presses when QComboBox is in focus.
        This is needed to prevent showing the 'Not a valid Spine Toolbox project'
        Notifier every time Enter is pressed.

        Args:
            e (QKeyEvent): Received key press event.
        """
        if e.key() == Qt.Key_Enter or e.key() == Qt.Key_Return:
            state = self.ui.comboBox_current_path.validator().state
            fm_current_index = self.ui.treeView_file_system.currentIndex()
            if state == QValidator.Intermediate:
                # Remove path from qsettings
                self.remove_directory_from_recents(
                    os.path.abspath(self.selection()),
                    self._toolbox.qsettings())
                # Remove path from combobox as well
                cb_index = self.ui.comboBox_current_path.findText(
                    os.path.abspath(self.selection()))
                if cb_index == -1:
                    pass
                    # logging.error("{0} not found in combobox")
                else:
                    self.ui.comboBox_current_path.removeItem(cb_index)
                notification = Notification(self, "Path does not exist")
                notification.show()
            elif state == QValidator.Acceptable:
                p = self.ui.comboBox_current_path.currentText()
                fm_index = self.file_model.index(p)
                if not fm_current_index == fm_index:
                    self.ui.treeView_file_system.collapseAll()
                    self.ui.treeView_file_system.setCurrentIndex(fm_index)
                    self.ui.treeView_file_system.expand(fm_index)
                    self.ui.treeView_file_system.scrollTo(
                        fm_index, hint=QAbstractItemView.PositionAtTop)
                else:
                    project_json_fp = os.path.abspath(
                        os.path.join(self.selection(), ".spinetoolbox",
                                     "project.json"))
                    if os.path.isfile(project_json_fp):
                        self.done(QDialog.Accepted)
            else:
                # INVALID (or None). Happens if Enter key is pressed and the combobox text has not been edited yet.
                pass
            e.accept()
        else:
            QComboBox.keyPressEvent(self.ui.comboBox_current_path, e)