Skip to content

Commit

Permalink
Updated doc strings
Browse files Browse the repository at this point in the history
  • Loading branch information
RabiyaF committed Sep 1, 2024
1 parent a944047 commit 915de3e
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 50 deletions.
56 changes: 26 additions & 30 deletions rascal2/dialogs/project_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class ProjectDialog(QtWidgets.QDialog):
"""
The Project Dialog
The Project dialog
"""

_button_style = """background-color: {};
Expand All @@ -25,7 +25,7 @@ class ProjectDialog(QtWidgets.QDialog):

def __init__(self, parent):
"""
Initializes the dialog
Initialize dialog.
Parameters
----------
Expand All @@ -41,13 +41,13 @@ def __init__(self, parent):
self.name_error = False
self.folder_error = False

self.create_project_dialog_labels()
self.create_project_dialog_buttons()
self.create_buttons()
self.create_labels()
self.add_widgets_to_layout()

def add_widgets_to_layout(self) -> None:
"""
Adds the widgets to the layout
Add widgets to the layout.
"""
self.main_layout = QtWidgets.QVBoxLayout()

Expand Down Expand Up @@ -79,9 +79,9 @@ def add_widgets_to_layout(self) -> None:

self.setLayout(self.main_layout)

def create_project_dialog_labels(self) -> None:
def create_labels(self) -> None:
"""
Creates the labels for the project dialog.
Create labels.
"""
# Project name labels
self.project_name_label = QtWidgets.QLabel("Project Name:", self)
Expand All @@ -108,17 +108,17 @@ def create_project_dialog_labels(self) -> None:
self.project_folder_error.setStyleSheet(self._error_style)
self.project_folder_error.hide()

def create_project_dialog_buttons(self) -> None:
def create_buttons(self) -> None:
"""
Creates the buttons for the project dialog.
Create buttons.
"""
self.browse_button = QtWidgets.QPushButton(" Browse", self)
self.browse_button.setIcon(QtGui.QIcon(path_for("open-project-light.png")))
self.browse_button.setIcon(QtGui.QIcon(path_for("browse-light.png")))
self.browse_button.clicked.connect(self.open_folder_selector)
self.browse_button.setStyleSheet(self._button_style.format("#403F3F"))

self.create_button = QtWidgets.QPushButton(" Create", self)
self.create_button.setIcon(QtGui.QIcon(path_for("plus.png")))
self.create_button.setIcon(QtGui.QIcon(path_for("create.png")))
self.create_button.clicked.connect(self.create_project)
self.create_button.setStyleSheet(self._button_style.format("#0D69BB"))

Expand All @@ -136,7 +136,7 @@ def cancel_project_creation(self) -> None:

def reset_variables(self) -> None:
"""
Resets the variables.
Reset variables.
"""
self.project_folder.setText("")
self.project_name.setText("")
Expand All @@ -145,52 +145,48 @@ def reset_variables(self) -> None:

def open_folder_selector(self) -> None:
"""
Opens the folder selector.
Open folder selector.
"""
folder_path = QtWidgets.QFileDialog.getExistingDirectory(self, "Select Folder")
if folder_path:
files_in_folder = list(filter(lambda x: x[0] != ".", os.listdir(folder_path)))
if files_in_folder:
self.handle_error("folder")
else:
self.handle_non_error("folder")
self.handle_success("folder")
self.project_folder.setText(folder_path)

def handle_error(self, tag: Literal["name", "folder"]) -> None:
"""
Displays the line edit error msgs.
Display error msgs.
Parameters
----------
tag: Literal["name", "folder"]
Specifies whether the input verification
is for the project name or folder.
Specifies whether to show the error
for the project name or folder.
"""
input = getattr(self, "project_" + tag)
input.setStyleSheet(self._line_edit_error_style)
error_label = getattr(self, "project_" + tag + "_error")
error_label.show()
getattr(self, "project_" + tag).setStyleSheet(self._line_edit_error_style)
getattr(self, "project_" + tag + "_error").show()
setattr(self, tag + "_error", True)

def handle_non_error(self, tag: Literal["name", "folder"]) -> None:
def handle_success(self, tag: Literal["name", "folder"]) -> None:
"""
Clears the style sheets of the error line edits.
Hide error msgs.
Parameters
----------
tag: Literal["name", "folder"]
Specifies whether to clear the error
for the project name or folder.
"""
input = getattr(self, "project_" + tag)
input.setStyleSheet("")
error_label = getattr(self, "project_" + tag + "_error")
error_label.hide()
getattr(self, "project_" + tag).setStyleSheet("")
getattr(self, "project_" + tag + "_error").hide()
setattr(self, tag + "_error", False)

