Skip to content

Commit

Permalink
Rename some deprecated enum and method in qt5 to qt6 (#637)
Browse files Browse the repository at this point in the history
* Remove exec_ in favor of exec

* Replace deprecated enum in qt5 for the equivalent in qt6

Other enums are not yet convert to pyqt6
  • Loading branch information
ValentinBuira authored Oct 23, 2024
1 parent ef0b250 commit bace3cd
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 42 deletions.
8 changes: 4 additions & 4 deletions Mergin/clone_project_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, user_info, default_workspace=None):
"""
QDialog.__init__(self)
self.ui = uic.loadUi(ui_file, self)
self.ui.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False)
self.ui.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False)
self.ui.buttonBox.accepted.connect(self.accept_dialog)

workspaces = user_info.get("workspaces", None)
Expand Down Expand Up @@ -67,14 +67,14 @@ def validate_input(self):
msg = "Incorrect project name!"

self.ui.edit_project_name.setToolTip(msg)
self.ui.buttonBox.button(QDialogButtonBox.Ok).setToolTip(msg)
self.ui.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setToolTip(msg)
has_error = bool(msg)
self.ui.warningMessageLabel.setVisible(has_error)
self.ui.warningMessageLabel.setText(msg)
self.ui.buttonBox.button(QDialogButtonBox.Ok).setEnabled(not has_error)
self.ui.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(not has_error)

def accept_dialog(self):
self.project_name = self.ui.edit_project_name.text()
self.project_namespace = self.ui.projectNamespace.currentText()

self.accept() # this will close the dialog and dlg.exec_() returns True
self.accept() # this will close the dialog and dlg.exec() returns True
4 changes: 2 additions & 2 deletions Mergin/collapsible_message_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ def __init__(self, text, details, title="Mergin Maps error", parent=None):
msg.setWindowTitle(title)
msg.setTextFormat(Qt.RichText)
msg.setText(text)
msg.setIcon(QMessageBox.Warning)
msg.setIcon(QMessageBox.Icon.Warning)
msg.setStandardButtons(QMessageBox.Close)
msg.setDefaultButton(QMessageBox.Close)
msg.setDetailedText(details)
msg.exec_()
msg.exec()
2 changes: 1 addition & 1 deletion Mergin/configuration_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def server_url(self):

def check_credentials(self):
credentials_are_set = bool(self.ui.username.text()) and bool(self.ui.password.text())
self.ui.buttonBox.button(QDialogButtonBox.Ok).setEnabled(credentials_are_set)
self.ui.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(credentials_are_set)
self.ui.test_connection_btn.setEnabled(credentials_are_set)

def check_master_password(self):
Expand Down
8 changes: 4 additions & 4 deletions Mergin/create_project_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,9 @@ def __init__(self, parent=None):
self.expandAll()
self.header().setStretchLastSection(False)
self.resizeColumnToContents(0)
self.header().setSectionResizeMode(0, QHeaderView.Stretch)
self.header().setSectionResizeMode(0, QHeaderView.ResizeMode.Stretch)

self.setSelectionMode(QAbstractItemView.NoSelection)
self.setSelectionMode(QAbstractItemView.SelectionMode.NoSelection)
self.setEditTriggers(QTreeView.NoEditTriggers)

self.clicked.connect(self.model().toggle_item)
Expand Down Expand Up @@ -419,7 +419,7 @@ def __init__(self, project_manager, user_info, default_workspace=None, parent=No
self.iface = iface
self.settings = QSettings()
self.setWindowTitle("Create new Mergin Maps project")
self.setWizardStyle(QWizard.ClassicStyle)
self.setWizardStyle(QWizard.WizardStyle.ClassicStyle)
self.setDefaultProperty("QComboBox", "currentText", QComboBox.currentTextChanged)
self.project_manager = project_manager
self.username = user_info["username"]
Expand All @@ -437,7 +437,7 @@ def __init__(self, project_manager, user_info, default_workspace=None, parent=No
self.package_page = PackagingPage(parent=self)
self.setPage(PACK_PAGE, self.package_page)

self.cancel_btn = self.button(QWizard.CancelButton)
self.cancel_btn = self.button(QWizard.WizardButton.CancelButton)
self.cancel_btn.clicked.connect(self.cancel_wizard)

# these are the variables used by the caller
Expand Down
24 changes: 12 additions & 12 deletions Mergin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def show_browser_panel(self):
def configure(self):
"""Open plugin configuration dialog."""
dlg = ConfigurationDialog()
if dlg.exec_():
if dlg.exec():
self.mc = dlg.writeSettings()
self.on_config_changed()
self.show_browser_panel()
Expand Down Expand Up @@ -321,7 +321,7 @@ def configure_db_sync(self):
return

wizard = DbSyncConfigWizard(project_name)
if not wizard.exec_():
if not wizard.exec():
return

def show_no_workspaces_dialog(self):
Expand All @@ -330,11 +330,11 @@ def show_no_workspaces_dialog(self):
"Click on the button below to create one. \n\n"
"A minimum of one workspace is required to use Mergin Maps."
)
msg_box = QMessageBox(QMessageBox.Critical, "You do not have any workspace", msg, QMessageBox.Close)
msg_box = QMessageBox(QMessageBox.Icon.Critical, "You do not have any workspace", msg, QMessageBox.Close)
create_button = msg_box.addButton("Create workspace", msg_box.ActionRole)
create_button.clicked.disconnect()
create_button.clicked.connect(partial(self.open_configured_url, "/workspaces"))
msg_box.exec_()
msg_box.exec()

def set_current_workspace(self, workspace):
"""
Expand Down Expand Up @@ -449,7 +449,7 @@ def create_new_project(self):
default_workspace = user_info["username"]

