Compare commits

..

No commits in common. "deb9b2069f81db7085179f057b8ddf356e2db0d6" and "2e360943b28fbd16f6c1d1a408ce3907e0c20ae5" have entirely different histories.

6 changed files with 26 additions and 122 deletions

View File

@ -112,7 +112,6 @@ class GeoTIFF(SQLSubModel):
elif key == "description":
self.description = value
elif key == "file_name":
if self._file_name != value:
self.read_file(value)
elif key == "coordinates":
self.coordinates = value

View File

@ -17,7 +17,6 @@
# -*- coding: utf-8 -*-
import logging
import traceback
from tools import trace, timer
@ -93,8 +92,7 @@ class ReplWindow(PamhyrWindow):
value = exec(rich_code)
value = self.__debug_exec_result__
except Exception as e:
value = f"<font color=\"red\">" + str(e) + "</font>\n"
value += f"<font color=\"grey\">{traceback.format_exc()}</font>"
value = f"<font color=\"red\">" + str(e) + "</font>"
# Display code
msg = f"<font color=\"grey\"> # " + code + " #</font>"

View File

@ -22,8 +22,8 @@ from Modules import Modules
from View.Tools.PamhyrWindow import PamhyrWindow
from PyQt5.QtWidgets import (
QLabel, QPlainTextEdit, QPushButton, QCheckBox,
QFileDialog, QVBoxLayout, QDoubleSpinBox,
QLabel, QPlainTextEdit, QPushButton,
QCheckBox, QFileDialog, QVBoxLayout,
)
from PyQt5.QtCore import (
@ -78,15 +78,14 @@ class EditGeoTIFFWindow(PamhyrWindow):
self._undo = undo
self.setup_values()
self.setup_graph()
self.setup_values()
self.setup_connection()
def setup_graph(self):
self.canvas = MplCanvas(width=5, height=4, dpi=100)
self.canvas.setObjectName("canvas")
self.plot_layout = self.find(QVBoxLayout,
"verticalLayout_geotiff")
self.plot_layout = self.find(QVBoxLayout, "verticalLayout_geotiff")
self.plot_layout.addWidget(self.canvas)
self.plot = PlotXY(
@ -110,10 +109,14 @@ class EditGeoTIFFWindow(PamhyrWindow):
self.set_line_edit_text("lineEdit_description",
self._geotiff.description)
bounds = list(self._geotiff.coordinates.values())
self._set_values_from_bounds(bounds)
self._set_default_values_from_bounds(bounds)
self._reset_spinboxes()
self._values = {
"bottom": self._geotiff.coord_bottom,
"top": self._geotiff.coord_top,
"left": self._geotiff.coord_left,
"right": self._geotiff.coord_right,
}
self._reset_values()
if self._study.is_read_only():
self.set_check_box_enable("checkBox", False)
@ -129,23 +132,14 @@ class EditGeoTIFFWindow(PamhyrWindow):
"right": bounds[3],
}
def _set_default_values_from_bounds(self, bounds):
self._values_default = {
"bottom": bounds[0],
"top": bounds[2],
"left": bounds[1],
"right": bounds[3],
}
self._reset_values()
def _reset_spinboxes(self):
def _reset_values(self):
for key in self._values:
self._reset_spinbox(key)
self._reset_values_key(key)
def _reset_spinbox(self, key):
self.set_double_spin_box(
f"doubleSpinBox_{key}",
self._values_default[key]
)
def _reset_values_key(self, key):
self.set_double_spin_box(f"doubleSpinBox_{key}", self._values[key])
def setup_connection(self):
self.find(QPushButton, "pushButton_cancel")\
@ -157,18 +151,7 @@ class EditGeoTIFFWindow(PamhyrWindow):
for key in self._values:
self.find(QPushButton, f"pushButton_{key}")\
.clicked.connect(lambda: self._reset_spinbox(key))
self.find(QDoubleSpinBox, f"doubleSpinBox_{key}")\
.valueChanged.connect(
lambda: self.update_values_from_spinbox(key)
)
def update_values_from_spinbox(self, key):
self._values[key] = self.get_double_spin_box(f"doubleSpinBox_{key}")
self._plot_img.set_extent(list(self._values.values()))
self.plot.idle()
.clicked.connect(lambda: self._reset_values_key(key))
def draw_geotiff(self, memfile=None):
if not _rasterio_loaded:
@ -181,8 +164,6 @@ class EditGeoTIFFWindow(PamhyrWindow):
with rasterio.open(self._file_name) as data:
img = data.read()
b = data.bounds[:]
self._set_values_from_bounds(b)
else:
with memfile.open() as gt:
img = gt.read()
@ -191,9 +172,11 @@ class EditGeoTIFFWindow(PamhyrWindow):
if self._plot_img is not None:
self._plot_img.remove()
self._set_values_from_bounds(b)
self._plot_img = self.canvas.axes.imshow(
img.transpose((1, 2, 0)),
extent=list(self._values.values())
extent=[b[0], b[2], b[1], b[3]]
)
self.plot.idle()
@ -219,7 +202,7 @@ class EditGeoTIFFWindow(PamhyrWindow):
if filename != "":
self._file_name = filename
self.draw_geotiff()
self. draw_geotiff()
def accept(self):
if self._study.is_editable():

View File

@ -19,7 +19,7 @@
from tools import trace, timer
from PyQt5.QtWidgets import (
QAction, QListView, QVBoxLayout,
QAction, QListView,
)
from View.Tools.PamhyrWindow import PamhyrWindow
@ -28,23 +28,6 @@ from View.GeoTIFF.List import ListModel
from View.GeoTIFF.Translate import GeoTIFFTranslate
from View.GeoTIFF.Edit.Window import EditGeoTIFFWindow
from View.Tools.Plot.PamhyrCanvas import MplCanvas
from View.PlotXY import PlotXY
try:
import rasterio
import rasterio.control
import rasterio.crs
import rasterio.sample
import rasterio.vrt
import rasterio._features
from rasterio.io import MemoryFile
_rasterio_loaded = True
except Exception as e:
print(f"Module 'rasterio' is not available: {e}")
_rasterio_loaded = False
class GeoTIFFListWindow(PamhyrWindow):
_pamhyr_ui = "GeoTIFFList"
@ -65,7 +48,6 @@ class GeoTIFFListWindow(PamhyrWindow):
)
self.setup_list()
self.setup_graph()
self.setup_connections()
def setup_list(self):
@ -77,26 +59,6 @@ class GeoTIFFListWindow(PamhyrWindow):
trad=self._trad,
)
def setup_graph(self):
self.canvas = MplCanvas(width=5, height=4, dpi=100)
self.canvas.setObjectName("canvas")
self.plot_layout = self.find(QVBoxLayout, "verticalLayout")
self.plot_layout.addWidget(self.canvas)
self.plot = PlotXY(
canvas=self.canvas,
data=self._study.river.enable_edges(),
trad=self._trad,
toolbar=None,
parent=self
)
self.plot.update()
self._plot_img = {}
for geotiff in self._study.river.geotiff.lst:
self.draw_geotiff(geotiff)
def setup_connections(self):
if self._study.is_editable():
self.find(QAction, "action_add").triggered.connect(self.add)
@ -104,39 +66,9 @@ class GeoTIFFListWindow(PamhyrWindow):
self.find(QAction, "action_edit").triggered.connect(self.edit)
def draw_geotiff(self, geotiff):
if not _rasterio_loaded:
return
memfile = geotiff.memfile
if memfile is None:
return
with memfile.open() as gt:
img = gt.read()
coords = geotiff.coordinates
if geotiff in self._plot_img:
self._plot_img[geotiff].remove()
self._plot_img[geotiff] = self.canvas.axes.imshow(
img.transpose((1, 2, 0)),
extent=list(coords.values())
)
self.plot.idle()
def update(self):
self._list.update()
for geotiff in self._plot_img:
self._plot_img[geotiff].remove()
self._plot_img = {}
for geotiff in self._study.river.geotiff.files:
self.draw_geotiff(geotiff)
def selected_rows(self):
lst = self.find(QListView, f"listView")
return list(map(lambda i: i.row(), lst.selectedIndexes()))
@ -156,7 +88,6 @@ class GeoTIFFListWindow(PamhyrWindow):
return
self._list.delete(rows[0])
self.update()
def edit(self):
rows = self.selected_rows()

