-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.py
More file actions
170 lines (138 loc) · 5.27 KB
/
Copy pathmodule.py
File metadata and controls
170 lines (138 loc) · 5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import sys
import time
import threading
import keyboard
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from ui_auto_wechat import WeChat
from functools import partial
# 定时发送子线程类
class ClockThread(QThread):
def __init__(self):
super().__init__()
# 是否正在定时
self.time_counting = False
# 发送信息的函数
self.send_func = None
# 定时列表
self.clocks = None
def __del__(self):
self.wait()
def run(self):
while self.time_counting:
localtime = time.localtime(time.time())
hour = localtime.tm_hour % 24
min = localtime.tm_min % 60
for i in range(self.clocks.count()):
clock_hour, clock_min, st_ed = self.clocks.item(i).text().split(" ")
st, ed = st_ed.split('-')
if int(clock_hour) == hour and int(clock_min) == min:
self.send_func(st=int(st), ed=int(ed))
# self.send_func()
time.sleep(60)
class MyListWidget(QListWidget):
"""支持双击可编辑的QListWidget"""
def __init__(self, parent=None) -> None:
super().__init__(parent)
self.setSelectionMode(QAbstractItemView.ExtendedSelection) # 设置选择多个
# 双击可编辑
self.edited_item = self.currentItem()
self.close_flag = True
self.doubleClicked.connect(self.item_double_clicked)
self.currentItemChanged.connect(self.close_edit)
def keyPressEvent(self, e: QKeyEvent) -> None:
"""回车事件,关闭edit"""
super().keyPressEvent(e)
if e.key() == Qt.Key_Return:
if self.close_flag:
self.close_edit()
self.close_flag = True
def edit_new_item(self) -> None:
"""edit一个新的item"""
self.close_flag = False
self.close_edit()
count = self.count()
self.addItem('')
item = self.item(count)
self.edited_item = item
self.openPersistentEditor(item)
self.editItem(item)
def item_double_clicked(self, modelindex: QModelIndex) -> None:
"""双击事件"""
self.close_edit()
item = self.item(modelindex.row())
self.edited_item = item
self.openPersistentEditor(item)
self.editItem(item)
def close_edit(self, *_) -> None:
"""关闭edit"""
if self.edited_item and self.isPersistentEditorOpen(self.edited_item):
self.closePersistentEditor(self.edited_item)
class MultiInputDialog(QDialog):
"""
用于用户输入的输入框,可以根据传入的参数自动创建输入框
"""
def __init__(self, inputs: list, parent=None) -> None:
"""
inputs: list, 代表需要input的标签,如['姓名', '年龄']
"""
super().__init__(parent)
layout = QVBoxLayout(self)
self.inputs = []
for i in inputs:
layout.addWidget(QLabel(i))
input = QLineEdit(self)
layout.addWidget(input)
self.inputs.append(input)
ok_button = QPushButton("确认")
ok_button.clicked.connect(self.accept)
cancel_button = QPushButton("取消")
cancel_button.clicked.connect(self.reject)
button_layout = QHBoxLayout()
button_layout.addWidget(ok_button)
button_layout.addWidget(cancel_button)
layout.addLayout(button_layout)
def get_input(self):
"""获取用户输入"""
return [i.text() for i in self.inputs]
class FileDialog(QDialog):
"""
文件选择框
"""
def __init__(self, parent=None) -> None:
super().__init__(parent)
self.inputs = []
layout = QVBoxLayout(self)
layout.addWidget(QLabel("请指定发送给哪些用户(1,2,3代表发送给前三位用户),如需全部发送请忽略此项"))
input = QLineEdit(self)
layout.addWidget(input)
self.inputs.append(input)
# 选择文件
choose_layout = QHBoxLayout()
path = QLineEdit(self)
choose_layout.addWidget(path)
self.inputs.append(path)
file_button = QPushButton("选择文件")
file_button.clicked.connect(self.select)
choose_layout.addWidget(file_button)
layout.addLayout(choose_layout)
# 确认按钮
ok_button = QPushButton("确认")
ok_button.clicked.connect(self.accept)
# 取消按钮
cancel_button = QPushButton("取消")
cancel_button.clicked.connect(self.reject)
# 按钮布局
button_layout = QHBoxLayout()
button_layout.addWidget(ok_button)
button_layout.addWidget(cancel_button)
layout.addLayout(button_layout)
def select(self):
path_input = self.inputs[1]
path = QFileDialog.getOpenFileName(self, '打开文件', '/home')[0]
if path != "":
path_input.setText(path)
def get_input(self):
"""获取用户输入"""
return [i.text() for i in self.inputs]