wxpython control problems when migrating from win to mac - python

I have a python(2.7)/wxpython program developed on windows, which I am trying to migrate to mac but am encountering some problems.
The bit I am having problems with consists of two panels:
Panel A consists of a tree control containing key=value pairs and with user editing disabled.
Panel B consists of a set of controls of various types (filePicker, textCtrl, valueCtrl, choice, checkbox, comboBox, and spinEdit), all of which are initially disabled
When the user selects a tree node the program checks the key and decides which control on panel B should be used to edit the tree node's value. Panel A then sends the relevant info to panel B using pubsub which initializes and enables the relevant control. Each control on panel B has a EVT_KILL_FOCUS event so that when the user moves away from the control, the controls value is sent back to panel A using pubsub and the tree node's value is updated and the editing control on panel B is disabled. This works fine on windows.
On mac I have the following problems:
The filepicker and spinCtrl can not be disabled - this could lead to incorrect information being sent back to the treeCtrl if either of these controls inappropriately receives focus
the spinctrl, choice, checkbox, and comboctrl appear not be be triggering EVT_KILL_FOCUS events and so no information is sent back to the treeCtrl. I fixed this on the choice control by binding the EVT_CHOICE. Using non-focus events for the other controls doesn't work as well and creates undesired behaviors.
So my questions are:
1: is it possible to disable the filepicker and spinCtrl on OSX?
2: is there a way to use the kill focus events of the spinctrl, choice, checkbox, and comboctrl controls on mac?
3: if fill focus events can not be used, is there an alternate event that would be triggered after editing is complete, for each of these controls?
Thanks
Rob

Which version of wxPython are you using? Disabling those kinds of widgets seems to be working fine for me with current builds.
For some reason Apple thought that it was a good idea to never give the keyboard focus to some types of controls, because apparently nobody would ever want to use them with anything but a mouse or trackpad. So if the widget never gets the focus, then it can never lose it and so there won't be any EVT_KILL_FOCUS for it either. You can change this in the Keyboard panel in System Preferences by setting "Full Keyboard Access" to "All Controls"

Related

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?

Preventing a Button Press From Registering TKInter/Python 3.3

I'm in the process of creating a filling program with Python 3.3/Tkinter and have run into an issue that's really stumping me. Basically, I want to prevent button presses from registering while certain processes are taking place. I tried changing the button's state to state='disabled' but this only delays the click from registering until after the function is finished running. In other words, despite the button being "disabled", if it's clicked, the button press will register as soon as it's re-enabled. Please see the example code below.
def Button_Action:
Button.config(state='disabled')
#Activate some hardware that takes a few seconds.
Button.config(state='normal')
So, the question is: How can one selectively ignore button presses in Tkinter/Python 3?
I'm really new to Python and have tried searching for relevant questions to no avail, so please forgive me if this is a stupid question, or has been asked before. Also, I have tested this with both Radiobuttons as well as, standard Buttons (in case that helps).
You can use update method.
def button_action():
b.config(state='disabled')
b.update() # <----------
# Activate some hardware that takes a few seconds.
b.update() # <----------
b.config(state='normal')
The first call to update is to make the button displayed as disabled state.
The second call to update is to handle all pending event (clicks in your case) before enable the button.
BTW, it's normal state, not enabled that make the button back to normal state.

Difference between iconify() and withdraw() in Python Tkinter

I've been searching and not finding an answer as far as the differences of iconify() and withdraw() methods of Tkinter are concerned.
iconify() seems to "convert" the window to a taskbar icon and has a state of "iconic"
withdraw() seems to just remove the window from the screen, after which the window has a state of "withdrawn"
If you need to reverse the situation, you simply call deiconify() on both situations.
However, what is the real difference between the two methods and how do they essentially differ from one another?
Moreover, are they applied in different situations?
You've got it down correctly.
In more detail:
iconify() Turns the window into an icon (without destroying it). To redraw the window, use deiconify. Under Windows, the window will show up in the taskbar.
When the window has been iconified, the state method returns “iconic”.
withdraw() Removes the window from the screen (without destroying it). To redraw the window, use deiconify.
When the window has been withdrawn, the state method returns “withdrawn”.
Source: Tkinter -- Toplevel Window Methods
As far as use-cases go, you would normally use iconify() in situations where you want the user to be able to easily gain access to a window that was "minimized" (via iconify()) for whatever reason. For example, say a user clicks a button that "minimizes" a window and opens up a new one. Using iconify() lets the user do whatever they need to do in the new window and then return to the previous one easily since it appears to them as an icon.
On the other hand, withdraw() is useful to "hide" windows. For example, I have developed some applications that automatically created multiple windows on start-up of the application. If I had used iconify() the user would be aware of all the windows that had been created because they'd see them as icons. Imagine the shock of a user seeing 10 windows by simply starting up an application! Therefore, I used withdraw() so that each window would appear (via deiconify()) only if the user triggered the right event.

Python/Tkinter: Using the new ttk.Notebook widget (custom font, trapping tab focus/mouseover)

I'm using the new ttk.Notebook widget available in Python 2.7 and Python 3.1.
I'm struggling with the following tasks:
How to change the font associated with notebook tab captions. I want to use a named font object whose size a user controls. (Could a ttk.Style help me here?)
How can I bind to tab specific keyboard focus (<FocusIn>), mouseover events (<Enter>), and rightclicks (<Button-3>). I have a total fail trying to bind to tab specific keyboard focus and mouseover events. I can bind to a <Button-3> rightclick, but I can't figure out how to determine the tab a user clicked on. Using .identify( event.x, event.y ) returns the string 'label' vs. a widget reference.
Is there a way to give tabs an id (the documentation hints at this via tab_id) so we can reference tabs independent of their physical position in an array of tabs?
Thank you,
Malcolm
We're actually answering these questions in the Tkinter mailing list; in fact, I have mixed feelings about saying anything in Stackoverflow apart from, "See the mailing list". It's surely fair to note, though, that this answers the question about fonts, and this heads a thread on tab events.

Dealing with simultaneous button presses and changing shift states

I am currently working on a (Python2.5) application which handles input from a game controller. We've designated a button as a shift button to change the mapping (inputtype,value->function) of the other buttons on the fly. The mapping also depends on the mode our application is running in. We are running into lots of hairy edge cases (e.g. how to handle press shift, press button x, release shift, release button x) and I was wondering if there are any known good structures/architectures/patterns for dealing with this kind of input?
Satemachines are a good pattern to handle complex inputs.
Here is a machine that handle the above sequence.
You can implement statemachines with switch or state pattern (see Python state-machine design )

Categories

Resources