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>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>1330</width>
|
<width>1330</width>
|
||||||
<height>630</height>
|
<height>685</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@ -23,6 +23,85 @@
|
|||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</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>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
|
@ -133,7 +133,7 @@ class SIPPCompare(QMainWindow):
|
|||||||
# Show the output window - this func is called from calculate_fee()
|
# Show the output window - this func is called from calculate_fee()
|
||||||
def show_output_win(self):
|
def show_output_win(self):
|
||||||
# Refresh the results when new fees are calculated
|
# 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()
|
self.output_win.show()
|
||||||
|
|
||||||
def show_platform_list(self):
|
def show_platform_list(self):
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import datetime
|
|
||||||
import os
|
import os
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from PyQt6 import uic
|
from PyQt6 import uic
|
||||||
from PyQt6.QtGui import QIcon
|
from PyQt6.QtGui import QIcon
|
||||||
from PyQt6.QtWidgets import QWidget
|
from PyQt6.QtWidgets import QWidget, QFileDialog
|
||||||
|
|
||||||
import resource_finder
|
import resource_finder
|
||||||
|
from widgets.mpl_widget import MplWidget
|
||||||
|
|
||||||
|
|
||||||
class OutputWindow(QWidget):
|
class OutputWindow(QWidget):
|
||||||
@ -15,17 +16,43 @@ class OutputWindow(QWidget):
|
|||||||
uic.loadUi(resource_finder.get_res_path("gui/output_window.ui"), self)
|
uic.loadUi(resource_finder.get_res_path("gui/output_window.ui"), self)
|
||||||
self.setWindowIcon(QIcon(resource_finder.get_res_path("icon2.ico")))
|
self.setWindowIcon(QIcon(resource_finder.get_res_path("icon2.ico")))
|
||||||
|
|
||||||
def display_output(self, results: list):
|
# Define class variables
|
||||||
ax = self.graphWidget.canvas.axes
|
self.canvas = self.graphWidget.canvas
|
||||||
ax.clear()
|
self.ax = self.canvas.axes
|
||||||
ax.cla()
|
self.fig = self.canvas.figure
|
||||||
self.graphWidget.canvas.draw_idle()
|
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 = []
|
names = []
|
||||||
values = []
|
values = []
|
||||||
for result in results:
|
for result in results:
|
||||||
names.append(result[4])
|
names.append(result[4])
|
||||||
values.append(sum(result[:4]))
|
values.append(sum(result[:4]) * years)
|
||||||
|
|
||||||
h_bars = ax.barh(names, values)
|
h_bars = self.ax.barh(names, values)
|
||||||
ax.bar_label(h_bars, label_type='center', labels=[f"£{x:,.2f}" for x in h_bars.datavalues])
|
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,8 +6,8 @@ from PyQt6.QtWidgets import QWidget, QVBoxLayout
|
|||||||
class MplWidget(QWidget):
|
class MplWidget(QWidget):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
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 = QVBoxLayout()
|
||||||
vertical_layout.addWidget(self.canvas)
|
vertical_layout.addWidget(self.canvas)
|
||||||
self.canvas.axes = self.canvas.figure.add_subplot(1, 1, 1)
|
self.canvas.axes = self.canvas.figure.add_subplot(1, 1, 1)
|
||||||
self.setLayout(vertical_layout)
|
self.setLayout(vertical_layout)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user