Exemple #1
0
def load_interpreters(combo, default=None, locals=True, virtualenvs=True):
    def _add(combo, interpreters, default, default_index=None, icon=None):
        if icon is None:
            icon = icons.python_interpreter
        for interpreter in sorted(interpreters):
            index = combo.count()
            try:
                combo.addItem(icon, interpreter)
            except TypeError:
                pass
            else:
                if interpreter == default:
                    default_index = index
        return default_index

    combo.clear()
    if default is None:
        default = Preferences().interpreters.default
    default_index = _add(combo, detect_system_interpreters(), default)
    if virtualenvs:
        default_index = _add(combo,
                             Preferences().interpreters.virtual_envs,
                             default,
                             default_index,
                             icon=icons.python_virtualenv)
    if locals:
        default_index = _add(combo,
                             Preferences().interpreters.locals, default,
                             default_index)
    combo.setCurrentIndex(default_index if default_index is not None else 0)
Exemple #2
0
 def current_interpreter(self):
     cfg = Preferences().cache.get_run_config_for_file(self.path)
     if cfg is None:
         interpreter = Preferences().interpreters.default
     else:
         interpreter = cfg['interpreter']
     return interpreter
Exemple #3
0
 def _restore_default_panels(self):
     editor = Preferences().editor
     installed_modes = self._get_installed_panels()
     d = {}
     for mode, _ in installed_modes:
         d[mode] = True
     editor.panels = d
Exemple #4
0
 def ask(cls, parent):
     ret_val = None
     dlg = cls(parent)
     if dlg.exec_() == dlg.Accepted:
         if dlg.ui.rb_new.isChecked():
             ret_val = Preferences().general.OpenActions.NEW
         else:
             ret_val = Preferences().general.OpenActions.CURRENT
     return ret_val
Exemple #5
0
 def _add_local(self):
     """
     Adds a local interpeter.        """
     path, filter = QtWidgets.QFileDialog.getOpenFileName(
         self, 'Add local interpreter')
     if path:
         lst = Preferences().interpreters.locals
         lst.append(path)
         Preferences().interpreters.locals = lst
         self.reset()
         self.ui.combo_interpreters.setCurrentIndex(
             self.ui.combo_interpreters.count() - 1)
         _logger().info('local interpreter added: %s', path)
Exemple #6
0
 def on_action_run_triggered(self):
     if 'Run' in self.ui.actionRun.text():
         if Preferences().general.save_before_run:
             self.save()
         self.run_script()
     elif 'Stop' in self.ui.actionRun.text():
         self.stop_script()
Exemple #7
0
 def _on_open_file_triggered(self):
     path, filter = QtWidgets.QFileDialog.getOpenFileName(
         self, 'Open script', self.path, filter='Python files (*.py *.pyw)')
     if path:
         script = os.path.isfile(path)
         action = Preferences().general.open_scr_action
         if action == Preferences().general.OpenActions.NEW:
             self._open_in_new_window(path, script)
         elif action == Preferences().general.OpenActions.CURRENT:
             self._open_in_current_window(path, script)
         else:
             # ask
             val = DlgAskOpenScript.ask(self)
             if val == Preferences().general.OpenActions.NEW:
                 self._open_in_new_window(path, script)
             elif val == Preferences().general.OpenActions.CURRENT:
                 self._open_in_current_window(path, script)
Exemple #8
0
 def _on_open_project_triggered(self):
     path = QtWidgets.QFileDialog.getExistingDirectory(
         self, 'Open project', os.path.expanduser('~'))
     if path:
         script = os.path.isfile(path)
         action = Preferences().general.open_project_action
         if action == Preferences().general.OpenActions.NEW:
             self._open_in_new_window(path, script)
         elif action == Preferences().general.OpenActions.CURRENT:
             self._open_in_current_window(path, script)
         else:
             # ask
             val = DlgAskOpenScript.ask(self)
             if val == Preferences().general.OpenActions.NEW:
                 self._open_in_new_window(path, script)
             elif val == Preferences().general.OpenActions.CURRENT:
                 self._open_in_current_window(path, script)
