I want to know if it is possible to extract data out of any windows application.
The problem i am facing is that i want to be able to monitor the text that is being generated on a certain label field on an window application i have running on my desktop.
I want to know if there is a python library or way to read the values generated by the application.
Just to make it clear an example would be:
If i use the default calc.exe on windows and i want to run a script to get me the answer being displayed on the calc application.
Related
I am developing a program that parses a file searching specific data requested by a user and returns that requested data as a .csv file. I have the main functionality of the program completed and tested it through manually changing variables which represent potential user inputs. The program is comprised of several scripts forming specific functionality modules.
At this point I am working on development of the GUI with Tkinter in order to obtain the user inputs for use in running the program. All of the user inputs are stored in the user_input.py file I have created. The other scripts then import specific items from user_input.py for use in the parsing functions. The issue I am running into is I select a file to parse through the GUI and store that file name as a global variable into user_input.py but cannot run the other scripts which need that input (the actual parsing of the file) until the GUI window is closed (i.e. mainloop() is completed).
I am new to programming and just learning on my own through development of this program. This boils down to two questions.
Do I have some fundamental misunderstanding of project structure which is causing this issue (i.e, I want to gather user input, run a program that relies on that input, output the results of that program back to the user, have them act on those results to generate final results which are stored as a .csv file)?
How do I run a program relying on user inputs while maintaining the GUI on screen without breaking mainloop()
I cannot figure out a way to do what I want in the order specified without closing the GUI to allow the rest of the program to run. Any help is appreciated.
I am trying to upload a file to a website, and when I click on the upload button (using module WebBot) it opens Windows Explorer. Am I able to output the name of the file into the File Name field? I have the full path of the file, I just need to get the actual text into the File Name box.
I'd consider two approaches here:
Use a python library specifically for interaction with the Windows GUI. I've had good experiences with Pywinauto once, seems still pretty usable at first glance. Hook this in when you expect the explorer window to open. Code may conceptually look like this - do some test run and print all available handles from the upload dialog (just guessing here as a hint, see Pywindocs):
app = Application().connect(title_re=".*Upload file", path=r"c:\windows\explorer.exe")
dlg = app.window(title_re=".*Upload file", path=r"c:\windows\explorer.exe")
app.dlg.print_control_identifiers()
Check if you could simply do a POST or similar with the corresponding data. This is a very vague alternative as you do not provide information about what to upload and what the underlying backend/concept of the website is, but in the simplest case this may even be a more elegant option. A quick search brought up this short and simple example for this: https://stackoverflow.com/a/43942648/10192615
I'm interested in writing an OS X service and figured python would be the easiest way. Is it possible to write a script to get the active PDF in the foreground window of any app, and then open that file (or a copy) in a different app?
What function calls would I need to get this done? Would it be easier to do this with AppleScript?
Edit: Apparently, the application I want to send the PDF to (Papers 2) isn't AppleScriptable. Python it is, I guess.
I want to collect data and parse it eventually from an open window in linux.
An example- Suppose a terminal window is open. I need to retrieve all the data that appears on that window. After retrieval, I would parse it to get specific commands entered.
So is it possible to do that? If so, how? I would prefer to use python to code this entire thing.
I am making a guess that first I would have to get some sort of ID for the open window and then use some kind of library to get the content from the window whose ID I have got.
Please help. I am quite a newbie.
You can (ab)use the assistive technologies support (for screen readers and such) that exist in the toolkit libraries. Whether it will work is toolkit specific—Gtk and Qt have this support, but others (like Tk, Fltk, etc.) may or may not.
The Linux Desktop Testing Project is a python toolkit for abusing these interfaces for testing GUI applications, so you can either use it or look how it works and do similar thing.
I think the correct answer may be "with some difficulty". Essentially, the contents of a window is a bitmap. This bitmap is drawn on by a whole slew of primitives (including "display this octet-string, using that encoding and a specific font"), but the window contents is still "just pixels".
Getting the "just pixels" is pretty straight-forward, as these things go. You open a session to the X server and say "given me the contents of window W" and it hands it over.
Doing something useful with it is, unfortunately, a completely different matter, as you'd potentially have to (essentially) OCR the bitmap for what you want.
If you decide to take that route, have a look at the source of xwd, as that does, essentially, that.
Do you have some sort of control over the execution of the terminal? In that case, you can use the script command in the terminal session to log all interaction to a file and then read and parse the file.
$ script myfile
Script started, file is myfile
$ ls
...
$ exit
Script done, file is myfile
$ parse_file.py myfile
If the terminal is running inside of screen, you have other options as well. Screen has logging built in, screen -X sends commands to a running screen session (man screen).
I was thinking that for a learning project for myself, I would try to make a GUI for ffdshow on linux, using tkinter. Wanted to make sure this project would be feasible first, before I get halfway through and run into something that cant be done in python.
Basic idea is to have a single GUI window with a bunch of drop down boxes that have the various presets (like format or bitrate), as well as a text box where a custom number can be entered if applicable. Then when all the options are selected, the user hits the Start button on the GUI and it shows a progress little bar with a percentage. All the options selected would just send the relevant selections as cli arguments for ffdshow, and begin the conversion progress (essentially turning all the user's input into a single perfect cli command).
Is all this doable with python and tkinter? and is it something that a relative newb with only very basic tkinter experience could pull off with books and other python resources?
Thanks
That is precisely the type of thing that python and Tkinter excel at. And yes, a relative newbie can easily do a task like that.