2005-10-29 16:51:47 +02:00
|
|
|
## message_textview.py
|
|
|
|
##
|
2005-12-09 18:15:30 +01:00
|
|
|
## Contributors for this file:
|
2007-10-22 13:33:50 +02:00
|
|
|
## - Yann Leboulanger <asterix@lagaule.org>
|
2005-10-29 16:51:47 +02:00
|
|
|
## - Nikos Kouremenos <kourem@gmail.com>
|
|
|
|
##
|
2007-10-22 13:33:50 +02:00
|
|
|
## Copyright (C) 2003-2004 Yann Leboulanger <asterix@lagaule.org>
|
2005-12-10 00:30:28 +01:00
|
|
|
## Vincent Hanquez <tab@snarc.org>
|
2007-10-22 13:33:50 +02:00
|
|
|
## Copyright (C) 2005 Yann Leboulanger <asterix@lagaule.org>
|
2005-12-10 00:30:28 +01:00
|
|
|
## Vincent Hanquez <tab@snarc.org>
|
2006-09-28 13:31:25 +02:00
|
|
|
## Nikos Kouremenos <kourem@gmail.com>
|
2005-12-10 00:30:28 +01:00
|
|
|
## Dimitur Kirov <dkirov@gmail.com>
|
|
|
|
## Travis Shirk <travis@pobox.com>
|
|
|
|
## Norman Rasmussen <norman@rasmussen.co.za>
|
2005-10-29 16:51:47 +02:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## This file is part of Gajim.
|
|
|
|
##
|
|
|
|
## Gajim is free software; you can redistribute it and/or modify
|
2005-10-29 16:51:47 +02:00
|
|
|
## it under the terms of the GNU General Public License as published
|
2007-10-22 13:13:13 +02:00
|
|
|
## by the Free Software Foundation; version 3 only.
|
2005-10-29 16:51:47 +02:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## Gajim is distributed in the hope that it will be useful,
|
2005-10-29 16:51:47 +02:00
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## You should have received a copy of the GNU General Public License
|
|
|
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
##
|
2005-10-29 16:51:47 +02:00
|
|
|
|
|
|
|
import gtk
|
|
|
|
import gobject
|
|
|
|
|
|
|
|
class MessageTextView(gtk.TextView):
|
2005-10-29 17:30:24 +02:00
|
|
|
'''Class for the message textview (where user writes new messages)
|
|
|
|
for chat/groupchat windows'''
|
2005-10-29 16:51:47 +02:00
|
|
|
__gsignals__ = dict(
|
|
|
|
mykeypress = (gobject.SIGNAL_RUN_LAST | gobject.SIGNAL_ACTION,
|
|
|
|
None, # return value
|
2005-10-29 18:06:39 +02:00
|
|
|
(int, gtk.gdk.ModifierType ) # arguments
|
2005-10-29 16:51:47 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self):
|
2005-10-29 18:06:39 +02:00
|
|
|
gtk.TextView.__init__(self)
|
|
|
|
|
2005-10-29 17:26:41 +02:00
|
|
|
# set properties
|
|
|
|
self.set_border_width(1)
|
|
|
|
self.set_accepts_tab(True)
|
|
|
|
self.set_editable(True)
|
|
|
|
self.set_cursor_visible(True)
|
2006-05-27 11:18:30 +02:00
|
|
|
self.set_wrap_mode(gtk.WRAP_WORD_CHAR)
|
2005-10-29 17:03:50 +02:00
|
|
|
self.set_left_margin(2)
|
|
|
|
self.set_right_margin(2)
|
|
|
|
self.set_pixels_above_lines(2)
|
|
|
|
self.set_pixels_below_lines(2)
|
2005-10-29 16:51:47 +02:00
|
|
|
|
2006-09-04 10:00:49 +02:00
|
|
|
self.lang = None # Lang used for spell checking
|
|
|
|
|
2006-04-18 17:36:16 +02:00
|
|
|
def destroy(self):
|
|
|
|
import gc
|
|
|
|
gobject.idle_add(lambda:gc.collect())
|
2006-05-07 14:47:24 +02:00
|
|
|
|
|
|
|
def clear(self, widget = None):
|
|
|
|
'''clear text in the textview'''
|
|
|
|
buffer = self.get_buffer()
|
|
|
|
start, end = buffer.get_bounds()
|
|
|
|
buffer.delete(start, end)
|
|
|
|
|
2005-10-29 16:51:47 +02:00
|
|
|
|
|
|
|
# We register depending on keysym and modifier some bindings
|
|
|
|
# but we also pass those as param so we can construct fake Event
|
2005-11-02 20:01:17 +01:00
|
|
|
# Here we register bindings for those combinations that there is NO DEFAULT
|
|
|
|
# action to be done by gtk TextView. In such case we should not add a binding
|
|
|
|
# as the default action comes first and our bindings is useless. In that case
|
|
|
|
# we catch and do stuff before default action in normal key_press_event
|
|
|
|
# and we also return True there to stop the default action from running
|
2005-10-29 16:51:47 +02:00
|
|
|
|
|
|
|
# CTRL + SHIFT + TAB
|
|
|
|
gtk.binding_entry_add_signal(MessageTextView, gtk.keysyms.ISO_Left_Tab,
|
|
|
|
gtk.gdk.CONTROL_MASK, 'mykeypress', int, gtk.keysyms.ISO_Left_Tab,
|
|
|
|
gtk.gdk.ModifierType, gtk.gdk.CONTROL_MASK)
|
|
|
|
|
|
|
|
# CTRL + TAB
|
|
|
|
gtk.binding_entry_add_signal(MessageTextView, gtk.keysyms.Tab,
|
|
|
|
gtk.gdk.CONTROL_MASK, 'mykeypress', int, gtk.keysyms.Tab,
|
|
|
|
gtk.gdk.ModifierType, gtk.gdk.CONTROL_MASK)
|
2005-10-29 18:33:59 +02:00
|
|
|
|
|
|
|
# TAB
|
|
|
|
gtk.binding_entry_add_signal(MessageTextView, gtk.keysyms.Tab,
|
|
|
|
0, 'mykeypress', int, gtk.keysyms.Tab, gtk.gdk.ModifierType, 0)
|
2005-10-29 16:51:47 +02:00
|
|
|
|
|
|
|
# CTRL + UP
|
|
|
|
gtk.binding_entry_add_signal(MessageTextView, gtk.keysyms.Up,
|
|
|
|
gtk.gdk.CONTROL_MASK, 'mykeypress', int, gtk.keysyms.Up,
|
|
|
|
gtk.gdk.ModifierType, gtk.gdk.CONTROL_MASK)
|
|
|
|
|
|
|
|
# CTRL + DOWN
|
|
|
|
gtk.binding_entry_add_signal(MessageTextView, gtk.keysyms.Down,
|
|
|
|
gtk.gdk.CONTROL_MASK, 'mykeypress', int, gtk.keysyms.Down,
|
|
|
|
gtk.gdk.ModifierType, gtk.gdk.CONTROL_MASK)
|
|
|
|
|
|
|
|
# ENTER
|
|
|
|
gtk.binding_entry_add_signal(MessageTextView, gtk.keysyms.Return,
|
|
|
|
0, 'mykeypress', int, gtk.keysyms.Return,
|
|
|
|
gtk.gdk.ModifierType, 0)
|
|
|
|
|
2005-10-29 18:06:39 +02:00
|
|
|
# Ctrl + Enter
|
2005-10-29 16:51:47 +02:00
|
|
|
gtk.binding_entry_add_signal(MessageTextView, gtk.keysyms.Return,
|
|
|
|
gtk.gdk.CONTROL_MASK, 'mykeypress', int, gtk.keysyms.Return,
|
|
|
|
gtk.gdk.ModifierType, gtk.gdk.CONTROL_MASK)
|
|
|
|
|
|
|
|
# Keypad Enter
|
|
|
|
gtk.binding_entry_add_signal(MessageTextView, gtk.keysyms.KP_Enter,
|
|
|
|
0, 'mykeypress', int, gtk.keysyms.KP_Enter,
|
|
|
|
gtk.gdk.ModifierType, 0)
|
|
|
|
|
2005-10-29 18:06:39 +02:00
|
|
|
# Ctrl + Keypad Enter
|
2005-10-29 16:51:47 +02:00
|
|
|
gtk.binding_entry_add_signal(MessageTextView, gtk.keysyms.KP_Enter,
|
|
|
|
gtk.gdk.CONTROL_MASK, 'mykeypress', int, gtk.keysyms.KP_Enter,
|
|
|
|
gtk.gdk.ModifierType, gtk.gdk.CONTROL_MASK)
|