while(True):
plyer.notification.notify(
title = title,
message = message,
app_icon = icon,
timeout = 50
)
time.sleep(3600)
I want to be able to access a link when the notification is clicked. I have not found anything like a click event in the source code. I was thinking that maybe it could be called when the timeout is 0 or something similar. If there is another way of doing it without plyer it could also work for me, but I have not found anything. Thanks in advance.
Try win10toast-click. It is not in-built so you have to pip install it.
You can use
from win10toast_click import ToastNotifier
to import it
You can use it by typing
toaster = ToastNotifier() toaster.show_toast(title=,message=,icon_path=,duration=,threaded=True,callback_on_click=yourfunction )
after that you could use webbrowser module to create your function to open the link
Related
I have an application in the hidden part of the systray in Windows 10. I am trying to connect to the application, right-click on it, and then select something like "About". I understand that once I have the target application, I need to connect to the application, which I do in line 25 of the code, but I cannot get further from there.
This is the code I have so far:
from pywinauto import Application
import time
app = Application(backend="uia").connect(path="explorer.exe")
systemTray = app.window(class_name="Shell_TrayWnd")
systemTray.child_window(title="Notification Chevron").click_input(button="left")
#systemTray.print_control_identifiers()
time.sleep(0.25)
list_box = Application(backend="uia").connect(class_name="NotifyIconOverflowWindow")
list_box_win = list_box.window(class_name="NotifyIconOverflowWindow")
list_box_win.wait('visible', timeout=30, retry_interval=3)
# List all the icons in the systray
for notification_area in list_box_win.children():
for app_in_tray in notification_area.children():
print(str(app_in_tray))
target_app = list_box_win.child_window(title="TrayStatus Pro Trial 4.6\r\nCaps Lock: Off")
target_app.wait('visible', timeout=30, retry_interval=3)
target_app.click_input(button="right")
target_app.target_app.print_control_identifiers()
target_app.dump_tree()
sysapp = Application().connect(path='TrayStatus.exe')
sysapp.menu_select('About') #This part fails
Application() class represents the application and sometime it fails to identify the window. Having said that, you have not mentioned the backend of the application at the beginning you have used UIA backend so figure out for the line sysapp = Application().connect(path='TrayStatus.exe') as well and add, Also adding timeout=10 parameter to the connect() works many times.
Still if the above option doesn't not work for you then try using Desktop class.
again you can mention backend of your choice and compatibility, there is no such way to identify backend of application.
window2 = Desktop(backend="win32").window(title='title of the rayStatus.exe window')
you will need to import -
from pywinauto import Desktop.
Finally you can print the titile of windows using
list_window = Desktop().windows()
for window in list_window:
window.window_texts() # this should print the all open window names on desktop
I face an issue and I want to understand why this problem happens and how to solve this problem. I know a lot of questions on stack overflow that talk about tkinter freeze when button pressed I saw many solutions but it is not working for me and I want some help to understand how to solve this problem, I work on some app using tkinter I trying use libraries like TikTokLive to learn new something and I tried to make a button that when pressed gives some information I tried threading but not working and tried to see about use queue and I understand the queue and I saw solutions like use multiprocess but nothing works for me so I thought that problem happens because of the tiktoklive library may be because we use async programming so I made some search and saw solution but not working, I want to some help to understand more how to solve this problem.
Sample code below:
from tkinter import *
root = Tk()
root.geometry("300x300")
get_information = Button(text="get", font='normal 30 bold', command=lambda: connect_with_tiktok_live())
get_information.pack()
def connect_with_tiktok_live():
# dependencies
import TikTokLive.types.events
from TikTokLive import TikTokLiveClient
from TikTokLive.types.events import ConnectEvent
username = "put the username of tiktok live"
# Instantiate the client with the user's username
client: TikTokLiveClient = TikTokLiveClient(
unique_id=username, **({
"process_initial_data": False,
"enable_extended_gift_info": True,
}))
#client.on('connect')
async def on_connect(_: ConnectEvent):
print("Connected to Room ID: ", client.room_id)
# Run the client and block the main thread
# await client.start() to run non-blocking
try:
return client.run()
except FailedConnection: # if live is ended
print('finished')
mainloop()
gif problrm:
some links solution not working for me
How can I prevent a tkinter Gui from freezing while an async task is running?
python running task in the background while allowing tkinter to be active
Tkinter window says (not responding) but code is running
How to easily avoid Tkinter freezing?
How to run a function in the background of tkinter
Tkinter: How to use threads to preventing main event loop from "freezing"
You can use multithreading here using threading.Thread method.
from tkinter import *
from threading import Thread
root = Tk()
root.geometry("300x300")
get_information = Button(text="get", font='normal 30 bold', command= lambda:Thread(target=connect_with_tiktok_live).start())
get_information.pack()
def connect_with_tiktok_live():
# dependencies
import TikTokLive.types.events
from TikTokLive import TikTokLiveClient
from TikTokLive.types.events import ConnectEvent
username = "put the username of tiktok live"
# Instantiate the client with the user's username
client: TikTokLiveClient = TikTokLiveClient(
unique_id=username, **({
"process_initial_data": False,
"enable_extended_gift_info": True,
}))
#client.on('connect')
async def on_connect(_: ConnectEvent):
print("Connected to Room ID: ", client.room_id)
# Run the client and block the main thread
# await client.start() to run non-blocking
try:
return client.run()
except FailedConnection: # if live is ended
print('finished')
mainloop()
I wrote a little script in python, it basically open a VPN program and then it open a new window in firefox and log in a website. I would like now to avoid launching it from the terminal, and be able to make double click on it(is it called an executable file?). How can I achieve this? I work with python 2.7 on a mac 10.11.1.
I am sorry for eventual mistake but programming is still quite new for me!
import webbrowser
from Quartz.CoreGraphics import *
import subprocess as sp
import time
import pyautogui
def mouseEvent(type, posx, posy):
theEvent = CGEventCreateMouseEvent(None, type, (posx,posy),
kCGMouseButtonLeft)
CGEventPost(kCGHIDEventTap, theEvent)
def mousemove(posx,posy):
mouseEvent(kCGEventMouseMoved, posx,posy);
def mouseclick(posx,posy):
mouseEvent(kCGEventLeftMouseDown, posx,posy);
mouseEvent(kCGEventLeftMouseUp, posx,posy);
# opening strong VPN
xfoil = sp.Popen(['open', '-a', '/Applications/StrongVPN Client.app'], stdin=sp.PIPE, stdout=sp.PIPE)
time.sleep(5)
mouseclick(900,360);
time.sleep(1)
#open firefox and going to skygo
b = webbrowser.get('firefox')
b.open('http://skygo.sky.it/index.shtml')
time.sleep( 5 )
mouseclick(1010,225);
#clicking on login;
mouseclick(1074,123);
time.sleep( 5 )
mouseclick(830,225);
time.sleep(2)
pyautogui.typewrite('myusername')
time.sleep(1)
#inserting password
mouseclick(830,290);
time.sleep(2)
pyautogui.typewrite('mypassword')
time.sleep(1)
#pressing enter
mouseclick(920,400);
time.sleep(2)
#mousemove(int(currentpos.x),int(currentpos.y)); # Restore mouse position
You can use Automator to wrap a Python script to a normal Mac App bundle that can be opened from OSX GUI.
Better still, what you are trying to achieve can be probably better implemented as set of action in Automator without having to write any Python scripts.
I have written this little script to show current track playing on xmms2 on a notification widget using xmms client and pynotify, so when i run it i can see the widget popup with current artist and title using xmmsclient methods.
Can anybody give some hints about how to detect track change to notify automatically without having to run the script manually?
You connect the client library to a main loop, and register as a listener via the broadcast_ playback_current_id method. If you want the currently playing id when the script starts as well you can call the playback_current_id method.
Here is a small adaptation of tutorial6 in the xmms2-tutorial.git which uses the GLib Mainloop to drive the connection:
import xmmsclient
import xmmsclient.glib
import os
import sys
import gobject
def cb(result):
if not result.is_error():
print "Current: %(artist)s - %(title)s" % result.value()
ml = gobject.MainLoop(None, False)
xc = xmmsclient.XMMS("stackoverflow")
xc.connect()
conn = xmmsclient.glib.GLibConnector(xc)
xc.broadcast_playback_current_id(lambda r: xc.medialib_get_info(r.value(), cb))
ml.run()
For the extraction of text from a chat window I started off by gathering the window handles.
I managed doing this by the following code:
import time, win32gui
def callback(hwnd, IEServers):
if win32gui.GetClassName(hwnd) == 'Internet Explorer_Server':
IEServers.append(hwnd)
print "IE server found:", hwnd
time.sleep(3)
mainHwnd = win32gui.GetForegroundWindow()
IEServers = []
win32gui.EnumChildWindows(mainHwnd, callback, IEServers)
for serv in IEServers:
print win32gui.GetClassName(serv)
Next thing I want to do is get the content (inner html?) as a string.
I believe it can be done via a IHTMLDocument2 object.
Info: http://support.microsoft.com/kb/q249232
How to do this?
You can try something like this. Maybe not exactly what you want but should get you on your way:
import time, win32gui
import win32com.client
time.sleep(2)
mainHwnd = win32gui.GetForegroundWindow()
s = win32com.client.Dispatch("Shell.Application")
for w in s.Windows():
if int(w.Hwnd) == mainHwnd:
print w.LocationURL
print w.Document.body.innerText
print w.Document.body.innerHTML
break
I think innerText is what you want, but I included several attributes so you can take your pick. This will only work with IE, of course.