Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update extractDoc.py, gtk autocomplete #841

Merged
merged 6 commits into from
May 20, 2023
Merged

Conversation

sebastiansam55
Copy link
Contributor

Updates extractDoc.py, this will now generate the qt api.txt and two files for gtk autocompletion, api.csv and macro.csv.

Adds autocompletion to Gtk for both the phrase and script pages.

At this time I don't see any easy way to add autocompletion to the Qt phrase pages.

@sebastiansam55 sebastiansam55 marked this pull request as ready for review April 22, 2023 14:31
@sebastiansam55
Copy link
Contributor Author

@josephj11 or @Elliria (or anyone else that reads this)

Can y'all install this and test the autocomplete for a bit before we merge it in?

@Elliria
Copy link
Contributor

Elliria commented Apr 22, 2023

Sure, but first, what does it do? I'm not clear on what's being auto-completed or what would need to be done to test if it's doing what it ought to do.

@sebastiansam55
Copy link
Contributor Author

sebastiansam55 commented Apr 22, 2023 via email

@Elliria
Copy link
Contributor

Elliria commented Apr 22, 2023

Oh, how nice!

@Elliria
Copy link
Contributor

Elliria commented Apr 22, 2023

Okay, I've cloned it with this command:

git clone --branch develop-autocomplete --single-branch https://github.com/autokey/autokey.git

Now, how do I run it without installing it? It looks like our Zero-installation Method instructions are outdated and will need an update.

@sebastiansam55
Copy link
Contributor Author

sebastiansam55 commented Apr 22, 2023 via email

@Elliria
Copy link
Contributor

Elliria commented Apr 22, 2023

There are no prior instances of AutoKey and it's not even installed in this VM. Here's what happens when I follow those steps in an up-to-date copy of Kubuntu 22.04 LTS:

elliria@elliria-VirtualBox:~/Desktop/autokey$ cd lib
elliria@elliria-VirtualBox:~/Desktop/autokey/lib$ python3 -m autokey.gtkui
Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/elliria/Desktop/autokey/lib/autokey/gtkui/__main__.py", line 4, in <module>
    from autokey.gtkapp import Application
  File "/home/elliria/Desktop/autokey/lib/autokey/gtkapp.py", line 35, in <module>
    from autokey.autokey_app import AutokeyApplication
  File "/home/elliria/Desktop/autokey/lib/autokey/autokey_app.py", line 32, in <module>
    from autokey import service, monitor
  File "/home/elliria/Desktop/autokey/lib/autokey/service.py", line 33, in <module>
    from autokey.iomediator.iomediator import IoMediator
  File "/home/elliria/Desktop/autokey/lib/autokey/iomediator/iomediator.py", line 24, in <module>
    from autokey.interface import XRecordInterface, AtSpiInterface
  File "/home/elliria/Desktop/autokey/lib/autokey/interface.py", line 41, in <module>
    import Xlib.threaded as xlib_threaded
ModuleNotFoundError: No module named 'Xlib'
elliria@elliria-VirtualBox:~/Desktop/autokey/lib$ python3 -m autokey.qtui
Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/elliria/Desktop/autokey/lib/autokey/qtui/__main__.py", line 23, in <module>
    from autokey.qtapp import Application
  File "/home/elliria/Desktop/autokey/lib/autokey/qtapp.py", line 33, in <module>
    from autokey.autokey_app import AutokeyApplication
  File "/home/elliria/Desktop/autokey/lib/autokey/autokey_app.py", line 32, in <module>
    from autokey import service, monitor
  File "/home/elliria/Desktop/autokey/lib/autokey/service.py", line 33, in <module>
    from autokey.iomediator.iomediator import IoMediator
  File "/home/elliria/Desktop/autokey/lib/autokey/iomediator/iomediator.py", line 24, in <module>
    from autokey.interface import XRecordInterface, AtSpiInterface
  File "/home/elliria/Desktop/autokey/lib/autokey/interface.py", line 41, in <module>
    import Xlib.threaded as xlib_threaded
ModuleNotFoundError: No module named 'Xlib'
elliria@elliria-VirtualBox:~/Desktop/autokey/lib$ 

@sebastiansam55
Copy link
Contributor Author

sebastiansam55 commented Apr 22, 2023 via email

@Elliria
Copy link
Contributor

Elliria commented Apr 22, 2023

Install the one from the Ubuntu repository normally and then do the Zero-installation method inside of the cloned directory?

@sebastiansam55
Copy link
Contributor Author

sebastiansam55 commented Apr 22, 2023 via email

@Elliria
Copy link
Contributor

Elliria commented Apr 22, 2023

