Skip to content

Commit 23254d2

Browse files
shymegaclaude
andcommitted
Position popup windows on the screen where the mouse cursor is located
Adds get_mouse_location() function that uses tkinter to get the current mouse position, then passes this location to PySimpleGUI windows so they appear on the active screen in multi-monitor setups. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 6ac323d commit 23254d2

3 files changed

Lines changed: 38 additions & 7 deletions

File tree

src/coreutils.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import (
1111
Callable,
1212
Optional,
13+
Tuple,
1314
Union,
1415
List,
1516
Any,
@@ -22,6 +23,21 @@
2223
read_file,
2324
)
2425

26+
27+
def get_mouse_location() -> Optional[Tuple[int, int]]:
28+
"""Get the current mouse position to place windows on the active screen."""
29+
try:
30+
import tkinter as tk
31+
32+
root = tk.Tk()
33+
root.withdraw()
34+
x = root.winfo_pointerx()
35+
y = root.winfo_pointery()
36+
root.destroy()
37+
return (x, y)
38+
except Exception:
39+
return None
40+
2541
if getattr(sys, "frozen", False):
2642
SCRIPT_IMP_FILE = os.path.realpath(sys.executable)
2743
else:
@@ -93,19 +109,22 @@ def show_message(
93109
close = True
94110
if timeout == None:
95111
close = False
112+
location = get_mouse_location()
96113
if yesno:
97114
response = sg.popup_yes_no(
98115
message,
99116
title=title,
100117
auto_close=close,
101118
auto_close_duration=timeout,
119+
location=location,
102120
)
103121
else:
104122
response = sg.popup_ok(
105123
message,
106124
title=title,
107125
auto_close=close,
108126
auto_close_duration=timeout,
127+
location=location,
109128
)
110129
return response
111130

@@ -380,6 +399,7 @@ def popup_options(
380399
finalize=True,
381400
auto_close=close,
382401
auto_close_duration=timeout,
402+
location=get_mouse_location(),
383403
)
384404

385405
# Event loop to process button clicks
@@ -421,6 +441,7 @@ def get_user_input(
421441
finalize=True,
422442
auto_close=close,
423443
auto_close_duration=timeout,
444+
location=get_mouse_location(),
424445
)
425446

426447
# Event loop to process button clicks and input

src/mainutils.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
load_conf_setting,
2626
cache,
2727
log,
28+
get_mouse_location,
2829
)
2930

3031
if getattr(sys, "frozen", False):
@@ -171,7 +172,7 @@ def popup_execute(
171172
text_str = [""]
172173
text = sg.Multiline("", disabled=True, autoscroll=True, size=(80, 30))
173174
layout = [[text]]
174-
window = sg.Window(title, layout, finalize=True)
175+
window = sg.Window(title, layout, finalize=True, location=get_mouse_location())
175176
exitcode = [-1]
176177

177178
def process_func() -> None:
@@ -244,7 +245,7 @@ def popup_download(title: str, link: str, file_name: str) -> str:
244245
progress = sg.ProgressBar(100, orientation="h", s=(50, 10))
245246
text = sg.Text("0%")
246247
layout = [[progress], [text]]
247-
window = sg.Window(title, layout, finalize=True)
248+
window = sg.Window(title, layout, finalize=True, location=get_mouse_location())
248249

249250
def update_log(status: list[int], dl: int, total: int) -> None:
250251
status.clear()
@@ -343,7 +344,9 @@ def update_progress(percentage: int) -> None:
343344
text = sg.Text("0%")
344345
extra = sg.Text("Reading directory, please wait...")
345346
layout = [[extra], [progress], [text]]
346-
window = sg.Window("De-referencing Links", layout, finalize=True)
347+
window = sg.Window(
348+
"De-referencing Links", layout, finalize=True, location=get_mouse_location()
349+
)
347350
window.refresh()
348351

349352
window.perform_long_operation(dereference_links, "-DEREF DONE-")
@@ -479,10 +482,11 @@ def copy_files() -> None:
479482
extra = sg.Text("Reading prefix directory, please wait...")
480483
layout = [[extra], [progress], [text]]
481484

485+
location = get_mouse_location()
482486
if zipup:
483-
window = sg.Window("Copying Prefix", layout, finalize=True)
487+
window = sg.Window("Copying Prefix", layout, finalize=True, location=location)
484488
else:
485-
window = sg.Window("Zipping File", layout, finalize=True)
489+
window = sg.Window("Zipping File", layout, finalize=True, location=location)
486490

487491
window.refresh()
488492
window.perform_long_operation(copy_files, "-COPY DONE-")
@@ -565,7 +569,9 @@ def unpack_files() -> None:
565569
text = sg.Text("0% (0/?)")
566570
extra = sg.Text("Reading ZIP file, please wait...")
567571
layout = [[extra], [progress], [text]]
568-
window = sg.Window("Unpacking Prefix", layout, finalize=True)
572+
window = sg.Window(
573+
"Unpacking Prefix", layout, finalize=True, location=get_mouse_location()
574+
)
569575
window.refresh()
570576

571577
window.perform_long_operation(unpack_files, "-UNPACK DONE-")

src/setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
log,
1212
pip,
1313
exit_with_message,
14+
get_mouse_location,
1415
)
1516

1617
from corenodep import (
@@ -61,6 +62,7 @@ def welcome() -> bool:
6162
title="WeMod Launcher Setup",
6263
image=wemod_logo.content,
6364
icon=wemod_logo.content,
65+
location=get_mouse_location(),
6466
)
6567
return ret == "OK"
6668

@@ -76,7 +78,9 @@ def download_wemod(temp_dir: str) -> str:
7678
text = sg.Text("0%")
7779
# text = sg.Multiline(str.join("", log), key="-LOG-", autoscroll=True, size=(50,50), disabled=True)
7880
layout = [[progress], [text]]
79-
window = sg.Window("Downloading WeMod", layout, finalize=True)
81+
window = sg.Window(
82+
"Downloading WeMod", layout, finalize=True, location=get_mouse_location()
83+
)
8084

8185
def update_log(status: list[int], dl: int, total: int) -> None:
8286
status.clear()

0 commit comments

Comments
 (0)