吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1235|回复: 11
收起左侧

[Python 原创] 有点南辕北辙的桌面管理工具

  [复制链接]
LiCan857 发表于 2025-7-7 17:14
本帖最后由 LiCan857 于 2025-7-8 10:23 编辑

由于以前一直用的itop easy desktop来管理桌面图标,最近它开始收费了,所以有了以下创意。
本人只会python和一点前端,借鉴了个前端模板实现了下面功能。

1、读取并展示桌面(可自定义指定文件夹)的所有文件夹下面一层的文件及文件夹已经软件图标并展示
2、点击图标可直接打开对应软件或文件夹

第一次执行可能有点慢,需要转换图标到当前目录下用于读取。可自己修改一些默认文件图标,如文件夹,word,excel等,详细内容见压缩包
缺点:只能用浏览器展示

源码:
[Python] 纯文本查看 复制代码
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
from flask import Flask, render_template_string, request, jsonify, url_for
import subprocess
import win32com.client
import pythoncom
import configparser
import os
 
app = Flask(__name__)
 
 
@app.route('/open-folder', methods=['POST'])
def open_folder():
    data = request.get_json()
    folder_path = data.get('path')
 
    if not folder_path:
        return jsonify({"success": False, "error": "未提供路径"}), 400
 
    try:
        # 使用 Windows 资源管理器打开文件夹
        subprocess.Popen(f'explorer "{folder_path}"')
        return jsonify({"success": True})
    except Exception as e:
        return jsonify({"success": False, "error": str(e)})
 
 
def html(data):
    # 包含 HTML、CSS 和 JS 的完整页面字符串
    html_content = f"""
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>图标管理工具</title>
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
        <style>
            :root {{
                --primary-color: #2563eb;
                --hover-color: #1d4ed8;
                --background: #f8fafc;
            }}
      
            body {{
                font-family: 'Segoe UI', system-ui, sans-serif;
                background-color: var(--background);
                margin: 0;
                padding: 20px;
                color: #334155;
            }}
      
            .container {{
                max-width: 1200px;
                margin: 0 auto;
            }}
      
            header {{
                text-align: center;
                margin-bottom: 40px;
            }}
      
            h1 {{
                color: var(--primary-color);
                font-size: 2.5rem;
                margin: 20px 0;
            }}
      
            .search-box {{
                max-width: 600px;
                margin: 20px auto;
                position: relative;
            }}
      
            .search-input {{
                width: 100%;
                padding: 12px 20px;
                border: 2px solid #e2e8f0;
                border-radius: 30px;
                font-size: 16px;
                transition: all 0.3s;
            }}
      
            .search-input:focus {{
                outline: none;
                border-color: var(--primary-color);
                box-shadow: 0 0 10px rgba(37, 99, 235, 0.1);
            }}
      
            .tools-grid {{
                display: grid;
                grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
                gap: 20px;
            }}
      
            .tool-card {{
                background: white;
                border-radius: 12px;
                padding: 20px;
                box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
                transition: transform 0.2s, box-shadow 0.2s;
                display: flex;
                align-items: center;
                gap: 15px;
                text-decoration: none;
                color: inherit;
            }}
      
            .tool-card:hover {{
                transform: translateY(-3px);
                box-shadow: 0 8px 15px rgba(0, 0, 0, 0.1);
            }}
      
            .tool-icon {{
                width: 40px;
                height: 40px;
                display: flex;
                align-items: center;
                justify-content: center;
                background: #eff6ff;
                border-radius: 8px;
                color: var(--primary-color);
            }}
      
            .tool-text {{
                flex: 1;
            }}
      
            .tool-title {{
                font-weight: 600;
                margin-bottom: 5px;
            }}
      
            .tool-desc {{
                font-size: 0.9em;
                color: #64748b;
            }}
      
            .category-section {{
                margin: 40px 0;
            }}
      
            .category-title {{
                color: var(--primary-color);
                border-bottom: 2px solid #e2e8f0;
                padding-bottom: 10px;
                margin-bottom: 20px;
                display: flex;
                align-items: center;
                gap: 10px;
            }}
      
            .category-icon {{
                font-size: 1.2em;
            }}
            .category-section.hidden {{
                display: none;
            }}
      
            @media (max-width: 768px) {{
                .tools-grid {{
                    grid-template-columns: 1fr;
                }}
            }}
        </style>
    </head>
    <script>
    // 打开本地文件功能
    function openLocalFolder(path) {{
        fetch('/open-folder', {{
            method: 'POST',
            headers: {{
                'Content-Type': 'application/json'
            }},
            body: JSON.stringify({{ path: path }})
        }})
        .then(response => response.json())
        .then(data => {{
            if (!data.success) {{
                alert("打开失败: " + data.error);
            }}
        }})
        .catch(err => {{
            alert("无法连接工具服务,请确保Flask正在运行。");
        }});
    }}
    </script>
    <script>
    // 搜索功能
    document.addEventListener('DOMContentLoaded', function () {{
        const searchInput = document.querySelector('.search-input');
        const categorySections = document.querySelectorAll('.category-section');
 
        function performSearch() {{
            const keyword = searchInput.value.trim().toLowerCase();
 
            categorySections.forEach(section => {{
                const content = section.querySelector('.tools-grid');
                const titleElement = section.querySelector('.category-title');
                const toolCards = section.querySelectorAll('.tool-card');
 
                const categoryTitleText = titleElement.textContent.toLowerCase();
 
                // 判断是否匹配标题
                const isCategoryMatch = keyword !== '' && categoryTitleText.includes(keyword);
 
                if (isCategoryMatch || keyword === '') {{
                    // 标题匹配 或 搜索框为空,则显示所有卡片并展开分类
                    toolCards.forEach(card => {{
                        card.style.display = 'flex';
                    }});
 
                    section.classList.remove('hidden');
                    content.style.maxHeight = content.scrollHeight + 'px';
                    const icon = section.querySelector('.toggle-icon');
                    if (icon) icon.style.transform = 'rotate(180deg)';
                }} else {{
                    // 否则检查是否有卡片匹配
                    let matchCount = 0;
 
                    toolCards.forEach(card => {{
                        const cardTitle = card.querySelector('.tool-title').textContent.toLowerCase();
                        if (cardTitle.includes(keyword)) {{
                            card.style.display = 'flex';
                            matchCount++;
                        }} else {{
                            card.style.display = 'none';
                        }}
                    }});
 
                    if (matchCount > 0) {{
                        // 有卡片匹配,展开分类
                        section.classList.remove('hidden');
                        content.style.maxHeight = content.scrollHeight + 'px';
                        const icon = section.querySelector('.toggle-icon');
                        if (icon) icon.style.transform = 'rotate(180deg)';
                    }} else {{
                        // 没有任何匹配项,隐藏整个分类
                        section.classList.add('hidden');
                        content.style.maxHeight = '0px';
                        const icon = section.querySelector('.toggle-icon');
                        if (icon) icon.style.transform = 'rotate(0deg)';
                    }}
                }}
            }});
        }}
 
        searchInput.addEventListener('input', performSearch);
    }});
</script>
<script>
    // 展开收起功能
    function toggleCategory(titleElement) {{
        const content = titleElement.nextElementSibling;
        const icon = titleElement.querySelector('.toggle-icon');
        const isOpen = !content.style.maxHeight || content.style.maxHeight === '0px';
 
        if (isOpen) {{
            content.style.maxHeight = content.scrollHeight + 'px';
            icon.style.transform = 'rotate(180deg)';
        }} else {{
            content.style.maxHeight = '0px';
            icon.style.transform = 'rotate(0deg)';
        }}
    }}
</script>
    <body>
        <div class="container">
            <header>
                <h1><i class="fas fa-tools"></i> 图标管理工具</h1>
                <div class="search-box">
                    <input type="text" class="search-input" placeholder="搜索工具...">
                </div>
            </header>
            {data}
        </div>
    </body>
    </html>
    """
    return html_content
 
 
