hook into wndproc of another application? - python

I have a small question hoping someone will help me.
Is there any way to hook into other applications WNDPROC?
The situation is that I want to insert a menu in the other app menubar and I want to define the commands for every menu item.
I was able to insert the menu with menu items using some Win32 API
functions (user32.dll), but I can't set the commands of that menu item so that it actually does something if clicked.
With some googling, I got some information about wndprocess, and I should intercept the ID Command sent and trigger some function, but I'm stuck.
Can anyone help me?

You are going about this the wrong way. If you think about it, you'll realize that responding to menu events with your custom "actions" must require some code to run in the process that you're targeting. This means you'll need to inject code into the other process in order to achieve what you want.
Since you're going to need to inject code anyway, I strongly suggest you look at DLL-injecting into the other process (search "Dll Injection example"). This will bootstrap your code into the other process, and you can construct your menu there.
This also has the advantage that the foreign app won't be reliant on your app being responsive - it'll all be in-process.

Related

Anki: Appending New Dropdown Option on MenuBar? (Pycharm, Windows)

Beginner in the whole Python/Anki thing. Learning more about coding for fun and I have set up a debugging environment with pycharm and an Anki profile with the bazelfixes and it seems to start anki up fine. I want to append an extra dropdown menu on the main menu toolbar in Anki so that I can connect the actions to my functions.
I went through the hooks and the toolbar hook worked but it is not exactly what I was going for because it adds to the toolbar, not the menu. I want to add a new dropdown into the actual main menu next to tools, help, etc. connect them to functions I have made. Kind of like this
I have looked at others and sometimes they work partially but it's like a fragmented puzzle some use qmainwindow and it makes a popup separate from anki when I run it, or other approaches where they use the aqt.mw.form() functions in various ways but when I do it it will be like "nonetype doesn't take .form function." or form is not an expected argument. I want to figure out the first basic step.
I have also looked at the aqt MW thing but I am kind of confused about how it works so I am not sure if that is a better approach to read up on. The whole class>def variable> mw.append type of structure I have been seeing in other's code is a little confusing for me. Or am I going about it the completely wrong way and should use html/CSS? Any help or advice is greatly appreciated!
Also here is the bazelfixes code I have been using on pycharm.
try:
import bazelfixes
bazelfixes.fix_pywin32_in_bazel()
bazelfixes.fix_extraneous_path_in_bazel()
bazelfixes.fix_run_on_macos()
except ImportError:
pass
if not os.environ.get(“ANKI_IMPORT_ONLY”):
aqt.run()
TL;DR How do I, within this code on pycharm append an extra dropdown item on the main menu bar. Is there a hook I am missing (not the init toolbar one)? Or a different approach I should try?

Background process and tkinter

Looking for help on where to start with this, not too good with Python. What I trying to do is use tkinter for a gui interface but i need to be able to process recieved data and update labels widgets as information changes. I all ready have the communication portion of my program working fine in the shell but when I try to tie it to tkinter it will stop processing as soon as the interface is generated. Anyone have a simple code for me to modify to my needs or point me to a reference example somewhere. Spent days so far trying different options and I still have yet to find something that works.
Thanks for any help
Convert your working program into functions that you can register as callbacks in the tkinter UI (say buttons, or other widgets), that is, make it event-driven, and then, for background processing register some of the functions with the after widget method. The root.mainloop() will never return (only on UI close), use it as the last instruction.
So you can't just write your logic in a top-down structure, and hope that it will work well with the UI. The mainloop will be permanently looping, and will call specific funtions in your code, as appropriate to the received events from the user, or to callbacks you registered to run after some time with after.
See here for the after part
Take a look here for structuring tkinter programs. It should have enough info and links for you to study and learn how to do it in a right way.

How to catch a specific window that could pop-up in any moment

In the app I'm trying to automate there is an error window that could pop-up in literally any moment of application work. Then I need to perform some actions like logging this event and stop next automation steps. So I need to catch this moment. How can I do it?
This window always has the same properties (auto_id) so I can describe it before it exist. I can think of using something like a timer which will always check for existence of this window (with the help of .exists(), I guess). But maybe there is a better way of doing it?

Inactivate pyside-generated windows for the duration of background task

I have a simple gui application written in python with pyside. There is a main window and also some modal QDialogs. Depending on the user's actions in some of these dialogs, the application might have to connect to a database and perform corresponding tasks in it.
The problem is: database actions might take a few seconds to complete and my users tend to think that the program is stuck, so they start furiously clicking around and mashing keys. To prevent this erratic behavior I want to deactivate all the windows and display some loading symbol to calm things down.
What I need to create (left - normal state, right - busy state):
This is not the actual app, just an approximate schema of what I want to achieve.
I think some kind of QMovie should do the trick, but I have no idea how to cover a dialog with semi-transparent white and to display the loading symbol on top of it. I am also considering QProgressBar, but I am not sure if it's the right solution for the task.
I would appreciate any advice or a link to similar tasks solved (for some reason I was unable to google anything relevant myself, maybe I am using wrong keywords).
Generally, the way you would do this is with some sort of progress indicator, either a QProgressBar or a QProgressDialog.
With the QProgressDialog, you can launch it modally to prevent users from interacting with the base QDialog or QMainWindow.
Either way, you should still be doing the slow-running task in another thread; otherwise, the GUI is just going to freeze. The user won't be able to move the window or dialog, it won't respond to their clicks, and any progress updates you're making won't be shown in the GUI.

How to disable button until check box is checked in pyqt?

I am creating an app and I need to disable a button until the user agrees to the terms. I looked online, but couldn't find anything. Any help would be great.
EDIT: I am using pyqt4.
You should use the strategy of signal/slots in Qt. When the checkbox send the checked signal you catch it with the slot defined in your button. Of course you should connect both widgets. For example:
connect(checkbox, SIGNAL(stateChanged(int)), button, SLOT(buttonStateChanged(int)));
This signals and slots maybe don't exists, and you have to create them. It is just the main idea.
I think that is a right way.
Here are some examples of connections in python, using signal/slots. And here is (maybe) what you need.

Categories

Resources