Skip to content

Commit

Permalink
Edit filename for file widgets (#359)
Browse files Browse the repository at this point in the history
- Reinstates the class SaveObjectWindow as it was before Improve graph window #335
- Creates files graphs_window, save_widgets
  • Loading branch information
DanicaSTFC authored Oct 10, 2024
1 parent 56960e2 commit 3713eb2
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 119 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Dependencies:
* Add pandas #335
* Add eqt and upgrade viewer version #364

Backend:
* Create files graphs_widgets, save_widgets #359

## v24.0.1
Bug fixes:
Expand Down
4 changes: 2 additions & 2 deletions src/idvc/dvc_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import os
from openpyxl import load_workbook
import sys
import PySide2
from PySide2 import QtCore, QtGui, QtWidgets
from PySide2.QtCore import (QByteArray, QRegExp, QSettings, QSize, Qt,
QThreadPool)
Expand Down Expand Up @@ -89,7 +88,8 @@

from idvc import version as gui_version

from idvc.ui.widgets import *
from idvc.ui.graphs_widgets import *
from idvc.ui.save_widgets import SaveObjectWindow
from idvc.ui.dialogs import *
from idvc.ui.windows import *
from idvc.utilities import *
Expand Down
111 changes: 5 additions & 106 deletions src/idvc/ui/widgets.py → src/idvc/ui/graphs_widgets.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
from PySide2 import QtWidgets, QtCore
from PySide2.QtWidgets import *
from PySide2.QtCore import *
from PySide2.QtGui import *
import numpy as np
import matplotlib
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
from functools import partial
import shutil
import os
import tempfile
from eqt.threading import Worker
from scipy.stats import norm
from eqt.ui.NoBorderScrollArea import NoBorderScrollArea


class BaseResultsWidget(QtWidgets.QWidget):
class BaseResultsWidget(QWidget):
'''
Creates a widget which can be set in a QDockWidget.
'''
Expand Down Expand Up @@ -61,9 +55,9 @@ def __init__(self, parent, result_data_frame):
self.linewidth = 3 #pixels?
self.fontsizes = {'figure_title':18, 'subplot_title':14, 'label':10}
super().__init__(parent = parent)
self.layout = QtWidgets.QVBoxLayout()
self.layout = QVBoxLayout()
self.setLayout(self.layout)
self.grid_layout = QtWidgets.QGridLayout()
self.grid_layout = QGridLayout()
self.grid_layout.setAlignment(Qt.AlignTop)
self.layout.addLayout(self.grid_layout,0)
self.addInfotoGridLayout(single_result)
Expand Down Expand Up @@ -222,7 +216,7 @@ def addWidgetsToGridLayout(self):
self.grid_layout.addWidget(self.subvol_size_widget,widgetno,2)
widgetno+=1

self.button = QtWidgets.QPushButton("Plot histograms")
self.button = QPushButton("Plot histograms")
self.button.clicked.connect(partial(self.addSubplotsToFigure))
self.grid_layout.addWidget(self.button,widgetno,2)
widgetno+=1
Expand Down Expand Up @@ -363,7 +357,7 @@ def addWidgetstoGridLayout(self, param_list, button_text):
self.parameter_fix_widget.currentIndexChanged.connect(lambda: self.showParameterValues())

widgetno+=1
self.button = QtWidgets.QPushButton(button_text)
self.button = QPushButton(button_text)
self.button.clicked.connect(partial(self.addSubplotsToFigure))
self.grid_layout.addWidget(self.button,widgetno,2)

Expand Down Expand Up @@ -722,98 +716,3 @@ def addSubplotsToFigure(self):
self.canvas.draw()


class SaveObjectWindow(QtWidgets.QWidget):
'''a window which will appear when saving a mask or pointcloud
'''
#self.copy_files_label = QLabel("Allow a copy of the image files to be stored: ")

def __init__(self, parent, object_type, save_only):
super().__init__(parent = parent)

self.object = object_type

if self.object == "mask":
self.setWindowTitle("Save Existing Mask")
self.label = QLabel("Save mask as:")
elif self.object == "pointcloud":
self.setWindowTitle("Save Existing Point Cloud")
self.label = QLabel("Save Point Cloud as:")


self.setWindowModality(QtCore.Qt.ApplicationModal)
#self.setInputMode(QtWidgets.QInputDialog.TextInput)

self.textbox = QLineEdit(self)
rx = QRegExp("[A-Za-z0-9]+")
validator = QRegExpValidator(rx, self.textbox) #need to check this
self.textbox.setValidator(validator)

self.save_button = QPushButton("Save")
self.quit_button = QPushButton("Discard")
self.save_button.clicked.connect(lambda: self.save(save_only))
self.quit_button.clicked.connect(self.quit)

self.setWindowFlags(QtCore.Qt.WindowTitleHint )
#self.setCancelButtonText("New Session")
#self.setAttribute(Qt.WA_DeleteOnClose)
self.layout = QtWidgets.QFormLayout()
self.layout.addRow(self.label)
self.layout.addRow(self.textbox)
self.layout.addRow(self.save_button, self.quit_button)
self.setLayout(self.layout)

def save(self, save_only):
if self.object == "mask":
#Load Saved Session
#print("Write mask to file, then carry on")
filename = self.textbox.text() + ".mha"
shutil.copyfile(os.path.join(tempfile.tempdir, self.parent().mask_file), os.path.join(tempfile.tempdir, "Masks", filename))
self.parent().mask_parameters['masksList'].addItem(filename)
self.parent().mask_details[filename] = self.parent().mask_details['current']
#print(self.parent().mask_details)

self.parent().mask_parameters['loadButton'].setEnabled(True)
self.parent().mask_parameters['masksList'].setEnabled(True)


if not save_only:
#print("Not save only")
#would be better to move this elsewhere
self.parent().mask_worker = Worker(self.parent().extendMask)
self.parent().create_progress_window("Loading", "Loading Mask")
self.parent().mask_worker.signals.progress.connect(self.parent().progress)
self.parent().mask_worker.signals.finished.connect(self.parent().DisplayMask)
self.parent().threadpool.start(self.parent().mask_worker)
self.parent().progress_window.setValue(10)

if self.object == "pointcloud":
filename = self.textbox.text() + ".roi"
shutil.copyfile(os.path.join(tempfile.tempdir, "latest_pointcloud.roi"), os.path.join(tempfile.tempdir, filename))

self.parent().pointcloud_parameters['loadButton'].setEnabled(True)
self.parent().pointcloud_parameters['pointcloudList'].setEnabled(True)
self.parent().pointcloud_parameters['pointcloudList'].addItem(filename)
self.parent().pointCloud_details[filename] = self.parent().pointCloud_details['latest_pointcloud.roi']
#print(self.parent().pointCloud_details)
#self.parent().createPointCloud()
if not save_only:
self.parent().PointCloudWorker("create")


self.close()

def quit(self):
if self.object == "mask":
#would be better to move this elsewhere
self.parent().mask_worker = Worker(self.parent().extendMask)
self.parent().create_progress_window("Loading", "Loading Mask")
self.parent().mask_worker.signals.progress.connect(self.parent().progress)
self.parent().mask_worker.signals.finished.connect(self.parent().DisplayMask)
self.parent().threadpool.start(self.parent().mask_worker)
self.parent().progress_window.setValue(10)

if self.object == "pointcloud":
self.parent().PointCloudWorker("create")
#self.parent().createPointCloud()

self.close()
106 changes: 106 additions & 0 deletions src/idvc/ui/save_widgets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
from PySide2 import QtWidgets, QtCore
from PySide2.QtWidgets import *
from PySide2.QtCore import *
from PySide2.QtGui import *
import shutil
import os
import tempfile
from eqt.threading import Worker


class SaveObjectWindow(QtWidgets.QWidget):
'''a window which will appear when saving a mask or pointcloud
'''
#self.copy_files_label = QLabel("Allow a copy of the image files to be stored: ")

def __init__(self, parent, object_type, save_only):
super().__init__()

self.parent = parent
self.object = object_type

if self.object == "mask":
self.setWindowTitle("Save Existing Mask")
self.label = QLabel("Save mask as:")
elif self.object == "pointcloud":
self.setWindowTitle("Save Existing Point Cloud")
self.label = QLabel("Save Point Cloud as:")


self.setWindowModality(QtCore.Qt.ApplicationModal)
#self.setInputMode(QtWidgets.QInputDialog.TextInput)

self.textbox = QLineEdit(self)
rx = QRegExp("[A-Za-z0-9]+")
validator = QRegExpValidator(rx, self.textbox) #need to check this
self.textbox.setValidator(validator)

self.save_button = QPushButton("Save")
self.quit_button = QPushButton("Discard")
self.save_button.clicked.connect(lambda: self.save(save_only))
self.quit_button.clicked.connect(self.quit)

self.setWindowFlags(QtCore.Qt.WindowTitleHint )
#self.setCancelButtonText("New Session")
#self.setAttribute(Qt.WA_DeleteOnClose)
self.layout = QtWidgets.QFormLayout()
self.layout.addRow(self.label)
self.layout.addRow(self.textbox)
self.layout.addRow(self.save_button, self.quit_button)
self.setLayout(self.layout)

def save(self, save_only):
if self.object == "mask":
#Load Saved Session
#print("Write mask to file, then carry on")
filename = self.textbox.text() + ".mha"
shutil.copyfile(os.path.join(tempfile.tempdir, self.parent.mask_file), os.path.join(tempfile.tempdir, "Masks", filename))
self.parent.mask_parameters['masksList'].addItem(filename)
self.parent.mask_details[filename] = self.parent.mask_details['current']
#print(self.parent.mask_details)

self.parent.mask_parameters['loadButton'].setEnabled(True)
self.parent.mask_parameters['masksList'].setEnabled(True)


if not save_only:
#print("Not save only")
#would be better to move this elsewhere
self.parent.mask_worker = Worker(self.parent.extendMask)
self.parent.create_progress_window("Loading", "Loading Mask")
self.parent.mask_worker.signals.progress.connect(self.parent.progress)
self.parent.mask_worker.signals.finished.connect(self.parent.DisplayMask)
self.parent.threadpool.start(self.parent.mask_worker)
self.parent.progress_window.setValue(10)

if self.object == "pointcloud":
filename = self.textbox.text() + ".roi"
shutil.copyfile(os.path.join(tempfile.tempdir, "latest_pointcloud.roi"), os.path.join(tempfile.tempdir, filename))

self.parent.pointcloud_parameters['loadButton'].setEnabled(True)
self.parent.pointcloud_parameters['pointcloudList'].setEnabled(True)
self.parent.pointcloud_parameters['pointcloudList'].addItem(filename)
self.parent.pointCloud_details[filename] = self.parent.pointCloud_details['latest_pointcloud.roi']
#print(self.parent.pointCloud_details)
#self.parent.createPointCloud()
if not save_only:
self.parent.PointCloudWorker("create")


self.close()

def quit(self):
if self.object == "mask":
#would be better to move this elsewhere
self.parent.mask_worker = Worker(self.parent.extendMask)
self.parent.create_progress_window("Loading", "Loading Mask")
self.parent.mask_worker.signals.progress.connect(self.parent.progress)
self.parent.mask_worker.signals.finished.connect(self.parent.DisplayMask)
self.parent.threadpool.start(self.parent.mask_worker)
self.parent.progress_window.setValue(10)

if self.object == "pointcloud":
self.parent.PointCloudWorker("create")
#self.parent.createPointCloud()

self.close()
15 changes: 4 additions & 11 deletions src/idvc/ui/windows.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import glob
import os

import ccpi.viewer.viewerLinker as vlink

import vtk
from ccpi.viewer import viewer2D, viewer3D
from ccpi.viewer.CILViewer2D import (SLICE_ORIENTATION_XY,
Expand All @@ -12,15 +9,9 @@
from ccpi.viewer.utils import *
from ccpi.viewer.utils.error_handling import ErrorObserver
from PySide2 import QtCore, QtGui, QtWidgets
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *

from idvc.ui.widgets import *

from idvc.utilities import RunResults
from idvc.ui.graphs_widgets import *
import logging
import json
import pandas as pd
from idvc.utils.manipulate_result_files import createResultsDataFrame, addMeanAndStdToResultDataFrame

Expand All @@ -40,6 +31,7 @@ def createPopupMenu(self):
'''
return QtWidgets.QMenu(self)


class VisualisationWidget(QtWidgets.QMainWindow):
'''creates a window with a QCILViewerWidget as the central widget
'''
Expand Down Expand Up @@ -177,7 +169,8 @@ def consumeCharEvent(self, interactor, event):
logging.info("Consuming event: " + interactor.GetKeyCode())
interactor.SetKeyCode("")

class GraphsWindow(QMainWindow):

class GraphsWindow(QtWidgets.QMainWindow):
"""
Creates a new window with graphs from results saved in the selected run folder.
"""
Expand Down

0 comments on commit 3713eb2

Please sign in to comment.