Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
pzy2000 committed Aug 28, 2024
2 parents 3b56e46 + f4935f2 commit 6457ada
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 23 deletions.
17 changes: 16 additions & 1 deletion .deepsource.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,19 @@ version = 1
name = "python"

[analyzers.meta]
runtime_version = "3.x.x"
runtime_version = "3.x.x"

[[transformers]]
name = "autopep8"

[[transformers]]
name = "isort"

[[transformers]]
name = "black"

[[transformers]]
name = "ruff"

[[transformers]]
name = "yapf"
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

0 comments on commit 6457ada

Please sign in to comment.