From e7e9f0ff87b4c02f2e7804be0f9f44c0885d8343 Mon Sep 17 00:00:00 2001 From: Joe R Date: Thu, 6 Mar 2025 22:38:13 -0500 Subject: [PATCH] Configure topmost dialogs to not stay on top when PySol loses focus --- pysollib/app.py | 12 +++++++++++- pysollib/game/__init__.py | 2 ++ pysollib/help.py | 7 +++++++ pysollib/kivy/findcarddialog.py | 4 ++++ pysollib/kivy/fullpicturedialog.py | 4 ++++ pysollib/kivy/solverdialog.py | 4 ++++ pysollib/pysolgtk/findcarddialog.py | 4 ++++ pysollib/pysolgtk/fullpicturedialog.py | 6 +++++- pysollib/pysolgtk/solverdialog.py | 4 ++++ pysollib/tile/solverdialog.py | 7 +++++++ pysollib/ui/tktile/findcarddialog.py | 7 +++++++ pysollib/ui/tktile/fullpicturedialog.py | 7 +++++++ pysollib/ui/tktile/tkwrap.py | 8 ++++++++ 13 files changed, 74 insertions(+), 2 deletions(-) diff --git a/pysollib/app.py b/pysollib/app.py index 5b621e49..3ddb1650 100644 --- a/pysollib/app.py +++ b/pysollib/app.py @@ -35,7 +35,8 @@ from pysollib.app_stat_result import GameStatResult from pysollib.app_statistics import Statistics from pysollib.cardsetparser import read_cardset_config from pysollib.gamedb import GAME_DB, GI, loadGame -from pysollib.help import destroy_help_html, help_about, raise_help_html +from pysollib.help import (destroy_help_html, help_about, raise_help_html, + unraise_help_html) from pysollib.images import Images, SubsampledImages from pysollib.mfxutil import Struct, destruct from pysollib.mfxutil import USE_PIL @@ -58,6 +59,9 @@ from pysollib.pysoltk import loadImage, wm_withdraw from pysollib.pysoltk import raise_find_card_dialog from pysollib.pysoltk import raise_full_picture_dialog from pysollib.pysoltk import raise_solver_dialog +from pysollib.pysoltk import unraise_find_card_dialog +from pysollib.pysoltk import unraise_full_picture_dialog +from pysollib.pysoltk import unraise_solver_dialog from pysollib.resource import CSI, CardsetManager from pysollib.resource import Music, MusicManager from pysollib.resource import Sample, SampleManager @@ -525,6 +529,12 @@ class Application: raise_solver_dialog(self.game) raise_help_html(self.game) + def unraiseAll(self): + unraise_find_card_dialog() + unraise_full_picture_dialog() + unraise_solver_dialog() + unraise_help_html() + def loadImages1(self): # load dialog images dirname = os.path.join("images", "logos") diff --git a/pysollib/game/__init__.py b/pysollib/game/__init__.py index 3b8b7ac4..836ce32d 100644 --- a/pysollib/game/__init__.py +++ b/pysollib/game/__init__.py @@ -591,6 +591,8 @@ class Game(object): self.initBindings() # self.top.bind('', self.top._sleepEvent) # self.top.bind('<3>', self.top._sleepEvent) + self.top.bind("", self.top._focusOutEvent) + self.top.bind("", self.top._focusInEvent) # update display properties self.canvas.busy = True # geometry diff --git a/pysollib/help.py b/pysollib/help.py index 4d680efd..78bd2c6a 100644 --- a/pysollib/help.py +++ b/pysollib/help.py @@ -175,6 +175,13 @@ def raise_help_html(game): pass +def unraise_help_html(): + try: + help_html_viewer.parent.attributes("-topmost", False) + except Exception: + pass + + def destroy_help_html(): try: help_html_viewer.destroy() diff --git a/pysollib/kivy/findcarddialog.py b/pysollib/kivy/findcarddialog.py index 64858d6e..de3dcab1 100644 --- a/pysollib/kivy/findcarddialog.py +++ b/pysollib/kivy/findcarddialog.py @@ -73,6 +73,10 @@ def raise_find_card_dialog(game): pass +def unraise_find_card_dialog(): + pass + + def destroy_find_card_dialog(): pass ''' diff --git a/pysollib/kivy/fullpicturedialog.py b/pysollib/kivy/fullpicturedialog.py index 7e83b071..d3b6e59e 100644 --- a/pysollib/kivy/fullpicturedialog.py +++ b/pysollib/kivy/fullpicturedialog.py @@ -112,6 +112,10 @@ def raise_full_picture_dialog(game): pass +def unraise_full_picture_dialog(): + pass + + def destroy_full_picture_dialog(): pass ''' diff --git a/pysollib/kivy/solverdialog.py b/pysollib/kivy/solverdialog.py index 2e0f4b58..4d7cf43a 100644 --- a/pysollib/kivy/solverdialog.py +++ b/pysollib/kivy/solverdialog.py @@ -50,6 +50,10 @@ def raise_solver_dialog(game): pass +def unraise_solver_dialog(): + pass + + def destroy_solver_dialog(): global solver_dialog solver_dialog = None diff --git a/pysollib/pysolgtk/findcarddialog.py b/pysollib/pysolgtk/findcarddialog.py index d05d924d..1c97667d 100644 --- a/pysollib/pysolgtk/findcarddialog.py +++ b/pysollib/pysolgtk/findcarddialog.py @@ -54,5 +54,9 @@ def raise_find_card_dialog(game): pass +def unraise_find_card_dialog(): + pass + + def destroy_find_card_dialog(): pass diff --git a/pysollib/pysolgtk/fullpicturedialog.py b/pysollib/pysolgtk/fullpicturedialog.py index 5b7a6854..385d9cc9 100644 --- a/pysollib/pysolgtk/fullpicturedialog.py +++ b/pysollib/pysolgtk/fullpicturedialog.py @@ -50,7 +50,11 @@ def connect_game_full_picture_dialog(game): pass -def raise_find_card_dialog(game): +def raise_full_picture_dialog(game): + pass + + +def unraise_full_picture_dialog(): pass diff --git a/pysollib/pysolgtk/solverdialog.py b/pysollib/pysolgtk/solverdialog.py index 389768e2..e573ec09 100644 --- a/pysollib/pysolgtk/solverdialog.py +++ b/pysollib/pysolgtk/solverdialog.py @@ -34,6 +34,10 @@ def raise_solver_dialog(game): pass +def unraise_solver_dialog(): + pass + + def destroy_solver_dialog(): pass # solver_dialog = None diff --git a/pysollib/tile/solverdialog.py b/pysollib/tile/solverdialog.py index 3f82ef23..69dd7ecf 100644 --- a/pysollib/tile/solverdialog.py +++ b/pysollib/tile/solverdialog.py @@ -95,3 +95,10 @@ def raise_solver_dialog(game): solver_dialog.top.attributes("-topmost", False) except Exception: pass + + +def unraise_solver_dialog(): + try: + solver_dialog.top.attributes("-topmost", False) + except Exception: + pass diff --git a/pysollib/ui/tktile/findcarddialog.py b/pysollib/ui/tktile/findcarddialog.py index 98e4f471..bd4e24a7 100644 --- a/pysollib/ui/tktile/findcarddialog.py +++ b/pysollib/ui/tktile/findcarddialog.py @@ -254,6 +254,13 @@ def raise_find_card_dialog(game): pass +def unraise_find_card_dialog(): + try: + find_card_dialog.attributes("-topmost", False) + except Exception: + pass + + def destroy_find_card_dialog(): global find_card_dialog try: diff --git a/pysollib/ui/tktile/fullpicturedialog.py b/pysollib/ui/tktile/fullpicturedialog.py index d9ecec32..1001e860 100644 --- a/pysollib/ui/tktile/fullpicturedialog.py +++ b/pysollib/ui/tktile/fullpicturedialog.py @@ -146,6 +146,13 @@ def raise_full_picture_dialog(game): pass +def unraise_full_picture_dialog(): + try: + full_picture_dialog.attributes("-topmost", False) + except Exception: + pass + + def destroy_full_picture_dialog(): global full_picture_dialog try: diff --git a/pysollib/ui/tktile/tkwrap.py b/pysollib/ui/tktile/tkwrap.py index d85b1e2e..4a7e95c5 100644 --- a/pysollib/ui/tktile/tkwrap.py +++ b/pysollib/ui/tktile/tkwrap.py @@ -133,6 +133,14 @@ class MfxRoot(tkinter.Tk): # # + def _focusInEvent(self, *args): + if self.app: + self.app.raiseAll() + + def _focusOutEvent(self, *args): + if self.app: + self.app.unraiseAll() + def update(self): tkinter.Tk.update(self)