Dealing with simultaneous button presses and changing shift states - python

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 )

Related

Can I put input in Mindstorms 51515 while programming in python?

When I was programming in Mindstorms Robot Inventor, and decided to put an input in my code, I bumped into this NameErrorThis is the Error
Is it Even possible to put an input in Mindstorms??
The Python available isn’t the complete Python standard library. The terminal view in the code editor doesn’t provide for a way to put in input either, so unfortunately no.
What you can do instead is use the buttons on the hub as a type of input. This wouldn’t be free-form text, but if you’re using input() as a user-controlled wait before progressing, you can do that.
_ = hub.right_button.was_pressed() # clear out any button press
while not hub.right_button.was_pressed():
# do something
# do something after the button was pressed
You can string multiple of the above in a row if you want to do multiple actions separated by waiting for you to let it continue, or even take different actions based on which button was pressed.
Finally, you could do a very slow text input using the buttons and the display screen to scroll through the alphabet, confirm the letter, and finish the input.

Keyboard output to multiple programs simultaneously?

My issue currently is that of emulating keystroke input to an arbitrary program (such as a running game).
Currently I am using win32 libraries on Windows to find windows (win32gui.FindWindow) and grab focus (via win32gui.SetForegroundWindow), then send keyboard input (win32api.keybd_event).
This works if I am only sending input to a single program, but I wish to parallelize, playing multiple games simultaneously. This does not work with my current method as both applications demand "focus" for the keys to go to the right application, thus interfering with each other.
Ideally I would like something that sends input to a given window, that does not require focus , and is independent of input given to other windows or the currently focused window.
My understanding is, only the foreground window get the focus and can handle keyboard input to play. Not sure in make sense to send input to background window or not....

wxpython control problems when migrating from win to mac

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"

How to read/edit a GUI/MFC application in Python?

I want to automate one of my tasks, by changing a third-party GUI/MFC application's properties as per my requirements. Every time I need to carry out any testing, I need to change the properties of the application to test my software.
I tried to automate it by using Python and IronPython. After Googling a lot I found IronPython, because the GUI is written C# and VB.NET.
Suppose when opening the GUI in its editor it gives me the option to edit the properties, MFC contains lots of controls.. e.g.:
Enter Time |__| //Need to enter the value in the box
Enter the dealy |__| //Need to enter the value in the box
Want to display |_| //Check box , check or uncheck
some Radio buttons.
Some more controls.
....
....
I want to control all the changes from my Python script. I will just enter the value from my script and it will update them in the GUI.
I wrote a script in IronPython to read the GUI:
fw = open("MyFile.vnb", 'r')
for line in fw.readlines():
print (line)
I found plenty of encrypted/encoded characters along with some of the C#/VB.NET codes in the console. So, I am completely stuck here.
I would like to know can we edit a third-party GUI with Python/IronPython or not? Do I need to use some special tools from Python to edit the GUI?
If you need classic GUI automation you can control MFC application by pywinauto library. You can send keyboard events, mouse clicks, moves etc. pywinauto has also limited support for .NET controls (simple automation like buttons, text boxes etc. is available). I guess this is realistic task (see sample video by the link above).
But if you need some binary instrumentation to change the GUI executable permanently (it sounds strange), this is completely another topic. Read about PIN tool. It's used for profilers development, for example. Collecting stack samples, unwinding call stacks and other tricky reverse engineering things. :)

wx.SpinButton acceleration when holding down one of the buttons (up/down)

Some GUI's libraries have spin button widget with optional feature - acceleration.
When holding down one of the buttons (up or down) - as a result an acceleration of change in the value according to how long it is depressed.
Is this feature in wx.SpinButton and what's the best way to implement it?
No, that's not a built in feature of the SpinButton. Note that the SpinButton isn't implemented cross-platform, so you might want to look at wx.SpinCtrl or FloatSpin. Anyway, to implement what you want, you could probably catch the wx.EVT_SPIN and start a wx.Timer. When the timer hits some pre-determined value, you could start updating the control yourself. I'm not sure if this would work as you would be trying to update a widget that is already being updated, but it might...
Of course, you'd also have to bind to the mouse up event to stop the timer and stop the updates. I suspect you my have to roll your own widget though...
I would ask on the wxPython mailing list. Someone there might have more ideas.

Categories

Resources