Location>code7788 >text

Windows quick launcher

Popularity:205 ℃/2025-01-21 14:50:05
python
copy
import tkinter as tk
import keyboard
import ctypes
import sys
import os
import psutil
import webbrowser
import subprocess
import time

class StoreItem:
    def __init__(self, keyword, content, type_):
        self.keyword = keyword
        self.content = content
        self.type_ = type_

class Store:
    def __init__(self, file_path):
        self.file_path = file_path
        self.items = {}
        self.last_modified = 0
        self.load()

    def load(self):
        if not os.path.exists(self.file_path):
            print(f" error: file not found{self.file_path}, please make sure that is in the same directory as the script.  ")
            return

        self.last_modified = os.path.getmtime(self.file_path)
        self.items.clear()

        with open(self.file_path, "r", encoding="utf-8") as file:
            for line in file:
                columns = line.strip().split()
                if len(columns) == 3:
                    keyword, content, type_ = columns
                    self.items[keyword] = StoreItem(keyword, content, type_)

    def get_item(self, keyword):
        if os.path.getmtime(self.file_path) > self.last_modified:
            self.load()
        return self.items.get(keyword)

def is_already_running():
    current_pid = os.getpid()
    for proc in psutil.process_iter(['pid', 'name']):
        try:
            if proc.info['name'] == os.path.basename(sys.argv[0]) and proc.info['pid'] != current_pid:
                return True
        except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
            pass
    return False

if is_already_running():
    print("The program is already running, exit the current instance.")
    sys.exit(0)

user32 = ctypes.windll.user32
imm32 = ctypes.windll.imm32

def show_window():
    if not root.winfo_viewable():
        root.deiconify()
    root.lift()
    root.focus_force(