Cannot change content of an Edit control - ui-automation

I am using pywinauto to open a file in some software. My code is supposed to open a specific file using the Open dialog:
import pywinauto
from pywinauto.application import Application
app = Application(backend="uia").start(cmd_line="C:\\Program Files (x86)\... etc")
app.Dialog.Close.click()
app.FORAM3.Derivative.OpenSpectrum.click()
app.FORAM3.Open.Edit.SetEditText(r"C:\\Users\... etc")
The code opens the software and clicks the "Open Spectrum" button, where it gets the standard Open dialog:
on the line app.FORAM3.Open.Edit.SetEditText("Paracetamol 4.foram") I get a pywinauto.findwindows.ElementNotFoundError which states that it could not find an element or a method called SetEditText.
I have already looked around on the internet and cannot find any solutions.
How to open an existing file using pywinauto from SourceForge says to use app.Open.Edit.SetEditText.
I tried using app.Open.Edit, removing the "FORAM3" part, and it could not find "Open".
I replaced this with app.Dialog.Edit and it gave me the original ElementNotFoundError.
I also looked at Open an existing excel workbook using pywinauto, however the answer to this question suggests opening the file within excel itself, which does not apply to me.
I even tried replacing SetEditText with TypeKeys and got AttributeError: Neither GUI element (wrapper) nor wrapper method 'TypeKeys' were found (typo?)
One answer in another question, "Open file from windows file dialog with python automatically", suggests to use pywinauto and gives the following code:
from pywinauto import application
app = application.Application().start_('notepad.exe')
app.Notepad.MenuSelect('File->Open')
# app.[window title].[control name]...
app.Open.Edit.SetText('filename.txt')
app.Open.Open.Click()
I tried again using SetText and again got the AttributeError saying that it could not find an element or method with that name.
The accepted answer for this particular question says to use ctypes. I may resort to this if I cannot find a solution in pywinauto. The question has also been suggested as a possible duplicate of Choosing a file in Python with simple Dialog so I looked at that.
The accepted answer here suggests to use Tkinter. The other two suggest easygui and Zenity. Not what I'm after. There are no mentions of pywinauto in the other answers.
I am not asking how to open a file. From the answers I've looked at I can clearly see how to do it. My question is: Why isn't it working? It's clear that my code isn't recognising any of these Methods that have been suggested, so there must be something else wrong.
I started using Inspect.exe.
Part of the hierarchy has a Pane with an empty string for a name. This could be the problem, however I've worked on other software with empty panes in. In those cases I have been able to ignore the empty panes and still use the child controls. There are also three different controls with the name "Filename" which could be an issue, however since I have referred to the Edit control, it can only be one of them. I did a quick check to see whether I had to refer to the Edit control as a child of the combo box, used the line app.Dialog.combobox.Edit.SetText, and got the same AttributeError again.
My final attempt at fixing the problem was to try a different console. I have been running my code in PyCharm and found a question on jetbrains asking if it was possible to run code from PyCharm in an external console, stating that the PyCharm console did not have the same low-level control that the windows cmd.exe has.
I ran my code in the IDLE shell, and got the same error:
I tried running the code in the regular python command prompt, and it closes with the same error. This seems enough evidence to suggest that PyCharm itself isn't the issue here.
So, to reiterate: Why doesn't python recognise any Edit control methods?

backend="uia" provides different hierarchy and different method names (sometimes). Default backend is "win32" so old Notepad examples are not always relevant for "uia" backend. Also old CamelCase methods are deprecated in 0.6.5 and they even exist in "win32" backend only. Use PEP-8 method names for "uia" backend like set_text. And upgrade by pip install -U pywinauto.

Related

Adding the run-code option to a new language in VSCode

I'm currently writing my own language and I'm at a point where I would like to publish it to the VSCode-Marketplace so people can test it.
I have written a language extension and a syntax highlighter with the Yeoman-Generator and now want to merge it with my executable file that launches the interpreter, so that a file can get interpreted after clicking the run-code button.
I now have checked multiple articles, like:
How to add a run button in visual studio code? - StackOverflow
How to define or support a code language on Visual Studio? - StackOverflow
Debugger Extension Guide - VSCode API
However, I haven't found anything useful.
Currently, the code-runner displays the following error, when clicking on run, or pressing the shortcut:
(Code language not supported or defined.)
But even after a lot of browsing Google for adding new language support to the code-runner, I found absolutely nothing helpful.
(See this page, idk what Settings/Preferences they are referring to!?)
I also was not successful with tasks, as they don't seem to connect to the run-buttom or debug-button in any way.
My question is: How can I make the run-button execute a custom bash-command, when a file in my language is opened?
Okay, I finally did it.
For anyone wondering:
You have to go to the settings and type "code-runner" into the search bar.
Scroll down a little, and you should find the code runner-executor map.
Click on the "edit in settings.json" button.
Now a .json-file should've opened. There are two possible scenarios: Either, there is a json-object called code-runner.executorMapBy... or not.
If there is none, type code-runner.executorMapByFileExtension and let autocomplete do the job.
If the json-object exists, add the file-extension and a bash command that executes your compiler/interpreter. It gets automatically executed in the directory the program-file lies in.
Now still dont know, how to include the settings in my extension, but that was already a big step. Further help is still appreciated!
There is an open source extension called code runner, you can check source code there.

Fuzzy file opening in vscode

