mirror of
https://github.com/yuruotong1/autoMate.git
synced 2026-03-22 13:07:17 +08:00
backspace 监听
This commit is contained in:
@@ -45,6 +45,7 @@ class ActionBase(BaseModel):
|
||||
raise TypeError("Not realize run function")
|
||||
|
||||
def run_with_out_arg(self):
|
||||
print("运行中...")
|
||||
res = self.run(**self.args.model_dump())
|
||||
# 保存输出结果
|
||||
if self.output_save_name:
|
||||
@@ -104,6 +105,7 @@ class ActionBase(BaseModel):
|
||||
self._config_ui.output_config.addWidget(output_label)
|
||||
self._config_ui.output_config.addWidget(output_line_edit)
|
||||
else:
|
||||
|
||||
self._config_ui.output_config.addWidget(QLabel("当前行为不包含输出项"))
|
||||
|
||||
def __cancel_button_clicked(self):
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import pickle
|
||||
from typing import List
|
||||
import uuid
|
||||
from PyQt6.QtCore import Qt, QMimeData, QByteArray, QPoint, pyqtSignal
|
||||
from PyQt6.QtCore import Qt, QMimeData, QByteArray, QPoint, pyqtSignal, QEvent, QObject
|
||||
from PyQt6.QtGui import QDrag
|
||||
from PyQt6.QtWidgets import QListWidget, QApplication, QStyle, QMenu
|
||||
from actions.action_list_item import ActionListItem
|
||||
from actions.action_signal import ActionSignal
|
||||
from pages.styled_item_delegate import StyledItemDelegate
|
||||
from utils.global_util import GlobalUtil
|
||||
from utils.undo_command import ActionListAddCommand
|
||||
from utils.undo_command import ActionListAddCommand, ActionListDeleteCommand
|
||||
|
||||
class ActionList(QListWidget):
|
||||
MY_MIME_TYPE = "ActionListView/data_drag"
|
||||
@@ -84,11 +84,10 @@ class ActionList(QListWidget):
|
||||
"QListView{background:rgb(220,220,220); border:0px; margin:0px 0px 0px 0px;}"
|
||||
"QListView::Item{height:40px; border:0px; background:rgb(255,255,255);margin-left: 3px;}"
|
||||
# "QListView::Item:hover{color:rgba(40, 40, 200, 255); padding-left:14px;})"
|
||||
"QListView::Item:selected{color:rgb(0, 0, 0);}"
|
||||
)
|
||||
"QListView::Item:selected{ :rgb(0, 0, 0);}")
|
||||
self.setItemDelegate(StyledItemDelegate())
|
||||
# 选中时不出现虚线框
|
||||
self.setFocusPolicy(Qt.FocusPolicy.NoFocus)
|
||||
self.setFocusPolicy(Qt.FocusPolicy.StrongFocus)
|
||||
|
||||
# 双击打开配置页面
|
||||
def mouseDoubleClickEvent(self, event):
|
||||
@@ -97,8 +96,16 @@ class ActionList(QListWidget):
|
||||
item = self.itemAt(event.pos())
|
||||
item.action.config_page_show()
|
||||
event.accept()
|
||||
|
||||
|
||||
|
||||
# def keyPressEvent(self, event):
|
||||
# if event.key() == Qt.Key.Key_Backspace:
|
||||
# # 获取当前选中的项
|
||||
# GlobalUtil.current_page.q_undo_stack.push(ActionListDeleteCommand(self, self.currentIndex().row()))
|
||||
# self.action_signal.size_changed_emit()
|
||||
# else:
|
||||
# super().keyPressEvent(event)
|
||||
|
||||
|
||||
# 记录拖拽初始位置
|
||||
def mousePressEvent(self, e):
|
||||
super().mousePressEvent(e)
|
||||
@@ -126,8 +133,8 @@ class ActionList(QListWidget):
|
||||
def right_menu_triggered(self, act):
|
||||
# 如果是删除,则从列表中删除该选择
|
||||
if act.text() == "删除":
|
||||
self.opeartion_list.append({"type": "delete", "item": self.currentIndex().row(), "row": self.currentIndex().row()})
|
||||
self.model().removeRow(self.currentIndex().row())
|
||||
GlobalUtil.current_page.q_undo_stack.push(ActionListDeleteCommand(self, self.currentIndex().row()))
|
||||
self.action_signal.size_changed_emit()
|
||||
|
||||
|
||||
@staticmethod
|
||||
@@ -169,7 +176,7 @@ class ActionList(QListWidget):
|
||||
the_remove_row = self.the_drag_row
|
||||
# 组件内部拖动
|
||||
else:
|
||||
# 元素向上拖动,会在上面新增一个,因此要删除的位置需要+1
|
||||
# 元素向上拖动,会在上面新增一个,要删除的位置需要+1
|
||||
if self.the_insert_row < self.the_drag_row:
|
||||
the_remove_row = self.the_drag_row + 1
|
||||
# 元素向下拖动,会在下面新增一个,因此直接删除即可
|
||||
@@ -284,3 +291,6 @@ class ActionList(QListWidget):
|
||||
if widget.uuid != self.uuid:
|
||||
widget.setCurrentRow(-1)
|
||||
widget.update()
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from PyQt6.QtGui import QUndoCommand
|
||||
from PyQt6 import QtCore
|
||||
class ActionListAddCommand(QUndoCommand):
|
||||
def __init__(self, action_list, row, action_item):
|
||||
super().__init__()
|
||||
@@ -19,12 +18,34 @@ class ActionListAddCommand(QUndoCommand):
|
||||
def undo(self):
|
||||
self.action_list.takeItem(self.row)
|
||||
from actions.action_list_item import ActionListItem
|
||||
# 重新加载,避免被 pyqt GC
|
||||
action_list_item = ActionListItem.load(self.action_item.dump())
|
||||
# action_list_item.setData(QtCore.Qt.ItemDataRole.UserRole, self.action_item.data(QtCore.Qt.ItemDataRole.UserRole))
|
||||
# action_list_item.set_parent(self.action_list.get_parent())
|
||||
self.action_item = action_list_item
|
||||
self.action_list.adjust_ui()
|
||||
|
||||
|
||||
class ActionListDeleteCommand(QUndoCommand):
|
||||
def __init__(self, action_list, row):
|
||||
super().__init__()
|
||||
self.action_list = action_list
|
||||
self.delete_action_list_item = None
|
||||
self.row = row
|
||||
self.tmp = None
|
||||
self.setText(f"Add data to {row}")
|
||||
|
||||
|
||||
def redo(self):
|
||||
from actions.action_list_item import ActionListItem
|
||||
# 重新加载,避免被 pyqt GC
|
||||
self.delete_action_list_item = ActionListItem.load(self.action_list.item(self.row).dump())
|
||||
self.action_list.takeItem(self.row)
|
||||
self.action_list.adjust_ui()
|
||||
|
||||
|
||||
|
||||
def undo(self):
|
||||
self.action_list.insertItem(self.row, self.delete_action_list_item)
|
||||
self.delete_action_list_item.render()
|
||||
self.action_list.adjust_ui()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user