How to get the Input and Output of an external Executable? - python

I wannted to dig deeper in automation but didnt find anything about gettin information from any Executable.
What i want is to start an exe via Python so python can watch what happens when i press a button or do smt else in that external Programm. And with that given data i want to automate the external Programm and give it the Data to press the button it self.
Like silenium, where i know the code and can directly interact with it.
Is there any way to do so?
I was looking for that type of automation. And landed somewhere where u can use subprocess but couldnt find a way to give me that what i want to do or i just didnt get it right.

Related

pywinaudio doesn't recognize all of the controls in Audacity

Hello I'm once again looking for help. While trying to automate Audacity I came to a problem with what I could find being that it doesn't recognize the sub menu Audacity uses. Whenever I run this code:
app = Application(backend= 'uia').start(r'C:\Program Files (x86)\Audacity\audacity.exe')
app.Audacity.menu_select('File->Import')
app.Audacity.menu_select('Import->Audio... Ctrl+Shift+I')
It can't select the audio part (The whole submenu of Import is this way) but tries to find the nearest name to that, which apparently is somewhere in the transport menu. Also when I try to run print_control_identifiers() it doesn't show the submenu or any submenu in fact, even when trying to control the depth, it doesn't find the submenu.
you can use 'inspect.exe' to identify the control on your application, you can try UIA or MSAA to see which automation tech is feasible for the application.
or you can use other tools AccessBridgeExplorer or clicknium recorder to check whether the control can be recognized.

How do I make an interactive application at the command line with Python, rather than just a script which returns output?

I would like to make a command line application in Python which, when I call its name, launches a new "mode" or interface at the command line, like launching Vim or Mutt, where key presses like 'q' or 'y' have specific functions - rather than just a script you run which returns some output.
How do I make this? Is there a specific library I would use for making this application? Or are there specific commands that tell the shell to display a kind of "window", and to listen for key presses and to execute commands on them?
You can take a look at this question, there are some useful advices. In particular the best option seems to be the curses extension module.
I suggest also to check out this project that can give you an useful example to do what you ask, even if it uses a GUI kit.

Make a full terminal window application like Vim/Mutt/Cmus

I'm not sure quite how to word this, which is probably why I'm having trouble finding an answer.
I have a command line script that runs a rummy game, I want it to take over the terminal kind of like how Vim or Mutt does, so that each round is refreshed in the full terminal window rather than just printing out row after row of text.
Can someone tell me what that is called, so I can research it and find out how to do it?
Repo: https://github.com/sarcoma/Cards
You're looking for a console user interface. One of the best libraries for python would be http://urwid.org/
As mentioned in a comment "pythons curses module does what you require".
This is what you need to take over the terminal: https://docs.python.org/3.9/howto/curses.html

Python compile a script within a GUI

I am currently working on the final year project for my degree. I have chosen to research and develop a tool to aid the delivery of the new Computing curriculum that is coming to schools next year.
I am using a Raspberry Pi in my development, and I aim to teach extremely basic Python programming to children between the ages of 8 and 10. They are going to be able to control some hardware attached to the Pi using a simple API that I am going to create.
My question is: I would like to be able to create a GUI for the children to work in, which would allow them to write and compile scripts. This is mainly to get away from the unfamiliar interface of Linux and terminals etc, and put them in a friendly, basic interface which will pretty much just allow them to write their code and click a big red button to compile and run it to interact with the hardware. Is it possible to allow for text to be written in a GUI and then compiled when the button is pressed?
I am pretty new to Python myself so I am not as clued up as I'd like to be about the specifics of it. I know that it is possible to have the output of IDLE inside of a tkinter interface, and that it is possible to have text boxes for user input and stuff, but would it actually be possible to compile a script on button press and then run it? I have been thinking that maybe threading is the answer. Perhaps I could create a new thread to do it when the button is pressed?
My apologies if this is incredibly basic, but I am having no luck finding any answers about how I would do this. I think it's mainly because I am unsure on what exactly to ask for.
I appreciate any feedback/help, thank you very much.
Dell
Have your GUi write the Python code to a file, then dynamically import using the imp module. I actually do something similar :-)
import imp
hest = imp.load_source("Name", Path)

Python Image processing screenshots

I'm trying to write a program than will detect when my mouse pointer will change icon and automatically send out a mouse click. Is there a better way to do this than to take screenshots and parse the image for the mouse icon?
EDIT:
I'm running my program on windows 7.
I'm trying to learn some image processing and make a simple flash game i made automated.
Rules: when the curses changes shape, click to get a point.
Also what imaging modules for python will allow you to take a specific size screenshot not just the whole screen? This question has moved to a new thread: "Taking Screen shots of specific size"
The way to do this in Windows is to install either a global message hook with SetWindowsHookEx or SetWinEventHook. (Alternatively, you could build a DLL that embeds Python and hooks into the browser or its Flash wrapper app and do it less intrusively from within the app, but that's much more work.)
The message you want is WM_SETCURSOR. Note that this is the message sent by Windows to the app to ask whether it wants to change the cursor, not a message sent when the cursor changes. So, IIRC, you will want to put a WH_CALLWNDPROC and a WH_CALLWNDPROCRET and check GetCursorInfo before and after to see if the app has done so.
So, how do you do this from Python? Honestly, if you don't already know both win32api and friends from the pywin32 package, and how to write Windows message procs in some language, you probably don't want to. If you do want to, I'd start off with the (abandoned) pyHook project from UNC Assist. Even if you can't get it working, it's full of useful source code.
You should also search SO for [python] SetWinEventHook and [python] SetWindowsHookEx, and google around a bit; there are some examples out there (I even wrote one here somewhere…)
You can look at higher-level wrapper frameworks like pywinauto and winGuiAuto, but as far as I know, none of them has much help for capturing events.
I believe there are other tools, maybe AutoIt, that have all the functionality you need, but not in Python module. (AutoIt, for example, has its own VB-like scripting language instead.)

Categories