class A:
def __init__(self, val_1=10, val_2=10):
self.val_1 = 10
self.val_2 = 10
if val_1:
self.val_1 = val_1
if val_2:
self.val_2 = val_2
def get_val_1(self):
return self.val_1
def get_val_2(self):
return self.val_2
def set_val_1(self, val=None):
if val:
self.val_1 = val
return self
def set_val_2(self, val=None):
if val:
self.val_2 = val
return self
class B:
def __init__(self, val_1=None, val_2=None):
self.a_obj = A(val_1, val_2)
def summa(self, val_1=None, val_2=None):
return self.a_obj.set_val_1(val_1).get_val_1() + self.a_obj.set_val_2(val_2).get_val_2()
print(B().summa())
# 20
print(B().summa(100))
# 100
print(B(34, 45).summa())
# 79
print(B().summa(120, 345))
# 465
(?<!\d|[-])(\d{1,2}|100)(?!\d)
(?<!\d|[-]|\w)(\d{1,2}|100)(?!\d|\w)
[1-9][0-9]?
- одно число и второе может быть или нет \d{1,2}
Т.е. при кликанье и таскании окон сквозь это фрейм происходит то же самое что происходиит при кликаньи и таскании окон без этого фрейма
QtGui.QPainter
под замеры QMainWindow
?self.setWindowFlags(QtCore.Qt.Window |
QtCore.Qt.CustomizeWindowHint |
QtCore.Qt.WindowStaysOnTopHint |
QtCore.Qt.X11BypassWindowManagerHint)
self.setWindowFlags
перезаписывает все настройки import sys
from PyQt5 import QtGui, QtCore
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QMainWindow, QApplication
import random
import signal
# ------------------------------------------------------------------------------- #
#
# ------------------------------------------------------------------------------- #
class main_window(QMainWindow):
# --------------------------------------------------------------------------- #
#
# --------------------------------------------------------------------------- #
def __init__(self, parent=None):
QMainWindow.__init__(self, parent)
self.setWindowFlags(QtCore.Qt.Window |
QtCore.Qt.CustomizeWindowHint |
QtCore.Qt.WindowStaysOnTopHint |
QtCore.Qt.X11BypassWindowManagerHint)
self.left_x = 0
self.left_y = 0
self.rec_width = 0
self.rec_height = 0
self.speed = 1000
self.get_coordinates()
self.get_size()
self.setGeometry(self.left_x, self.left_y,
self.rec_width, self.rec_height)
self.timer_process_run = QtCore.QTimer()
self.timer_process_run.timeout.connect(self.on_timer_process_run)
self.timer_process_run.start(self.speed)
signal.signal(signal.SIGINT, self.interrupt_handler)
# --------------------------------------------------------------------------- #
#
# --------------------------------------------------------------------------- #
def interrupt_handler(self, signum, frame):
"""
"""
print("Фиг тебе... Поймай меня")
# --------------------------------------------------------------------------- #
#
# --------------------------------------------------------------------------- #
def on_timer_process_run(self):
"""
"""
self.get_coordinates()
self.get_size()
self.setGeometry(self.left_x, self.left_y,
self.rec_width, self.rec_height)
self.update()
# --------------------------------------------------------------------------- #
#
# --------------------------------------------------------------------------- #
def get_size(self):
"""
"""
self.rec_width = random.randint(10, 100)
self.rec_height = random.randint(10, 100)
# --------------------------------------------------------------------------- #
#
# --------------------------------------------------------------------------- #
def get_coordinates(self):
"""
"""
desctop = QtWidgets.QApplication.desktop()
self.left_x = random.randint(0, desctop.width() - self.rec_width)
self.left_y = random.randint(0, desctop.height() - self.rec_height)
# --------------------------------------------------------------------------- #
#
# --------------------------------------------------------------------------- #
def mousePressEvent(self, event):
"""
"""
print("Ты меня поймал...")
QtWidgets.qApp.quit()
# --------------------------------------------------------------------------- #
#
# --------------------------------------------------------------------------- #
def paintEvent(self, event):
"""
"""
rec = QtGui.QPainter(self)
rec.setBrush(QtGui.QColor(random.randint(0, 255),
random.randint(0, 255), random.randint(0, 255)))
rec.drawRect(0, 0, self.rec_width, self.rec_height)
# ------------------------------------------------------------------------------- #
#
# ------------------------------------------------------------------------------- #
if __name__ == '__main__':
app = QApplication(sys.argv)
mywindow = main_window()
mywindow.show()
app.exec_()
def update_widget():
time.sleep(3)
self.update()
threading.Thread(target=update_widget).start()