How Change TaskTray icon by time???
namashin opened this issue · 1 comments
namashin commented
I have simple question.
Every 1 seconds , example.ico change to example2.ico, and change to example3.ico and so on.
I made TCP/IP connection Server and i want to cancel TCP connection by putting tasktray ico, while connecting Client and Server, icon change every 1 seconds.
Is there any way to solve this question???
class TaskTrayOperator(object):
def __init__(self, finish_TCP_connection_function):
self.finish_gw = finish_TCP_connection_function
# set icon images
self.images = (Image.open('gw.ico'), Image.open('gw2.ico'), Image.open('gw3.ico'),
Image.open('gw4.ico'), Image.open('gw5.ico'))
# change icon by time
self.timer = 0
# tasktray menu
menu = Menu(MenuItem('FINISH', self.quit_gateway))
self.icon = Icon(
'gateway',
icon=self.images[0],
menu=menu)
# blocking here
self.icon.run()
def quit_gateway(self):
self.finish_gw()
def on_activate(self):
# call this method by one second
if self.timer == 5:
self.timer = 0
self.icon.icon = self.images[self.timer]
self.timer += 1
def finish_gw():
print("finish gw")
if __name__ == '__main__':
S = TaskTrayOperator(finish_gw)
Thank you
moses-palmer commented
I suggest you look into the threading
module. It does contain a Timer
class, but it appears to support triggering only once; writing one that triggers continuously should not be that hard.
Since this question is not related to pystray, I will close it. If you think that is incorrect, please reopen.