Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Split Working Directory module #5219

Merged
merged 6 commits into from
Sep 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spyder/app/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ def create_edit_action(text, tr_text, icon):

# Working directory plugin
self.debug_print(" ..plugin: working directory")
from spyder.plugins.workingdirectory import WorkingDirectory
from spyder.plugins.workingdirectory.plugin import WorkingDirectory
self.workingdirectory = WorkingDirectory(self, self.init_workdir, main=self)
self.workingdirectory.register_plugin()
self.toolbarslist.append(self.workingdirectory.toolbar)
Expand Down
9 changes: 9 additions & 0 deletions spyder/plugins/workingdirectory/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
#
# Copyright © Spyder Project Contributors
# Licensed under the terms of the MIT License
# (see spyder/__init__.py for details)

"""
Spyder Working Directory plugin.
"""
111 changes: 111 additions & 0 deletions spyder/plugins/workingdirectory/confpage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# -*- coding: utf-8 -*-
#
# Copyright © Spyder Project Contributors
# Licensed under the terms of the MIT License
# (see spyder/__init__.py for details)

"""Working Directory Plugin"""

# pylint: disable=C0103
# pylint: disable=R0903
# pylint: disable=R0911
# pylint: disable=R0201

# Third party imports
from qtpy.QtWidgets import (QButtonGroup, QGroupBox, QHBoxLayout, QLabel,
QVBoxLayout)

# Local imports
from spyder.config.base import _
from spyder.api.preferences import PluginConfigPage
from spyder.py3compat import getcwd


class WorkingDirectoryConfigPage(PluginConfigPage):
def setup_page(self):
about_label = QLabel(_("The <b>current working directory</b> is "
"the working directory for IPython consoles "
"and the current directory for the File Explorer."))
about_label.setWordWrap(True)

startup_group = QGroupBox(_("Startup"))
startup_bg = QButtonGroup(startup_group)
startup_label = QLabel(_("At startup, the current working "
"directory is:"))
startup_label.setWordWrap(True)
lastdir_radio = self.create_radiobutton(
_("The current project directory "
"or user home directory "
"(if no project is active)"),
'startup/use_project_or_home_directory',
True,
_("At startup,"), # TODO
button_group=startup_bg)
thisdir_radio = self.create_radiobutton(
_("the following directory:"),
'startup/use_fixed_directory', False,
_("At startup, the current working "
"directory will be the specified path"),
button_group=startup_bg)
thisdir_bd = self.create_browsedir("", 'startup/fixed_directory',
getcwd())
thisdir_radio.toggled.connect(thisdir_bd.setEnabled)
lastdir_radio.toggled.connect(thisdir_bd.setDisabled)
thisdir_layout = QHBoxLayout()
thisdir_layout.addWidget(thisdir_radio)
thisdir_layout.addWidget(thisdir_bd)

startup_layout = QVBoxLayout()
startup_layout.addWidget(startup_label)
startup_layout.addWidget(lastdir_radio)
startup_layout.addLayout(thisdir_layout)
startup_group.setLayout(startup_layout)

# Console Directory

console_group = QGroupBox(_("Console directory"))
console_label = QLabel(_("The working directory for new consoles is:"))
console_label.setWordWrap(True)
console_bg = QButtonGroup(console_group)
console_project_radio = self.create_radiobutton(
_("The current project directory "
"or user home directory "
"(if no project is active)"),
'console/use_project_or_home_directory',
True,
button_group=console_bg)
console_cwd_radio = self.create_radiobutton(
_("The current working directory"),
'console/use_cwd',
False,
button_group=console_bg)

console_dir_radio = self.create_radiobutton(
_("the following directory:"),
'console/use_fixed_directory', False,
_("The directory when a new console "
"is open will be the specified path"),
button_group=console_bg)
console_dir_bd = self.create_browsedir("", 'console/fixed_directory',
getcwd())
console_dir_radio.toggled.connect(console_dir_bd.setEnabled)
console_project_radio.toggled.connect(console_dir_bd.setDisabled)
console_cwd_radio.toggled.connect(console_dir_bd.setDisabled)
console_dir_layout = QHBoxLayout()
console_dir_layout.addWidget(console_dir_radio)
console_dir_layout.addWidget(console_dir_bd)

console_layout = QVBoxLayout()
console_layout.addWidget(console_label)
console_layout.addWidget(console_project_radio)
console_layout.addWidget(console_cwd_radio)
console_layout.addLayout(console_dir_layout)
console_group.setLayout(console_layout)

vlayout = QVBoxLayout()
vlayout.addWidget(about_label)
vlayout.addSpacing(10)
vlayout.addWidget(startup_group)
vlayout.addWidget(console_group)
vlayout.addStretch(1)
self.setLayout(vlayout)
Original file line number Diff line number Diff line change
Expand Up @@ -18,108 +18,17 @@
# Third party imports
from qtpy.compat import getexistingdirectory
from qtpy.QtCore import QSize, Signal, Slot
from qtpy.QtWidgets import (QButtonGroup, QGroupBox, QHBoxLayout, QLabel,
QToolBar, QVBoxLayout)
from qtpy.QtWidgets import QToolBar

