forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkbox.py
43 lines (35 loc) · 1.3 KB
/
checkbox.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
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
from qtpy import QtCore, QtWidgets
class Checkbox(QtWidgets.QCheckBox):
checked = QtCore.Signal(object)
unchecked = QtCore.Signal(object)
def __init__(self, name):
super(QtWidgets.QCheckBox, self).__init__(name)
self.name = name
self.stateChanged.connect(self._check_state)
def _check_state(self, state):
if state == 2:
self.checked.emit(self)
elif state == 1:
pass # partially checked; not implemented, future...?
elif not state:
self.unchecked.emit(self)
def on_checkbox_checked(self, slot):
self.checked.connect(slot)
def on_checkbox_unchecked(self, slot):
self.unchecked.connect(slot)
def unreg_on_checkbox_checked(self, slot):
try:
self.checked.disconnect(slot)
except TypeError:
return
def unreg_on_checkbox_unchecked(self, slot):
try:
self.unchecked.disconnect(slot)
except TypeError:
return