Почему при доступе к аттрибутам lt и gt объектов классов BothCheck и GtCheck не вызывается __get__?
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QVBoxLayout, QRadioButton, QGroupBox, QLineEdit, QCheckBox, QGridLayout, QLabel, QFrame, QPushButton
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIntValidator
from PyQt5.QtWidgets import QMainWindow
class LineDescriptor:
def __init__(self, row=1, label=None):
self.label = label
self.row = row
self.__name = None
def __get__(self, instance, owner=None):
print('get_called')
if instance is None:
print('is none')
return self
else:
private_name = '_{0}__{1}'.format(type(instance).__name__,
self.__name)
check_name = '_{0}__{1}'.format(type(instance).__name__,
self.__name)
if getattr(instance, check_name).isChecked():
return getattr(instance, private_name).text()
else:
return None
class CheckSelector(QGroupBox):
def __init__(self, name):
self.__dictionary = []
super(CheckSelector, self).__init__()
layout = QGridLayout()
layout.setAlignment(Qt.AlignTop)
name = QLabel(name)
layout.addWidget(name, 0, 0, 1, 1)
self.__check = QCheckBox()
layout.addWidget(self.__check, 0, 1, 1, 1)
self.setLayout(layout)
for name, attribute in type(self).__dict__.items():
if isinstance(attribute, LineDescriptor):
row = attribute.row
if attribute.label is not None:
label = QLabel(attribute.label)
self.layout().addWidget(label, row, 0, 1, 1)
int_validator = QIntValidator()
field = QLineEdit()
field.setValidator(int_validator)
layout.addWidget(field, row, 1, 1, 1)
private_name = '_{0}__{1}'.format(type(self).__name__, name)
setattr(attribute, '_LineDescriptor__name', name)
setattr(self, name, attribute)
setattr(self, private_name, field)
print(attribute)
print(attribute.__dict__)
class GtCheck(CheckSelector):
gt = LineDescriptor(1, '>')
class BothCheck(CheckSelector):
gt = LineDescriptor(1, '>')
lt = LineDescriptor(2, '<')