That worked! It's very cool. Is there any way to have it auto-detect that you're inside of a comment and have it not fire?

For example, this should not trigger the menu:

# Blah blah blah keyboard.

Neither should this:

'''
Blah blah blah keyboard.
'''

Nor should this:

"""
Blah blah blah keyboard.
"""

@Elliria
Copy link
Contributor

Elliria commented Apr 22, 2023

Also, can the drop-down offerings be sorted alphabetically?

It's very cool. I can see how this would save a lot of time and effort, especially if you're writing a script with a lot of API calls in it.

@sebastiansam55
Copy link
Contributor Author

I might update it so that it doesn't autocomplete when on a line after a #, I'm sure the other one is possible but not something I'm super interested in doing.

It's mostly there to give you a quick reference on what methods are available.

yeah, idk what the deal with the 3.10 test was, I cancelled it, not sure why it was looping, can't imagine how this type of change would have impacted the tests, I don't think there's any coverage for anything that I touched here

@Elliria
Copy link
Contributor

Elliria commented Apr 22, 2023

Yeah, I think the test is a problem at GitHub's end. I had one that cancelled after a while the other day. They may be doing work on those.

@Elliria
Copy link
Contributor

Elliria commented Apr 22, 2023

Okay, disabling it in lines that start with # would be wonderful. The other two are used less frequently, anyway. Also, I noticed that you can press something like an arrow key to turn off the drop-down menu if you don't want to use it. I'd still like it not to show up on the hash-mark lines, though, because I comment the heck out of my code and am likely to trigger it.

@Elliria
Copy link
Contributor

Elliria commented Apr 22, 2023

This is absolutely awesome, @sebastiansam55. I have a feeling @josephj11 is going to love it, too.

@Elliria
Copy link
Contributor

Elliria commented Apr 22, 2023

Are you planning on doing the store API call, too?

@sebastiansam55
Copy link
Contributor Author

@Elliria I actually forgot about those functions, I've added them in, you should be able to git pull and then relaunch it and it will be sorted and have the store api now

@Elliria
Copy link
Contributor

Elliria commented Apr 22, 2023

Okay, I'll do that. I'm running out of time, though. This is New York and we're about to get hammered by storms.

By the way, I've updated the Running Tests wiki page by adding the Trying out a clone of AutoKey section so that anyone who'd like to help out the developers by trying out their code can do so without having to install it. As always, feedback is welcome, as are edits.

Please ignore the outdated Running unit tests section on that page. That will be taken care of once we've got something solid to replace it with.

@josephj11
Copy link
Contributor

@sebastiansam55 Could you give us a hand on how rebasing and merging works so we do it the right way? You seem to have it down.

@josephj11
Copy link
Contributor

josephj11 commented Apr 22, 2023

I have used autocomplete a bit in AutoKey before. It seems to work - at least in the Qt version.

I primarily use the Qt version, but I will try to test your new changes in the GTK version.

The main problem I have is that (especially in Qt) the editing panel theme is almost unusable in Breese dark. Most text is almost invisible and the cursor is completely invisible - so I do almost all my editing in kate where I can see what I'm doing.

I tried the GTK version a while ago. It had the same problems. I was able to select a different theme (using the option that was added to the GTK version) and that helped a lot. I don't remember if the cursor was fixed as well.

@Elliria
Copy link
Contributor

Elliria commented Apr 23, 2023

Thank you for adding the store functions and for alphabetizing the entries in the auto-complete menu. That's perfect.

I tested both the GTK and Qt auto-complete behaviors and noticed a difference between them:

  • The GTK auto-complete menu shows you the name of each API call followed by prompts for the arguments inside of parentheses followed by a description. When you select one and press the Enter key, it prints the full API call with the prompted arguments inserted for you.
  • The Qt auto-complete menu shows you just the name of each API call. When you select one and press the Enter key, it prints just the name of the API call. If, however, you continue typing out the API call, it prompts you as you do to guide you through the process.

In each test, I saw some X protocol errors that had something to do with Xlib.error.BadAccess. Those may or may not be related to the auto-complete code, but I thought I'd mention them as a possible matter of interest.

Below are the steps I took, the logs from each session, a couple of animated GIFs, a screenshot, and a final follow-up with some odd behavior after getting rid of the clone directory.

SHOW THE TESTS


