Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

入力レイヤ・出力レイヤを選択するuiを追加 #9

Merged
merged 3 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions dem_to_csmap.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

from PyQt5.QtWidgets import QDialog, QMessageBox
from PyQt5.QtWidgets import QDialog
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QDialogQgsFileWidget のインポートが追加されましたが、QgsFileWidget は使用されていないようです。

- from qgis.gui import QgsFileWidget

Also applies to: 5-5

Committable suggestion was skipped due to low confidence.

from qgis.PyQt import uic

from csmap_py.csmap import process
Expand All @@ -13,22 +13,27 @@ def __init__(self):
os.path.join(os.path.dirname(__file__), "dem_to_csmap.ui"), self
)

# ウィンドウタイトル
self.setWindowTitle("CSMap Plugin")
# ラスタデータのみ選択(現状tifのみにしています)
self.ui.mQgsFileWidget.setFilter('*.tif')
# 出力先をフォルダに指定
self.ui.mQgsFileWidget_.setStorageMode(1)

self.ui.pushButton_run.clicked.connect(self.get_and_show_input_text)
self.ui.pushButton_cancel.clicked.connect(self.close)

def get_and_show_input_text(self):
# テキストボックス値取得
text_value = self.ui.lineEdit.text()
# テキストボックス値をメッセージ表示
QMessageBox.information(None, "ウィンドウ名", text_value)

# 試しにCSMapの処理を実行:ちゃんと入力・出力をUIから参照しよう
params = process.CsmapParams()
input_path = "/Users/kanahiro/Downloads/dem.tif"
output_path = "/Users/kanahiro/Downloads/out.tif"

# 入力・出力をUIで操作
input_path = self.ui.mQgsFileWidget.filePath()
output_path = self.ui.mQgsFileWidget_.filePath()
process.process(
input_path,
output_path,
256,
output_path=os.path.join(output_path, 'csmap.tif'),
Comment on lines +31 to +34
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits:

31行目で宣言したoutput_pathと、process.process()の引数のoutput_pathは意味が違うので、別の名前をつけておくべきです。
=31行目の方は出力先ディレクトリ、process()の方は出力先のフルパスをそれぞれ意味している。

ただしこちらは、次のブランチでまとめて修正しましょう。

chunk_size=256,
params=params,
)

self.close()
37 changes: 27 additions & 10 deletions dem_to_csmap.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,61 @@
<rect>
<x>0</x>
<y>0</y>
<width>318</width>
<height>68</height>
<width>357</width>
<height>168</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLineEdit" name="lineEdit">
<property name="minimumSize">
<size>
<width>300</width>
<height>0</height>
</size>
<widget class="QLabel" name="label">
<property name="text">
<string>入力レイヤ</string>
</property>
</widget>
</item>
<item>
<widget class="QgsFileWidget" name="mQgsFileWidget"/>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>出力フォルダ</string>
</property>
</widget>
</item>
<item>
<widget class="QgsFileWidget" name="mQgsFileWidget_"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="pushButton_run">
<property name="text">
<string>OK</string>
<string>Run</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_cancel">
<property name="text">
<string>キャンセル</string>
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsFileWidget</class>
<extends>QWidget</extends>
<header>qgsfilewidget.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
Loading