trayicon for windows is 100% ready

This commit is contained in:
Nikos Kouremenos 2005-08-16 20:24:56 +00:00
parent ea47fd6f08
commit 9c05382fc5
4 changed files with 75 additions and 64 deletions

View File

@ -88,8 +88,8 @@ class PreferencesWindow:
self.auto_away_message_entry = self.xml.get_widget \
('auto_away_message_entry')
self.auto_xa_checkbutton = self.xml.get_widget('auto_xa_checkbutton')
self.auto_xa_time_spinbutton = self.xml.get_widget \
('auto_xa_time_spinbutton')
self.auto_xa_time_spinbutton = self.xml.get_widget(
'auto_xa_time_spinbutton')
self.auto_xa_message_entry = self.xml.get_widget('auto_xa_message_entry')
self.trayicon_checkbutton = self.xml.get_widget('trayicon_checkbutton')
self.notebook = self.xml.get_widget('preferences_notebook')
@ -99,10 +99,7 @@ class PreferencesWindow:
st = gajim.config.get('trayicon')
self.trayicon_checkbutton.set_active(st)
else:
if os.name == 'nt':
self.trayicon_checkbutton.set_no_show_all(True)
else:
self.trayicon_checkbutton.set_sensitive(False)
self.trayicon_checkbutton.set_sensitive(False)
#Show roster on Gajim startup
st = gajim.config.get('show_roster_on_startup')

View File

@ -1506,7 +1506,6 @@ _('If "%s" accepts this request you will know his status.') %jid)
def on_manage_bookmarks_menuitem_activate(self, widget):
config.ManageBookmarksWindow(self.plugin)
#config.FirstTimeWizardWindow(self.plugin)
def close_all(self, dic):
'''close all the windows in the given dictionary'''
@ -1769,7 +1768,7 @@ _('If "%s" accepts this request you will know his status.') %jid)
image = gtk.Image()
image.show()
imgs[state] = image
for file in files:
for file in files: # loop seeking for either gif or png
if os.path.exists(file):
image.set_from_file(file)
break

View File

@ -27,7 +27,6 @@ import os
import tooltips
from common import gajim
from common.connection import STATUS_LIST
from common import helpers
from common import i18n
@ -65,10 +64,10 @@ class Systray:
def set_img(self):
if len(self.jids) > 0:
status = 'message'
state = 'message'
else:
status = self.status
image = self.plugin.roster.jabber_state_images[status]
state = self.status
image = self.plugin.roster.jabber_state_images[state]
if image.get_storage_type() == gtk.IMAGE_ANIMATION:
self.img_tray.set_from_animation(image.get_animation())
elif image.get_storage_type() == gtk.IMAGE_PIXBUF:
@ -79,10 +78,10 @@ class Systray:
if not l in self.jids:
self.jids.append(l)
self.set_img()
#we append to the number of unread messages
# we append to the number of unread messages
nb = self.plugin.roster.nb_unread
for acct in gajim.connections:
#in chat / groupchat windows
# in chat / groupchat windows
for kind in ['chats', 'gc']:
jids = self.plugin.windows[acct][kind]
for jid in jids:
@ -94,10 +93,10 @@ class Systray:
if l in self.jids:
self.jids.remove(l)
self.set_img()
#we remove from the number of unread messages
# we remove from the number of unread messages
nb = self.plugin.roster.nb_unread
for acct in gajim.connections:
#in chat / groupchat windows
# in chat / groupchat windows
for kind in ['chats', 'gc']:
for jid in self.plugin.windows[acct][kind]:
if jid != 'tabbed':

View File