Exemple #9
0
    def edit_configs(cls, parent, prj_path):
        """
        Edit project run configurations.

        :param parent: parent widget
        :param prj_path: project path
        """
        dlg = cls(parent, prj_path)
        if dlg.exec_() == dlg.Accepted:
            dlg._store_current_config()
            project.set_run_configurations(prj_path, dlg._configs)
            Preferences().cache.set_project_interpreter(
                prj_path, dlg.ui.comboInterpreters.currentText())
            Preferences().cache.set_project_config(
                prj_path, dlg.ui.listConfigs.currentItem().text())
            return True
        return False
Exemple #10
0
 def apply(self):
     """
     Apply page settings to the application preferences (here we just set
     the default interpreter).
     """
     prefs = Preferences()
     prefs.interpreters.default = self.ui.combo_interpreters.currentText()
     _logger().info('default interpreter: %s' % prefs.interpreters.default)
Exemple #11
0
 def restore_defaults(self):
     prefs = Preferences()
     prefs.general.confirm_application_exit = True
     prefs.general.reopen_last_window = True
     prefs.general.open_scr_action = prefs.general.OpenActions.NEW
     prefs.general.restore_window_state = False
     prefs.general.save_before_run = True
     self.reset()
Exemple #12
0
 def _open_document(self, path, line=None):
     if line is not None:
         PyFileManager.restore_cursor = False
     tab = self.ui.tabWidget.open_document(
         path, color_scheme=Preferences().editor_appearance.color_scheme)
     self._restart_backend(tab)
     try:
         mode = tab.modes.get('GoToAssignmentsMode')
     except KeyError:
         pass
     else:
         mode.out_of_doc.connect(self._on_go_out_of_document)
     self._apply_editor_preferences(tab, False)
     if line is not None:
         TextHelper(tab).goto_line(line)
         PyFileManager.restore_cursor = Preferences().editor.restore_cursor
     return tab
Exemple #13
0
    def __init__(self, parent, prj_path):
        super(DlgProjectRunConfig, self).__init__(parent)
        self._current_cfg = None
        self.ui = dlg_prj_run_ui.Ui_Dialog()
        self.ui.setupUi(self)

        # enable project mode
        self.ui.cfgWidget.set_mode(1)

        # setup icons
        self.ui.pushButtonRmConfig.setIcon(icons.list_remove)
        self.ui.pushButtonAddConfig.setIcon(icons.list_add)

        # load combo box interpreters
        load_interpreters(
            self.ui.comboInterpreters,
            default=Preferences().cache.get_project_interpreter(prj_path))

        # load project run configurations
        self._configs = project.get_run_configurations(prj_path)
        for cfg in self._configs:
            self.ui.listConfigs.addItem(cfg['name'])
        self.ui.listConfigs.currentItemChanged.connect(
            self._on_current_item_changed)
        if self.ui.listConfigs.count() == 0:
            # first time configuration, create one new unamed config
            self._create_new()
            self.ui.cfgWidget.ui.lineEditName.setFocus()

        # select current config
        current_config = Preferences().cache.get_project_config(prj_path)
        if current_config is None:
            self.ui.listConfigs.setCurrentRow(0)
        else:
            items = self.ui.listConfigs.findItems(
                current_config, QtCore.Qt.MatchExactly)
            if len(items):
                item = items[0]
                self.ui.listConfigs.setCurrentItem(item)

        # configure signal/slots
        self.ui.cfgWidget.ui.lineEditName.textChanged.connect(
            self._on_name_changed)
        self.ui.pushButtonAddConfig.clicked.connect(self._create_new)
        self.ui.pushButtonRmConfig.clicked.connect(self._rm_current_cfg)
