90 lines
3.3 KiB
Python
90 lines
3.3 KiB
Python
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton, QDialog
|
|
from PyQt5.QtCore import Qt, QRect
|
|
|
|
class KetWidget(QWidget) :
|
|
def __init__(self, parent) :
|
|
super().__init__()
|
|
self.initUI()
|
|
self.parent = parent
|
|
|
|
def initUI(self) :
|
|
btn_box = QVBoxLayout()
|
|
|
|
self.float_button1 = QPushButton("↑", self)
|
|
self.float_button1.move(self.width() - 200, self.height() - 200)
|
|
self.float_button1.setFixedSize(90, 90)
|
|
self.float_button1.clicked.connect(self.focus_do_inscrease)
|
|
|
|
self.float_button2 = QPushButton("↓", self)
|
|
self.float_button2.move(self.width() - 200, self.height() - 100)
|
|
self.float_button2.setFixedSize(90, 90)
|
|
self.float_button2.clicked.connect(self.focus_do_decrease)
|
|
|
|
self.float_button3 = QPushButton("enter", self)
|
|
self.float_button3.move(self.width() - 100, self.height() - 200)
|
|
self.float_button3.setFixedSize(90, 90)
|
|
self.float_button3.clicked.connect(self.focus_do_action)
|
|
|
|
self.float_button4 = QPushButton("esc", self)
|
|
self.float_button4.move(self.width() - 100, self.height() - 100)
|
|
self.float_button4.setFixedSize(90, 90)
|
|
self.float_button4.clicked.connect(self.focus_do_escape)
|
|
|
|
self.show_hide_button = QPushButton("show/hide", self)
|
|
self.show_hide_button.move(self.width()-10, self.height() - 100)
|
|
self.show_hide_button.setFixedSize(90, 90)
|
|
self.show_hide_button.clicked.connect(self.focus_show_hide)
|
|
|
|
btn_box.addWidget(self.float_button1)
|
|
btn_box.addWidget(self.float_button2)
|
|
btn_box.addWidget(self.float_button3)
|
|
btn_box.addWidget(self.float_button4)
|
|
|
|
|
|
def focus_do_inscrease(self) :
|
|
if hasattr(self.parent, 'stack'):
|
|
self.parent.stack.currentWidget().key_decrease_parameter()
|
|
else :
|
|
self.parent.key_increase_parameter()
|
|
|
|
def focus_do_decrease(self) :
|
|
if hasattr(self.parent, 'stack'):
|
|
self.parent.stack.currentWidget().key_increase_parameter()
|
|
else :
|
|
self.parent.key_decrease_parameter()
|
|
|
|
def focus_do_action(self) :
|
|
if hasattr(self.parent, 'stack'):
|
|
self.parent.stack.currentWidget().key_enter_process()
|
|
else :
|
|
self.parent.key_enter_process()
|
|
|
|
def focus_do_escape(self) :
|
|
if hasattr(self.parent, 'stack'):
|
|
self.parent.stack.currentWidget().key_escape_process()
|
|
else :
|
|
self.parent.key_escape_process()
|
|
|
|
def focus_show_hide(self) :
|
|
if self.float_button1.isHidden() :
|
|
self.float_button1.show()
|
|
self.float_button2.show()
|
|
self.float_button3.show()
|
|
self.float_button4.show()
|
|
else :
|
|
self.float_button1.hide()
|
|
self.float_button2.hide()
|
|
self.float_button3.hide()
|
|
self.float_button4.hide()
|
|
|
|
def showEvent(self, event):
|
|
super().showEvent(event)
|
|
# 获取屏幕大小
|
|
screen = QApplication.primaryScreen()
|
|
screen_rect = screen.geometry()
|
|
# 计算窗口在屏幕右下角的位置
|
|
width, height = self.width(), self.height()
|
|
x = screen_rect.width() - width
|
|
y = screen_rect.height() - height
|
|
# 设置窗口位置
|
|
self.move(x, y) |