window message not received using python win32api - python

I am using win32 packages to send messages to a window. I manage to get the handle and apparently the message is sent as I get return value 0 from send code. however it has no action in the window, and spyxx does not see the message on the specified handle.
my window has no child window and is class UnityWndClass. (I believe it uses a 64 bit process as it was not visible with spy++?)

Running the IDE as admin made it work (the program also requires admin)

Related

Python2.7 + Bluez 5.61 + dbus - InterfacesRemoved never called

I'm trying to get a raspberry scanning for Bluetooth devices using Bluez 5.61.
I need this raspberry to be able to detect when a Bluetooth device (here, another Raspberry also using Bluez) cannot be detected anymore.
I was thinking using InterfacesRemoved signal from dbus but I guess I don't understand properly how it works as it's never called.
My questions:
I'm not sure I understand properly what interfacesAdded and interfacesRemoved are used for as they are rarely called when expected (propertiesChanged works fine)
Is it possible to get a signal for each advertisement message received even if the content has not changed since the last one? That would allow me to set up a timer to trigger the "non detectable anymore" event.
Here is the code I use to register my signals:
self.bus.add_signal_receiver(
self._interfaces_added,
dbus_interface=common.OBJECT_MANAGER,
signal_name="InterfacesAdded")
self.bus.add_signal_receiver(
self._interfaces_removed,
dbus_interface=common.OBJECT_MANAGER,
signal_name="InterfacesRemoved")
self.bus.add_signal_receiver(
self._properties_changed,
dbus_interface=common.DBUS_PROP_IFACE,
signal_name="PropertiesChanged",
arg0=common.DEVICE_INTERFACE,
path_keyword="path")

How to prevent win10Toast notifications from disappearing?

I want to send windows notification about some important message via python. I have tried win10Toast, but notifications disappear after program is finished.
My code is:
## program to generate a simple toast notifier
from win10toast import ToastNotifier
## instantiating the class
n = ToastNotifier()
n.show_toast("Test Message","Notification body",duration=15)`
It runs fine as long as my program is running, but it disappears after the program is finished. I want to show this message in system tray until user discards this message.
Secondly can you please tell me how to see notification history?
I am using Python 3.7 and Windows 10
change "duration=15" for 'duration=None

Python tkinter Capture windows system shutdown

I'm trying to get my tkinter app (python 3.4.2) to be aware of the system shutdown event so it can release the sqlite3 connection and close a log. I found a post from 2009 about using the win32 api module. I can't get the posted sample to work as I expect (I may not understand it), where a message should cause the wndproc function to fire.
2009 reference:
Python - Windows Shutdown Events
Any other good references or pointers to how to accomplish this?
Typically you want to close the connection anytime the app closes, even if it wasn't a normal closure (ie: by picking "Exit" from a menu). The normal way to do that is to set up a handler for the WM_DELETE_WINDOW protocol (something of a dinosaur left over from when tk only worked on X11 systems). I don't know for certain your app will be notified this way when the system shuts down, but it probably does.
For more information see this question on stackoverflow: Intercept Tkinter "Exit" command?

Tkinter wait for tcp input/output

I wrote a networked chatroom server and client and it works in a simple Terminal environment just fin, and just today started to translate it to over to a GUI form using Tkinter. The sending of messages is fine as I can handle them with button press event handlers and key handles, but the problem is receiving messages. I need to be able to check to see if data has been received while still in the Tkinter window. Is there a nice way of doing something like this? I've tried checking every second using the root.action(time,event) call, but that didn't seem to work, and have just tried running loops in different spots (against my better judgement).
What can I do to have Tkinter listen to something outside of itself, but still be listening to the events going on within my Tkinter window?
See
How do you run your own code alongside Tkinter's event loop?
In particular, the comment about setting the timeout to 0 in the Tk().after() call, so you have non-blocking, outside the Tk event loop code handling possibilities.
Hope that helps.

Python desktop software with web interface

I am building desktop software with a Python backend and a web interface. Currently, I have to start the backend, then open up the interface in the browser. If I accidentally refresh the page - then that clears everything! What I'd like to do is start the application and have a fullscreen browser window appear (using Chrome) - that shouldn't be difficult. I have two questions:
Can refresh be disabled?
Is it possible to hook into closing my program when the web UI is closed?
Update:
What I'm looking for is more like this: geckofx. A way to embed a Chrome webpage in a desktop app. Except I'm using Python rather than C#
Your first question is a dup of disable f5 and browser refresh using javascript.
For your second question, it depends on what kind of application you're building, but generally, the answer is no.
If you can rely on the JS to catch the close and, e.g., send a "quit" message to the service before closing, that's easy. However, there are plenty of cases where that won't work, because the client has no way to catch the close.
If, on the other hand, you can rely on a continuous connection between the client and the service—e.g., using a WebSocket—you can just quit when the connection goes down. But usually, you can't.
Finally, if you're writing something specifically for one platform, you may be able to use OS-level information to handle the cases that JS can't. (For example, on OS X, you can attach a listener to the default NSDistributedNotificationCenter and be notified whenever Chrome quits.) But generally, you can't rely on this, and even when you can, it may still not cover 100% of the cases.
So, you need to use the same tricks that every "real" web app uses for managing sessions. For example, the client can send a keepalive every 5 minutes, and the server can quit if it doesn't get any requests for 5 minutes. (You can still have an explicit "quit" command, you just can't rely on always receiving it.) If you want more information on ways to do this, there are probably 300 questions on SO about it.
Instead of embeding Chrome, you may embed only Webkit ( I don't know on Windows, but on Mac and Linux is easy).
Application logic seams to be on server side, and browser used only as interface. If that is the case, you may put „onbeforeunload” in body tag, and call a js function that send an ajax request to server to die.

Categories

Resources