Exemple #14
0
 def quit_confirmation(self):
     if Preferences().general.confirm_application_exit and \
             not self._quitting:
         button = QtWidgets.QMessageBox.question(
             self, "Confirm exit", "Are you sure you want to exit QIdle?",
             QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
         res = button == QtWidgets.QMessageBox.Yes
         return res
     return True
Exemple #15
0
 def on_action_run_triggered(self):
     if 'Run' in self.ui.actionRun.text():
         if Preferences().general.save_before_run:
             self.save(ignore_os_errors=True)
         self.run_script()
         self.ui.dockWidgetProgramOutput.show()
         self.ui.textEditPgmOutput.setFocus(True)
     elif 'Stop' in self.ui.actionRun.text():
         self.stop_script()
Exemple #16
0
 def _set_current_config(self):
     configs = project.get_run_configurations(self.window.path)
     src = self.tree_view.helper.get_current_path()
     config = self.find_config_from_script(configs, src)
     if config is None:
         config = self._create_default_working_config(configs, src)
     # change current config
     Preferences().cache.set_project_config(self.window.path,
                                            config['name'])
     self.window.update_combo_run_configs()
Exemple #17
0
    def reset(self):
        appearance = Preferences().editor_appearance
        self.ui.line_edit_font.setText(appearance.font)
        self.ui.spinbox_font_size.setValue(appearance.font_size)
        self.ui.checkbox_whitespaces.setChecked(appearance.show_whitespaces)
        self.ui.list_color_schemes.clear()
        current_index = 0
        for style in PYGMENTS_STYLES:
            self.ui.list_color_schemes.addItem(style)
            if style == appearance.color_scheme:
                current_index = self.ui.list_color_schemes.count() - 1
        self.ui.list_color_schemes.setCurrentRow(current_index)

        # update preview
        prefs = Preferences()
        self.ui.edit_preview.font_name = prefs.editor_appearance.font
        self.ui.edit_preview.font_size = prefs.editor_appearance.font_size
        self.ui.edit_preview.show_whitespaces = \
            prefs.editor_appearance.show_whitespaces
        scheme = ColorScheme(prefs.editor_appearance.color_scheme)
        self.ui.edit_preview.syntax_highlighter.color_scheme = scheme
Exemple #18
0
 def _remove_interpreter(self):
     """
     Removes the selected interpreter.
     """
     path = self.ui.combo_interpreters.currentText()
     lst = Preferences().interpreters.locals
     try:
         lst.remove(path)
     except ValueError:
         lst = Preferences().interpreters.virtual_envs
         try:
             lst.remove(path)
         except ValueError:
             pass
         else:
             Preferences().interpreters.virtual_envs = lst
     else:
         Preferences().interpreters.locals = lst
     self.ui.combo_interpreters.removeItem(
         self.ui.combo_interpreters.currentIndex())
     _logger().info('interpreter removed: %s', path)
Exemple #19
0
 def apply(self):
     appearance = Preferences().editor_appearance
     appearance.font = self.ui.line_edit_font.text()
     appearance.font_size = self.ui.spinbox_font_size.value()
     appearance.color_scheme = \
         self.ui.list_color_schemes.currentItem().text()
     appearance.show_whitespaces = self.ui.checkbox_whitespaces.isChecked()
Exemple #20
0
 def restore_defaults(self):
     appearance = Preferences().editor_appearance
     appearance.font = 'Source Code Pro'
     appearance.font_size = 10
     appearance.show_whitespaces = False
     appearance.color_scheme = 'qt'
     self.reset()
Exemple #21
0
    def _apply_editor_preferences(self, editor, show_panels):
        _logger(self).info('applying preferences on editor: %s' %
                           editor.file.path)
        prefs = Preferences()
        # appearance
        editor.font_name = prefs.editor_appearance.font
        editor.font_size = prefs.editor_appearance.font_size
        editor.show_whitespaces = prefs.editor_appearance.show_whitespaces
        scheme = ColorScheme(prefs.editor_appearance.color_scheme)
        editor.syntax_highlighter.color_scheme = scheme
        self.ui.textEditPgmOutput.apply_color_scheme(scheme)
        # editor settings
        editor.panels.get('FoldingPanel').highlight_caret_scope = \
            prefs.editor.highlight_caret_scope
        editor.use_spaces_instead_of_tabs = \
            prefs.editor.use_spaces_instead_of_tabs
        editor.modes.get('RightMarginMode').position = \
            prefs.editor.margin_pos
        editor.tab_length = prefs.editor.tab_len
        editor.file.replace_tabs_by_spaces = \
            prefs.editor.convert_tabs_to_spaces
        editor.file.clean_trailing_whitespaces = \
            prefs.editor.clean_trailing
        editor.file.fold_imports = prefs.editor.fold_imports
        editor.file.fold_docstrings = prefs.editor.fold_docstrings
        editor.file.restore_cursor = prefs.editor.restore_cursor
        editor.file.safe_save = prefs.editor.safe_save
        mode = editor.modes.get('CodeCompletionMode')
        mode.trigger_length = prefs.editor.cc_trigger_len
        mode.show_tooltips = prefs.editor.cc_show_tooltips
        mode.case_sensitive = prefs.editor.cc_case_sensitive
        editor.setCenterOnScroll(prefs.editor.center_on_scroll)
        # modes
        for m in editor.modes:
            if m.name in prefs.editor.modes:
                m.enabled = prefs.editor.modes[m.name]
            else:
                m.enabled = True

        # disable unwanted panels
        for name, state in prefs.editor.panels.items():
            try:
                panel = editor.panels.get(name)
            except KeyError:
                _logger().exception('failed to retrieve mode by name: %r' %
                                    name)
            else:
                if name not in commons.DYNAMIC_PANELS:
                    if not show_panels and state is True:
                        continue
                    panel.setEnabled(state)
                    panel.setVisible(state)
Exemple #22
0
    def _on_virtualenv_created(self, path):
        """
        Display the new virtual env in the interpreter list and refresh
        its packages.

        :param path: path to the new interpreter
        """
        if path:
            envs = Preferences().interpreters.virtual_envs
            envs.append(path)
            Preferences().interpreters.virtual_envs = envs
            self.reset(default=path)
            self._stop_gif()
            self.ui.widgetInfos.show()
            self.ui.lblInfos.setText('Virtual env sucessfully created at %s' %
                                     path)
            _logger().info('virtualenv created successfully')
        else:
            self._stop_gif()
            self.ui.widgetInfos.show()
            _logger().info('failed to create virtualenv')
            self.ui.lblInfos.setText('Failed to create virtual env')
Exemple #23
0
 def __init__(self, parent=None):
     self.ui = Ui_Form()
     super(PageAppearance, self).__init__(self.ui, parent)
     self.ui.edit_preview.setPlainText(self.demo)
     self.ui.edit_preview.backend.start(server.__file__,
                                        Preferences().interpreters.default)
     self.ui.bt_font.clicked.connect(self._choose_font)
     self.ui.spinbox_font_size.valueChanged.connect(
         self._on_font_size_changed)
     self.ui.checkbox_whitespaces.stateChanged.connect(
         self._on_show_whitespaces_changed)
     self.ui.list_color_schemes.currentItemChanged.connect(
         self._on_color_scheme_changed)
Exemple #24
0
 def _reset_panels(self):
     self.ui.lw_panels.clear()
     editor = Preferences().editor
     installed_panels = self._get_installed_panels()
     for mode, description in installed_panels:
         enabled = True
         if mode in editor.panels.keys():
             enabled = editor.panels[mode]
         item = QtWidgets.QListWidgetItem(mode, self.ui.lw_panels)
         item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable)
         item.setCheckState(
             QtCore.Qt.Checked if enabled else QtCore.Qt.Unchecked)
         self.ui.lw_panels.addItem(item)
         item.setToolTip(description)
