Problems Connecting to Minimized Signal - python

Problem: I have a gtk.Dialog. Whenever the 'minimize' button on the dialog is clicked, the window is destroyed.
Question: How can I connect to the minimize button of a gtk.Dialog so that I can iconify the window?

Are you sure it's the minimize button? Because GTK doesn't deal with (or even know about the existence of) minimize buttons at all, they are part of the window manager.

Related

background window and main window tkinter

I'm learning Tkinter and just had a doubt.
Is there any method that prevents me from working with the window in the background until I close the main window? I saw that there is an argument about this here, but I ended up losing it and decided to ask.
Yes, it is possible (IIUC) and if I do understand correctly you simply want to block user for accessing other windows while your window is open. It has a slight flaw in that if user does a lot of alt-tabbing they may get keyboard focus on some other window but only the keyboard, as soon as they do anything with mouse they should get back to the main window. This can be handled using some module like keyboard to listen for global keyboard input but also perhaps it could be done using Windows API but for a tkinter only solution that is/should be effective enough you can use this:
import tkinter as tk
def check_focus():
if root.focus_get() is None:
root.focus_force()
root.after(100, check_focus)
def create_shield():
shield = tk.Toplevel(root)
shield.attributes('-topmost', True)
shield.attributes('-fullscreen', True)
shield.attributes('-alpha', 0.01)
shield.overrideredirect(True)
shield.bind('<FocusIn>', lambda _: root.focus_force())
root = tk.Tk()
root.attributes('-topmost', True)
create_shield()
check_focus()
root.mainloop()
First there is the after "loop" that checks for focus to see if the window has any, this prevents some attempts of trying to alt-tab away but enough attempts may cause some kind of timeout and the window will get out of focus.
The other part is a "shield" that simply is another fullscreen window that is almost completely invisible (on other OS the attribute name may be -splash instead of -alpha) and just keeps it in top to assist in focusing on the main window.
Or just make the window fullscreen and topmost (again the issues with keyboard focus on other windows but now user has no issues whatsoever with accessing the other windows except they wouldn't see what they are typing) and this requires to implement some button to close the window (currently doable by alt+f4 or shutting down the computer or killing the process via run without looking at what you are typing and perhaps some other way I haven't thought about, but for user convenience probably a button should be made that would simply destroy the window):
import tkinter as tk
root = tk.Tk()
root.attributes('-topmost', True)
root.attributes('-fullscreen', True)
root.mainloop()

How to set tkinter window focus out?

I am trying to do make a virtual keyboard using tkinter. Is there any method that allow tkinter window focus out? For example in java we can have setFocusableWindowState(false)
Thank you very much for your help.
I believe you can accomplish what you want with tkinter, but it's not about not getting focus. I don't think, that other GUI tools will make it any easier.
It's part of operation system, or more precisely window manager to give focus to some window, when it is clicked. So, in case of virtual keyboard:
User has focus in text editor (for example).
User presses a button on your virtual keyboard.
OS/Window manager gives focus to your keyboard window and sends mouse click event to the GUI library (tkinter).
Here you need to identify where was the focus before your window got it, i.e. get the text editor window handler somehow.
Send the button press event to that window and return focus.
Repeat.
You'll use tkinter to draw the keyboard window and handle mouse clicks/touches on virtual keyboard keys. But you'll need to work with OS/Window manager to identify other windows by handlers and send keypress events to them. May be you will be able to prevent focus switch by working with OS/Window manager, but it's not tkinter or other GUI library functionality.

Pass clicks through Tkinter window? Mac OSX

Is there a way to make a Tkinter window unclickable? Meaning that any input that should be caught by the handler are redirected to whatever window is behind it? If not in Tkinter, would there be a way in PyQt or wxPython? My goal is to have a handler catch keyboard events while still letting them input into the windows behind. I don't need to catch clicks but that would be nice to have if possible.
My current plan:
A Tkinter window with a geometry of 10000x10000, alpha of 0 and topmost set to true. The frame will catch all keyboard & mouse events and when anything is entered the frame will catch it, hide the Tkinter window using an apple script function which is run from terminal with osascript, use autopy to simulate whatever was entered such as a click/keyboard event and unhide the window again. Does this even sound viable?
When I have the time I will test out this idea and post if it works. I'm thinking computation speed will be an issue here.

GTK focus-out-event

I am showing a user a popup menu when they right click.
According to the popup behaviour, I want to destroy the popup when it looses focus(when user clicks outside the popup window). For that I tried to connect the popup window to "focus-out-event", using Glade. But for some reason, that event is not getting fired. I tried to print something on the terminal when the event is fired, but nothing gets printed.
I am new to Python and GTK, and now I have no clue how to proceed further.
#handler to catch the focus out event
def on_popup_menu_add_attachment_focus_out_event(self, *args):
print("Destroying the popup.....")
focus-out-signal and its handler
I just changed the Type as Top Level and it worked!

Python / Tkinter keep window in back

In Python with Tkinter, if you use the command:
`sometkapp.overrideredirect(True)`
It will make a Tkinter window that doesn't have a border from the window manager; however, at least on my windowing system, the Tkinter window then stays on top of all the other windows.
Is there a way to send a Tkinter window to the back, so that it always stays under all other open windows?
In some system window manager decides which window is on top or on bottom.
Using overrideredirect(True) you resign with its services - on some systems this meen no drawing border, no moving on top/on bottom (probably no refreshing window), no sending events (key pressed, mouse move).
I think you can do nothing with this using Tkinter or even pure Python. Maybe other module could do something.

Categories