basic app with dummy data
This commit is contained in:
commit
4497c312f7
95
imreceived.py
Executable file
95
imreceived.py
Executable file
@ -0,0 +1,95 @@
|
||||
#!/bin/env python3
|
||||
|
||||
import pystray
|
||||
import os
|
||||
import sys
|
||||
from dbus.mainloop.glib import DBusGMainLoop
|
||||
DBusGMainLoop(set_as_default=True)
|
||||
import dbus.decorators
|
||||
from gi.repository.Gtk import AboutDialog
|
||||
from gi.repository.GLib import source_remove, timeout_add
|
||||
# from gi.repository.GdkPixbuf import Pixbuf
|
||||
from PIL import Image
|
||||
|
||||
|
||||
bus = dbus.SessionBus()
|
||||
timer_id = None
|
||||
timer_count = 20
|
||||
|
||||
def resource_path(relative_path):
|
||||
""" Get absolute path to resource, works for dev and for PyInstaller """
|
||||
try:
|
||||
base_path = sys._MEIPASS
|
||||
except Exception:
|
||||
base_path = os.path.abspath(".")
|
||||
return os.path.join(base_path, relative_path)
|
||||
|
||||
|
||||
def timer_callback():
|
||||
global timer_id, timer_count
|
||||
timer_count -= 1
|
||||
if not timer_count:
|
||||
source_remove(timer_id)
|
||||
timer_id = None
|
||||
return False
|
||||
if timer_count % 2 :
|
||||
icon.icon = MsgYes
|
||||
else:
|
||||
icon.icon = MsgNo
|
||||
return True
|
||||
|
||||
|
||||
def item_about(icon, query):
|
||||
about = AboutDialog()
|
||||
about.set_program_name("Finch Indicator")
|
||||
about.set_version("0.1")
|
||||
about.set_copyright("(c) Fred Warren")
|
||||
about.set_comments("Taskbar indicator for Finch Messenger")
|
||||
about.set_website("http://www.elder-geek.net")
|
||||
#about.set_logo(Pixbuf.new_from_file(resource_path("user-invisible.png")))
|
||||
about.run()
|
||||
about.destroy()
|
||||
|
||||
|
||||
|
||||
def after_click(icon, query):
|
||||
if str(query) == "Exit":
|
||||
icon.stop()
|
||||
else:
|
||||
icon.icon = MsgNo
|
||||
|
||||
|
||||
menu = pystray.Menu(
|
||||
pystray.MenuItem("Clear", after_click),
|
||||
pystray.MenuItem("About", item_about),
|
||||
pystray.MenuItem("Exit", after_click))
|
||||
|
||||
|
||||
MsgNo = Image.open(resource_path("user-invisible.png"))
|
||||
MsgYes = Image.open(resource_path("user-available.png"))
|
||||
|
||||
|
||||
def message_received(account, sender, message, conversation, flags):
|
||||
global timer_id, timer_count
|
||||
icon.icon = MsgYes
|
||||
if not timer_id:
|
||||
timer_count = 16
|
||||
timer_id = timeout_add(250, timer_callback)
|
||||
|
||||
|
||||
def message_sent(account, message, id):
|
||||
global timer_id
|
||||
if timer_id:
|
||||
source_remove(timer_id)
|
||||
timer_id = None
|
||||
icon.icon = MsgNo
|
||||
|
||||
|
||||
bus.add_signal_receiver( message_received, dbus_interface="im.pidgin.purple.PurpleInterface", signal_name="ReceivedImMsg")
|
||||
bus.add_signal_receiver( message_received, dbus_interface="im.pidgin.purple.PurpleInterface", signal_name="ReceivedChatMsg")
|
||||
bus.add_signal_receiver( message_sent, dbus_interface="im.pidgin.purple.PurpleInterface", signal_name="SendingImMsg")
|
||||
bus.add_signal_receiver( message_sent, dbus_interface="im.pidgin.purple.PurpleInterface", signal_name="SendingChatMsg")
|
||||
|
||||
|
||||
icon = pystray.Icon("Finch", MsgNo, "Finch Message Indicator", menu)
|
||||
icon.run()
|
Loading…
Reference in New Issue
Block a user