| 1 | ## message_textview.py |
|---|
| 2 | ## |
|---|
| 3 | ## Contributors for this file: |
|---|
| 4 | ## - Yann Le Boulanger <asterix@lagaule.org> |
|---|
| 5 | ## - Nikos Kouremenos <kourem@gmail.com> |
|---|
| 6 | ## |
|---|
| 7 | ## Copyright (C) 2003-2004 Yann Le Boulanger <asterix@lagaule.org> |
|---|
| 8 | ## Vincent Hanquez <tab@snarc.org> |
|---|
| 9 | ## Copyright (C) 2005 Yann Le Boulanger <asterix@lagaule.org> |
|---|
| 10 | ## Vincent Hanquez <tab@snarc.org> |
|---|
| 11 | ## Nikos Kouremenos <nkour@jabber.org> |
|---|
| 12 | ## Dimitur Kirov <dkirov@gmail.com> |
|---|
| 13 | ## Travis Shirk <travis@pobox.com> |
|---|
| 14 | ## Norman Rasmussen <norman@rasmussen.co.za> |
|---|
| 15 | ## |
|---|
| 16 | ## This program is free software; you can redistribute it and/or modify |
|---|
| 17 | ## it under the terms of the GNU General Public License as published |
|---|
| 18 | ## by the Free Software Foundation; version 2 only. |
|---|
| 19 | ## |
|---|
| 20 | ## This program is distributed in the hope that it will be useful, |
|---|
| 21 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 22 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 23 | ## GNU General Public License for more details. |
|---|
| 24 | ## |
|---|
| 25 | |
|---|
| 26 | import gtk |
|---|
| 27 | import gobject |
|---|
| 28 | |
|---|
| 29 | class MessageTextView(gtk.TextView): |
|---|
| 30 | '''Class for the message textview (where user writes new messages) |
|---|
| 31 | for chat/groupchat windows''' |
|---|
| 32 | __gsignals__ = dict( |
|---|
| 33 | mykeypress = (gobject.SIGNAL_RUN_LAST | gobject.SIGNAL_ACTION, |
|---|
| 34 | None, # return value |
|---|
| 35 | (int, gtk.gdk.ModifierType ) # arguments |
|---|
| 36 | ) |
|---|
| 37 | ) |
|---|
| 38 | |
|---|
| 39 | def __init__(self): |
|---|
| 40 | gtk.TextView.__init__(self) |
|---|
| 41 | |
|---|
| 42 | # set properties |
|---|
| 43 | self.set_border_width(1) |
|---|
| 44 | self.set_accepts_tab(True) |
|---|
| 45 | self.set_editable(True) |
|---|
| 46 | self.set_cursor_visible(True) |
|---|
| 47 | self.set_wrap_mode(gtk.WRAP_WORD) |
|---|
| 48 | self.set_left_margin(2) |
|---|
| 49 | self.set_right_margin(2) |
|---|
| 50 | self.set_pixels_above_lines(2) |
|---|
| 51 | self.set_pixels_below_lines(2) |
|---|
| 52 | |
|---|
| 53 | if gobject.pygtk_version < (2, 8, 0): |
|---|
| 54 | gobject.type_register(MessageTextView) |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | # We register depending on keysym and modifier some bindings |
|---|
| 58 | # but we also pass those as param so we can construct fake Event |
|---|
| 59 | # Here we register bindings for those combinations that there is NO DEFAULT |
|---|
| 60 | # action to be done by gtk TextView. In such case we should not add a binding |
|---|
| 61 | # as the default action comes first and our bindings is useless. In that case |
|---|
| 62 | # we catch and do stuff before default action in normal key_press_event |
|---|
| 63 | # and we also return True there to stop the default action from running |
|---|
| 64 | |
|---|
| 65 | # CTRL + SHIFT + TAB |
|---|
| 66 | gtk.binding_entry_add_signal(MessageTextView, gtk.keysyms.ISO_Left_Tab, |
|---|
| 67 | gtk.gdk.CONTROL_MASK, 'mykeypress', int, gtk.keysyms.ISO_Left_Tab, |
|---|
| 68 | gtk.gdk.ModifierType, gtk.gdk.CONTROL_MASK) |
|---|
| 69 | |
|---|
| 70 | # CTRL + TAB |
|---|
| 71 | gtk.binding_entry_add_signal(MessageTextView, gtk.keysyms.Tab, |
|---|
| 72 | gtk.gdk.CONTROL_MASK, 'mykeypress', int, gtk.keysyms.Tab, |
|---|
| 73 | gtk.gdk.ModifierType, gtk.gdk.CONTROL_MASK) |
|---|
| 74 | |
|---|
| 75 | # TAB |
|---|
| 76 | gtk.binding_entry_add_signal(MessageTextView, gtk.keysyms.Tab, |
|---|
| 77 | 0, 'mykeypress', int, gtk.keysyms.Tab, gtk.gdk.ModifierType, 0) |
|---|
| 78 | |
|---|
| 79 | # CTRL + UP |
|---|
| 80 | gtk.binding_entry_add_signal(MessageTextView, gtk.keysyms.Up, |
|---|
| 81 | gtk.gdk.CONTROL_MASK, 'mykeypress', int, gtk.keysyms.Up, |
|---|
| 82 | gtk.gdk.ModifierType, gtk.gdk.CONTROL_MASK) |
|---|
| 83 | |
|---|
| 84 | # CTRL + DOWN |
|---|
| 85 | gtk.binding_entry_add_signal(MessageTextView, gtk.keysyms.Down, |
|---|
| 86 | gtk.gdk.CONTROL_MASK, 'mykeypress', int, gtk.keysyms.Down, |
|---|
| 87 | gtk.gdk.ModifierType, gtk.gdk.CONTROL_MASK) |
|---|
| 88 | |
|---|
| 89 | # ENTER |
|---|
| 90 | gtk.binding_entry_add_signal(MessageTextView, gtk.keysyms.Return, |
|---|
| 91 | 0, 'mykeypress', int, gtk.keysyms.Return, |
|---|
| 92 | gtk.gdk.ModifierType, 0) |
|---|
| 93 | |
|---|
| 94 | # Ctrl + Enter |
|---|
| 95 | gtk.binding_entry_add_signal(MessageTextView, gtk.keysyms.Return, |
|---|
| 96 | gtk.gdk.CONTROL_MASK, 'mykeypress', int, gtk.keysyms.Return, |
|---|
| 97 | gtk.gdk.ModifierType, gtk.gdk.CONTROL_MASK) |
|---|
| 98 | |
|---|
| 99 | # Keypad Enter |
|---|
| 100 | gtk.binding_entry_add_signal(MessageTextView, gtk.keysyms.KP_Enter, |
|---|
| 101 | 0, 'mykeypress', int, gtk.keysyms.KP_Enter, |
|---|
| 102 | gtk.gdk.ModifierType, 0) |
|---|
| 103 | |
|---|
| 104 | # Ctrl + Keypad Enter |
|---|
| 105 | gtk.binding_entry_add_signal(MessageTextView, gtk.keysyms.KP_Enter, |
|---|
| 106 | gtk.gdk.CONTROL_MASK, 'mykeypress', int, gtk.keysyms.KP_Enter, |
|---|
| 107 | gtk.gdk.ModifierType, gtk.gdk.CONTROL_MASK) |
|---|