1
# -*- coding: utf-8 -*-
2
# Copyright © 2005 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 USA
21
This module exposes a class that documents the implementation of the replace
22
button for the text editor's replace bar.
24
@author: Lateef Alabi-Oki
25
@organization: The Scribes Project
26
@copyright: Copyright © 2005 Lateef Alabi-Oki
27
@license: GNU GPLv2 or Later
28
@contact: mystilleef@gmail.com
31
from gtk import Button
33
class ReplaceButton(Button):
35
This class creates the text editor's replace bar's replace button. The
36
class defines the behavior and default properties of the entry object.
39
def __init__(self, replacebar):
41
Initialize the entry object.
43
@param self: Reference to the ScribesReplaceButton instance.
44
@type self: A ScribesReplaceButton object.
46
@param replacebar: The text editor's replace bar.
47
@type replacebar: A ScribesReplaceBar object.
50
self.__init_attributes(replacebar)
51
self.__set_properties()
52
self.__create_button()
53
self.__signal_id_1 = self.connect("clicked", self.__button_clicked_cb)
54
self.__signal_id_2 = self.__editor.connect("show-bar", self.__button_show_bar_cb)
55
self.__signal_id_3 = self.__searchmanager.connect("searching", self.__button_searching_cb)
56
self.__signal_id_4 = self.__searchmanager.connect("matches-found", self.__button_matches_found_cb)
57
self.__signal_id_5 = self.__searchmanager.connect("no-matches-found", self.__button_no_matches_found_cb)
58
self.__signal_id_6 = self.__searchmanager.connect("cancel", self.__button_cancel_cb)
59
self.__signal_id_7 = self.__replacemanager.connect("cancel", self.__button_cancel_cb)
60
self.__signal_id_8 = self.__replacemanager.connect("replacing", self.__button_replacing_cb)
61
self.__signal_id_9 = self.__replacemanager.connect("replaced", self.__button_replaced_cb)
62
self.__signal_id_10 = self.__find_entry.connect("changed", self.__button_changed_cb)
63
self.__signal_id_11 = self.__match_word_button.connect("toggled", self.__button_toggled_cb)
64
self.__signal_id_12 = self.__match_case_button.connect("toggled", self.__button_toggled_cb)
65
self.__signal_id_13 = replacebar.connect("delete", self.__destroy_cb)
67
def __init_attributes(self, replacebar):
69
Initialize the entry object's attributes
71
@param self: Reference to the ScribesReplaceButton instance.
72
@type self: A ScribesReplaceButton object.
74
@param replacebar: The text editor's replace bar.
75
@type replacebar: A ScribesReplaceBar object.
77
self.__replacebar = replacebar
78
self.__editor = replacebar.editor
79
self.__searchmanager = self.__replacemanager = replacebar.search_replace_manager
80
self.__find_entry = replacebar.find_text_entry
81
self.__match_case_button = replacebar.match_case_button
82
self.__match_word_button = replacebar.match_word_button
83
self.__signal_id_1 = self.__signal_id_2 = self.__signal_id_3 = None
84
self.__signal_id_4 = self.__signal_id_5 = self.__signal_id_6 = None
85
self.__signal_id_7 = self.__signal_id_8 = self.__signal_id_9 = None
86
self.__signal_id_10 = self.__signal_id_11 = self.__signal_id_12 = None
87
self.__signal_id_13 = None
90
def __set_properties(self):
92
Define the entry object's properties.
94
@param self: Reference to the ScribesReplaceButton instance.
95
@type self: A ScribesReplaceButton object.
97
self.set_property("sensitive", False)
100
def __create_button(self):
102
Create the replace button.
104
@param self: Reference to the ScribesReplaceButton instance.
105
@type self: A ScribesReplaceButton object.
107
from SCRIBES.utils import create_button
108
from gtk import STOCK_FIND_AND_REPLACE
109
from i18n import msg0011
110
hbox = create_button(STOCK_FIND_AND_REPLACE, msg0011)
114
def __button_clicked_cb(self, button):
116
Handles callback when the "activate" signal is emitted.
118
@param self: Reference to the ScribesReplaceButton instance.
119
@type self: A ScribesReplaceButton object.
121
@param button: The replace bar's replace text entry widget.
122
@type button: A ScribesReplaceButton object.
124
self.__replacemanager.replace(self.__replacebar.replace_entry.get_text())
127
def __button_show_bar_cb(self, editor, bar):
129
Handles callback when the "show-bar" signal is emitted.
131
@param self: Reference to the ScribesReplaceButton instance.
132
@type self: A ScribesReplaceButton object.
134
@param editor: Reference to the text editor.
135
@type editor: An Editor object.
137
@param bar: The text editor's replace bar.
138
@type bar: A ScribesReplaceBar object.
140
self.set_property("sensitive", False)
143
def __button_searching_cb(self, searchmanager):
145
Handles callback when the "searching" signal is emitted.
147
@param self: Reference to the ScribesReplaceButton instance.
148
@type self: A ScribesReplaceButton object.
150
@param searchmanager: The text editor's search processing object.
151
@type searchmanager: A SearchProcessor object.
153
self.set_property("sensitive", False)
156
def __button_matches_found_cb(self, searchmanager):
158
Handles callback when the "matches-found" signal is emitted.
160
@param self: Reference to the ScribesReplaceButton instance.
161
@type self: A ScribesReplaceButton object.
163
@param searchmanager: The text editor's search processing object.
164
@type searchmanager: A SearchProcessor object.
166
self.set_property("sensitive", True)
169
def __button_no_matches_found_cb(self, searchmanager):
171
Handles callback when the "no-matches-found" signal is emitted.
173
@param self: Reference to the ScribesReplaceButton instance.
174
@type self: A ScribesReplaceButton object.
176
@param searchmanager: The text editor's search processing object.
177
@type searchmanager: A SearchProcessor object.
179
self.set_property("sensitive", False)
182
def __button_cancel_cb(self, searchmanager):
184
Handles callback when the "cancel" signal is emitted.
186
@param self: Reference to the ScribesReplaceButton instance.
187
@type self: A ScribesReplaceButton object.
189
@param searchmanager: The text editor's search processing object.
190
@type searchmanager: A SearchProcessor object.
192
self.set_property("sensitive", False)
195
def __button_changed_cb(self, entry):
197
Handles callback when the find entry's "changed" signal is emitted.
199
@param self: Reference to the ScribesReplaceButton instance.
200
@type self: A ScribesReplaceButton object.
202
@param entry: The text editor's replace bar's find entry.
203
@type entry: A ScribesFindEntry object.
205
self.set_property("sensitive", False)
208
def __button_toggled_cb(self, checkbutton):
210
Handles callback when the "toggled" signal is emitted.
212
@param self: Reference to the ScribesReplaceButton instance.
213
@type self: A ScribesReplaceButton object.
215
@param checkbutton: Either checkbutton on the replace bar.
216
@type checkbutton: A gtk.CheckButton object.
218
self.set_property("sensitive", False)
221
def __button_replacing_cb(self, replacemanager):
223
Handles callback when the "replacing" signal is emitted.
225
@param self: Reference to the ScribesReplaceButton instance.
226
@type self: A ScribesReplaceButton object.
228
@param replacemanager: The text editor's replace object.
229
@type replacemanager: A Replace object.
231
self.set_property("sensitive", False)
234
def __button_replaced_cb(self, replacemanager):
236
Handles callback when the "replacing" signal is emitted.
238
@param self: Reference to the ScribesReplaceButton instance.
239
@type self: A ScribesReplaceButton object.
241
@param replacemanager: The text editor's replace object.
242
@type replacemanager: A Replace object.
244
find_text = self.__replacebar.find_text_entry.get_text()
245
replace_text = self.__replacebar.replace_entry.get_text()
248
def __destroy_cb(self, replacebar):
250
Handles callback when the "delete" signal is emitted.
252
@param self: Reference to the ReplaceButton instance.
253
@type self: A ReplaceButton object.
255
@param replacebar: Reference to the ReplaceButton instance.
256
@type replacebar: A ReplaceButton object.
258
from SCRIBES.utils import disconnect_signal, delete_attributes
259
disconnect_signal(self.__signal_id_1, self)
260
disconnect_signal(self.__signal_id_2, self.__editor)
261
disconnect_signal(self.__signal_id_3, self.__searchmanager)
262
disconnect_signal(self.__signal_id_4, self.__searchmanager)
263
disconnect_signal(self.__signal_id_5, self.__searchmanager)
264
disconnect_signal(self.__signal_id_6, self.__searchmanager)
265
disconnect_signal(self.__signal_id_7, self.__replacemanager)
266
disconnect_signal(self.__signal_id_8, self.__replacemanager)
267
disconnect_signal(self.__signal_id_9, self.__replacemanager)
268
disconnect_signal(self.__signal_id_10, self.__find_entry)
269
disconnect_signal(self.__signal_id_11, self.__match_word_button)
270
disconnect_signal(self.__signal_id_12, self.__match_case_button)
271
disconnect_signal(self.__signal_id_13, replacebar)
273
delete_attributes(self)