# Local imports
from spyder.config.base import _, get_conf_path, get_home_dir
from spyder.api.plugins import SpyderPluginWidget
from spyder.api.preferences import PluginConfigPage
from spyder.py3compat import to_text_string, getcwd
from spyder.utils import encoding
from spyder.utils import icon_manager as ima
from spyder.utils.qthelpers import create_action
from spyder.widgets.comboboxes import PathComboBox


class WorkingDirectoryConfigPage(PluginConfigPage):
def setup_page(self):
about_label = QLabel(_("The <b>current working directory</b> is "
"the working directory for IPython consoles "
"and the current directory for the File Explorer."))
about_label.setWordWrap(True)

startup_group = QGroupBox(_("Startup"))
startup_bg = QButtonGroup(startup_group)
startup_label = QLabel(_("At startup, the current working "
"directory is:"))
startup_label.setWordWrap(True)
lastdir_radio = self.create_radiobutton(
_("The current project directory "
"or user home directory "
"(if no project is active)"),
'startup/use_project_or_home_directory',
True,
_("At startup,"), # TODO
button_group=startup_bg)
thisdir_radio = self.create_radiobutton(
_("the following directory:"),
'startup/use_fixed_directory', False,
_("At startup, the current working "
"directory will be the specified path"),
button_group=startup_bg)
thisdir_bd = self.create_browsedir("", 'startup/fixed_directory',
getcwd())
thisdir_radio.toggled.connect(thisdir_bd.setEnabled)
lastdir_radio.toggled.connect(thisdir_bd.setDisabled)
thisdir_layout = QHBoxLayout()
thisdir_layout.addWidget(thisdir_radio)
thisdir_layout.addWidget(thisdir_bd)

startup_layout = QVBoxLayout()
startup_layout.addWidget(startup_label)
startup_layout.addWidget(lastdir_radio)
startup_layout.addLayout(thisdir_layout)
startup_group.setLayout(startup_layout)

# Console Directory

console_group = QGroupBox(_("Console directory"))
console_label = QLabel(_("The working directory for new consoles is:"))
console_label.setWordWrap(True)
console_bg = QButtonGroup(console_group)
console_project_radio = self.create_radiobutton(
_("The current project directory "
"or user home directory "
"(if no project is active)"),
'console/use_project_or_home_directory',
True,
button_group=console_bg)
console_cwd_radio = self.create_radiobutton(
_("The current working directory"),
'console/use_cwd',
False,
button_group=console_bg)

console_dir_radio = self.create_radiobutton(
_("the following directory:"),
'console/use_fixed_directory', False,
_("The directory when a new console "
"is open will be the specified path"),
button_group=console_bg)
console_dir_bd = self.create_browsedir("", 'console/fixed_directory',
getcwd())
console_dir_radio.toggled.connect(console_dir_bd.setEnabled)
console_project_radio.toggled.connect(console_dir_bd.setDisabled)
console_cwd_radio.toggled.connect(console_dir_bd.setDisabled)
console_dir_layout = QHBoxLayout()
console_dir_layout.addWidget(console_dir_radio)
console_dir_layout.addWidget(console_dir_bd)

console_layout = QVBoxLayout()
console_layout.addWidget(console_label)
console_layout.addWidget(console_project_radio)
console_layout.addWidget(console_cwd_radio)
console_layout.addLayout(console_dir_layout)
console_group.setLayout(console_layout)

vlayout = QVBoxLayout()
vlayout.addWidget(about_label)
vlayout.addSpacing(10)
vlayout.addWidget(startup_group)
vlayout.addWidget(console_group)
vlayout.addStretch(1)
self.setLayout(vlayout)
from spyder.plugins.workingdirectory.confpage import WorkingDirectoryConfigPage


class WorkingDirectory(SpyderPluginWidget):
Expand Down
7 changes: 7 additions & 0 deletions spyder/plugins/workingdirectory/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright © Spyder Project Contributors
# Licensed under the terms of the MIT License
# (see spyder/__init__.py for details)

"""Working Directory Tests."""
34 changes: 34 additions & 0 deletions spyder/plugins/workingdirectory/tests/test_workingdirectory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
#
# Copyright © Spyder Project Contributors
# Licensed under the terms of the MIT License
#
"""Tests for workingdirectory plugin."""

# Test library imports
import pytest

# Local imports
from spyder.plugins.workingdirectory.plugin import WorkingDirectory


@pytest.fixture
def setup_workingdirectory(qtbot):
"""Setupp working directory plugin."""
workingdirectory = WorkingDirectory(None)
qtbot.addWidget(workingdirectory)
workingdirectory.show()

return workingdirectory, qtbot


def test_basic_initialization(setup_workingdirectory):
"""Test Working Directory plugin initialization."""
workingdirectory, qtbot = setup_workingdirectory

# Assert that workingdirectory exists
assert workingdirectory is not None


if __name__ == "__main__":
pytest.main()