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!
Related
I have a Python 3.6.3 script that incorporates PyQt5. The GUI has a button that toggles play and pause of a video file. Pressing the spacebar also toggles play and pause. The button works fine all the time. The spacebar also works as intended, except at the very start of executing the script. I need to click some other event first (such as a button or slider bar) before the spacebar will correctly triggers the signal to pause or play the video. I want to start playing the video with the spacebar when the script starts up. Here is how I create the connections in the same __init__(self) function . As you can see, clicking on the button and pressing the spacebar both connect the signal to the same function (self.pauseVideo).
self.btnPause = QtWidgets.QPushButton(self.centralwidget)
self.btnPause.clicked.connect(self.pauseVideo)
self.spacebar = QShortcut(QKeySequence(Qt.Key_Space), self)
self.spacebar.activated.connect(self.pauseVideo)
Suggestions on how to get the spacebar to trigger the signal when the script first starts?
After a lot more searching, reassigning keyboard shortcuts (without success), etc., I found this post PyQt widget keyboard focus. I inserted
self.setFocusPolicy(Qt.StrongFocus)
into __init__(self) and it seemed to solve my problem! Now I'm just hoping it doesn't cause other issues.
I press this tkinter button, and the function bound to it finishes, but the button is stuck down. The rest of the gui is fine, its responsive, everything normal except for the button that is stuck down. I can even press the "stuck down" button again, and the bound function executes and finishes, but the button is still stuck down.
Sometimes the first few times I click the button it works fine and the button comes back up, but then after a few more clicks it will be stuck down. What could be causing this?
Here is the code for the button:
bf1=Button(self.canvas,text='F1',fg='tan1')
bf1.grid(row=4,column=1,sticky='nwse',columnspan=4)
bf1.bind('<Button-1>',self.f1)
I have found what is causing this, it is the fact that I am using the 'bind' function instead of the 'command'.
When I use this, the button sticks if you move the mouse off the button before the callback finishes (you can only realistically do this if you have a lot of work to do in the callback):
bf1=Button(self.canvas,text='F1',fg='tan1')
bf1.grid(row=4,column=1,sticky='nwse',columnspan=4)
bf1.bind('<Button-1>',self.f1)
But if you use the 'command', then there is no problem:
bf1=Button(self.canvas,text='F1',fg='tan1',command=self.f1)
bf1.grid(row=4,column=1,sticky='nwse',columnspan=4)
Is this a bug with tkinter's 'bind'?
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.
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.
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.