Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: format code with Autopep8, Black, isort, Ruff Formatter and Yapf #2

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions auto_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

blacklist = set()


def save_blacklist():
global blacklist
with open("blacklist.txt", "w") as file:
Expand Down
74 changes: 52 additions & 22 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import os
import tkinter as tk
from tkinter import (
BooleanVar,
Button,
Checkbutton,
Frame,
Label,
Toplevel,
simpledialog,
)
from tkinter.dialog import Dialog

import numpy as np
import win32con
import win32gui
import win32ui
import win32con
from PIL import Image, ImageTk
import tkinter as tk
from tkinter import Label, Frame, Checkbutton, BooleanVar, simpledialog, Toplevel, Button
import numpy as np

# Global blacklist variable
blacklist = set()
Expand Down Expand Up @@ -50,10 +58,19 @@ def get_window_screenshot(hwnd):
bmpstr = bmp.GetBitmapBits(True)

# Ensure the bitmap data is valid
if len(bmpstr) != bmpinfo['bmWidth'] * bmpinfo['bmHeight'] * 4: # 4 bytes per pixel (BGRX)
# 4 bytes per pixel (BGRX)
if len(bmpstr) != bmpinfo["bmWidth"] * bmpinfo["bmHeight"] * 4:
raise ValueError("Not enough image data")

img = Image.frombuffer('RGB', (bmpinfo['bmWidth'], bmpinfo['bmHeight']), bmpstr, 'raw', 'BGRX', 0, 1)
img = Image.frombuffer(
"RGB",
(bmpinfo["bmWidth"], bmpinfo["bmHeight"]),
bmpstr,
"raw",
"BGRX",
0,
1,
)

win32gui.ReleaseDC(hwnd, hwindc)
memdc.DeleteDC()
Expand Down Expand Up @@ -124,7 +141,11 @@ def preprocess_title(origin_title):

def enum_window_callback(hwnd, extra):
window_text = win32gui.GetWindowText(hwnd)
if win32gui.IsWindowVisible(hwnd) and window_text != "" and window_text not in blacklist:
if (
win32gui.IsWindowVisible(hwnd)
and window_text != ""
and window_text not in blacklist
):
frame = Frame(root)
frame.pack(side="top", fill="both", expand=True, padx=5, pady=5)

Expand All @@ -133,7 +154,9 @@ def enum_window_callback(hwnd, extra):
thumbnail_label.pack(side="left")

# Window name
name_label = Label(frame, text=preprocess_title(window_text), font=("Arial", 8))
name_label = Label(
frame, text=preprocess_title(window_text), font=("Arial", 8)
)
name_label.pack(side="left")

def on_thumbnail_click(event, hwnd=hwnd):
Expand Down Expand Up @@ -203,30 +226,37 @@ def set_interval():
try:
new_interval = float(interval_var.get())
if new_interval > 0:
window_interval = int(new_interval * 1000) # Convert to milliseconds
# Convert to milliseconds
window_interval = int(new_interval * 1000)
if window_interval < 500:
_ = Dialog(None, {'title': 'File Modified',
'text':
'window_interval is set too small.\n '
'This Window may flash frequently!\n'
'window_interval 设置值过小。\n'
'此窗口可能会频繁闪烁!',
'bitmap': 'questhead',
'default': 0,
'strings': ('Ignore',
)})
_ = Dialog(
None,
{
"title": "File Modified",
"text": "window_interval is set too small.\n "
"This Window may flash frequently!\n"
"window_interval 设置值过小。\n"
"此窗口可能会频繁闪烁!",
"bitmap": "questhead",
"default": 0,
"strings": ("Ignore",),
},
)
except ValueError:
print("Invalid interval value. Please enter an integer.")

Button(interval_frame, text="设置", command=set_interval).pack(side="right")
blacklist_window.protocol("WM_DELETE_WINDOW", on_close)

Button(root, text="Blacklist Management", command=manage_blacklist).pack(side="bottom", pady=10)
Button(root, text="Blacklist Management", command=manage_blacklist).pack(
side="bottom", pady=10
)

win32gui.EnumWindows(enum_window_callback, None)
update_thumbnails(root, frames, refresh_rate)
update_blacklist_periodically(root, frames, refresh_rate)
root.after(5000, refresh_windows, root) # Schedule the refresh_windows function
# Schedule the refresh_windows function
root.after(5000, refresh_windows, root)
root.mainloop()


Expand All @@ -239,7 +269,7 @@ def set_interval():
"Enter Refresh Rate(ms):",
minvalue=1,
maxvalue=10000,
initialvalue=100
initialvalue=100,
)
root.destroy() # Destroy the input dialog root window

Expand Down
Loading