Skip to content

Commit

Permalink
Merge pull request #82 from MIERUNE/feat/multilanguage
Browse files Browse the repository at this point in the history
Feat/multilanguage
  • Loading branch information
nbayashi authored Aug 9, 2024
2 parents 34e6287 + ce473ae commit ab0cc10
Show file tree
Hide file tree
Showing 9 changed files with 646 additions and 25 deletions.
71 changes: 58 additions & 13 deletions contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

class Contents:
def __init__(self, iface):
progress_dialog = ProgressDialog(None)

self.iface = iface
self.dlg = QuickDEMforJPDialog()

Expand All @@ -46,14 +48,14 @@ def __init__(self, iface):
self.dlg.mQgsFileWidget_outputPath.setFilePath(QgsProject.instance().homePath())
self.dlg.mQgsFileWidget_outputPath.setFilter("*.tiff")
self.dlg.mQgsFileWidget_outputPath.setDialogTitle(
"保存ファイルを選択してください"
progress_dialog.translate("Set the output file")
)
self.dlg.mQgsFileWidget_outputPathTerrain.setFilePath(
QgsProject.instance().homePath()
)
self.dlg.mQgsFileWidget_outputPathTerrain.setFilter("*.tiff")
self.dlg.mQgsFileWidget_outputPathTerrain.setDialogTitle(
"保存ファイルを選択してください"
progress_dialog.translate("Set the output file")
)

# set terrain path if changed
Expand Down Expand Up @@ -97,6 +99,11 @@ def convert(self, output_path, filename, rgbify):
thread.postMessage.connect(progress_dialog.set_message)
thread.setAbortable.connect(progress_dialog.set_abortable)
thread.processFinished.connect(progress_dialog.close)
thread.processFailed.connect(
lambda error_message: [
self.handle_process_failed(error_message, thread, progress_dialog)
]
)

thread.start()
progress_dialog.exec_()
Expand All @@ -106,39 +113,55 @@ def add_layer(self, output_path, tiff_name, layer_name):
QgsProject.instance().addMapLayer(layer)

def convert_DEM(self):
progress_dialog = ProgressDialog(None)

do_GeoTiff = self.dlg.checkBox_outputGeoTiff.isChecked()
do_TerrainRGB = self.dlg.checkBox_outputTerrainRGB.isChecked()

if not do_GeoTiff and not do_TerrainRGB:
QMessageBox.information(
None, "エラー", "出力形式にチェックを入れてください"
None,
progress_dialog.translate("Error"),
progress_dialog.translate("Output format is not checked."),
)
return

self.import_path = self.dlg.mQgsFileWidget_inputPath.filePath()
if not self.import_path:
QMessageBox.information(None, "エラー", "DEMの入力先パスを入力してください")
QMessageBox.information(
None,
progress_dialog.translate("Error"),
progress_dialog.translate("Input DEM path is not defined."),
)
return

self.output_path = self.dlg.mQgsFileWidget_outputPath.filePath()
if do_GeoTiff and not self.output_path:
QMessageBox.information(
None, "エラー", "GeoTIFFの出力先パスを入力してください"
None,
progress_dialog.translate("Error"),
progress_dialog.translate("GeoTIFF output path is not defined."),
)
return

self.output_path_terrain = self.dlg.mQgsFileWidget_outputPathTerrain.filePath()
if do_TerrainRGB and not self.output_path_terrain:
QMessageBox.information(
None, "エラー", "Terrain RGBの出力先パスを入力してください"
None,
progress_dialog.translate("Error"),
progress_dialog.translate("Terrain RGB output path is not defined."),
)
return

self.output_epsg = (
self.dlg.mQgsProjectionSelectionWidget_outputCrs.crs().authid()
)
if not self.output_epsg:
QMessageBox.information(None, "エラー", "DEMの出力CRSを入力してください")
QMessageBox.information(
None,
progress_dialog.translate("Error"),
progress_dialog.translate("CRS of output file is not defined."),
)
return

do_add_layer = self.dlg.checkBox_openLayers.isChecked()
Expand All @@ -149,7 +172,10 @@ def convert_DEM(self):
directory = os.path.dirname(self.output_path)
if not os.path.isdir(directory):
QMessageBox.information(
None, "エラー", f"Cannot find output folder.\n{directory}"
None,
progress_dialog.translate("Error"),
progress_dialog.translate("Cannot find output folder.")
+ f"\n{directory}",
)
return
filename = os.path.basename(self.output_path)
Expand All @@ -173,7 +199,10 @@ def convert_DEM(self):
directory = os.path.dirname(self.output_path_terrain)
if not os.path.isdir(directory):
QMessageBox.information(
None, "エラー", f"Cannot find output folder.\n{directory}"
None,
progress_dialog.translate("Error"),
progress_dialog.translate("Cannot find output folder.")
+ f"\n{directory}",
)
return
filename = os.path.basename(self.output_path_terrain)
Expand All @@ -193,11 +222,17 @@ def convert_DEM(self):
layer_name=os.path.splitext(filename)[0],
)
except Exception as e:
QMessageBox.information(None, "エラー", f"{e}")
QMessageBox.information(
None, progress_dialog.translate("Error"), progress_dialog.translate(e)
)
return

if not self.process_interrupted:
QMessageBox.information(None, "完了", "処理が完了しました")
QMessageBox.information(
None,
progress_dialog.translate("Completed"),
progress_dialog.translate("Process completed."),
)

self.dlg.hide()

Expand Down Expand Up @@ -237,8 +272,8 @@ def on_download_page_clicked(self):
def on_abort_clicked(self, thread, progress_dialog: ProgressDialog) -> None:
if QMessageBox.Yes == QMessageBox.question(
None,
"Aborting",
"Are you sure to cancel process?",
progress_dialog.translate("Aborting"),
progress_dialog.translate("Are you sure to cancel process?"),
QMessageBox.Yes,
QMessageBox.No,
):
Expand All @@ -255,3 +290,13 @@ def abort_process(self, thread, progress_dialog: ProgressDialog) -> None:

def set_interrupted(self):
self.process_interrupted = True

def handle_process_failed(self, error_message, thread, progress_dialog):
progress_dialog.close()
QMessageBox.information(
None,
progress_dialog.translate("Error"),
progress_dialog.translate(error_message),
)
self.set_interrupted()
self.abort_process(thread, progress_dialog)
2 changes: 1 addition & 1 deletion convert_fgd_dem
1 change: 1 addition & 0 deletions i18n/QuickDEMforJP_en.qm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<�d��!�`���
Loading

0 comments on commit ab0cc10

Please sign in to comment.