HaujetZhao / CapsWriter-Offline

CapsWriter 的离线版,一个好用的 PC 端的语音输入工具
2.44k stars 192 forks source link

【功能添加】windows下启动服务端和客户端时自动把它们的命令行窗口隐藏到托盘 #40

Open wjz2001 opened 5 months ago

wjz2001 commented 5 months ago

因为我任务栏的东西比较多,如果再增加两个窗口的话就太占地方了,希望可以隐藏到托盘,这样可以节约空间

HaujetZhao commented 5 months ago

虚拟桌面

qmzmdqs commented 5 months ago

可以看看 https://github.com/winsw/winsw ,包装成 Windows 服务。当然软件原本就带了 winsw 的配置就最好了。

wjz2001 commented 5 months ago

虚拟桌面

我在网上教程和chatgpt的帮助写了一个python程序,基本实现了我说的功能,请您将其加入源代码中。

import tkinter as tk
import pystray
from PIL import Image
import subprocess
from queue import Queue

class GUI:
    def __init__(self):
        self.root = tk.Tk()
        self.root.title('演示窗口')
        self.root.geometry("500x200+1100+150")
        self.root.protocol('WM_DELETE_WINDOW', self.hide_window)
        self.create_systray_icon()
        self.interface()
        self.output_queue = Queue()
        self.start_test_script()
        self.hide_window()

    def interface(self):
        self.text_box = tk.Text(self.root, wrap="word")
        self.text_box.pack(expand=True, fill="both")

    def create_systray_icon(self):
        menu = (
            pystray.MenuItem('显示', self.show_window, default=True),
            pystray.Menu.SEPARATOR,
            pystray.MenuItem('退出', self.quit_window))
        image = Image.open("ICO.ico")
        self.icon = pystray.Icon("icon", image, "图标名称", menu)
        threading.Thread(target=self.icon.run, daemon=True).start()

    def hide_window(self):
        self.root.withdraw()

    def show_window(self):
        self.icon.visible = True
        self.root.deiconify()

    def quit_window(self, icon: pystray.Icon):
        icon.stop()
        self.root.quit()
        self.root.destroy()

    def start_test_script(self):
        # 启动test.py并将输出重定向到队列
        process = subprocess.Popen(['python', 'test.py'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
        threading.Thread(target=self.enqueue_output, args=(process.stdout,), daemon=True).start()
        self.root.after(100, self.update_text_box)

    def enqueue_output(self, out):
        for line in out:
            self.output_queue.put(line)

    def update_text_box(self):
        # 从队列中获取输出并显示在文本框中
        while not self.output_queue.empty():
            line = self.output_queue.get()
            self.text_box.insert("end", line)
            self.text_box.see("end")  # 滚动文本框以显示最新输出
        self.root.after(100, self.update_text_box)

if __name__ == '__main__':
    a = GUI()
    a.root.mainloop()
HaujetZhao commented 5 months ago

我在网上教程和chatgpt的帮助写了一个python程序,基本实现了我说的功能,请您将其加入源代码中。

两年内不考虑集成 GUI,这东西不是说加就加,而是加上以后新的需求就更不断了。

H1DDENADM1N commented 5 months ago

@wjz2001 试试我这个 https://github.com/HaujetZhao/CapsWriter-Offline/pull/53

start_server_and_client_in_tray

wjz2001 commented 5 months ago

@wjz2001 试试我这个 #53

start_server_and_client_in_tray start_server_and_client_in_tray

你速度好快😂,我还打算晚上写一个来着。 建议你干脆重新弄个库,把这个gui开源出来,再问问作者能不能把你的仓库的链接放到readme

H1DDENADM1N commented 5 months ago

你速度好快😂,我还打算晚上写一个来着。 建议你干脆重新弄个库,把这个gui开源出来,再问问作者能不能把你的仓库的链接放到readme

恰好我也需要这个功能,就用ChatGLM4生成了下,AI太强了https://github.com/H1DDENADM1N/CapsWriter-Offline

GaoYuan522 commented 4 months ago

恰好我也需要这个功能,就用ChatGLM4生成了下,AI太强了https://github.com/H1DDENADM1N/CapsWriter-Offline

为什么我的ChatGPT4都写不出来这么华丽的GUI😭

H1DDENADM1N commented 4 months ago

为什么我的ChatGPT4都写不出来这么华丽的GUI😭

prompt的艺术😆,要先让它角色扮演成为专业的软件工程师