From 9472d318b207ac34b68da4c6d1f8932e559dd817 Mon Sep 17 00:00:00 2001 From: Nikos Kouremenos Date: Sun, 7 Aug 2005 15:19:21 +0000 Subject: [PATCH] do not send inactive if context menu is shown and fixes in glade (we also now use a dict to connect custom signals) --- src/chat.py | 29 +++++++++++---- src/groupchat_window.py | 68 +++++++++++++++++++---------------- src/gtkgui.glade | 74 ++++++++++++++++++++++++++++++++++++--- src/tabbed_chat_window.py | 49 +++++++++++--------------- 4 files changed, 150 insertions(+), 70 deletions(-) diff --git a/src/chat.py b/src/chat.py index 80ca3b6b2..6f49d8b09 100644 --- a/src/chat.py +++ b/src/chat.py @@ -61,8 +61,9 @@ class Chat: self.print_time_timeout_id = {} self.names = {} # what is printed in the tab (eg. user.name) self.childs = {} # holds the contents for every tab (VBox) + self.popup_is_shown = False # is a context menu shown or not? - #The following vars are used to keep history of user's messages + # the following vars are used to keep history of user's messages self.sent_history = {} self.sent_history_pos = {} self.typing_new = {} @@ -259,10 +260,13 @@ class Chat: return menu - def on_chat_window_button_press_event(self, widget, event): + def on_banner_button_press_event(self, widget, event): '''If right-clicked, show popup''' + print 'banner button press' #NEVER GETS CALLED! if event.button == 3: # right click + self.popup_is_shown = True menu = self.prepare_context_menu() + menu.connect('deactivate', self.on_popup_deactivate) # common menuitems (tab switches) if len(self.xmls) > 1: # if there is more than one tab menu.append(gtk.MenuItem()) # seperator @@ -280,6 +284,9 @@ class Chat: menu.popup(None, None, None, event.button, event.time) menu.show_all() + def on_popup_deactivate(self, widget): + self.popup_is_shown = False + def on_chat_notebook_switch_page(self, notebook, page, page_num): # get the index of the page and then the page that we're leaving old_no = notebook.get_current_page() @@ -435,6 +442,8 @@ class Chat: def on_tab_eventbox_button_press_event(self, widget, event, child): if event.button == 3: + self.popup_is_shown = True + menu.connect('deactivate', self.on_popup_deactivate) n = self.notebook.page_num(child) self.notebook.set_current_page(n) @@ -446,7 +455,7 @@ class Chat: self.set_compact_view(self.always_compact_view) self.nb_unread[jid] = 0 gajim.last_message_time[self.account][jid] = 0 - self.last_time_printout[jid] = float(0.0) + self.last_time_printout[jid] = 0. if gajim.config.get('use_speller') and 'gtkspell' in globals(): message_textview = self.xmls[jid].get_widget('message_textview') @@ -567,7 +576,7 @@ class Chat: message_textview.emit('key_press_event', event) def on_chat_notebook_key_press_event(self, widget, event): - st = '1234567890' # zero is here cause humans count from 1, pc from 0 :P + st = '1234567890' # alt+1 means the first tab (tab 0) jid = self.get_active_jid() if event.keyval == gtk.keysyms.Escape: # ESCAPE if self.widget_name == 'tabbed_chat_window': @@ -690,18 +699,24 @@ class Chat: '''basically it filters out the widget instance''' self.plugin.launch_browser_mailer('url', link) + def on_message_textview_populate_popup(self, textview, menu): + self.popup_is_shown = True + menu.connect('deactivate', self.on_popup_deactivate) + def on_conversation_textview_populate_popup(self, textview, menu): '''we override the default context menu and we prepend Clear and if we have sth selected we show a submenu with actions on the phrase (see on_conversation_textview_button_press_event)''' - item = gtk.MenuItem() # seperator + self.popup_is_shown = True + menu.connect('deactivate', self.on_popup_deactivate) + item = gtk.SeparatorMenuItem() menu.prepend(item) item = gtk.ImageMenuItem(gtk.STOCK_CLEAR) menu.prepend(item) item.connect('activate', self.on_clear, textview) if self.selected_phrase: s = self.selected_phrase - if len(s) > 25: #FIXME: do me with pango ellipseEND when gtk24 is OLD + if len(s) > 25: s = s[:21] + '...' item = gtk.MenuItem(_('Actions for "%s"') % s) menu.prepend(item) @@ -839,6 +854,8 @@ class Chat: def make_link_menu(self, event, kind, text): xml = gtk.glade.XML(GTKGUI_GLADE, 'chat_context_menu', APP) menu = xml.get_widget('chat_context_menu') + self.popup_is_shown = True + menu.connect('deactivate', self.on_popup_deactivate) childs = menu.get_children() if kind == 'url': childs[0].connect('activate', self.on_copy_link_activate, text) diff --git a/src/groupchat_window.py b/src/groupchat_window.py index f6e47ecf1..0c437c2d0 100644 --- a/src/groupchat_window.py +++ b/src/groupchat_window.py @@ -64,20 +64,26 @@ class GroupchatWindow(chat.Chat): self.gc_refer_to_nick_char = gajim.config.get('gc_refer_to_nick_char') self.new_room(room_jid, nick) self.show_title() - self.xml.signal_connect('on_groupchat_window_destroy', - self.on_groupchat_window_destroy) - self.xml.signal_connect('on_groupchat_window_delete_event', - self.on_groupchat_window_delete_event) - self.xml.signal_connect('on_groupchat_window_focus_in_event', - self.on_groupchat_window_focus_in_event) - self.xml.signal_connect('on_groupchat_window_button_press_event', - self.on_chat_window_button_press_event) - self.xml.signal_connect('on_chat_notebook_key_press_event', - self.on_chat_notebook_key_press_event) - self.xml.signal_connect('on_chat_notebook_switch_page', - self.on_chat_notebook_switch_page) - self.xml.signal_connect('on_close_window_activate', - self.on_close_window_activate) + + + # NOTE: if it not a window event, connect in new_room function + signal_dict = { +'on_groupchat_window_destroy': self.on_groupchat_window_destroy, +'on_groupchat_window_delete_event': self.on_groupchat_window_delete_event, +'on_groupchat_window_focus_in_event': self.on_groupchat_window_focus_in_event, +'on_groupchat_window_focus_out_event': self.on_groupchat_window_focus_out_event, +'on_chat_notebook_key_press_event': self.on_chat_notebook_key_press_event, + } + + self.xml.signal_autoconnect(signal_dict) + + + #FIXME: 0.9 implement you lost focus of MUC room here (Psi has a
) + # DO NOT CONNECT ABOVE but in glade.. + #'on_chat_notebook_switch_page' + #'on_groupchat_popup_menu_destroy' + + # get size and position from config if gajim.config.get('saveposition'): @@ -104,10 +110,6 @@ class GroupchatWindow(chat.Chat): self.set_subject(room_jid, var['subject']) self.subjects[room_jid] = var['subject'] - def on_close_window_activate(self, widget): - if not self.on_groupchat_window_delete_event(widget, None): - self.window.destroy() - def on_groupchat_window_delete_event(self, widget, event): """close window""" for room_jid in self.xmls: @@ -169,12 +171,15 @@ class GroupchatWindow(chat.Chat): del gajim.gc_connected[self.account][room_jid] def on_groupchat_window_focus_in_event(self, widget, event): - """When window get focus""" + '''When window gets focus''' chat.Chat.on_chat_window_focus_in_event(self, widget, event) - def on_groupchat_window_key_press_event(self, widget, event): - self.on_chat_window_button_press_event(widget, event) - return True + def on_groupchat_window_focus_out_event(self, widget, event): + '''When window loses focus''' + #chat.Chat.on_chat_window_focus_out_event(self, widget, event) + #FIXME: merge with on_tabbed_chat_window_focus_out_event in chat.py + #do the you were here in MUC conversation thing + pass def on_chat_notebook_key_press_event(self, widget, event): chat.Chat.on_chat_notebook_key_press_event(self, widget, event) @@ -857,7 +862,7 @@ class GroupchatWindow(chat.Chat): self.revoke_owner(widget, room_jid, jid) def mk_menu(self, room_jid, event, iter): - """Make user's popup menu""" + '''Make contact's popup menu''' model = self.list_treeview[room_jid].get_model() nick = model[iter][1] c = gajim.gc_contacts[self.account][room_jid][nick] @@ -944,6 +949,8 @@ class GroupchatWindow(chat.Chat): # show the popup now! menu = xml.get_widget('gc_occupants_menu') menu.popup(None, None, None, event.button, event.time) + self.popup_is_shown = True + menu.connect('deactivate', self.on_popup_deactivate) menu.show_all() def remove_tab(self, room_jid): @@ -1076,20 +1083,21 @@ class GroupchatWindow(chat.Chat): int(event.y)) except TypeError: widget.get_selection().unselect_all() - return False + return widget.get_selection().select_path(path) model = widget.get_model() iter = model.get_iter(path) if len(path) == 2: self.mk_menu(room_jid, event, iter) return True - if event.button == 2: # middle click + + elif event.button == 2: # middle click try: path, column, x, y = widget.get_path_at_pos(int(event.x), int(event.y)) except TypeError: widget.get_selection().unselect_all() - return False + return widget.get_selection().select_path(path) model = widget.get_model() iter = model.get_iter(path) @@ -1104,13 +1112,14 @@ class GroupchatWindow(chat.Chat): self.plugin.windows[self.account]['chats'][fjid].set_active_tab(fjid) self.plugin.windows[self.account]['chats'][fjid].window.present() return True - if event.button == 1: # left click + + elif event.button == 1: # left click try: path, column, x, y = widget.get_path_at_pos(int(event.x), int(event.y)) except TypeError: widget.get_selection().unselect_all() - return False + return model = widget.get_model() iter = model.get_iter(path) @@ -1121,13 +1130,10 @@ class GroupchatWindow(chat.Chat): widget.collapse_row(path) else: widget.expand_row(path, False) - - return False def on_list_treeview_key_press_event(self, widget, event): if event.keyval == gtk.keysyms.Escape: widget.get_selection().unselect_all() - return False def on_list_treeview_row_activated(self, widget, path, col = 0): """When an iter is double clicked: open the chat window""" diff --git a/src/gtkgui.glade b/src/gtkgui.glade index 72971f8a1..69f527140 100644 --- a/src/gtkgui.glade +++ b/src/gtkgui.glade @@ -4827,6 +4827,7 @@ True + The auto away status message True True True @@ -4849,6 +4850,7 @@ True + The auto not available status message True True True @@ -8564,7 +8566,7 @@ Custom - + @@ -8604,7 +8606,8 @@ Custom @@ -8717,6 +8721,7 @@ Custom 0 + @@ -9948,7 +9953,6 @@ Custom - @@ -9993,6 +9997,7 @@ Custom True False 0 + @@ -11315,12 +11321,70 @@ Status message True True True - Open Download Page - True GTK_RELIEF_NORMAL True 0 + + + + True + 0.5 + 0.5 + 0 + 0 + 0 + 0 + 0 + 0 + + + + True + False + 2 + + + + True + gtk-jump-to + 4 + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + Open Download Page + True + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + diff --git a/src/tabbed_chat_window.py b/src/tabbed_chat_window.py index 34925dc4c..9d5166a16 100644 --- a/src/tabbed_chat_window.py +++ b/src/tabbed_chat_window.py @@ -52,22 +52,20 @@ class TabbedChatWindow(chat.Chat): self.possible_inactive_timeout_id = {} self.new_user(user) self.show_title() - self.xml.signal_connect('on_tabbed_chat_window_destroy', - self.on_tabbed_chat_window_destroy) - self.xml.signal_connect('on_tabbed_chat_window_delete_event', - self.on_tabbed_chat_window_delete_event) - self.xml.signal_connect('on_tabbed_chat_window_focus_in_event', - self.on_tabbed_chat_window_focus_in_event) - self.xml.signal_connect('on_tabbed_chat_window_focus_out_event', - self.on_tabbed_chat_window_focus_out_event) - self.xml.signal_connect('on_tabbed_chat_window_button_press_event', - self.on_chat_window_button_press_event) - self.xml.signal_connect('on_chat_notebook_key_press_event', - self.on_chat_notebook_key_press_event) - self.xml.signal_connect('on_chat_notebook_switch_page', - self.on_chat_notebook_switch_page) - self.xml.signal_connect('on_tabbed_chat_window_motion_notify_event', - self.on_tabbed_chat_window_motion_notify_event) + + # NOTE: if it not a window event, connect in new_user function + signal_dict = { +'on_tabbed_chat_window_destroy': self.on_tabbed_chat_window_destroy, +'on_tabbed_chat_window_delete_event': self.on_tabbed_chat_window_delete_event, +'on_tabbed_chat_window_focus_in_event': self.on_tabbed_chat_window_focus_in_event, +'on_tabbed_chat_window_focus_out_event': self.on_tabbed_chat_window_focus_out_event, +'on_chat_notebook_key_press_event': self.on_chat_notebook_key_press_event, +'on_chat_notebook_switch_page': self.on_chat_notebook_switch_page, # in chat.py +'on_tabbed_chat_window_motion_notify_event': self.on_tabbed_chat_window_motion_notify_event, + } + + self.xml.signal_autoconnect(signal_dict) + if gajim.config.get('saveposition'): # get window position and size from config @@ -81,7 +79,7 @@ class TabbedChatWindow(chat.Chat): self.window.set_events(gtk.gdk.POINTER_MOTION_MASK) self.window.show_all() - + def save_var(self, jid): '''return the specific variable of a jid, like gpg_enabled the return value have to be compatible with wthe one given to load_var''' @@ -232,7 +230,7 @@ class TabbedChatWindow(chat.Chat): status_image.set_from_pixbuf(pix) def on_tabbed_chat_window_delete_event(self, widget, event): - """close window""" + '''close window''' for jid in self.contacts: if time.time() - gajim.last_message_time[self.account][jid] < 2: # 2 seconds @@ -269,17 +267,12 @@ class TabbedChatWindow(chat.Chat): # focus-out is also emitted by showing context menu # so check to see if we're really not paying attention to window/tab - x, y, width, height, depth = widget.window.get_geometry() - mouse_x, mouse_y, state = widget.window.get_pointer() - # mouse_x, mouse_y are relative to window that is: - # (0, 0) is the left upper corner of the window - # so just check if mouse_x is inside width value to see where the pointer - # is at the time of focus-out # NOTE: if the user changes tab, (switch-tab send inactive to current tab # so that's not a problem) - if mouse_x < 0 or mouse_x > width: # it's outside of window - # so no context menu, so sent inactive - self.send_chatstate('inactive') + if self.popup_is_shown is False: # we are outside of the window + # so no context menu, so send inactive to alls tabs + for jid in self.xmls: + self.send_chatstate('inactive', jid) def on_chat_notebook_key_press_event(self, widget, event): chat.Chat.on_chat_notebook_key_press_event(self, widget, event) @@ -321,7 +314,7 @@ class TabbedChatWindow(chat.Chat): chat.Chat.remove_tab(self, jid, 'chats') del self.contacts[jid] - + def new_user(self, contact): '''when new tab is created''' self.names[contact.jid] = contact.name