emoticons_menu is created only once, and correctly destroyed when we change emoticon theme. (It was never destroyed before -> memory leak)
This commit is contained in:
parent
e181a707d5
commit
d91d0e0b0e
|
@ -16,7 +16,6 @@
|
||||||
##
|
##
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import math
|
|
||||||
import time
|
import time
|
||||||
import gtk
|
import gtk
|
||||||
import gtk.glade
|
import gtk.glade
|
||||||
|
@ -272,7 +271,8 @@ class ChatControlBase(MessageControl):
|
||||||
cursor.x, cursor.y)
|
cursor.x, cursor.y)
|
||||||
x = origin[0] + cursor[0]
|
x = origin[0] + cursor[0]
|
||||||
y = origin[1] + size[1]
|
y = origin[1] + size[1]
|
||||||
menu_width, menu_height = self.emoticons_menu.size_request()
|
menu_width, menu_height = \
|
||||||
|
gajim.interface.emoticons_menu.size_request()
|
||||||
#FIXME: get_line_count is not so good
|
#FIXME: get_line_count is not so good
|
||||||
#get the iter of cursor, then tv.get_line_yrange
|
#get the iter of cursor, then tv.get_line_yrange
|
||||||
# so we know in which y we are typing (not how many lines we have
|
# so we know in which y we are typing (not how many lines we have
|
||||||
|
@ -286,8 +286,9 @@ class ChatControlBase(MessageControl):
|
||||||
#else: # move menu just below cursor
|
#else: # move menu just below cursor
|
||||||
# y -= (msg_tv.allocation.height / buf.get_line_count())
|
# y -= (msg_tv.allocation.height / buf.get_line_count())
|
||||||
return (x, y, True) # push_in True
|
return (x, y, True) # push_in True
|
||||||
self.emoticons_menu.popup(None, None, set_emoticons_menu_position,
|
gajim.interface.emoticon_menuitem_clicked = self.append_emoticon
|
||||||
1, 0)
|
gajim.interface.emoticons_menu.popup(None, None,
|
||||||
|
set_emoticons_menu_position, 1, 0)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _on_message_textview_key_press_event(self, widget, event):
|
def _on_message_textview_key_press_event(self, widget, event):
|
||||||
|
@ -462,50 +463,26 @@ class ChatControlBase(MessageControl):
|
||||||
when needed'''
|
when needed'''
|
||||||
emoticons_button = self.xml.get_widget('emoticons_button')
|
emoticons_button = self.xml.get_widget('emoticons_button')
|
||||||
if gajim.config.get('emoticons_theme'):
|
if gajim.config.get('emoticons_theme'):
|
||||||
self.emoticons_menu = self.prepare_emoticons_menu()
|
|
||||||
emoticons_button.show()
|
emoticons_button.show()
|
||||||
emoticons_button.set_no_show_all(False)
|
emoticons_button.set_no_show_all(False)
|
||||||
else:
|
else:
|
||||||
self.emoticons_menu = None
|
|
||||||
emoticons_button.hide()
|
emoticons_button.hide()
|
||||||
emoticons_button.set_no_show_all(True)
|
emoticons_button.set_no_show_all(True)
|
||||||
|
|
||||||
def prepare_emoticons_menu(self):
|
def append_emoticon(self, str_):
|
||||||
menu = gtk.Menu()
|
buffer = self.msg_textview.get_buffer()
|
||||||
|
if buffer.get_char_count():
|
||||||
def append_emoticon(w, d):
|
buffer.insert_at_cursor(' %s ' % str_)
|
||||||
buffer = self.msg_textview.get_buffer()
|
else: # we are the beginning of buffer
|
||||||
if buffer.get_char_count():
|
buffer.insert_at_cursor('%s ' % str_)
|
||||||
buffer.insert_at_cursor(' %s ' % d)
|
self.msg_textview.grab_focus()
|
||||||
else: # we are the beginning of buffer
|
|
||||||
buffer.insert_at_cursor('%s ' % d)
|
|
||||||
self.msg_textview.grab_focus()
|
|
||||||
|
|
||||||
counter = 0
|
|
||||||
# Calculate the side lenght of the popup to make it a square
|
|
||||||
size = int(round(math.sqrt(len(gajim.interface.emoticons_images))))
|
|
||||||
for image in gajim.interface.emoticons_images:
|
|
||||||
item = gtk.MenuItem()
|
|
||||||
img = gtk.Image()
|
|
||||||
if type(image[1]) == gtk.gdk.PixbufAnimation:
|
|
||||||
img.set_from_animation(image[1])
|
|
||||||
else:
|
|
||||||
img.set_from_pixbuf(image[1])
|
|
||||||
item.add(img)
|
|
||||||
item.connect('activate', append_emoticon, image[0])
|
|
||||||
#FIXME: add tooltip with ascii
|
|
||||||
menu.attach(item, counter % size, counter % size + 1,
|
|
||||||
counter / size, counter / size + 1)
|
|
||||||
counter += 1
|
|
||||||
menu.show_all()
|
|
||||||
return menu
|
|
||||||
|
|
||||||
def on_emoticons_button_clicked(self, widget):
|
def on_emoticons_button_clicked(self, widget):
|
||||||
'''popup emoticons menu'''
|
'''popup emoticons menu'''
|
||||||
#FIXME: BUG http://bugs.gnome.org/show_bug.cgi?id=316786
|
#FIXME: BUG http://bugs.gnome.org/show_bug.cgi?id=316786
|
||||||
self.button_clicked = widget
|
self.button_clicked = widget
|
||||||
self.emoticons_menu.popup(None, None, self.position_menu_under_button, 1,
|
gajim.interface.emoticon_menuitem_clicked = self.append_emoticon
|
||||||
0)
|
gajim.interface.emoticons_menu.popup(None, None,
|
||||||
|
self.position_menu_under_button, 1, 0)
|
||||||
|
|
||||||
def on_actions_button_clicked(self, widget):
|
def on_actions_button_clicked(self, widget):
|
||||||
'''popup action menu'''
|
'''popup action menu'''
|
||||||
|
|
33
src/gajim.py
33
src/gajim.py
|
@ -95,6 +95,7 @@ import signal
|
||||||
import getopt
|
import getopt
|
||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
|
import math
|
||||||
|
|
||||||
import gtkgui_helpers
|
import gtkgui_helpers
|
||||||
import notify
|
import notify
|
||||||
|
@ -1470,6 +1471,32 @@ class Interface:
|
||||||
def on_launch_browser_mailer(self, widget, url, kind):
|
def on_launch_browser_mailer(self, widget, url, kind):
|
||||||
helpers.launch_browser_mailer(kind, url)
|
helpers.launch_browser_mailer(kind, url)
|
||||||
|
|
||||||
|
def prepare_emoticons_menu(self):
|
||||||
|
menu = gtk.Menu()
|
||||||
|
|
||||||
|
def emoticon_clicked(w, str_):
|
||||||
|
if self.emoticon_menuitem_clicked:
|
||||||
|
self.emoticon_menuitem_clicked(str_)
|
||||||
|
|
||||||
|
counter = 0
|
||||||
|
# Calculate the side lenght of the popup to make it a square
|
||||||
|
size = int(round(math.sqrt(len(gajim.interface.emoticons_images))))
|
||||||
|
for image in gajim.interface.emoticons_images:
|
||||||
|
item = gtk.MenuItem()
|
||||||
|
img = gtk.Image()
|
||||||
|
if type(image[1]) == gtk.gdk.PixbufAnimation:
|
||||||
|
img.set_from_animation(image[1])
|
||||||
|
else:
|
||||||
|
img.set_from_pixbuf(image[1])
|
||||||
|
item.add(img)
|
||||||
|
item.connect('activate', emoticon_clicked, image[0])
|
||||||
|
#FIXME: add tooltip with ascii
|
||||||
|
menu.attach(item, counter % size, counter % size + 1,
|
||||||
|
counter / size, counter / size + 1)
|
||||||
|
counter += 1
|
||||||
|
menu.show_all()
|
||||||
|
return menu
|
||||||
|
|
||||||
def init_emoticons(self):
|
def init_emoticons(self):
|
||||||
if not gajim.config.get('emoticons_theme'):
|
if not gajim.config.get('emoticons_theme'):
|
||||||
return
|
return
|
||||||
|
@ -1503,6 +1530,9 @@ class Interface:
|
||||||
self.emoticons[emot.upper()] = emot_file
|
self.emoticons[emot.upper()] = emot_file
|
||||||
sys.path.remove(path)
|
sys.path.remove(path)
|
||||||
del emots
|
del emots
|
||||||
|
if self.emoticons_menu:
|
||||||
|
gtkgui_helpers.destroy_widget(self.emoticons_menu)
|
||||||
|
self.emoticons_menu = self.prepare_emoticons_menu()
|
||||||
|
|
||||||
def register_handlers(self):
|
def register_handlers(self):
|
||||||
self.handlers = {
|
self.handlers = {
|
||||||
|
@ -1638,6 +1668,9 @@ class Interface:
|
||||||
gajim.interface = self
|
gajim.interface = self
|
||||||
# This is the manager and factory of message windows set by the module
|
# This is the manager and factory of message windows set by the module
|
||||||
self.msg_win_mgr = None
|
self.msg_win_mgr = None
|
||||||
|
self.emoticons_menu = None
|
||||||
|
# handler when an emoticon is clicked in emoticons_menu
|
||||||
|
self.emoticon_menuitem_clicked = None
|
||||||
self.default_values = {
|
self.default_values = {
|
||||||
'inmsgcolor': gajim.config.get('inmsgcolor'),
|
'inmsgcolor': gajim.config.get('inmsgcolor'),
|
||||||
'outmsgcolor': gajim.config.get('outmsgcolor'),
|
'outmsgcolor': gajim.config.get('outmsgcolor'),
|
||||||
|
|
|
@ -602,3 +602,19 @@ def get_possible_button_event(event):
|
||||||
event_button = event.button
|
event_button = event.button
|
||||||
|
|
||||||
return event_button
|
return event_button
|
||||||
|
|
||||||
|
def destroy_widget(widget):
|
||||||
|
if not widget:
|
||||||
|
return
|
||||||
|
children = []
|
||||||
|
try:
|
||||||
|
children = widget.get_children()
|
||||||
|
except:
|
||||||
|
sys.exc_clear()
|
||||||
|
try:
|
||||||
|
widget.destroy()
|
||||||
|
except:
|
||||||
|
sys.exc_clear()
|
||||||
|
while children:
|
||||||
|
child = children.pop(0)
|
||||||
|
destroy_widget(child)
|
||||||
|
|
Loading…
Reference in New Issue