pygtk combobox focus signal handling - python

I've been trying to find a way to handle focusing on a pygtk combobox. The goal is to change the color of the combobox when it is focused and then change it back when focus leaves the combobox. I've tried using the "focus_out_event" but this doesn't seem to work with combobox. I've searched extensively for an answer to this problem and it seems this may be a gtk+ bug??
The solution I've come up with so far...
I have 4 separate combobox's cb0 - cb3. I have connected them to the same method...
self.cb0.connect("focus", self.focus)
In the method I change the state and color...
def focus(self, widget, direction):
if widget.get_state() == gtk.STATE_NORMAL:
widget.set_state(gtk.STATE_SELECTED)
widget.modify_base(gtk.STATE_SELECTED, gtk.gdk.Color("#99CCFF"))
else:
widget.set_state(gtk.STATE_NORMAL)
widget.modify_base(gtk.STATE_NORMAL, gtk.gdk.Color("#FFFFFF"))
This provides the desired effect when tabbing with the keyboard. But if the combo boxes are clicked with the mouse I get undesirable results. Now I'm looking for a way to track mouse clicks.
I can't seem to find a signal or method to check when a specific combo box is clicked. Using the "grab_notify" signal will fire off a signal for all 4 combo boxes (thus changing all the boxes base color at once.)
This has been a frustrating problem taking waaay too much of my time. Seems like there should be a simple solution.

Related

What is the difference between a Primitive, Control and Complex Control widget?

Qt supports custom paint events for drawing of widgets through QStyle.
However when using the QStyle you need to specify what type of element you're trying to draw,
i.e, if you want a control element you need to paint it by using QStyle.drawControl(CE_Example, style).
My question is, how is someone who is relatively new meant to understand which method to correctly call, or find which element to paint when I want to perform the actions myself, say for example I want to draw my SpinButton with purple up and down arrows. I tried to google and see if I could find an explanation but could not, so I was wondering if this is common terminology or if it was some jargon used by the Qt community.
Any advice for correctly traversing documentation or anything like that appreciated, maybe I have an incorrect approach.
I eventually found my answer traversing https://doc.qt.io/qt-5/qstyle.html#details
Primitive Element: A primitive element is a common GUI element, such as a checkbox indicator or button bevel.
Control Element: A control element is a part of a widget that performs some action or displays information to the user.
Complex Control: Complex controls have different behavior depending upon where the user clicks on them or which keys are pressed.

Tkinter - Adjusting widgets

I'm recently getting into Tkinter. Today I needed to create a scale, which has values snap to the left mouse button click. The standard seems to be, that it snaps to the right button.
Anyways, I found an answer:
Force TkInter Scale slider to snap to mouse
My question is: Where can I find documentation of the "Scale" class, or any other class, so I can make such adjustments myself in the future?
I tried my best to contact the user who provided the answer and ask him instead. But the terrible and deliberate design choices of this site do not allow that.

Moving through panes in AUI managed frame

My wx.Frame derived class is managed by AuiManager. I have several panes in this frame (all are derived from wx.Panel and all have wx.TAB_TRAVERSAL flag set). Pressing TAB key on the keyboard moves focus inside every pane correctly. The problem is, I don't know how to (or even if it is possible) move focus to the next pane. Any ideas about this?
P.S. I've tried googling and reading through wxPython docs, but couldn't find any clue.
I try to be as helpful as I can, given the little information you provided. To shift the focus to another Panel use that Panel's SetFocus() function. (See function description in the link)
Your question also seems to imply that you are interested in the key bindings of focus events. To manage the key bindings to focus events in wxpython, please checkout wx.NavigationKeyEvent. This will allow you to get and set the directions and events resulting from your navigation key inputs.
Last, have you tried pressing the [page down] key for switching panes?

In a GUI, how to change the mouse to Zoom-to-rectangle

I am creating a GUI that revolves around looking at a plot. The users are assumed to be very dense, as per instruction. That being said, I have been told that the default Zoom-to-rectangle button needs to have another button in the toolbar at the top of the program (which I would also program to a shortcut for ease of use).
The problem I am having is I don't know how to turn the mouse into the Zoom-to-rectangle. I don't want it to actually zoom, just change the mouse to where if it is then dragged across the plot while clicking, it will then zoom.
This is hard to explain, so if you need more information than what is provided please ask.

Grab the focus from GTK popup menu

In my python GTK project, I have a popup menu which pop-ups while typing in a particular text area. But, when type a letter popup menu get the focus and I can't type anymore in the text area until I click on the text area and grab the focus manually. I want to keep the focus to the text area as I type regularly while popup menu comes. Can anyone give tell me a way to do this. I tried widget.grab_focus() method. But it didn't solve my problem.
Also I want to know how to set the position of the popup menu. It always appears near by mouse pointer. I want it to appear near by my application.
Thanks all.
I ran into the same problem using the C API, the solution was to invoke the following functions, I presume they're approximately similar to the python equivalents:
gdk_pointer_ungrab(GDK_CURRENT_TIME);
gdk_keyboard_ungrab(GDK_CURRENT_TIME);
gtk_grab_remove(menu);

Categories

Resources