GTK test:

  1. I cloned the develop-autocomplete branch of AutoKey:
    git clone --branch develop-autocomplete --single-branch https://github.com/autokey/autokey.git
  2. I launched the GTK front-end of AutoKey in verbose mode with the main window opening on startup with this command: python3 -m autokey.gtkui -cl
  3. I opened a script and typed this part of an API call: keyboard.
  4. The auto-complete menu opened and I scrolled down to the press_key entry and pressed the Enter key.
  5. It finished the command this way, with the two parentheses highlighted: keyboard.press_key(key)
  6. Here's an animated GIF showing the interaction with the auto-complete menu:
    GTK
  7. I closed the AutoKey main window.
  8. I right-clicked the AutoKey tray icon and chose Quit from the context menu.
  9. The AutoKey icon vanished and I was returned to a plain prompt in the terminal window.
  10. I copied the log information to this text file: GTK.log

Qt test:

  1. I launched the Qt front-end of AutoKey in verbose mode with the main window opening on startup with this command: python3 -m autokey.qtui -cl
  2. I opened a script and typed this part of an API call: keyboard.
  3. The auto-complete menu opened and I scrolled down to the press_key entry and pressed the Enter key.
  4. It finished the command this way, with no parentheses and no argument: keyboard.press_key
  5. Here's an animated GIF showing the interaction with the auto-complete menu:
    Qt
  6. I closed the AutoKey main window.
  7. I right-clicked the AutoKey tray icon and chose Exit AutoKey from the context menu.
  8. Nothing happened.
  9. I copied the log information to this text file: Qt.log
  10. I clicked the X in the upper right corner of the terminal window to try to close it.
  11. I got a pop-up window from the terminal window letting me know there was a process still running and asking if I really wanted to close it. The process it showed was python3.
  12. I told it I really did want to close it by clicking the Close Window button.
  13. It closed.
  14. I opened a terminal window and checked if AutoKey was still running with the pgrep -c autokey command.
  15. It returned a zero, letting me know that AutoKey had been successfully shut down.

Qt test again a bit differently:

  1. I launched the Qt front-end of AutoKey with the main window opening on startup with this command: python3 -m autokey.qtui -c
  2. I opened a script and typed this part of an API call: keyboard.
  3. The auto-complete menu opened.
  4. I continued typing. Now I had this: keyboard.press
  5. The auto-complete menu reacted to the change and offered me only keyboard API calls that started with press.
  6. I continued typing. Now I had this: keyboard.press_key
  7. The auto-complete menu closed.
  8. I continued typing. Now I had this: keyboard.press_key(
  9. The auto-complete menu opened again and displayed the name of the API call followed by an argument prompt inside of parentheses followed by a description of the API call. Note that it won't auto-type for you if you press the Enter key while that's being displayed, but you can use it as a reference to help you figure out the structure of the command while you continue typing.
  10. Here's a screenshot of that:
    QtIfYouKeepTyping
    You don't need the rest of these steps since they've already been done above.

Odd behavior after deleting the clone

Last, but not least, I manually deleted the clone's directory when I was finished with the tests. I then ran AutoKey from the KDE menu, which should have run the standard installation of AutoKey 0.95.10 that I had installed from the Ubuntu repositories before grabbing the clone. When I launched the GTK front-end and tried to trigger the auto-complete menu, it wouldn't trigger, so I reassured myself that I was running the correct version of AutoKey. When I ran the Qt front-end of AutoKey, however, and tried to trigger the auto-complete menu, it triggered. This means the cloned Qt front-end is still running even though I deleted the directory.

I did the sudo updatedb command to update the database used by the locate command then then I did the locate autokey command to see where it is on my system. That resulted in this WhereIsAutoKey.txt list, which doesn't have anything in it that immediately jumped out at me as odd, but I'll use @josephj11's technique of staring at it tomorrow (it's bed-time here) to see if I can't figure it out. It's possible I got rid of the clone incorrectly. Is there some housekeeping involved in that that I overlooked?

@sebastiansam55
Copy link
Contributor Author

With Autokey 0.96 it updates config files in a way that breaks backwards compatibly iirc, related to the sidecar file changes.

and yeah, the Qt/GTK autocomplete behavior is not going to be exactly the same, they use different underlying systems for the auto complete.

@josephj11 re: git, I know enough to be dangerous and that's it.

I'm very much a self taught programmer, and to that end, the best way to figure things out is to do them, you should make a fork of autokey and then open a PR on your for for master>develop and see what issues arise and learn about it.

@Elliria
Copy link
Contributor

Elliria commented Apr 23, 2023

@josephj11 re: git, I know enough to be dangerous and that's it.

That was a terrific line. I'll second it.

@sebastiansam55 sebastiansam55 merged commit 9140642 into develop May 20, 2023
6 checks passed
@Elliria
Copy link
Contributor

Elliria commented May 21, 2023

Well done, @sebastiansam55. It's a wonderful new feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants