Skip to content

Commit

Permalink
Fix a Python error about iface and use the message bar for better dis…
Browse files Browse the repository at this point in the history
…play
  • Loading branch information
Gustry committed Jul 2, 2024
1 parent 15f88ef commit 08860f1
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 27 deletions.
2 changes: 1 addition & 1 deletion lizmap/dialogs/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ def display_message_bar(
if self.isVisible():
self.message_bar.pushWidget(widget, level, duration)
else:
self.iface.messageBar().pushWidget(widget, level, duration)
iface.messageBar().pushWidget(widget, level, duration)

def setup_icons(self):
""" Setup icons in the left menu. """
Expand Down
85 changes: 59 additions & 26 deletions lizmap/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1254,9 +1254,10 @@ def initGui(self):
self.help_action.triggered.connect(self.show_help_cloud)

# connect Lizmap signals and functions

self.dlg.buttonBox.button(QDialogButtonBox.Cancel).clicked.connect(self.dlg.close)
self.dlg.buttonBox.button(QDialogButtonBox.Apply).clicked.connect(self.save_cfg_file_cursor)
self.dlg.buttonBox.button(QDialogButtonBox.Ok).clicked.connect(self.ok_button_clicked)
self.dlg.buttonBox.button(QDialogButtonBox.Apply).clicked.connect(partial(self.save_cfg_file_cursor, False))
self.dlg.buttonBox.button(QDialogButtonBox.Ok).clicked.connect(partial(self.save_cfg_file_cursor, True))
self.dlg.buttonBox.button(QDialogButtonBox.Help).clicked.connect(self.show_help_question)

# Connect the left menu to the right panel
Expand Down Expand Up @@ -3030,7 +3031,10 @@ def write_project_config_file(self, lwc_version: LwcVersions, with_gui: bool = T
with open(json_file, 'w', encoding='utf8') as cfg_file:
cfg_file.write(json_file_content)

LOGGER.info('The Lizmap configuration file has been written to "{}"'.format(json_file))
LOGGER.info(
'The Lizmap configuration file has been written to <a href="file://{path}">"{path}"</a>'.format(
path=json_file.absolute(),
))
self.clean_project()
return True

Expand Down Expand Up @@ -4277,15 +4281,7 @@ def check_global_project_options(self) -> Tuple[bool, str]:

return True, ''

def ok_button_clicked(self):
"""When the OK button is press, we 'apply' and close the dialog."""
if not self.save_cfg_file_cursor():
return

# Only close the dialog if no error
self.dlg.close()

def save_cfg_file_cursor(self) -> bool:
def save_cfg_file_cursor(self, close_dialog: bool):
""" Save CFG file with a waiting cursor. """
if not self.dlg.check_cfg_file_exists():
new_project = NewConfigDialog()
Expand All @@ -4295,13 +4291,59 @@ def save_cfg_file_cursor(self) -> bool:
result = self.save_cfg_file()

if not result:
return result
# Generation failed, error message without closing the dialog
# noinspection PyUnresolvedReferences
self.dlg.display_message_bar(
'Lizmap',
tr('An error occurred while generating the projet, please check logs'),
level=Qgis.Critical,
duration=DURATION_SUCCESS_BAR,
)
return

# Generation is OK
auto_send = None
url = None
upload_is_visible = not self.dlg.mOptionsListWidget.item(Panels.Upload).isHidden()
if upload_is_visible and self.dlg.send_webdav.isChecked():
return self.send_files()
# Send files if necessary
auto_send, url = self.send_files()

return result
if close_dialog:
# First close the dialog
# The method if the dialog will check which message bar is appropriate according to visibility
self.dlg.close()

if auto_send is None:
# noinspection PyUnresolvedReferences
self.dlg.display_message_bar(
'Lizmap',
tr(
'The project has been generated in <a href="file://{path}">"{path}"</a>'
).format(
path=self.dlg.cfg_file().parent.absolute(),
),
level=Qgis.Success,
duration=DURATION_SUCCESS_BAR,
)
return

if auto_send:
# noinspection PyUnresolvedReferences
self.dlg.display_message_bar(
'Lizmap',
tr('Project <a href="{}">published !</a>'.format(url)),
level=Qgis.Success,
duration=DURATION_SUCCESS_BAR,
)
return

self.dlg.display_message_bar(
'Lizmap',
tr('Project file generated, but the upload has failed'),
level=Qgis.Warning,
duration=DURATION_SUCCESS_BAR,
)

def save_cfg_file(
self,
Expand Down Expand Up @@ -4475,23 +4517,14 @@ def save_cfg_file(

return True

def send_files(self):
def send_files(self) -> Tuple[bool, str]:
""" Send both files to the server, designed for UI interaction.
With a waiting cursor and sending messages to the message bar.
"""
with OverrideCursor(Qt.WaitCursor):
result, _, url = self.send_webdav()

if result:
# noinspection PyUnresolvedReferences
self.dlg.display_message_bar(
'Lizmap',
tr('Project <a href="{}">published !</a>'.format(url)),
level=Qgis.Success,
duration=DURATION_SUCCESS_BAR,
)
return True
return result, url

def create_new_repository(self):
""" Open wizard to create a new remote repository. """
Expand Down

0 comments on commit 08860f1

Please sign in to comment.