Skip to content

Commit

Permalink
Multi copy/paste
Browse files Browse the repository at this point in the history
  • Loading branch information
Wind2009-Louse committed Aug 1, 2020
1 parent e4c81cb commit 66083b9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
42 changes: 31 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
init_field = {"locations":{}, "desp":{}, "LP":[8000,8000], "fields":[]}
for t in range(len(idx_represent_str)):
init_field["fields"].append([])
version = 143
version = 144

class Update_Thread(Thread):
def __init__(self, window):
Expand Down Expand Up @@ -316,6 +316,7 @@ def init_frame(self):
self.Operator_search_button = QPushButton(self.centralwidget)
self.DeleteOpe_Button = QPushButton(self.centralwidget)
self.CopyingOpe_list = QListWidget(self.centralwidget)
self.CopyingOpe_list.setSelectionMode(QAbstractItemView.ExtendedSelection)
self.CopyOpe_Button = QPushButton(self.centralwidget)
self.MoveOpe_Button = QPushButton(self.centralwidget)

Expand Down Expand Up @@ -542,6 +543,7 @@ def __init__(self):
self.Operator_list.doubleClicked.connect(self.copy_ope)
self.CopyOpe_Button.clicked.connect(self.copy_ope)
self.CopyingOpe_list.itemSelectionChanged.connect(self.select_copying)
self.CopyingOpe_list.doubleClicked.connect(self.remove_from_copying)
self.MoveOpe_Button.clicked.connect(self.paste_operator)

# 对象部分
Expand Down Expand Up @@ -592,6 +594,8 @@ def keyPressEvent(self, event):
# Delete键删除操作
elif self.Operator_list.hasFocus():
self.remove_operator()
elif self.CopyingOpe_list.hasFocus():
self.remove_from_copying()
# 回车键默认减少LP
if self.LP_line.hasFocus() and event.key() == Qt.Key_Return:
self.ope_LPDec()
Expand Down Expand Up @@ -963,7 +967,7 @@ def remove_operator(self):
if len(selected) <= 0:
return
# 确认提示
reply = QMessageBox.information(self, 'Confirm', "确认要删除吗?该操作不可逆。", QMessageBox.Yes | QMessageBox.No)
reply = QMessageBox.information(self, 'Confirm', "确认要从操作列表中删除选定操作吗?该操作不可逆。", QMessageBox.Yes | QMessageBox.No)
if reply != QMessageBox.Yes:
return
idx_list = [item.row() for item in selected]
Expand All @@ -983,11 +987,13 @@ def remove_operator(self):

def paste_operator(self):
'''粘贴操作'''
if len(self.copying_operation) <= 0:
idx_list = self.CopyingOpe_list.selectedIndexes()
if len(idx_list) <= 0:
return
for operation in self.copying_operation:
for idx in idx_list:
operation = self.copying_operation[idx.row()]
self.insert_operation(operation)
self.copying_operation.clear()
self.remove_from_copying(False)
self.update_copying()

def copy_ope(self):
Expand All @@ -996,15 +1002,14 @@ def copy_ope(self):
idx_list = self.Operator_list.selectedIndexes()
if len(idx_list) < 1:
return
self.copying_operation.clear()
for item in idx_list:
idx = item.row()
ope = deepcopy(self.operators["operations"][idx])
self.copying_operation.append(ope)
self.update_copying()

def update_copying(self):
'''描绘复制中的操作'''
'''描绘复制列表中的操作'''
self.CopyingOpe_list.clear()
operation_list = self.copying_operation
# 判断当前是否有复制中的操作
Expand All @@ -1015,7 +1020,6 @@ def update_copying(self):
return
self.MoveOpe_Button.setEnabled(True)
self.CopyingOpe_list.setEnabled(True)

for operation in operation_list:
# 根据类型描绘操作
if operation["type"] == "move":
Expand Down Expand Up @@ -1059,10 +1063,10 @@ def update_copying(self):

def select_copying(self):
'''选择复制中的操作时,显示内容'''
idx_list = self.CopyingOpe_list.selectedIndexes()
if len(idx_list) <= 0:
idx_item = self.CopyingOpe_list.currentIndex().row()
if idx_item == -1 or idx_item >= len(self.copying_operation):
return
operation = self.copying_operation[idx_list[0].row()]
operation = self.copying_operation[idx_item]
if operation == {}:
return
result = ""
Expand Down Expand Up @@ -1109,6 +1113,22 @@ def select_copying(self):
result = operation["desp"]
self.Target_detail.setText(result)

def remove_from_copying(self, asking=True):
idx_list = self.CopyingOpe_list.selectedIndexes()
if len(idx_list) <= 0:
return
if asking:
# 确认提示
reply = QMessageBox.information(self, 'Confirm', "确认要从复制列表中删除选定操作吗?该操作不可逆。", QMessageBox.Yes | QMessageBox.No)
if reply != QMessageBox.Yes:
return
idx_list = [item.row() for item in idx_list]
idx_list.sort(reverse=True)
self.CopyingOpe_list.setCurrentRow(0)
for idx in idx_list:
del self.copying_operation[idx]
self.update_copying()

def target_index_changed(self):
'''对象列表发生变更时触发\n\n通常需要更新卡片描述'''
idx = self.Target_list.selectedIndexes()
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name": "v1.14.3", "version":143}
{"name": "v1.14.4", "version":144}

0 comments on commit 66083b9

Please sign in to comment.