From 8c3fa967f6172e03e2aff6e67d5f0445fef9951f Mon Sep 17 00:00:00 2001 From: Benjamin Blacher Date: Sun, 20 Feb 2022 12:35:24 +0100 Subject: [PATCH] added save button to map view Signed-off-by: Benjamin Blacher --- GUI/win_main.py | 15 +++++++++++++-- GUI/win_main.ui | 7 +++++++ main.py | 18 +++++++++++++----- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/GUI/win_main.py b/GUI/win_main.py index 287d6b3..00fe31b 100644 --- a/GUI/win_main.py +++ b/GUI/win_main.py @@ -8,9 +8,14 @@ ## WARNING! All changes made in this file will be lost when recompiling UI file! ################################################################################ -from PySide6.QtCore import (QCoreApplication, QMetaObject, QRect, Qt) +from PySide6.QtCore import (QCoreApplication, QMetaObject, QRect, + Qt) from PySide6.QtGui import (QAction, QFont) -from PySide6.QtWidgets import (QAbstractScrollArea, QGraphicsView, QHBoxLayout, QLabel, QMenu, QMenuBar, QPushButton, QSizePolicy, QSpacerItem, QStackedWidget, QTableWidget, QVBoxLayout, QWidget, QAbstractItemView) +from PySide6.QtWidgets import (QAbstractScrollArea, QGraphicsView, QHBoxLayout, + QLabel, QMenu, + QMenuBar, QPushButton, QSizePolicy, QSpacerItem, + QStackedWidget, QTableWidget, QVBoxLayout, + QWidget, QAbstractItemView) from pyqtgraph import PlotWidget @@ -153,6 +158,11 @@ def setupUi(self, win_main): self.verticalLayout.setObjectName(u"verticalLayout") self.horizontalLayout_3 = QHBoxLayout() self.horizontalLayout_3.setObjectName(u"horizontalLayout_3") + self.saveImage = QPushButton(self.view_mapview) + self.saveImage.setObjectName(u"saveImage") + + self.horizontalLayout_3.addWidget(self.saveImage) + self.horizontalSpacer_3 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_3.addItem(self.horizontalSpacer_3) @@ -266,6 +276,7 @@ def retranslateUi(self, win_main): self.lab_tableview.setText(QCoreApplication.translate("win_main", u"Table View", None)) self.lab_plotview.setText(QCoreApplication.translate("win_main", u"Plot View", None)) self.PlotSettings.setText(QCoreApplication.translate("win_main", u"Plot Settings", None)) + self.saveImage.setText(QCoreApplication.translate("win_main", u"Save Image", None)) self.lab_mapview.setText(QCoreApplication.translate("win_main", u"Map View", None)) self.styleSatellite.setText(QCoreApplication.translate("win_main", u"Satellite ", None)) self.styleMap.setText(QCoreApplication.translate("win_main", u"OpenStreetMap", None)) diff --git a/GUI/win_main.ui b/GUI/win_main.ui index fadef09..0768665 100644 --- a/GUI/win_main.ui +++ b/GUI/win_main.ui @@ -188,6 +188,13 @@ + + + + Save Image + + + diff --git a/main.py b/main.py index eb1b76a..ddba8ed 100644 --- a/main.py +++ b/main.py @@ -1,12 +1,8 @@ -# TODO add "Save as" for map view # TODO don't spawn a terminal window # TODO check screen res for map view # TODO allow zoom & pan on map view -# TODO fix plotsettings on "open file" +# TODO fix datatypes, plotcolor on "open file" # TODO close all child windows on main window close -# TODO Dropdown position for disabled items - -# TODO (feedback needed) resize graph on edit from csv import reader from datetime import datetime @@ -21,6 +17,7 @@ import os import numpy as np import staticmaps +from shutil import copy windowtitle = "RC-Car Viewer" plotinitialized = False @@ -90,8 +87,17 @@ def __init__(self): self.MapLoadButton.clicked.connect(self.draw_map) self.styleSatellite.clicked.connect(self.map_satellite) self.styleMap.clicked.connect(self.map_map) + self.saveImage.clicked.connect(self.save_map) self.PlotSettings.clicked.connect(lambda: win_plotsettings.show_window()) + def save_map(self): + savepath = QFileDialog.getSaveFileName(self, "Save Location", QDir.homePath(), "*.svg") + path = savepath[0] + if not path[-4:] == ".svg": + path = path + ".svg" + copy(os.getcwd() + "/temp/map_tmp.svg", path) + + def map_satellite(self): context.set_tile_provider(staticmaps.tile_provider_ArcGISWorldImagery) self.draw_map() @@ -220,6 +226,7 @@ def draw_map(self): map_scene.addItem(map_item) self.MapLoadButton.setVisible(0) self.mapdisplay.setVisible(1) + self.saveImage.setVisible(1) self.styleSatellite.setVisible(1) self.styleMap.setVisible(1) self.mapdisplay.setScene(map_scene) @@ -232,6 +239,7 @@ def toggle_fullscreen(self): def openfile(self): self.mapdisplay.setVisible(0) + self.saveImage.setVisible(0) self.MapLoadButton.setVisible(1) self.styleSatellite.setVisible(0) self.styleMap.setVisible(0)