Skip to content

Commit

Permalink
Fix open new file
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuellar committed Jan 23, 2024
1 parent 1c13586 commit 00e8a9a
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 29 deletions.
9 changes: 8 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,13 @@ def open_file(self, file_name=None, file_dir=None):

if isinstance(plot_data, PlotHorizo):
self.plot_horizo = plot_data
self.add_vertical_settings()
mpl_plot_vertical = self.findChild(MplPlotVertical, "mpl_plot_vertical")
if not mpl_plot_vertical:
self.add_vertical_settings()
mpl_plot_vertical = self.findChild(MplPlotVertical, "mpl_plot_vertical")
mpl_plot_vertical.set_new_file(
filename=self.plot_horizo.filename.split("/")[-1]
)
self.output_console.print_output(
f"{len(self.plot_horizo.names)} functions."
)
Expand All @@ -193,6 +199,7 @@ def open_folder_dialog(self):
def add_vertical_settings(self):
# Plot Vertical Lines
mpl_plot_vertical = MplPlotVertical()
mpl_plot_vertical.setObjectName("mpl_plot_vertical")
self.controls_layout.insertWidget(3, mpl_plot_vertical)


Expand Down
30 changes: 22 additions & 8 deletions data/plot_horizo.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
class PlotHorizo:
def __init__(self, names: list[str], x: list[float], z: float = 0.0) -> None:
def __init__(
self,
names: list[str],
x: list[float],
z: float = 0.0,
names_y: float = 0.1,
names_color: str = "black",
linestyles: str = "--",
colors: str = "blue",
label_colors: str = "black",
width: float = 1,
show_names: bool = True,
filename: str = "",
) -> None:
indexes = sorted(range(len(x)), key=x.__getitem__)
self.x = list(map(x.__getitem__, indexes))
self.names = list(map(names.__getitem__, indexes))

self.names_y = 0.1
self.names_color = "black"
self.names_y = names_y
self.names_color = names_color
self.z = z
self.linestyles = "--"
self.colors = "blue"
self.label_colors = "black"
self.width = 1
self.show_names = True
self.linestyles = linestyles
self.colors = colors
self.label_colors = label_colors
self.width = width
self.show_names = show_names
self.filename = filename

def set_colors(self, color: str) -> None:
self.colors = color
Expand Down
27 changes: 19 additions & 8 deletions data/plot_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@


class PlotPoints:
def __init__(self, name: str, points: Points) -> None:
def __init__(
self,
name: str,
points: Points,
color: str = "blue",
plot_line: str = "-",
marker: str = "",
marker_color: str = "blue",
show_error: bool = False,
error_color: str = "blue",
drawstyle: str = "default",
) -> None:
self.name = name
self.points = points
self.x_range = [
Expand All @@ -18,13 +29,13 @@ def __init__(self, name: str, points: Points) -> None:
]
self.x_limit = self.x_range
self.y_limit = self.y_range
self.color = "blue"
self.plot_line = "-"
self.marker = ""
self.marker_color = "blue"
self.show_error = False
self.error_color = "blue"
self.drawstyle = "default"
self.color = color
self.plot_line = plot_line
self.marker = marker
self.marker_color = marker_color
self.show_error = show_error
self.error_color = error_color
self.drawstyle = drawstyle

def set_x_limit(self, new_x_limit: list[float]) -> None:
self.x_limit = new_x_limit
Expand Down
32 changes: 30 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,37 @@ def open_data(window, file_name):
err += 1

if len(names) > 0:
res = PlotHorizo(names, xhorizo)
if app.plot_horizo:
res = PlotHorizo(
names=names,
x=xhorizo,
z=0,
names_y=app.plot_horizo.names_y,
names_color=app.plot_horizo.names_color,
linestyles=app.plot_horizo.linestyles,
colors=app.plot_horizo.colors,
label_colors=app.plot_horizo.label_colors,
width=app.plot_horizo.width,
show_names=app.plot_horizo.show_names,
filename=file_name,
)
else:
res = PlotHorizo(names, xhorizo)
else:
res = PlotPoints(file_name.split("/")[-1], Points(x, y, z))
if app.plot_points:
res = PlotPoints(
name=file_name.split("/")[-1],
points=Points(x, y, z),
color=app.plot_points.color,
plot_line=app.plot_points.plot_line,
marker=app.plot_points.marker,
marker_color=app.plot_points.marker_color,
show_error=app.plot_points.show_error,
error_color=app.plot_points.error_color,
drawstyle=app.plot_points.drawstyle,
)
else:
res = PlotPoints(file_name.split("/")[-1], Points(x, y, z))
window.setWindowTitle(file_name.split("/")[-1] + " - CUTA")

if err == 0:
Expand Down
28 changes: 18 additions & 10 deletions widgets/mpl_plot_vertical.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def __init__(self):
layout.addWidget(box)
box_layout = QFormLayout()

# Add filename
self.filename_mpl = QLineEdit("")
self.filename_mpl.setReadOnly(True)
box_layout.addRow("Filename:", self.filename_mpl)

# Add Plot Vertical Color
self.plot_vertical_color_mpl = QComboBox()
self.plot_vertical_color_mpl.addItems(
Expand Down Expand Up @@ -56,18 +61,11 @@ def __init__(self):
self.z_mpl.textChanged.connect(self.change_z)
box_layout.addRow("z:", self.z_mpl)

app = QApplication.activeWindow()
self.min_z = None
self.max_z = None
if app:
self.z_slider = QDoubleSlider(Qt.Orientation.Horizontal)
range_x = app.plot_points.x_range
self.min_z = range_x[0] / app.plot_horizo.x[-1] - 1
self.max_z = range_x[1] / app.plot_horizo.x[0] - 1
self.z_slider.setRange(self.min_z, self.max_z)
self.z_slider.setValue(0)
box_layout.addWidget(self.z_slider)
self.z_slider.sliderReleased.connect(self.slider_released)
self.z_slider = QDoubleSlider(Qt.Orientation.Horizontal)
box_layout.addWidget(self.z_slider)
self.z_slider.sliderReleased.connect(self.slider_released)

box.setContentLayout(box_layout)

Expand Down Expand Up @@ -112,3 +110,13 @@ def change_z(self, new_z):

def slider_released(self):
self.z_mpl.setText(f"{self.z_slider.value():.4f}")

def set_new_file(self, filename):
app = QApplication.activeWindow()
self.filename_mpl.setText(filename)
self.z_mpl.setText("0")
range_x = app.plot_points.x_range
self.min_z = range_x[0] / app.plot_horizo.x[-1] - 1
self.max_z = range_x[1] / app.plot_horizo.x[0] - 1
self.z_slider.setRange(self.min_z, self.max_z)
self.z_slider.setValue(0)

0 comments on commit 00e8a9a

Please sign in to comment.