Exemple #25
0
 def reset(self):
     prefs = Preferences()
     self.ui.cb_confirm_exit.setChecked(
         prefs.general.confirm_application_exit)
     self.ui.cb_reopen.setChecked(prefs.general.reopen_last_window)
     self.ui.cb_restore_prev_win_state.setChecked(
         prefs.general.restore_window_state)
     oa = prefs.general.open_scr_action
     if oa == prefs.general.OpenActions.NEW:
         self.ui.rb_open_scr_in_new.setChecked(True)
     elif oa == prefs.general.OpenActions.CURRENT:
         self.ui.rb_open_scr_in_same.setChecked(True)
     elif oa == prefs.general.OpenActions.ASK:
         self.ui.rb_open_scr_ask.setChecked(True)
     self.ui.cb_save_before_run.setChecked(prefs.general.save_before_run)
Exemple #26
0
 def init(self):
     if Preferences().general.reopen_last_window:
         try:
             path = self.recent_files_manager.last_file()
         except IndexError:
             self.create_script_window()
         else:
             _logger().info('reopen last window: %s' % path)
             if os.path.isfile(path):
                 self.create_script_window(path)
             else:
                 self.create_project_window(path)
     else:
         # create untitled script window
         self.create_script_window()
Exemple #27
0
 def configure_shortcuts(self):
     self.addActions(self.ui.menuFile.actions())
     # menu edit already added
     self.addActions(self.ui.menuRun.actions())
     self.addActions(self.ui.menuOptions.actions())
     self.addActions(self.ui.menuWindows.actions())
     self.addActions(self.ui.menuHelp.actions())
     key_bindings = Preferences().key_bindings.dict()
     for action in self.actions():
         try:
             key_sequence = key_bindings[action.objectName()]
         except KeyError:
             pass
         else:
             action.setShortcut(key_sequence)
