diff --git a/app.py b/app.py index 0f6b965..58bf308 100644 --- a/app.py +++ b/app.py @@ -13,6 +13,7 @@ QSplitter, QGridLayout, QTabWidget, + QTabBar, ) from PyQt6.QtCore import Qt from PyQt6.QtGui import QAction @@ -24,6 +25,7 @@ from widgets.mpl_canvas import MplCanvas from widgets.slider_zoom import SliderZoom from widgets.mpl_plot_vertical import MplPlotVertical +from widgets.image_viewer import ImageViewer from utils import open_data from data import Points, PlotPoints, PlotHorizo, Plot @@ -64,7 +66,8 @@ def __init__(self): # pylint: disable=R0915 canvas_workspace.setLayout(canvas_workspace_layout) # Canvas plot (with tabs) - self.tabs = QTabWidget() + self.tabs = QTabWidget(movable=False, tabsClosable=True) + self.tabs.tabCloseRequested.connect(self.close_tab) self.canvas_plot = MplCanvas(self, width=10, height=8, dpi=100) self.canvas_plot_grid = QWidget() canvas_plot_grid_layout = QGridLayout() @@ -79,6 +82,7 @@ def __init__(self): # pylint: disable=R0915 canvas_plot_grid_layout.addWidget(canvas_plot_null, 1, 0, 1, 1) canvas_plot_grid_layout.addWidget(self.canvas_plot, 0, 1, 1, 1) self.tabs.addTab(self.canvas_plot_grid, "Matplotlib") + self.tabs.tabBar().setTabButton(0, QTabBar.RightSide, None) # Splitter Canvas and Settings self.canvas_workspace_layout_splitter.addWidget(self.tabs) @@ -220,6 +224,17 @@ def add_vertical_settings(self): mpl_plot_vertical.setObjectName("mpl_plot_vertical") self.controls_layout.insertWidget(3, mpl_plot_vertical) + def open_image(self, file_name): + image = ImageViewer(file_name) + self.tabs.addTab(image, file_name.split("/")[-1]) + self.tabs.setCurrentIndex(self.tabs.count() - 1) + + def close_tab(self, idx): + self.tabs.removeTab(idx) + + def reload_files(self): + self.files_menu.open_folder(self.last_dir_open) + if __name__ == "__main__": app = QApplication([]) diff --git a/widgets/buttons_settings.py b/widgets/buttons_settings.py index 0a994c4..3970231 100644 --- a/widgets/buttons_settings.py +++ b/widgets/buttons_settings.py @@ -1,3 +1,4 @@ +from datetime import datetime from PyQt6.QtGui import QPainter from PyQt6.QtWidgets import QWidget, QHBoxLayout, QStyleOption, QStyle, QApplication from PyQt6.QtCore import Qt, QSize @@ -106,8 +107,21 @@ def take_screenshot(self): self.move_button.set_active(False) self.zoom_button.set_active(False) self.active = None - if app.last_dir_open: - app.canvas_plot.fig.savefig(app.last_file_open[:-4]) + name_file = ( + app.last_dir_open + + "/" + + app.plot_points.name.split(".")[0] + + "-" + + datetime.now().strftime("%b:%-d-%H:%M:%S") + ) + if ( + app.last_dir_open + and app.last_file_open + and app.plot_points.name != "Start Plot" + ): + app.canvas_plot.fig.savefig(name_file) + app.reload_files() + app.open_image(name_file) def paintEvent(self, _): # pylint: disable=C0103 o = QStyleOption() diff --git a/widgets/files_menu.py b/widgets/files_menu.py index 9ea3ebc..41cde53 100644 --- a/widgets/files_menu.py +++ b/widgets/files_menu.py @@ -69,12 +69,19 @@ def _open_folder_recursive(self, box, folder_name, deepth=0): normal_plot = True except: # pylint: disable=W0702 print("Unexpected error.") - file_widget = PushButtonMenu(file, normal_plot) + file_widget = PushButtonMenu(file, "normal" if normal_plot else "alt") file_widget.clicked.connect( partial(self.win.open_file, file_name=file, file_dir=folder_name) ) box.addWidget(file_widget) + if file.endswith(".png"): + file_widget = PushButtonMenu(file, "image") + file_widget.clicked.connect( + partial(self.win.open_image, file_name=folder_name + "/" + file) + ) + box.addWidget(file_widget) + if ( os.path.isdir(folder_name + "/" + file) and not "." in file diff --git a/widgets/image_viewer.py b/widgets/image_viewer.py new file mode 100644 index 0000000..1ac2e06 --- /dev/null +++ b/widgets/image_viewer.py @@ -0,0 +1,10 @@ +from PyQt6.QtWidgets import QLabel +from PyQt6.QtGui import QPixmap +from PyQt6.QtCore import Qt + + +class ImageViewer(QLabel): + def __init__(self, filename): + super().__init__() + self.setPixmap(QPixmap(filename)) + self.setAlignment(Qt.AlignCenter | Qt.AlignCenter) diff --git a/widgets/push_button_menu.py b/widgets/push_button_menu.py index 20c65d7..5bc4ef4 100644 --- a/widgets/push_button_menu.py +++ b/widgets/push_button_menu.py @@ -3,10 +3,12 @@ class PushButtonMenu(QPushButton): - def __init__(self, text, normal=False): + def __init__(self, text, file_type="normal"): icon = qta.icon("fa5.file") - if not normal: + if file_type == "alt": icon = qta.icon("fa5.file-alt") + if file_type == "image": + icon = qta.icon("fa5.file-image", color="#a86832") super().__init__(icon, text) self.filename = text