def get_icon():
    # 获取当前工作目录下的 icons 目录路径
    icons_dir = os.path.join(os.getcwd(), "static/icons")
 
    # 判断目录是否存在且是一个文件夹
    if not os.path.exists(icons_dir) or not os.path.isdir(icons_dir):
        print(f"目录不存在: {icons_dir}")
        return []
 
    # 遍历目录,筛选出文件(排除子目录)
    file_list = []
    for filename in os.listdir(icons_dir):
        file_path = os.path.join(icons_dir, filename)
        if os.path.isfile(file_path):
            file_list.append(filename.replace(".ico", ""))
    return file_list
 
 
def create_icon(file_paths, icon_list):
    for i in file_paths:
        icon_path = i.replace('\\', '\\\\')
        icon_name = os.path.basename(i)
        if icon_name.replace(".exe", "") in icon_list:
            continue
        if icon_path.endswith(".exe") and icon_name not in ["pycdas.exe", "pycdc.exe", "upx.exe"]:
            command = f'icoextract "{icon_path}" ".\\static\\icons\\{icon_name.replace(".exe", ".ico")}"'
            subprocess.Popen(command)
 
 
def get_html_content():
    config = configparser.ConfigParser()
    # 读取配置文件
    config.read('setting.ini')
    dir_path = config['DESKTOP_PATH']['PATH']
    dir_result = get_subdirectories(dir_path)
    out_section = ""
    icon_list = get_icon()
    for i in range(len(dir_result)):
        out_app_section = ""
        app_result, app_result_ini = get_direct_files_and_dirs(dir_result[i])
        create_icon(app_result, icon_list)
        section_name = dir_result[i].split('\\')[-1]
 
        for j in range(len(app_result)):
            app_name_ini = app_result_ini[j].split('\\')[-1]
            app_name = app_result[j].split('\\')[-1]
            app_path = app_result[j].replace('\\', '\\\\')
            if app_name.endswith(".exe"):
                ico_path = url_for('static', filename=f'icons/{app_name.replace(".exe", ".ico")}'# 浏览器可访问的 URL 路径
            elif app_name.endswith(".xls") or app_name.endswith(".xlsx"):
                ico_path = url_for('static', filename='default_icons/excel.ico')
            elif app_name.endswith(".doc") or app_name.endswith(".docx"):
                ico_path = url_for('static', filename='default_icons/word.ico')
            elif app_name.endswith(".ppt") or app_name.endswith(".pptx"):
                ico_path = url_for('static', filename='default_icons/ppt.ico')
            elif app_name.endswith(".pdf"):
                ico_path = url_for('static', filename='default_icons/pdf.ico')
            elif app_name.endswith(".txt"):
                ico_path = url_for('static', filename='default_icons/txt.ico')
            elif '.' not in app_name:
                ico_path = url_for('static', filename='default_icons/dir.ico')
            else:
                ico_path = url_for('static', filename='default_icons/other.ico')
 
            app_section = f"""
                <a class="tool-card">
                    <div class="tool-icon"><img src="{ico_path}" alt="Tool Icon" style="width: 40px; height: 40px;"></div>
                    <div class="tool-text">
                        <div class="tool-title">{app_name_ini}</div>
                    </div>
                </a>
                """
            out_app_section += app_section
        category_section = f"""
            <section class="category-section">
                <h2 class="category-title">
                    <i class="fas fa-code category-icon"></i>{section_name}
                    <i class="fas fa-chevron-down toggle-icon" style="margin-left: auto; transition: transform 0.3s;"></i>
                </h2>
                <div class="tools-grid" style="overflow: hidden; transition: max-height 0.3s ease-out; max-height: 0px;">
                {out_app_section}
                </div>
            </section>\n
            """
 
        out_section = out_section + category_section
 
    html_content = html(out_section)
    return html_content
 
 
@app.route('/')
def home():
    html_content = get_html_content()
    return render_template_string(html_content)
 
 
def get_subdirectories(directory):
    sub_dirs = []
    for name in os.listdir(directory):
        full_path = os.path.join(directory, name)
        if os.path.isdir(full_path):
            sub_dirs.append(full_path)
    return sub_dirs
 
 
def get_direct_files_and_dirs(directory):
    result = []
    result_ini = []
 
    pythoncom.CoInitialize()
 
    try:
        shell = win32com.client.Dispatch("WScript.Shell")
    except Exception as e:
        print(f"创建 WScript.Shell 失败: {e}")
        return result
 
    for name in os.listdir(directory):
        full_path = os.path.join(directory, name)
 
        if os.path.isfile(full_path) and name.lower().endswith(".lnk"):
            try:
                shortcut = shell.CreateShortcut(full_path)
                target_path = shortcut.TargetPath
                if target_path and os.path.exists(target_path):  # 确保路径存在
                    result.append(target_path)
            except Exception as e:
                print(f"解析快捷方式失败: {full_path} - {e}")
        else:
            result.append(full_path)
        result_ini.append(full_path)
 
    pythoncom.CoUninitialize()
    return result, result_ini
 
 
if __name__ == '__main__':
    app.run(debug=True)

1751879645119.jpg
1751879523601.jpg

桌面管理.zip

99.1 KB, 下载次数: 6, 下载积分: 吾爱币 -1 CB

免费评分

参与人数 2吾爱币 +9 热心值 +2 收起 理由
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
Codeman + 2 + 1 我很赞同!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| LiCan857 发表于 2025-7-8 09:55
Open74 发表于 2025-7-8 09:40
可以加个动态配置,扫描目录dir_path = r"D:\desktop"写死的话扫描其他目录又要改代码

有道理,这个可以改
Open74 发表于 2025-7-8 09:40
可以加个动态配置,扫描目录dir_path = r"D:\desktop"写死的话扫描其他目录又要改代码
linnimei 发表于 2025-7-7 19:18
wjqok 发表于 2025-7-7 20:19

这个是干什么的?
wjqok 发表于 2025-7-7 20:21
QQ图片20250707202028.png 我桌面不放任何图标。
afti 发表于 2025-7-7 21:18
用浏览器展示确实不是很方便
苏紫方璇 发表于 2025-7-7 23:30
壁纸盲猜是纳西妲
onetwo888 发表于 2025-7-8 08:31
感谢大佬分享!!
 楼主| LiCan857 发表于 2025-7-8 09:54
linnimei 发表于 2025-7-7 19:18
这个是做什么的?

简单地说就是整理桌面图标的
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-8-15 07:34

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表