wizard = NewMerginProjectWizard(self.manager, user_info=user_info, default_workspace=default_workspace)
if not wizard.exec_():
if not wizard.exec():
return # cancelled
if self.has_browser_item():
# make sure the item has the link between remote and local project we have just added
Expand All @@ -474,7 +474,7 @@ def find_project(self):
except:
pass

dlg.exec_()
dlg.exec()

def switch_workspace(self):
"""Open new Switch workspace dialog"""
Expand All @@ -490,7 +490,7 @@ def switch_workspace(self):

dlg = WorkspaceSelectionDialog(workspaces)
dlg.manage_workspaces_clicked.connect(self.open_configured_url)
if not dlg.exec_():
if not dlg.exec():
return

workspace = dlg.get_workspace()
Expand All @@ -501,7 +501,7 @@ def explore_public_projects(self):
dlg = PublicProjectSelectionDialog(self.mc)
dlg.open_project_clicked.connect(self.manager.open_project)
dlg.download_project_clicked.connect(self.manager.download_project)
dlg.exec_()
dlg.exec()

def on_qgis_project_changed(self):
"""
Expand Down Expand Up @@ -589,7 +589,7 @@ def view_local_changes(self):
dlg_diff_viewer.tab_bar.setCurrentIndex(i)
break
dlg_diff_viewer.show()
dlg_diff_viewer.exec_()
dlg_diff_viewer.exec()

def export_vector_tiles(self):
selected_layers = self.iface.layerTreeView().selectedLayersRecursive()
Expand Down Expand Up @@ -637,7 +637,7 @@ def clone_remote_project(self):
user_info = self.mc.user_info()

dlg = CloneProjectDialog(user_info=user_info, default_workspace=self.project["namespace"])
if not dlg.exec_():
if not dlg.exec():
return # cancelled
try:
self.mc.clone_project(self.project_name, dlg.project_name, dlg.project_namespace)
Expand All @@ -658,7 +658,7 @@ def clone_remote_project(self):

def remove_remote_project(self):
dlg = RemoveProjectDialog(self.project_name)
if dlg.exec_() == QDialog.Rejected:
if dlg.exec() == QDialog.Rejected:
return

try:
Expand Down Expand Up @@ -784,7 +784,7 @@ def clone_remote_project(self):

dlg = CloneProjectDialog(user_info=user_info, default_workspace=self.project["namespace"])

if not dlg.exec_():
if not dlg.exec():
return # cancelled
try:
self.mc.clone_project(self.project_name, dlg.project_name, dlg.project_namespace)
Expand Down
2 changes: 1 addition & 1 deletion Mergin/project_settings_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def __init__(self, parent=None):

def get_sync_dir(self):
abs_path = QFileDialog.getExistingDirectory(
None, "Select directory", self.local_project_dir, QFileDialog.ShowDirsOnly
None, "Select directory", self.local_project_dir, QFileDialog.Option.ShowDirsOnly
)
if self.local_project_dir not in abs_path:
return
Expand Down
6 changes: 3 additions & 3 deletions Mergin/project_status_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(
self.btn_sync.setIcon(QIcon(icon_path("refresh.svg")))
# add sync button with AcceptRole. If dialog accepted we will start
# sync, otherwise just close status dialog
self.ui.buttonBox.addButton(self.btn_sync, QDialogButtonBox.AcceptRole)
self.ui.buttonBox.addButton(self.btn_sync, QDialogButtonBox.ButtonRole.AcceptRole)

self.btn_view_changes.setIcon(QIcon(icon_path("file-diff.svg")))
self.btn_view_changes.clicked.connect(self.show_changes)
Expand All @@ -85,7 +85,7 @@ def __init__(
info_text = self._get_info_text(has_files_to_replace, has_write_permissions, self.mp.has_unfinished_pull())
for msg in info_text:
lbl = QLabel(msg)
lbl.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
lbl.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred)
lbl.setWordWrap(True)
self.ui.messageBar.pushWidget(lbl, Qgis.Warning)

Expand Down Expand Up @@ -226,7 +226,7 @@ def show_changes(self):
self.close()
self.ui.messageBar.pushMessage("Mergin", "No changes found in the project layers.", Qgis.Info)
dlg_diff_viewer.show()
dlg_diff_viewer.exec_()
dlg_diff_viewer.exec()

def link_clicked(self, url):
parsed_url = urlparse(url.toString())
Expand Down
18 changes: 10 additions & 8 deletions Mergin/projects_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def create_project(self, project_name, project_dir, is_public, namespace):
dlg = SyncDialog()
dlg.push_start(self.mc, project_dir, full_project_name)

dlg.exec_() # blocks until success, failure or cancellation
dlg.exec() # blocks until success, failure or cancellation

if dlg.exception:
# push failed for some reason
Expand Down Expand Up @@ -208,7 +208,7 @@ def project_status(self, project_dir):
# Sync button in the status dialog returns QDialog.Accepted
# and Close button returns QDialog::Rejected, so if dialog was
# accepted we start sync
return_value = dlg.exec_()
return_value = dlg.exec()

if return_value == ProjectStatusDialog.Accepted:
self.sync_project(project_dir)
Expand Down Expand Up @@ -314,7 +314,7 @@ def sync_project(self, project_dir, project_name=None):
dlg = SyncDialog()
dlg.pull_start(self.mc, project_dir, project_name)

dlg.exec_() # blocks until success, failure or cancellation
dlg.exec() # blocks until success, failure or cancellation

if dlg.exception:
# pull failed for some reason
Expand Down Expand Up @@ -355,7 +355,7 @@ def sync_project(self, project_dir, project_name=None):

dlg = SyncDialog()
dlg.push_start(self.mc, project_dir, project_name)
dlg.exec_() # blocks until success, failure or cancellation
dlg.exec() # blocks until success, failure or cancellation

qgis_proj_filename = os.path.normpath(QgsProject.instance().fileName())
qgis_proj_basename = os.path.basename(qgis_proj_filename)
Expand Down Expand Up @@ -469,11 +469,11 @@ def report_conflicts(self, conflicts):
)
msg_box = QMessageBox()
msg_box.setWindowTitle("Conflicts found")
msg_box.setIcon(QMessageBox.Warning)
msg_box.setIcon(QMessageBox.Icon.Warning)
msg_box.setTextFormat(Qt.RichText)
msg_box.setStandardButtons(QMessageBox.Ok)
msg_box.setText(msg)
msg_box.exec_()
msg_box.exec()

def resolve_unfinished_pull(self, project_dir, reopen_project=False):
"""
Expand Down Expand Up @@ -507,7 +507,9 @@ def download_project(self, project):
project_name = posixpath.join(project["namespace"], project["name"]) # we need posix path for server API calls
settings = QSettings()
last_parent_dir = settings.value("Mergin/lastUsedDownloadDir", str(Path.home()))
parent_dir = QFileDialog.getExistingDirectory(None, "Open Directory", last_parent_dir, QFileDialog.ShowDirsOnly)
parent_dir = QFileDialog.getExistingDirectory(
None, "Open Directory", last_parent_dir, QFileDialog.Option.ShowDirsOnly
)
if not parent_dir:
return
settings.setValue("Mergin/lastUsedDownloadDir", parent_dir)
Expand All @@ -522,7 +524,7 @@ def download_project(self, project):

