mirror of
https://github.com/RolandWH/SIPPCompare.git
synced 2025-05-10 08:41:49 +01:00
add time slider and saving functionality to output
This commit is contained in:
parent
348b027ede
commit
f2a0735972
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1330</width>
|
||||
<height>630</height>
|
||||
<height>685</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -23,6 +23,85 @@
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="save_graph_but">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>1231</x>
|
||||
<y>642</y>
|
||||
<width>91</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save graph</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QSlider" name="time_slider">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>370</x>
|
||||
<y>635</y>
|
||||
<width>581</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>20</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="tickPosition">
|
||||
<enum>QSlider::TickPosition::TicksAbove</enum>
|
||||
</property>
|
||||
<property name="tickInterval">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="save_csv_but">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>1134</x>
|
||||
<y>642</y>
|
||||
<width>91</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save CSV</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="time_lab">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>640</y>
|
||||
<width>341</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>11</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Fees over 1 year(s) (assuming no change in value)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
@ -133,7 +133,7 @@ class SIPPCompare(QMainWindow):
|
||||
# Show the output window - this func is called from calculate_fee()
|
||||
def show_output_win(self):
|
||||
# Refresh the results when new fees are calculated
|
||||
self.output_win.display_output(self.results)
|
||||
self.output_win.display_output(self.results, 1)
|
||||
self.output_win.show()
|
||||
|
||||
def show_platform_list(self):
|
||||
|
@ -1,11 +1,12 @@
|
||||
import datetime
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
from PyQt6 import uic
|
||||
from PyQt6.QtGui import QIcon
|
||||
from PyQt6.QtWidgets import QWidget
|
||||
from PyQt6.QtWidgets import QWidget, QFileDialog
|
||||
|
||||
import resource_finder
|
||||
from widgets.mpl_widget import MplWidget
|
||||
|
||||
|
||||
class OutputWindow(QWidget):
|
||||
@ -15,17 +16,43 @@ class OutputWindow(QWidget):
|
||||
uic.loadUi(resource_finder.get_res_path("gui/output_window.ui"), self)
|
||||
self.setWindowIcon(QIcon(resource_finder.get_res_path("icon2.ico")))
|
||||
|
||||
def display_output(self, results: list):
|
||||
ax = self.graphWidget.canvas.axes
|
||||
ax.clear()
|
||||
ax.cla()
|
||||
self.graphWidget.canvas.draw_idle()
|
||||
# Define class variables
|
||||
self.canvas = self.graphWidget.canvas
|
||||
self.ax = self.canvas.axes
|
||||
self.fig = self.canvas.figure
|
||||
self.results = []
|
||||
|
||||
# Handle events
|
||||
self.save_graph_but.clicked.connect(self.save_graph)
|
||||
self.time_slider.valueChanged.connect(self.change_time)
|
||||
|
||||
def display_output(self, results: list, years: int):
|
||||
self.results = results
|
||||
self.ax.clear()
|
||||
self.ax.cla()
|
||||
self.canvas.draw_idle()
|
||||
|
||||
names = []
|
||||
values = []
|
||||
for result in results:
|
||||
names.append(result[4])
|
||||
values.append(sum(result[:4]))
|
||||
values.append(sum(result[:4]) * years)
|
||||
|
||||
h_bars = ax.barh(names, values)
|
||||
ax.bar_label(h_bars, label_type='center', labels=[f"£{x:,.2f}" for x in h_bars.datavalues])
|
||||
h_bars = self.ax.barh(names, values)
|
||||
self.ax.bar_label(h_bars, label_type='center', labels=[f"£{x:,.2f}" for x in h_bars.datavalues])
|
||||
|
||||
def save_graph(self):
|
||||
file_picker = QFileDialog(self)
|
||||
file_picker.setFileMode(QFileDialog.FileMode.Directory)
|
||||
folder_path = ""
|
||||
if file_picker.exec():
|
||||
folder_path = file_picker.selectedFiles()[0]
|
||||
|
||||
cur_time = datetime.now()
|
||||
filename_str = f"{folder_path}/SIPPCompare-{cur_time.year}.{cur_time.month}.{cur_time.day}.png"
|
||||
self.fig.savefig(filename_str, dpi=150)
|
||||
|
||||
def change_time(self):
|
||||
years: int = self.time_slider.value()
|
||||
self.time_lab.setText(f"Fees over {years} year(s) (assuming no change in value)")
|
||||
self.display_output(self.results, years)
|
||||
|
@ -6,7 +6,7 @@ from PyQt6.QtWidgets import QWidget, QVBoxLayout
|
||||
class MplWidget(QWidget):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.canvas = FigureCanvasQTAgg(Figure(figsize=(10, 10), dpi=100))
|
||||
self.canvas = FigureCanvasQTAgg(Figure(figsize=(15, 8), dpi=100))
|
||||
vertical_layout = QVBoxLayout()
|
||||
vertical_layout.addWidget(self.canvas)
|
||||
self.canvas.axes = self.canvas.figure.add_subplot(1, 1, 1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user