Exemple #28
0
 def run_script(self):
     _logger().info('running script')
     self.ui.actionRun.setText('Stop')
     self.ui.actionRun.setIcon(icons.stop)
     path = self.ui.codeEdit.file.path
     cfg = Preferences().cache.get_run_config_for_file(path)
     _logger().info('run configuration: %r', cfg)
     opts = []
     if len(cfg['interpreter_options']):
         opts += cfg['interpreter_options']
     opts += [cfg['script']]
     if len(cfg['script_parameters']):
         opts += cfg['script_parameters']
     self.ui.textEditPgmOutput.start_process(cfg['interpreter'],
                                             opts,
                                             cwd=cfg['working_dir'],
                                             env=cfg['env_vars'])
Exemple #29
0
 def reset(self):
     editor = Preferences().editor
     self.ui.cb_caret_cope.setChecked(editor.highlight_caret_scope)
     self.ui.cb_spaces_instead_of_tabs.setChecked(
         editor.use_spaces_instead_of_tabs)
     self.ui.sb_tab_len.setValue(editor.tab_len)
     self.ui.sb_margin_pos.setValue(editor.margin_pos)
     self.ui.cb_convert_tabs_to_spaces.setChecked(
         editor.convert_tabs_to_spaces)
     self.ui.cb_clean_trailing.setChecked(editor.clean_trailing)
     self.ui.cb_restore_cursor.setChecked(editor.restore_cursor)
     self.ui.cb_safe_save.setChecked(editor.safe_save)
     self.ui.sb_cc_trigger_len.setValue(editor.cc_trigger_len)
     self.ui.cb_cc_tooltips.setChecked(editor.cc_show_tooltips)
     self.ui.cb_cc_case_sensitive.setChecked(editor.cc_case_sensitive)
     self.ui.cb_fold_doc.setChecked(editor.fold_docstrings)
     self.ui.cb_fold_imports.setChecked(editor.fold_imports)
     self.ui.cb_center_on_scoll.setChecked(editor.center_on_scroll)
Exemple #30
0
 def apply_preferences(self):
     prefs = Preferences()
     self.font_family = prefs.editor_appearance.font
     self.font_size = prefs.editor_appearance.font_size
     self.syntax_style = prefs.editor_appearance.color_scheme
     scheme = ColorScheme(self.syntax_style)
     foreground = scheme.formats['normal'].foreground().color()
     background = scheme.background
     if background.lightness() < 128:
         self.style_sheet = styles.default_dark_style_template % dict(
             bgcolor=background.name(),
             fgcolor=foreground.name(),
             select="#444")
     else:
         self.style_sheet = styles.default_light_style_template % dict(
             bgcolor=background.name(),
             fgcolor=foreground.name(),
             select="#ccc")