dlg = SyncDialog()
dlg.download_start(self.mc, target_dir, project_name)
dlg.exec_() # blocks until completion / failure / cancellation
dlg.exec() # blocks until completion / failure / cancellation
if dlg.exception:
if isinstance(dlg.exception, (URLError, ValueError)):
QgsApplication.messageLog().logMessage("Mergin Maps plugin: " + str(dlg.exception))
Expand Down
4 changes: 2 additions & 2 deletions Mergin/remove_project_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def __init__(self, project_name, parent=None):
"This action cannot be undone.<br><br>"
"In order to delete project, enter project name in the field below and click 'Yes'."
)
self.buttonBox.button(QDialogButtonBox.Yes).setEnabled(False)
self.buttonBox.button(QDialogButtonBox.StandardButton.Yes).setEnabled(False)

self.edit_project_name.textChanged.connect(self.project_name_changed)

def project_name_changed(self, text):
self.buttonBox.button(QDialogButtonBox.Yes).setEnabled(self.project_name == text)
self.buttonBox.button(QDialogButtonBox.StandardButton.Yes).setEnabled(self.project_name == text)
12 changes: 7 additions & 5 deletions Mergin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,9 @@ def get_new_qgis_project_filepath(project_name=None):
settings = QSettings()
last_dir = settings.value("Mergin/lastUsedDownloadDir", str(pathlib.Path.home()))
if project_name is not None:
dest_dir = QFileDialog.getExistingDirectory(None, "Destination directory", last_dir, QFileDialog.ShowDirsOnly)
dest_dir = QFileDialog.getExistingDirectory(
None, "Destination directory", last_dir, QFileDialog.Option.ShowDirsOnly
)
project_file = os.path.abspath(os.path.join(dest_dir, project_name))
else:
project_file, filters = QFileDialog.getSaveFileName(
Expand Down Expand Up @@ -908,7 +910,7 @@ def unhandled_exception_message(error_details, dialog_title, error_text, log_fil
"please report the problem</a>."
)
box = QMessageBox()
box.setIcon(QMessageBox.Critical)
box.setIcon(QMessageBox.Icon.Critical)
box.setWindowTitle(dialog_title)
box.setText(msg)
if log_file is None:
Expand All @@ -923,9 +925,9 @@ def unhandled_exception_message(error_details, dialog_title, error_text, log_fil
"and briefly describe the problem to add more context to the diagnostic log."
)
box.setDetailedText(error_details)
btn = box.addButton("Send logs", QMessageBox.ActionRole)
btn = box.addButton("Send logs", QMessageBox.ButtonRole.ActionRole)
btn.clicked.connect(lambda: send_logs(username, log_file))
box.exec_()
box.exec()


def write_project_variables(project_owner, project_name, project_full_name, version, server):
Expand Down Expand Up @@ -1242,7 +1244,7 @@ def is_dark_theme():

# check whether system-wide theme is dark
palette = QgsApplication.instance().palette()
bg_color = palette.color(QPalette.Window)
bg_color = palette.color(QPalette.ColorRole.Window)
brightness = (bg_color.red() * 299 + bg_color.green() * 587 + bg_color.blue() * 114) / 1000
return brightness < 155

Expand Down

0 comments on commit bace3cd

Please sign in to comment.