View File

@ -158,7 +158,7 @@ define_model_action = [
"action_menu_boundary_conditions_sediment",
"action_menu_rep_additional_lines", "action_menu_output_rk",
"action_menu_run_adists", "action_menu_pollutants",
"action_menu_d90", "action_menu_dif", "action_menu_edit_geotiff"
"action_menu_d90", "action_menu_dif",
]
action = (
@ -298,7 +298,6 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
self.open_reach_sediment_layers,
"action_menu_additional_file": self.open_additional_files,
"action_menu_rep_additional_lines": self.open_rep_lines,
"action_menu_edit_geotiff": self.open_geotiff,
"action_menu_close": self.close_model,
"action_menu_results_last": self.open_last_results,
"action_menu_open_results_from_file": self.open_results_from_file,

View File

@ -129,7 +129,6 @@
<string>&amp;Geometry</string>
</property>
<addaction name="action_menu_edit_geometry"/>
<addaction name="action_menu_edit_geotiff"/>
</widget>
<widget class="QMenu" name="menu_run">
<property name="locale">
@ -812,11 +811,6 @@
<string>Compare results</string>
</property>
</action>
<action name="action_menu_edit_geotiff">
<property name="text">
<string>GeoTIFF</string>
</property>
</action>
</widget>
<resources/>
<connections>