I am exploring vscode after using atom for a long while. One of the things I'm missing is an equivalent of the lovely package advanced-open-file. Is there something similar to this in vscode?
I found the advanced-new-file extension, but it is only helpful when it comes to new files. I would like to be able to quickly open files from all over my local files (not only the workspace).
Edit: I found the option of workbench.action.quickOpen; but it doesn't allow opening files from the whole file system.
Sorry, but currently the answer is no. The problem is that input box doesn't provide a way to listen to key events:
GitHub issue,
so even the extensions can't do that currently. Here's the comment from advanced-new-file extension creator:
Because VSCode extensions don't yet have the ability to do type-ahead autocomplete within the text input box (See https://github.com/Microsoft/vscode/issues/426), we work around this limitation and provide autocomplete using a two-step workflow of selecting existing path, then providing new filename/path relative to the selection.
The good news is that there is a new API addressing this issue, but it's currently in 'proposed' state and can't be used for published extensions.
One workaround could be typing code -r some/path in integrated terminal and using 'tab' for autocomplete.
The Fuzzy search extension seems to work for me.
It adds a new action to the command palette which allows you to search for files in the current project and open them.

Registry command entry isn't running like it runs in command line

My question clarified is, "What's different about running a command from within the registry at command line compared to running the same command from in a command line? Then how do I make it the same to work the way I want?"
Information about my program:
This is a ClickOnce application and from what I see there isn't a great way of getting the exact path of the exe instead of the appref-ms. So there is a caveat to my question this whole thing can be avoided if there was a way to find the exact path of the exe each time the program is deployed and I am able to edit the registry to point to said written down path.
I have this entry in HKEY_CLASSES_ROOT please see evidence below:
So right clicking below should work everything is typed in right, but it doesn't work.
So I figured maybe it didn't like my %APPDATA% which honestly should not matter and I got a new error message.
Just so you know my program does work and it's doing something and pulling paths from the args passed to it.
Thank you for reading my lengthy question.
Here is how you set up what I have been trying to setup for a while now. This explanation is assuming you know exactly what you are trying to do.
Publishing A (Offline) ClickOnce Application With Command Line Args Ran From A Right Click Context Menu Item That You Can Deploy As Many Times As You Want Without Editing the Registry Each Time.
If you are doing an online one just use this CTRL+F and type in deadlydog it has two stellar links in that answer. That is much simpler then this below.
Have a project that is published deployed on a file share using ClickOnce in Visual Studio project properties.
Get this code. (If you need multiple args treat them all as one large string then split it)
'VB.NET style code
Dim activationData() As String = AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData
MsgBox(activationData(0)) 'Your big long argument before being split editted or modified.
Why I asked this question and my answer to it.
Make a registry entry using ContextEdit as if you were making your very normal run of the mill context menu for your program. HOWEVER!!!! click the check box that says "expand environment variables".
So the command that you type in should look like this.
cmd.exe /C ""%InsertEnvironmentVariable%\Path\Name To\Your File.appref-ms" "%1""
It should work from that it was a ton of googling mostly because I have never done this and I give up easily on ideas. Also would like to comment on the information for command line and the registry is atrociously organized and abundant beyond belief.
Hope this helps someone trying to deploy a neat clickonce lightweight program that seems integrated like a normal program.

Matlab failed to open m file

I am new to matlab and I've installed it successfully. Everything works fine. But when ever I try to open .m files, I always get following error popping out of dialog box:
Error using open(line 162)
Failed to open matlab editor.
And in command window it throws a lot of Java exceptions.
First of all please forgive my poor English.
I've been searching for this problem all over the internet but couldn't find any useful solution.
I'm using windows 8.1 pro 64-bit os.
Your error message indicates that there is an error in a line that justs consists of
<br>
This is not valid matlab code (looks more like html). As such it seems like you have either messed up the open function, or overloaded it somehow.
I think the first thing to do is check which open and see where this points you.
If this does not help, try to look at the matlab path carefully and see whether you accidentally added a (html?) file on it called open.m.
Lastly, you could try to use the built in open function directly, check doc builtin for this. If you succeed at least you are sure it is not a matter of corrupting the standard file.

Groovy debugger out of sync

I am having a difficulty while attempting to debug some code in grails. It is difficult to put into text, so I have posted a screencast showing exactly what the problem is here. In short, while I am debugging the debugger starts jumping from place to place and not following the program logic I have in place. The only other similar question I have found is a year old, had no solution, and can be found here.
The best guess I have so far is that the debugger is displaying the text I have typed in, but is actually executing an older version of the class file which it has cached somewhere. Therefore, I tried:
cleaning the project
manually deleting all of the class files from the target folder and from the target-eclipse folder
Searching my entire hdd for additional files with similar names
removing my project from the workspace and re-adding it
closing and reopening the IDE
grails refresh-dependencies
Importing the project into a new IDE (I was using GGTS, I switched to IntelliJ)
None of those solutions had any effect. I realized that the issue was in a .groovy file, and I was writing almost pure Java, so I deleted the .groovy file, and re-created the class in a .java file. That solved my problem. Unfortunately I am having the problem again, and this time it is in a controller that heavily relies on the grails framework, so that solution is not an option. Other than also being in a .groovy file, another similarity is that the code breaks on an if statement.
My next steps:
Verify that the application is not executing the code I see by using print functions to monitor actual execution flow.
comment out the entire function and re-add functionality one line at a time to see if I can see what breaks it.
Delete the .groovy file, and re-create it as another .groovy file.
Any help is appreciated, and since I can't find any answers online I will continue to update this question as I learn more.
See my comment on the jira issue that you raised. You have found a problem with the groovy compiler and how it calculates line numbers. This is not a problem with executing the wrong class files or using a broken debugger. The debugger is doing exactly what it is expected to do. It is the compiler that is providing erroneous line number information.
The next step, as described in the issue, is to provide a simple project that recreates the bug. I tried to do so myself, but could not. So, please supply something that we can work with. Then we can notify the groovy compiler team.