Skip to content

Commit d816e34

Browse files
🌐 Internationalize code and improve readability across multiple modules
- Translate comments and docstrings to English in network, office, and other modules - Enhance code clarity by using more descriptive variable names - Remove unnecessary comments and improve code formatting - Standardize error messages and logging across different components
1 parent b123ef7 commit d816e34

File tree

11 files changed

+392
-342
lines changed

11 files changed

+392
-342
lines changed

src/etool/_network/_share.py

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,18 @@ def set_video_source(source):
9898

9999
@staticmethod
100100
def frames():
101-
fps = 24 # 限制帧率
101+
fps = 24 # Limit the frame rate
102102
frame_interval = 1.0 / fps
103103
while True:
104104
time.sleep(frame_interval - 0.001)
105-
image = ImageGrab.grab() # 获取屏幕数据
105+
106+
image = ImageGrab.grab() # Get screen data
106107
# w, h = image.size
107-
output_buffer = BytesIO() # 创建二进制对象
108-
image.save(output_buffer, format='JPEG', quality=100) # quality提升图片分辨率
109-
frame = output_buffer.getvalue() # 获取二进制数据
110-
yield frame # 生成器返回一张图片的二进制数据
108+
output_buffer = BytesIO() # Create a binary object
109+
image.save(output_buffer, format='JPEG', quality=100) # quality improves image resolution
110+
frame = output_buffer.getvalue() # Get binary data
111+
yield frame # Generator returns binary data for one image
112+
111113

112114
app = Flask(__name__)
113115

@@ -116,17 +118,18 @@ def frames():
116118
def index():
117119
return render_template_string('''<html>
118120
<head>
119-
<title>屏幕共享</title>
121+
<title>Screen Sharing</title>
120122
<script>
121-
// 定期清理旧图片,防止内存占用过大
123+
122124
function setupImageCleaning() {
123125
const img = document.querySelector('img');
124126
setInterval(() => {
125127
img.src = img.src.split('?')[0] + '?t=' + new Date().getTime();
126-
}, 5000); // 每5秒刷新一次
128+
}, 5000); // Refresh every 5 seconds
127129
}
128130
</script>
129131
</head>
132+
130133
<body>
131134
<img src="{{ url_for('video_feed') }}" onload="setupImageCleaning()">
132135
</body>
@@ -135,21 +138,23 @@ def index():
135138

136139
def gen(camera):
137140
"""
138-
流媒体发生器
141+
Stream media generator
139142
"""
140143
while True:
141144
frame = camera.get_frame()
142145

146+
143147
yield (b'--frame\r\n'
144148
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
145149

146150

147151
@app.route('/video_feed')
148152
def video_feed():
149-
"""流媒体数据"""
153+
"""Stream media data"""
150154
response = Response(gen(Camera()),
151155
mimetype='multipart/x-mixed-replace; boundary=frame')
152156
response.headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'
157+
153158
response.headers['Pragma'] = 'no-cache'
154159
return response
155160

@@ -160,26 +165,30 @@ def screen_share(port=8901):
160165
def share_file(port=8902):
161166
app_share_file = Flask(__name__)
162167

163-
# 设置桌面路径和文件夹名称
168+
# Set the desktop path and folder name
164169
desktop_path = os.path.join(os.path.expanduser("~"), "Desktop")
165170
etool_folder = os.path.join(desktop_path, "etool")
166171

167-
# 如果文件夹不存在,则创建
172+
173+
# If the folder does not exist, create it
168174
if not os.path.exists(etool_folder):
169175
os.makedirs(etool_folder)
170176

171-
# 首页模板
177+
178+
# Home page template
172179
index_template = '''
173180
<!doctype html>
174-
<title>eTool 文件上传</title>
175-
<h1>上传新文件</h1>
181+
<title>eTool File Upload</title>
182+
<h1>Upload New File</h1>
176183
<form method=post enctype=multipart/form-data>
184+
177185
<input type=file name=file>
178-
<input type=submit value=上传>
186+
<input type=submit value=Upload>
179187
</form>
180-
<h2>文件列表</h2>
188+
<h2>File List</h2>
181189
<ul>
182190
{% for filename in files %}
191+
183192
<li><a href="{{ url_for('download_file', filename=filename) }}">{{ filename }}</a></li>
184193
{% endfor %}
185194
</ul>
@@ -188,15 +197,17 @@ def share_file(port=8902):
188197
@app_share_file.route('/', methods=['GET', 'POST'])
189198
def upload_file():
190199
if request.method == 'POST':
191-
# 获取上传的文件
200+
# Get the uploaded file
192201
file = request.files['file']
193202
if file:
194-
# 保存文件到etool文件夹
203+
# Save the file to the etool folder
204+
195205
file.save(os.path.join(etool_folder, file.filename))
196-
# 获取文件夹中的文件列表
206+
# Get the file list in the folder
197207
files = os.listdir(etool_folder)
198208
return render_template_string(index_template, files=files)
199209

210+
200211
@app_share_file.route('/uploads/<filename>')
201212
def download_file(filename):
202213
return send_from_directory(etool_folder, filename)

0 commit comments

Comments
 (0)