do not send inactive if context menu is shown and fixes in glade (we also now use a dict to connect custom signals)

This commit is contained in:
Nikos Kouremenos 2005-08-07 15:19:21 +00:00
parent d313420dda
commit 9472d318b2
4 changed files with 150 additions and 70 deletions

View File

@ -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)

View File

@ -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 <hr/>)
# 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"""

View File

@ -4827,6 +4827,7 @@
<child>
<widget class="GtkEntry" id="auto_away_message_entry">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">The auto away status message</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
@ -4849,6 +4850,7 @@
<child>
<widget class="GtkEntry" id="auto_xa_message_entry">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">The auto not available status message</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
@ -8564,7 +8566,7 @@ Custom</property>
<signal name="focus_in_event" handler="on_groupchat_window_focus_in_event" last_modification_time="Sat, 05 Mar 2005 00:34:51 GMT"/>
<signal name="delete_event" handler="on_groupchat_window_delete_event" last_modification_time="Mon, 07 Mar 2005 11:19:05 GMT"/>
<signal name="destroy" handler="on_groupchat_window_destroy" last_modification_time="Mon, 07 Mar 2005 16:46:37 GMT"/>
<signal name="button_press_event" handler="on_groupchat_window_button_press_event" last_modification_time="Fri, 24 Jun 2005 23:52:31 GMT"/>
<signal name="focus_out_event" handler="on_groupchat_window_focus_out_event" last_modification_time="Sun, 07 Aug 2005 13:21:39 GMT"/>
<child>
<widget class="GtkNotebook" id="chat_notebook">
@ -8604,7 +8606,8 @@ Custom</property>
<child>
<widget class="GtkLabel" id="banner_name_label">
<property name="visible">True</property>
<property name="label" translatable="yes"></property>
<property name="label">&lt;span weight=&quot;heavy&quot; size=&quot;large&quot;&gt;room jid&lt;/span&gt;
topic</property>
<property name="use_underline">False</property>
<property name="use_markup">True</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
@ -8614,6 +8617,7 @@ Custom</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">6</property>
<signal name="button_press_event" handler="on_banner_label_button_press_event" last_modification_time="Sun, 07 Aug 2005 15:07:13 GMT"/>
</widget>
</child>
</widget>
@ -8717,6 +8721,7 @@ Custom</property>
<property name="indent">0</property>
<property name="text" translatable="yes"></property>
<signal name="key_press_event" handler="on_message_textview_key_press_event" last_modification_time="Sat, 05 Mar 2005 00:31:14 GMT"/>
<signal name="populate_popup" handler="on_message_textview_populate_popup" last_modification_time="Sun, 07 Aug 2005 14:10:41 GMT"/>
</widget>
</child>
</widget>
@ -9948,7 +9953,6 @@ Custom</property>
<signal name="focus_in_event" handler="on_tabbed_chat_window_focus_in_event" last_modification_time="Wed, 02 Mar 2005 17:57:33 GMT"/>
<signal name="delete_event" handler="on_tabbed_chat_window_delete_event" last_modification_time="Mon, 07 Mar 2005 11:06:00 GMT"/>
<signal name="destroy" handler="on_tabbed_chat_window_destroy" last_modification_time="Mon, 07 Mar 2005 16:35:25 GMT"/>
<signal name="button_press_event" handler="on_tabbed_chat_window_button_press_event" last_modification_time="Thu, 04 Aug 2005 08:33:10 GMT"/>
<signal name="focus_out_event" handler="on_tabbed_chat_window_focus_out_event" last_modification_time="Mon, 18 Jul 2005 22:07:30 GMT"/>
<signal name="motion_notify_event" handler="on_tabbed_chat_window_motion_notify_event" last_modification_time="Thu, 21 Jul 2005 22:24:26 GMT"/>
@ -9993,6 +9997,7 @@ Custom</property>
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<signal name="button_press_event" handler="on_banner_button_press_event" last_modification_time="Sun, 07 Aug 2005 15:06:55 GMT"/>
<child>
<widget class="GtkImage" id="banner_status_image">
@ -10150,6 +10155,7 @@ Status message</property>
<property name="indent">0</property>
<property name="text" translatable="yes"></property>
<signal name="key_press_event" handler="on_message_textview_key_press_event" last_modification_time="Wed, 02 Mar 2005 21:05:35 GMT"/>
<signal name="populate_popup" handler="on_message_textview_populate_popup" last_modification_time="Sun, 07 Aug 2005 14:10:24 GMT"/>
</widget>
</child>
</widget>
@ -11315,12 +11321,70 @@ Status message</property>
<property name="has_default">True</property>
<property name="can_focus">True</property>
<property name="has_focus">True</property>
<property name="label" translatable="yes">Open Download Page</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="on_open_download_page_button_clicked" last_modification_time="Thu, 14 Apr 2005 17:51:56 GMT"/>
<child>
<widget class="GtkAlignment" id="alignment88">
<property name="visible">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xscale">0</property>
<property name="yscale">0</property>
<property name="top_padding">0</property>
<property name="bottom_padding">0</property>
<property name="left_padding">0</property>
<property name="right_padding">0</property>
<child>
<widget class="GtkHBox" id="hbox2990">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">2</property>
<child>
<widget class="GtkImage" id="image1113">
<property name="visible">True</property>
<property name="stock">gtk-jump-to</property>
<property name="icon_size">4</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label353">
<property name="visible">True</property>
<property name="label" translatable="yes">Open Download Page</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
</widget>
</child>
</widget>

View File

@ -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