From f644cf11368d4bc428deb7255819c4c79cd04a59 Mon Sep 17 00:00:00 2001 From: Nikos Kouremenos Date: Wed, 4 Oct 2006 23:30:03 +0000 Subject: [PATCH] if we are windows users and we have GTK/PyGTK 2.10 we now use the GTK api about the status icon (trayicon). I tested under GNU/Linux [at gtk2.10 still is not out for Windows] and all works okay apart from the fact that we cannot do cool tooltips and cannot do animation (which is okay by me). TODO: make usage of basic tooltips [better something than nothing] for this new API --- src/gajim.py | 41 ++++++++++++++--------------------------- src/systray.py | 46 +++++++++++++++++++++++----------------------- 2 files changed, 37 insertions(+), 50 deletions(-) diff --git a/src/gajim.py b/src/gajim.py index 1dce8463f..518ef8a90 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -4,20 +4,11 @@ exec python -OOt "$0" ${1+"$@"} ' ''' ## gajim.py ## -## Contributors for this file: -## - Yann Le Boulanger -## - Nikos Kouremenos -## - Dimitur Kirov -## - Travis Shirk ## -## Copyright (C) 2003-2004 Yann Le Boulanger -## Vincent Hanquez -## Copyright (C) 2005 Yann Le Boulanger -## Vincent Hanquez -## Nikos Kouremenos -## Dimitur Kirov -## Travis Shirk -## Norman Rasmussen +## Copyright (C) 2003-2006 Yann Le Boulanger +## Copyright (C) 2005-2006 Nikos Kouremenos +## Copyright (C) 2005-2006 Dimitur Kirov +## Copyright (C) 2005 Travis Shirk ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published @@ -193,7 +184,6 @@ atexit.register(on_exit) parser = optparser.OptionsParser(config_filename) import roster_window -import systray import profile_window import config @@ -1925,21 +1915,18 @@ class Interface: self.systray_enabled = False self.systray_capabilities = False - if os.name == 'nt': - pass - ''' - try: - import systraywin32 - except: # user doesn't have trayicon capabilities - pass - else: - self.systray_capabilities = True - self.systray = systraywin32.SystrayWin32() - ''' - else: + if os.name == 'nt' and gtk.pygtk_version >= (2, 10, 0) and\ + gtk.gtk_version >= (2, 10, 0): + import statusicon + self.systray = statusicon.StatusIcon() + self.systray_capabilities = True + else: # use ours, not GTK+ one + # [FIXME: remove this when we migrate to 2.10 and we can do + # cool tooltips somehow and (not dying to keep) animation] + import systray self.systray_capabilities = systray.HAS_SYSTRAY_CAPABILITIES if self.systray_capabilities: - self.systray = systray.Systray() + self.systray = systray.Systray() if self.systray_capabilities and gajim.config.get('trayicon'): self.show_systray() diff --git a/src/systray.py b/src/systray.py index ade7ffd81..50c739944 100644 --- a/src/systray.py +++ b/src/systray.py @@ -43,7 +43,7 @@ except: class Systray: '''Class for icon in the notification area - This class is both base class (for systraywin32.py) and normal class + This class is both base class (for statusicon.py) and normal class for trayicon in GNU/Linux''' def __init__(self): @@ -94,16 +94,14 @@ class Systray: def on_new_chat(self, widget, account): dialogs.NewChatDialog(account) - def make_menu(self, event = None): - '''create chat with and new message (sub) menus/menuitems - event is None when we're in Windows - ''' - + def make_menu(self, event_button, event_time): + '''create chat with and new message (sub) menus/menuitems''' for m in self.popup_menus: m.destroy() chat_with_menuitem = self.xml.get_widget('chat_with_menuitem') - single_message_menuitem = self.xml.get_widget('single_message_menuitem') + single_message_menuitem = self.xml.get_widget( + 'single_message_menuitem') status_menuitem = self.xml.get_widget('status_menu') join_gc_menuitem = self.xml.get_widget('join_gc_menuitem') @@ -171,7 +169,8 @@ class Systray: self.popup_menus.append(account_menu_for_chat_with) account_menu_for_single_message = gtk.Menu() - single_message_menuitem.set_submenu(account_menu_for_single_message) + single_message_menuitem.set_submenu( + account_menu_for_single_message) self.popup_menus.append(account_menu_for_single_message) accounts_list = gajim.contacts.get_accounts() @@ -195,9 +194,11 @@ class Systray: label.set_use_underline(False) gc_item = gtk.MenuItem() gc_item.add(label) - gc_item.connect('state-changed', gtkgui_helpers.on_bm_header_changed_state) + gc_item.connect('state-changed', + gtkgui_helpers.on_bm_header_changed_state) gc_sub_menu.append(gc_item) - gajim.interface.roster.add_bookmarks_list(gc_sub_menu, account) + gajim.interface.roster.add_bookmarks_list(gc_sub_menu, + account) elif connected_accounts == 1: # one account # one account connected, no need to show 'as jid' @@ -207,24 +208,23 @@ class Systray: 'activate', self.on_new_chat, account) # for single message single_message_menuitem.remove_submenu() - self.single_message_handler_id = single_message_menuitem.connect( - 'activate', self.on_single_message_menuitem_activate, account) + self.single_message_handler_id = single_message_menuitem.\ + connect('activate', + self.on_single_message_menuitem_activate, account) # join gc - gajim.interface.roster.add_bookmarks_list(gc_sub_menu, account) + gajim.interface.roster.add_bookmarks_list(gc_sub_menu, + account) break # No other connected account - if event is None: - # None means windows (we explicitly popup in systraywin32.py) - if self.added_hide_menuitem is False: - self.systray_context_menu.prepend(gtk.SeparatorMenuItem()) - item = gtk.MenuItem(_('Hide this menu')) - self.systray_context_menu.prepend(item) - self.added_hide_menuitem = True + if gtk.pygtk_version >= (2, 10, 0) and gtk.gtk_version >= (2, 10, 0): + self.systray_context_menu.popup(None, None, + gtk.status_icon_position_menu, event_button, + event_time, self.status_icon) else: # GNU and Unices - self.systray_context_menu.popup(None, None, None, event.button, - event.time) + self.systray_context_menu.popup(None, None, None, event_button, + event_time) self.systray_context_menu.show_all() def on_show_all_events_menuitem_activate(self, widget): @@ -282,7 +282,7 @@ class Systray: elif event.button == 2: # middle click self.on_middle_click() elif event.button == 3: # right click - self.make_menu(event) + self.make_menu(event.button, event.time) def on_show_menuitem_activate(self, widget, show): # we all add some fake (we cannot select those nor have them as show)