Commit f82ce2ba authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[widgets] Mark all slots as pyqtSlots and update casing

Same for property related methods.
parent 5a7d1526
Pipeline #30059 passed with stage
in 8 minutes and 17 seconds
......@@ -110,7 +110,7 @@ class TestAssetWidget:
asset_widget.load_json(
self.get_asset_path(test_prefix, asset_type, asset_name)
)
assert not asset_widget.current_editor.is_dirty()
assert not asset_widget.current_editor.isDirty()
with qtbot.waitSignal(asset_widget.json_widget.textChanged):
asset_widget.current_editor.description_lineedit.selectAll()
......@@ -119,7 +119,7 @@ class TestAssetWidget:
)
assert asset_widget.save_button.isEnabled()
assert asset_widget.current_editor.is_dirty()
assert asset_widget.current_editor.isDirty()
dumped_json = asset_widget.current_editor.dump_json()
description_key = "description"
......
......@@ -26,6 +26,7 @@
import pytest
from PyQt5 import QtCore
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtCore import QStringListModel
from PyQt5.QtWidgets import QPushButton
......@@ -46,9 +47,10 @@ class MockAssetEditor(AbstractAssetEditor):
self.add_field_button = QPushButton(self.tr("Add"))
self.layout().addWidget(self.add_field_button)
self.add_field_button.clicked.connect(self.__add_field)
self.add_field_button.clicked.connect(self.__addField)
def __add_field(self):
@pyqtSlot()
def __addField(self):
self.layout().addWidget(FieldWidget(self.dataformat_model))
def set_dataformat_model(self, model):
......
......@@ -25,6 +25,7 @@
from PyQt5 import QtCore
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtCore import QSortFilterProxyModel
from PyQt5.QtWidgets import QHeaderView
......@@ -112,10 +113,11 @@ class AssetBrowser(QWidget):
layout = QVBoxLayout(self)
layout.addWidget(self.view)
self.view.doubleClicked.connect(self.__on_item_selected)
self.view.customContextMenuRequested.connect(self.__open_menu)
self.view.doubleClicked.connect(self.__onItemSelected)
self.view.customContextMenuRequested.connect(self.__openMenu)
def __on_item_selected(self, index):
@pyqtSlot("QModelIndex")
def __onItemSelected(self, index):
"""When an item is selected, emit the jsonSelected signal with
the corresponding JSON file path.
"""
......@@ -124,17 +126,19 @@ class AssetBrowser(QWidget):
if self.filesystem_model.type(source_index).lower() == "json file":
self.jsonSelected.emit(self.filesystem_model.filePath(source_index))
def __open_menu(self, position):
@pyqtSlot("QPoint")
def __openMenu(self, position):
indexes = self.view.selectedIndexes()
if indexes and indexes[0].data().endswith(".json"):
menu = QMenu()
action = menu.addAction(self.tr("Delete"))
action.triggered.connect(self.__on_delete)
action.triggered.connect(self.__onDelete)
menu.exec_(self.view.viewport().mapToGlobal(position))
def __on_delete(self):
@pyqtSlot()
def __onDelete(self):
file_index, _ = self.view.selectedIndexes()
source_index = self.proxy_model.mapToSource(file_index)
path = self.filesystem_model.filePath(source_index)
......
......@@ -161,7 +161,7 @@ class AssetWidget(QWidget):
self.watcher.fileChanged.connect(self.__reloadFromHarddrive)
self.update_timer.timeout.connect(self.__enableSave)
self.update_timer.timeout.connect(self.__updateJsonWidget)
self.save_button.clicked.connect(self.save_json)
self.save_button.clicked.connect(self.saveJson)
@property
def current_editor(self):
......@@ -254,7 +254,7 @@ class AssetWidget(QWidget):
def maybe_save(self):
"""If the editor has been modified ask for saving"""
if self.current_editor.is_dirty():
if self.current_editor.isDirty():
answer = QMessageBox.question(
self,
self.tr("Save ?"),
......@@ -262,9 +262,9 @@ class AssetWidget(QWidget):
)
if answer == QMessageBox.Yes:
self.save_json()
self.saveJson()
else:
self.current_editor.clear_dirty()
self.current_editor.clearDirty()
self.save_button.setEnabled(False)
......@@ -315,7 +315,7 @@ class AssetWidget(QWidget):
:param file_path str: path to the json file to load
"""
if self.current_json == file_path and not self.current_editor.is_dirty():
if self.current_json == file_path and not self.current_editor.isDirty():
return
self.maybe_save()
......@@ -327,7 +327,8 @@ class AssetWidget(QWidget):
self.__update_content()
def save_json(self):
@pyqtSlot()
def saveJson(self):
"""Save the editor content back to the file"""
json_data = self.current_editor.dump_json()
......@@ -342,5 +343,5 @@ class AssetWidget(QWidget):
with open(self.current_json, "wt") as json_file:
json_file.write(json.dumps(original, sort_keys=True, indent=4))
self.current_editor.clear_dirty()
self.current_editor.clearDirty()
self.save_button.setEnabled(False)
......@@ -27,6 +27,7 @@ import numpy as np
from PyQt5 import QtCore
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtCore import pyqtProperty
from PyQt5.QtCore import QStringListModel
......@@ -308,15 +309,16 @@ class ViewEditor(QWidget):
layout.addLayout(button_layout)
self.delete_button.clicked.connect(self.deletionRequested)
self.add_button.clicked.connect(self.__add_parameter)
self.remove_button.clicked.connect(self.__remove_parameters)
self.add_button.clicked.connect(self.__addParameter)
self.remove_button.clicked.connect(self.__removeParameters)
self.view_name_lineedit.textChanged.connect(self.dataChanged)
self.parameters_tablewidget.itemChanged.connect(self.dataChanged)
self.parameters_tablewidget.itemSelectionChanged.connect(
self.__on_item_selection_changed
self.__onItemSelectionChanged
)
def __add_parameter(self):
@pyqtSlot()
def __addParameter(self):
"""Add a new parameter"""
new_row = self.parameters_tablewidget.rowCount()
......@@ -329,7 +331,8 @@ class ViewEditor(QWidget):
self.parameters_tablewidget.setItem(new_row, 2, value_item)
self.parameters_tablewidget.scrollToItem(value_item)
def __remove_parameters(self):
@pyqtSlot()
def __removeParameters(self):
"""Remove the selected parameter(s)"""
selected_items = self.parameters_tablewidget.selectedItems()
......@@ -346,9 +349,11 @@ class ViewEditor(QWidget):
self.parameters_tablewidget.removeRow(row)
self.dataChanged.emit()
def __on_item_selection_changed(self):
@pyqtSlot()
def __onItemSelectionChanged(self):
self.remove_button.setEnabled(bool(self.parameters_tablewidget.selectedItems()))
@pyqtSlot(str)
def setDbSetName(self, name):
self.dbset_name_label.setText(name)
......@@ -435,7 +440,7 @@ class ViewsEditor(QWidget):
layout.addWidget(self.scroll_area, 1)
layout.addWidget(self.add_view_button, 1)
self.add_view_button.clicked.connect(self.__add_view)
self.add_view_button.clicked.connect(self.__addView)
def available_sets(self):
protocol_template = ProtocolTemplate(self.prefix_path, self.protocol)
......@@ -443,7 +448,8 @@ class ViewsEditor(QWidget):
protocol_sets = [set_["name"] for set_ in protocol_template.sets()]
return [set_ for set_ in protocol_sets if set_ not in used_sets]
def __add_view(self):
@pyqtSlot()
def __addView(self):
"""Add a new view"""
available_sets = self.available_sets()
......@@ -464,7 +470,8 @@ class ViewsEditor(QWidget):
available_sets.pop(available_sets.index(name))
self.add_view_button.setDisabled(not available_sets)
def __remove_view(self):
@pyqtSlot()
def __removeView(self):
"""Execute deletion request"""
self.__remove_widget(self.sender())
......@@ -484,7 +491,7 @@ class ViewsEditor(QWidget):
index = self.container_widget_layout.count() - 1
self.layout().insertWidget(index, view_editor)
view_editor.dataChanged.connect(self.dataChanged)
view_editor.deletionRequested.connect(self.__remove_view)
view_editor.deletionRequested.connect(self.__removeView)
self.view_editors.append(view_editor)
def set_procotol(self, protocol):
......@@ -537,6 +544,7 @@ class ProtocolEditor(QWidget):
self.name_lineedit.textChanged.connect(self.dataChanged)
self.views_editor.dataChanged.connect(self.dataChanged)
@pyqtSlot(str)
def setName(self, name):
self.name_lineedit.setText(name)
......@@ -545,6 +553,7 @@ class ProtocolEditor(QWidget):
name = pyqtProperty(str, fget=name, fset=setName)
@pyqtSlot(str)
def setProtocol(self, protocol):
self.templateprotocol_label.setText(protocol)
self.views_editor.set_procotol(protocol)
......@@ -598,11 +607,12 @@ class ProtocolDialog(QDialog):
layout.addLayout(form_layout)
layout.addWidget(self.buttonbox)
self.name_lineedit.textChanged.connect(self.__validate_name)
self.name_lineedit.textChanged.connect(self.__validateName)
self.buttonbox.accepted.connect(self.accept)
self.buttonbox.rejected.connect(self.reject)
def __validate_name(self, text):
@pyqtSlot(str)
def __validateName(self, text):
"""Ensure the name is not empty or already used"""
self.buttonbox.button(QDialogButtonBox.Ok).setDisabled(
......@@ -660,9 +670,10 @@ class DatabaseWidget(QWidget):
layout.addWidget(self.scroll_area, 1)
layout.addWidget(self.add_protocol_button, 1)
self.add_protocol_button.clicked.connect(self.__add_protocol)
self.add_protocol_button.clicked.connect(self.__addProtocol)
def __on_remove_requested(self):
@pyqtSlot()
def __onRemoveRequested(self):
"""Remove the widget clicked"""
self.__remove_widget(self.sender())
......@@ -682,9 +693,10 @@ class DatabaseWidget(QWidget):
index = self.container_widget_layout.count() - 1
self.container_widget_layout.insertWidget(index, protocol_editor, 2)
protocol_editor.dataChanged.connect(self.dataChanged)
protocol_editor.deletionRequested.connect(self.__on_remove_requested)
protocol_editor.deletionRequested.connect(self.__onRemoveRequested)
def __add_protocol(self):
@pyqtSlot()
def __addProtocol(self):
"""Add a new protocol to edit"""
protocol_names = [widgets.name for widgets in self.protocol_editors]
......
......@@ -24,6 +24,7 @@
###############################################################################
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtCore import QCoreApplication
from PyQt5.QtWidgets import QComboBox
......@@ -258,7 +259,8 @@ class DataformatObjectWidget(DataformatBaseWidget):
lambda: self.__add_entry([0, default_object_dataformat()])
)
def __on_remove_requested(self):
@pyqtSlot()
def __onRemoveRequested(self):
"""Removes the widget clicked"""
self.__remove_widget(self.sender())
......@@ -313,7 +315,7 @@ class DataformatObjectWidget(DataformatBaseWidget):
self.dataformat_widgets.append(dataformat_widget)
dataformat_widget.dataChanged.connect(self.dataChanged)
dataformat_widget.deletionRequested.connect(self.__on_remove_requested)
dataformat_widget.deletionRequested.connect(self.__onRemoveRequested)
def load(self, name, type_dict):
"""Load this widget with the content of type_dict
......@@ -417,7 +419,7 @@ class DataformatArrayWidget(DataformatBaseWidget):
self.__add_dimension(0, 0)
def __on_remove_requested(self):
def __onRemoveRequested(self):
"""Remove the widget clicked"""
self.__remove_widget(self.sender())
......@@ -464,7 +466,7 @@ class DataformatArrayWidget(DataformatBaseWidget):
dimension_widget.setDimension(dimension)
dimension_widget.setRemovable(dimension != 0)
dimension_widget.dataChanged.connect(self.dataChanged)
dimension_widget.deletionRequested.connect(self.__on_remove_requested)
dimension_widget.deletionRequested.connect(self.__onRemoveRequested)
self.dimension_widgets.append(dimension_widget)
......@@ -502,7 +504,7 @@ class DataformatArrayWidget(DataformatBaseWidget):
self.widget_layout.addWidget(self.dataformat_widget)
editor.dataChanged.connect(self.dataChanged)
editor.deletionRequested.connect(self.__on_remove_requested)
editor.deletionRequested.connect(self.__onRemoveRequested)
self.dataChanged.emit()
def load(self, name, type_array):
......@@ -621,7 +623,7 @@ class DataformatEditor(AbstractAssetEditor):
self.dataChanged.emit()
break
def __on_remove_requested(self):
def __onRemoveRequested(self):
self.__remove_widget(self.sender())
def __remove_widget(self, widget):
......@@ -674,7 +676,7 @@ class DataformatEditor(AbstractAssetEditor):
self.container_widget_layout.insertWidget(index, dataformat_widget)
self.dataformat_widgets.append(dataformat_widget)
dataformat_widget.dataChanged.connect(self.dataChanged)
dataformat_widget.deletionRequested.connect(self.__on_remove_requested)
dataformat_widget.deletionRequested.connect(self.__onRemoveRequested)
def _dump_json(self):
"""Returns the json representation of the asset"""
......@@ -709,7 +711,7 @@ class DataformatEditor(AbstractAssetEditor):
self._load_json(json_object)
self.clear_dirty()
self.clearDirty()
def dump_json(self):
"""Returns the json representation of the asset"""
......
......@@ -23,6 +23,7 @@
# #
###############################################################################
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtCore import QCoreApplication
from PyQt5.QtWidgets import QComboBox
......@@ -118,31 +119,33 @@ class AssetCreationDialog(QDialog, CreationType):
form_layout.addRow(self.buttonbox)
self.name_lineedit.textChanged.connect(self.__validate_name)
self.name_lineedit.textChanged.connect(self.__validateName)
self.new_radio_button.toggled.connect(self.name_lineedit.setEnabled)
self.new_radio_button.toggled.connect(self.__update_ui)
self.new_radio_button.toggled.connect(self.__updateUi)
self.fork_lineedit.textChanged.connect(self.__validate_name)
self.fork_lineedit.textChanged.connect(self.__validateName)
self.fork_radio_button.toggled.connect(self.fork_combobox.setEnabled)
self.fork_radio_button.toggled.connect(self.fork_lineedit.setEnabled)
self.fork_radio_button.toggled.connect(self.__update_ui)
self.fork_radio_button.toggled.connect(self.__updateUi)
self.new_version_radio_button.toggled.connect(
self.new_version_combobox.setEnabled
)
self.new_version_radio_button.toggled.connect(self.__update_ui)
self.new_version_radio_button.toggled.connect(self.__updateUi)
self.buttonbox.accepted.connect(self.accept)
self.buttonbox.rejected.connect(self.reject)
def __update_ui(self):
@pyqtSlot()
def __updateUi(self):
if self.isNew():
self.__validate_name(self.name_lineedit.text())
self.__validateName(self.name_lineedit.text())
elif self.isFork():
self.__validate_name(self.fork_lineedit.text())
self.__validateName(self.fork_lineedit.text())
else:
self.buttonbox.button(QDialogButtonBox.Ok).setEnabled(True)
def __validate_name(self, name):
@pyqtSlot(str)
def __validateName(self, name):
"""Validate that new name is not already used"""
ok_button = self.buttonbox.button(QDialogButtonBox.Ok)
......
......@@ -26,6 +26,7 @@
import simplejson as json
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtCore import pyqtProperty
from PyQt5.QtWidgets import QAction
......@@ -64,7 +65,7 @@ class AbstractAssetEditor(QWidget):
self.asset_type = asset_type
self.schema_version = None
self.clear_dirty()
self.clearDirty()
self.create_action = QAction("{}".format(asset_type.name.title()))
......@@ -82,9 +83,9 @@ class AbstractAssetEditor(QWidget):
layout.addWidget(self.title_label)
layout.addWidget(self.information_group_box)
self.create_action.triggered.connect(self._create_new_asset)
self.create_action.triggered.connect(self._createNewAsset)
self.description_lineedit.textChanged.connect(self.dataChanged)
self.dataChanged.connect(self.set_dirty)
self.dataChanged.connect(self.setDirty)
def _add_information_widget(self, label, widget):
"""Add field to information widget
......@@ -105,7 +106,8 @@ class AbstractAssetEditor(QWidget):
widget.setVisible(visible)
self.information_layout.labelForField(widget).setVisible(visible)
def _create_new_asset(self):
@pyqtSlot()
def _createNewAsset(self):
"""Implement whatever is needed to create a new asset managed by this editor"""
ok_pressed, creation_type, asset_info = AssetCreationDialog.getAssetInfo(
......@@ -168,17 +170,19 @@ class AbstractAssetEditor(QWidget):
return errors == [], errors
def set_dirty(self):
@pyqtSlot()
def setDirty(self):
"""Flag the editor as dirty"""
self._dirty = True
def clear_dirty(self):
@pyqtSlot()
def clearDirty(self):
"""Clear the dirty flag"""
self._dirty = False
def is_dirty(self):
def isDirty(self):
"""Returns whether there has been changes in this editor"""
return self._dirty
......@@ -219,7 +223,7 @@ class AbstractAssetEditor(QWidget):
self.description_lineedit.setText(json_object.get("description"))
self._load_json(json_object)
self.blockSignals(False)
self.clear_dirty()
self.clearDirty()
def dump_json(self):
"""Returns the json representation of the asset"""
......
......@@ -24,6 +24,7 @@
###############################################################################
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QPushButton
......@@ -94,8 +95,8 @@ class LibrariesWidget(QWidget):
layout.addLayout(libraries_used_layout)
# Signal/Slots connections
self.add_library_button.clicked.connect(self.__on_add_library_clicked)
self.remove_library_button.clicked.connect(self.__on_remove_library_clicked)
self.add_library_button.clicked.connect(self.__onAddLibraryClicked)
self.remove_library_button.clicked.connect(self.__onRemoveLibraryClicked)
self.add_library_button.clicked.connect(self.dataChanged)
self.remove_library_button.clicked.connect(self.dataChanged)
......@@ -125,7 +126,8 @@ class LibrariesWidget(QWidget):
row, 1, QTableWidgetItem(library_alias)
)
def __on_add_library_clicked(self):
@pyqtSlot()
def __onAddLibraryClicked(self):
selected_libraries = self.available_libraries_listwidget.selectedItems()
if selected_libraries:
for library in selected_libraries:
......@@ -133,7 +135,8 @@ class LibrariesWidget(QWidget):
library_alias = library_name.split("/")[1]
self.__use_library(library_name, library_alias)
def __on_remove_library_clicked(self):
@pyqtSlot()
def __onRemoveLibraryClicked(self):
# Get reverse order for deletion and set for possible rowcolumn selection
rows = sorted(
set(
......
......@@ -23,13 +23,14 @@
# #
###############################################################################
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtCore import QSettings
from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtWidgets import QMessageBox
from PyQt5.QtWidgets import QSplitter
from PyQt5.QtWidgets import qApp
from PyQt5.QtCore import QSettings
from .assetbrowser import AssetBrowser
from .assetwidget import AssetWidget
......@@ -71,9 +72,9 @@ class MainWindow(QMainWindow):
self.assetBrowser.jsonSelected.connect(self.assetWidget.load_json)
self.assetBrowser.deletionRequested.connect(self.assetWidget.deleteAsset)
quitAction.triggered.connect(qApp.quit)
aboutAction.triggered.connect(self.show_about)
aboutQtAction.triggered.connect(self.show_about_qt)
settingsAction.triggered.connect(self.show_settings)
aboutAction.triggered.connect(self.showAbout)
aboutQtAction.triggered.connect(self.showAboutQt)
settingsAction.triggered.connect(self.showSettings)
self.load_settings()
......@@ -83,7 +84,8 @@ class MainWindow(QMainWindow):
self.assetBrowser.set_context(context)
self.assetWidget.set_context(context)
def show_about(self):
@pyqtSlot()
def showAbout(self):
"""About box for the application"""
QMessageBox.about(
......@@ -96,12 +98,14 @@ class MainWindow(QMainWindow):
),
)
def show_about_qt(self):
@pyqtSlot()
def showAboutQt(self):
"""About box for Qt"""
QMessageBox.aboutQt(self, self.tr("About Qt"))
def show_settings(self):
@pyqtSlot()
def showSettings(self):
"""Show settings dialog"""
pass
......
......@@ -24,6 +24,7 @@
###############################################################################
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import QComboBox
......@@ -120,14 +121,15 @@ class SetWidget(QWidget):
self.name_lineedit.textChanged.connect(self.dataChanged)
self.delete_button.clicked.connect(self.deletionRequested)
self.add_button.clicked.connect(self.__add_output)
self.remove_button.clicked.connect(self.__remove_outputs)
self.add_button.clicked.connect(self.__addOutput)
self.remove_button.clicked.connect(self.__removeOutputs)
self.outputs_tablewidget.cellChanged.connect(self.dataChanged)
self.outputs_tablewidget.itemSelectionChanged.connect(
self.__on_item_selection_changed
self.__onItemSelectionChanged
)
def __add_output(self):
@pyqtSlot()
def __addOutput(self):
"""Add a new output"""
new_row = self.outputs_tablewidget.rowCount()
......@@ -139,7 +141,8 @@ class SetWidget(QWidget):
self.outputs_tablewidget.scrollToItem(type_item)
self.dataChanged.emit()
def __remove_outputs(self):
@pyqtSlot()
def __removeOutputs(self):
"""Remove the selected output(s)"""