mainView.py 3 KB
Newer Older
1
from PyQt5 import QtWidgets
2 3
from gui.filterView import FilterView
from gui.measureModes import MeasureMode, CrossBoxMode, CrossBoxesControls, SpiralBoxMode
4 5 6 7 8 9 10 11 12 13 14


class MainView(QtWidgets.QWidget):
    def __init__(self):
        super(MainView, self).__init__()

        self.setWindowTitle('Subsampling Selector')
        self.layout: QtWidgets.QVBoxLayout = QtWidgets.QVBoxLayout()
        self.setLayout(self.layout)

        self.modeSelector: QtWidgets.QComboBox = QtWidgets.QComboBox()
15
        self.modeSelector.currentTextChanged.connect(self._switch_to_mode)
16
        self.measureModes: dict = {}
17
        self.activeMode: MeasureMode = None
18 19
        self.activeModeControl: QtWidgets.QGroupBox = QtWidgets.QGroupBox()

20 21 22
        loadDsetBtn = QtWidgets.QPushButton('Load Dataset')
        loadDsetBtn.released.connect(self._load_dataset)

23 24 25 26
        self.controlGroup = QtWidgets.QGroupBox()
        self.controlGroupLayout = QtWidgets.QHBoxLayout()
        self.controlGroup.setLayout(self.controlGroupLayout)

27
        self.controlGroupLayout.addWidget(loadDsetBtn)
28 29 30 31 32 33 34 35 36 37 38
        self.controlGroupLayout.addWidget(QtWidgets.QLabel('Select Subsampling Mode:'))
        self.controlGroupLayout.addWidget(self.modeSelector)
        self.controlGroupLayout.addWidget(self.activeModeControl)

        self.layout.addWidget(self.controlGroup)
        self.filterView = FilterView()
        self.layout.addWidget(self.filterView)
        self._add_measure_modes()
        self._switch_to_default_mode()

    def _add_measure_modes(self) -> None:
39
        self.measureModes['spiralSelection'] = SpiralBoxMode(self.filterView)
40
        self.measureModes['crossSelection'] = CrossBoxMode(self.filterView)
41 42
        self.modeSelector.addItem('spiralSelection')
        self.modeSelector.addItem('crossSelection')
43 44 45 46

    def _switch_to_default_mode(self) -> None:
        modes: list = list(self.measureModes.keys())
        self._activate_mode(modes[0])
47 48 49 50 51
    
    def _switch_to_mode(self) -> None:
        newMode: str = self.modeSelector.currentText()
        self._activate_mode(newMode)
    
52
    def _activate_mode(self, modeName: str) -> None:
53 54 55 56 57 58 59 60
        requestedMode: MeasureMode = self.measureModes[modeName]
        if requestedMode is not self._activate_mode:
            self.activeModeControl.setParent(None)
            self.controlGroupLayout.removeWidget(self.activeModeControl)

            self.activeMode = requestedMode
            self.activeModeControl = self.activeMode.get_control_groupBox()
            self.controlGroupLayout.insertWidget(2, self.activeModeControl)
61

62
            self.activeMode.update_measure_viewItems()
63

64 65 66 67 68 69
    def _load_dataset(self) -> None:
        fname = QtWidgets.QFileDialog.getOpenFileName(self, 'Select .pkl file', filter='pkl file (*.pkl)')
        if fname[0] != '':
            self.filterView.load_and_update_from_dataset(fname[0])
            self.activeMode.update_measure_viewItems()

70 71 72 73 74 75 76

if __name__ == '__main__':
    import sys
    app = QtWidgets.QApplication(sys.argv)
    subsampling = MainView()
    subsampling.show()
    ret = app.exec_()