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
Related
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)
Using python-can library here. Here's a simple code to print out can messages:
from can.interface import Bus
bus = Bus(bustype='pcan', channel='PCAN_USBBUS1', bitrate=500000)
for msg in bus:
print(msg)
It runs just fine until I stop the program (running this in Pycharm IDE) and try to run it again. It will show this error:
can.interfaces.pcan.pcan.PcanError: A PCAN Channel has not been initialized yet or the initialization process has failed
I can't figure out why that is. It's fixed by 'restarting' the program, either by reinserting the CAN Dongle or by restarting Pycharm. Is it because the previous instance was cached somewhere? Would appreciate advice on this.
If I'm not mistaken you never shut down the first instance of the bus. You must call bus.shutdown() at the end of your script. If you do not call bus.shutdown() before you run it again, you are trying to instantiate and already existing bus instance.
This will happen, when your application will not close the channel with CAN_UnInitialize(), or when you break the application with a debugger. So please uninitialize the channel before you close your application, or reboot your system once.
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?
I wrote a python script that uses win32com.client.Dispatch("Outlook.Application") to send automated emails through outlook.
If I run the script myself everything works perfectly fine. But if I run it through Window's task scheduler it doesn't send the emails.
Just to check if I am running the script properly I made the script output a random text file and that works but email doesn't. Why?
Do you add any attachments to an email before you send it? I had a similar problem but it is working perfectly now. If I had two different functions in my script to send emails (for example one to send an email in the event of an error, and one to send an email if the script ran successfully) I would get an 'operation aborted' error from Outlook. This was because in one of the functions I would add an attachment to the email, however in the other function I wouldn't. Don't ask me why but this would cause an error. To resolve I just had to add a redundant attachment to the email that didn't need an attachment.
def emailComplete():
ol = DispatchEx("Outlook.Application")
Msg = ol.CreateItem(0)
Msg.To = "recip#ient.com"
Msg.Subject = "foo complete"
Msg.Attachments.Add("C:\Path\to\blank\attachment.txt") # send a blank attachment to stop the 'operation aborted' error
Msg.Send()
ol.Quit()
def emailError():
ol = DispatchEx("Outlook.Application")
Msg = ol.CreateItem(0)
Msg.To = "recip#ient.com"
Msg.Subject = "foo errored"
Msg.Attachments.Add("C:\path\to\error\file.txt") # send the error file with the email
Msg.Send()
ol.Quit()
It's not the most elegant solution, but it's got mine working!!
My similar issue has been cleared up. I used task scheduler to call a python script (via batch file) that has the pywin32com module. The python code opens excel and calls a macro. It will run fine from python, cmd and the batch file, but wasn't working when ran through task scheduler. It traced back to errors like:
"EnsureDispatch disp = win32com.client.Dispatch(prog_id)"
As noted on this thread, I changed the option to "Run only when user is logged on" and it ran successfully!
The only drawback is that I schedule the task for a time that I'm away from the computer. I suppose I just have to not log off and hope that the cpu doesn't go into sleep mode, but that's not really a big deal in this case.
I had the same issue with an Excel application I built. When executed during my trouble-shooting I would get an Outlook profile dialog box that I couldn't circumvent. Oddly enough, this dialog box wouldn't appear during scheduled execution. I found a way around this and that was to send email using CDO. I understand that you're not using VBA but this could point you to an alternate method of sending an email (like what I had to do):
http://www.rondebruin.nl/win/s1/cdo.htm
Note: I was only able to have success when I set the Security Option to "Run only when user is logged on" (I have full admin rights on my machine and am running w/highest privileges). I have a strong -- but unconfirmed -- suspicion that there is some security setting invoked when the Task Scheduler is involved, at least in a corporate environment.
I am having trouble with getting Skype4Py to attach to my Skype client. I downloaded easy _install and used it to install Skype4Py. I have 64bit Python and windows 7. When I try the example script (seen below) line by line using the IDLE, I can't get past the skype.attach(), nothing seems to happen. I end up having to close the IDLE and kill the application. If you have any ideas please let me know. I apologize in advance. Just figuring out how to download Skype4Py was challenging for me. Skype is running and I am logged in.
import Skype4Py
# Create an instance of the Skype class.
skype = Skype4Py.Skype()
# Connect the Skype object to the Skype client.
skype.Attach()
# Obtain some information from the client and print it out.
print 'Your full name:', skype.CurrentUser.FullName
print 'Your contacts:'
for user in skype.Friends:
print ' ', user.FullName
Currently looks like 64-bit Python is not supported, because Skype the client application is 32-bit.
https://github.com/awahlig/skype4py/issues/6
Use 32-bit Python.