1
# -*- coding: utf-8 -*-
2
# Copyright © 2006 Lateef Alabi-Oki
4
# This file is part of Scribes.
6
# Scribes is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# Scribes is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with Scribes; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
22
This module documents a class that adds/removes a menuitem to show the
23
automatic replacement dialog.
25
@author: Lateef Alabi-Oki
26
@organization: The Scribes Project
27
@copyright: Copyright © 2006 Lateef Alabi-Oki
28
@license: GNU GPLv2 or Later
29
@contact: mystilleef@gmail.com
32
class AutoReplaceMenuItem(object):
34
This class creates an object that adds or removes a menuitem that
35
shows the automatic replacement dialog.
38
def __init__(self, trigger, editor):
40
Initialize the object.
42
@param self: Reference to the AutoReplaceMenuItem instance.
43
@type self: An AutoReplaceMenuItem object.
45
@param trigger: Reference to the AutoReplaceTrigger instance.
46
@type trigger: An AutoReplaceTrigger object.
48
@param editor: Reference to the text editor.
49
@type editor: An Editor object.
51
self.__init_attributes(trigger, editor)
53
self.__signal_id_1 = self.__trigger.connect("destroy", self.__menuitem_destroy_cb)
54
self.__signal_id_2 = self.__menuitem.connect("activate", self.__menuitem_activate_cb)
56
def __init_attributes(self, trigger, editor):
58
Initialize the object.
60
@param self: Reference to the AutoReplaceMenuItem instance.
61
@type self: An AutoReplaceMenuItem object.
63
@param trigger: Reference to the AutoReplaceTrigger instance.
64
@type trigger: An AutoReplaceTrigger object.
66
@param editor: Reference to the text editor.
67
@type editor: An Editor object.
69
self.__trigger = trigger
70
self.__editor = editor
71
self.__signal_id_1 = None
72
self.__signal_id_2 = None
73
from gtk import STOCK_SELECT_COLOR, STOCK_PROPERTIES
74
from SCRIBES.utils import create_menuitem
75
from i18n import msg0001
76
self.__menuitem = create_menuitem(msg0001, STOCK_PROPERTIES)
79
def __add_menuitem(self):
81
Add menuitem to the editor's preference menu.
83
@param self: Reference to the AutoReplaceMenuItem instance.
84
@type self: An AutoReplaceMenuItem object.
86
self.__editor.preference_menu.append(self.__menuitem)
87
self.__editor.preference_menu.show_all()
90
def __menuitem_destroy_cb(self, trigger):
92
Handles callback when the "destroy" signal is emitted.
94
@param self: Reference to the AutoReplaceMenuItem instance.
95
@type self: An AutoReplaceMenuItem object.
97
@param trigger: Reference to the AutoReplaceTrigger instance.
98
@type trigger: An AutoReplaceTrigger object.
100
from SCRIBES.utils import disconnect_signal, delete_attributes
101
disconnect_signal(self.__signal_id_2, self.__menuitem)
102
disconnect_signal(self.__signal_id_1, self.__trigger)
103
self.__editor.preference_menu.remove(self.__menuitem)
104
self.__menuitem.destroy()
105
delete_attributes(self)
110
def __menuitem_activate_cb(self, menuitem):
112
Handles callback when the "activate" signal is emitted.
114
@param self: Reference to the AutoReplaceMenuItem instance.
115
@type self: An AutoReplaceMenuItem object.
117
@param menuitem: Reference the the automatic replacement menuitem.
118
@type menuitem: A gtk.MenuItem object.
120
@return: True to propagate signals to parent widgets.
121
@type: A Boolean Object.
123
self.__editor.triggermanager.trigger("show_autoreplace_dialog")