-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFilterWindow.py
100 lines (80 loc) · 3.21 KB
/
FilterWindow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 14 14:20:08 2023
@author: marek
"""
from PyQt5.QtWidgets import QDialog, QComboBox, QSlider, QLabel
from PyQt5 import QtCore, QtWidgets
from Topography import Topography
class FilterWindow(QDialog):
filters = ["Median", "Mean"]
maskSize = 3
def __init__(self, parent):
super(FilterWindow, self).__init__()
self.parent = parent
self._setup(self)
self._createActions()
self._connectActions()
self.installEventFilter(self)
self.active_filter = 0
self._update()
def _setup(self, Win):
Win.setObjectName("Filter image")
Win.setFixedSize(310, 440)
Win.setWindowTitle("Filter")
def _createActions(self):
# Create list of filters
self.filterList = QComboBox(self)
self.filterList.addItems(self.filters)
self.filterList.setGeometry(QtCore.QRect(10, 20, 80, 20))
# Create apply button
self.applyButton = QtWidgets.QPushButton("Apply", self)
self.applyButton.setGeometry(QtCore.QRect(60, 330, 81, 41))
self.applyButton.setObjectName("applyButton")
# Create cancel button
self.cancelButton = QtWidgets.QPushButton("Cancel", self)
self.cancelButton.setGeometry(QtCore.QRect(170, 330, 81, 41))
self.cancelButton.setObjectName("cancelButton")
def _connectActions(self):
self.applyButton.clicked.connect(self.apply)
self.cancelButton.clicked.connect(self.cancel)
self.filterList.currentIndexChanged.connect(self.index_changed)
def _update(self):
self.inputs = []
if self.active_filter in [0, 1]:
slider = QSlider(QtCore.Qt.Orientation.Horizontal, self)
slider.setGeometry(QtCore.QRect(20, 100, 150, 20))
slider.setRange(1, 20)
slider.setValue(3)
slider.setSingleStep(1)
slider.valueChanged.connect(self.updateMaskSize)
self.inputs.append(slider)
result_label = QLabel(f'Mask Size: {3}', self)
result_label.setGeometry(QtCore.QRect(180, 100, 80, 20))
self.inputs.append(result_label)
def updateMaskSize(self, value):
self.maskSize = value
self.inputs[1].setText(f'Mask Size: {value}')
def disable(self):
self.applyButton.setDisabled(True)
def enable(self):
self.applyButton.setDisabled(False)
def apply(self):
active_window = self.parent.results_windows[self.parent.active_result_window]
if self.filters[self.active_filter] == "Median":
active_window.modifyData(Topography.median, param=self.maskSize)
if self.filters[self.active_filter] == "Mean":
active_window.modifyData(Topography.mean, param=self.maskSize)
self.parent.update_windows()
def cancel(self):
self.hide()
def index_changed(self, i):
self.active_filter = i
self._update()
# Event handling
def eventFilter(self, source, event):
# Calling parent closing function on close
if event.type() == QtCore.QEvent.Hide:
self.parent.filter_win_active = False
self.parent.filter_button.setChecked(False)
return False