@ -21,14 +21,12 @@
## GNU General Public License for more details.
##
__version__ = '1.01'
import sys
import win32gui
import win32con # winapi contants
import systray
import gtk
import os
WM_TASKBARCREATED = win32gui.RegisterWindowMessage('TaskbarCreated')
WM_TRAYMESSAGE = win32con.WM_USER + 20
@ -202,7 +200,7 @@ class NotifyIcon:
self.remove
win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, self._get_nid())
#FIXME: subclass us under Systray
class SystrayWin32(systray.Systray):
def __init__(self, plugin):
# Note: gtk window must be realized before installing extensions.
@ -213,6 +211,8 @@ class SystrayWin32(systray.Systray):
self.xml = gtk.glade.XML(GTKGUI_GLADE, 'systray_context_menu', APP)
self.systray_context_menu = self.xml.get_widget('systray_context_menu')
self.tray_ico_imgs = self.load_icos()
self.systray_winapi = SystrayWINAPI(self.plugin.roster.window)
self.xml.signal_autoconnect(self)
@ -223,8 +223,10 @@ class SystrayWin32(systray.Systray):
})
def show_icon(self):
self.systray_winapi.add_notify_icon(self.systray_context_menu, tooltip = 'Gajim')
self.systray_winapi.notify_icon.menu = self.systray_context_menu
#self.systray_winapi.add_notify_icon(self.systray_context_menu, tooltip = 'Gajim')
#self.systray_winapi.notify_icon.menu = self.systray_context_menu
# do not remove set_img does both above. maybe I can only change img without readding
# the notify icon? F$ck WINAPI
self.set_img()
def hide_icon(self):
@ -240,67 +242,81 @@ class SystrayWin32(systray.Systray):
self.on_left_click()
def add_jid(self, jid, account):
print 'FIXME: add_jid'
return
list = [account, jid]
if not list in self.jids:
self.jids.append(list)
l = [account, jid]
if not l in self.jids:
self.jids.append(l)
self.set_img()
#we look for the number of unread messages
#in roster
# we append to the number of unread messages
nb = self.plugin.roster.nb_unread
for acct in gajim.connections:
#in chat / groupchat windows
# in chat / groupchat windows
for kind in ['chats', 'gc']:
jids = self.plugin.windows[acct][kind]
for jid in jids:
if jid != 'tabbed':
nb += jids[jid].nb_unread[jid]
#FIXME: prepare me for transltaion (ngeetext() and all) for 0.9
if nb > 1:
label = _('Gajim - %s unread messages') % nb
text = 'Gajim - %s unread messages' % nb
else:
label = _('Gajim - 1 unread message')
self.tip.set_tip(self.t, label)
def set_img(self):
print 'set_img'
self.systray_winapi.remove_notify_icon()
if len(self.jids) > 0:
status = 'message'
else:
#status = self.status
path_to_ico = '../data/pixmaps/gajim.ico'
hinst = win32gui.GetModuleHandle(None)
icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
hicon = win32gui.LoadImage(hinst,
path_to_ico, #FIXME: path
win32con.IMAGE_ICON,
0,
0,
icon_flags)
self.systray_winapi.add_notify_icon(self.systray_context_menu, hicon, 'Gajim')
self.systray_winapi.notify_icon.menu = self.systray_context_menu
text = 'Gajim - 1 unread message'
self.systray_winapi.notify_icon.set_tooltip(text)
def remove_jid(self, jid, account):
print 'FIXME: remove_jid'
return
list = [account, jid]
if list in self.jids:
self.jids.remove(list)
l = [account, jid]
if l in self.jids:
self.jids.remove(l)
self.set_img()
#we look for the number of unread messages
#in roster
# we remove from the number of unread messages
nb = self.plugin.roster.nb_unread
for acct in gajim.connections:
#in chat / groupchat windows
# in chat / groupchat windows
for kind in ['chats', 'gc']:
for jid in self.plugin.windows[acct][kind]:
if jid != 'tabbed':
nb += self.plugin.windows[acct][kind][jid].nb_unread[jid]
#FIXME: prepare me for transltaion (ngeetext() and all) for 0.9
if nb > 1:
label = _('Gajim - %s unread messages') % nb
text = 'Gajim - %s unread messages' % nb
elif nb == 1:
label = _('Gajim - 1 unread message')
text = 'Gajim - 1 unread message'
else:
label = 'Gajim'
self.tip.set_tip(self.t, label)
text = 'Gajim'
self.systray_winapi.notify_icon.set_tooltip(text)
def set_img(self):
self.systray_winapi.remove_notify_icon()
if len(self.jids) > 0:
state = 'message'
else:
state = self.status # FIXME: get LoadImage code to images[] dict in systray.py
hicon = self.tray_ico_imgs[state]
self.systray_winapi.add_notify_icon(self.systray_context_menu, hicon, 'Gajim')
self.systray_winapi.notify_icon.menu = self.systray_context_menu
def load_icos(self):
'''load .ico files and return them to a dic of SHOW --> img_obj'''
#iconset = gajim.config.get('iconset')
#if not iconset:
# iconset = 'sun'
iconset = 'gnome' # FIXME: add icos in all folders (icos are not as good as pngs in colors etc..)
imgs = {}
path = os.path.join(gajim.DATA_DIR, 'iconsets/' + iconset + '/16x16/icos/')
states_list = gajim.SHOW_LIST
states_list.append('message') # trayicon apart from show holds message state too
for state in states_list:
path_to_ico = path + state + '.ico'
if os.path.exists(path_to_ico):
hinst = win32gui.GetModuleHandle(None)
img_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
image = win32gui.LoadImage(hinst, path_to_ico, win32con.IMAGE_ICON,
0, 0, img_flags)
imgs[state] = image
return imgs