def verify_inputs(self, tag: Literal["name", "folder"]) -> None:
"""
Verifies the name and folder inputs of the project dialog.
Verify inputs.
Parameters
----------
Expand All @@ -201,11 +197,11 @@ def verify_inputs(self, tag: Literal["name", "folder"]) -> None:
if getattr(self, "project_" + tag).text() == "":
self.handle_error(tag)
else:
self.handle_non_error(tag)
self.handle_success(tag)

def create_project(self) -> None:
"""
Verifies the inputs specified.
Create project if inputs verified.
"""
self.verify_inputs("name")
self.verify_inputs("folder")
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
2 changes: 1 addition & 1 deletion rascal2/ui/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def createActions(self):

self.open_project_action = QtGui.QAction("&Open", self)
self.open_project_action.setStatusTip("Open an existing project")
self.open_project_action.setIcon(QtGui.QIcon(path_for("open-project.png")))
self.open_project_action.setIcon(QtGui.QIcon(path_for("browse-dark.png")))
self.open_project_action.setShortcut(QtGui.QKeySequence.StandardKey.Open)

self.save_project_action = QtGui.QAction("&Save", self)
Expand Down
30 changes: 14 additions & 16 deletions rascal2/widgets/startup_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class StartUpWidget(QtWidgets.QWidget):

def __init__(self, parent):
"""
Initializes the widget
Initialize widget.
Parameters
----------
Expand All @@ -29,14 +29,14 @@ def __init__(self, parent):
super().__init__(parent)

self.create_banner_and_footer()
self.create_buttons_for_startup_page()
self.create_labels_for_startup_page()
self.create_buttons()
self.create_labels()

self.add_widgets_to_startup_page_layout()
self.add_widgets_to_layout()

def add_widgets_to_startup_page_layout(self) -> None:
def add_widgets_to_layout(self) -> None:
"""
Adds the widgets to the startup layout.
Add widgets to layout.
"""
startup_layout = QtWidgets.QVBoxLayout()

Expand All @@ -62,44 +62,42 @@ def add_widgets_to_startup_page_layout(self) -> None:

def create_banner_and_footer(self) -> None:
"""
Creates the banner and footer for the startup page.
Create banner and footer.
"""
# Create the banner
self.banner_label = QtWidgets.QLabel(self)
self.banner_label.setPixmap(QtGui.QPixmap(path_for("banner.png")))
self.banner_label.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)

# Create the footer
self.footer_label = QtWidgets.QLabel(self)
self.footer_label.setPixmap(QtGui.QPixmap(path_for("footer.png")))
self.footer_label.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)

def toggle_view(self) -> None:
"""
Shows the project dialog
Show ProjectDialog.
"""
self.parent().toggleView()

def create_buttons_for_startup_page(self) -> None:
def create_buttons(self) -> None:
"""
Creates the buttons for the startup page.
Create buttons.
"""
self.new_project_button = QtWidgets.QPushButton(self)
self.new_project_button.setIcon(QtGui.QIcon(path_for("plus.png")))
self.new_project_button.setIcon(QtGui.QIcon(path_for("create.png")))
self.new_project_button.clicked.connect(self.toggle_view)
self.new_project_button.setStyleSheet(self._button_style)

self.import_project_button = QtWidgets.QPushButton(self)
self.import_project_button.setIcon(QtGui.QIcon(path_for("open-project-light.png")))
self.import_project_button.setIcon(QtGui.QIcon(path_for("browse-light.png")))
self.import_project_button.setStyleSheet(self._button_style)

self.import_r1_button = QtWidgets.QPushButton(self)
self.import_r1_button.setIcon(QtGui.QIcon(path_for("import-r1.png")))
self.import_r1_button.setStyleSheet(self._button_style)

def create_labels_for_startup_page(self) -> None:
def create_labels(self) -> None:
"""
Creates the labels for the startup page.
Create labels.
"""
self.new_project_label = QtWidgets.QLabel("New\nProject", self)
self.new_project_label.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def setup_project_dialog_widget():

def test_project_dialog_initial_state(setup_project_dialog_widget):
"""
Tests the inital state of the project dialog.
Tests the inital state of the ProjectDialog class.
"""
project_dialog, _ = setup_project_dialog_widget

Expand Down Expand Up @@ -57,9 +57,9 @@ def test_project_dialog_initial_state(setup_project_dialog_widget):
assert not project_dialog.folder_error


def test_lineedit_errors(setup_project_dialog_widget):
def test_inline_error_msgs(setup_project_dialog_widget):
"""
Tests the project name and folder line edit errors displayed.
Tests the project name and folder inline errors.
"""
project_dialog, _ = setup_project_dialog_widget

Expand Down

0 comments on commit 915de3e

Please sign in to comment.