~sir-rainbow/+junk/scribes-on-win

« back to all changes in this revision

Viewing changes to plugins/ReplaceBar/ReplaceButton.py

  • Committer: goldenmyst
  • Date: 2007-09-25 17:15:52 UTC
  • Revision ID: goldenmyst@goldenmyst-desktop-20070925171552-mvrhxdd39iibs0sr
New branch. New Trigger Management System. New Trigger API. New Plugin Management System. Fix for bug triggered by PyGTK+ version 2.11 or better.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
# Copyright © 2005 Lateef Alabi-Oki
 
3
#
 
4
# This file is part of Scribes.
 
5
#
 
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.
 
10
#
 
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.
 
15
#
 
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
 
19
 
 
20
"""
 
21
This module exposes a class that documents the implementation of the replace
 
22
button for the text editor's replace bar.
 
23
 
 
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
 
29
"""
 
30
 
 
31
from gtk import Button
 
32
 
 
33
class ReplaceButton(Button):
 
34
        """
 
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.
 
37
        """
 
38
 
 
39
        def __init__(self, replacebar):
 
40
                """
 
41
                Initialize the entry object.
 
42
 
 
43
                @param self: Reference to the ScribesReplaceButton instance.
 
44
                @type self: A ScribesReplaceButton object.
 
45
 
 
46
                @param replacebar: The text editor's replace bar.
 
47
                @type replacebar: A ScribesReplaceBar object.
 
48
                """
 
49
                Button.__init__(self)
 
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)
 
66
 
 
67
        def __init_attributes(self, replacebar):
 
68
                """
 
69
                Initialize the entry object's attributes
 
70
 
 
71
                @param self: Reference to the ScribesReplaceButton instance.
 
72
                @type self: A ScribesReplaceButton object.
 
73
 
 
74
                @param replacebar: The text editor's replace bar.
 
75
                @type replacebar: A ScribesReplaceBar object.
 
76
                """
 
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
 
88
                return
 
89
 
 
90
        def __set_properties(self):
 
91
                """
 
92
                Define the entry object's properties.
 
93
 
 
94
                @param self: Reference to the ScribesReplaceButton instance.
 
95
                @type self: A ScribesReplaceButton object.
 
96
                """
 
97
                self.set_property("sensitive", False)
 
98
                return
 
99
 
 
100
        def __create_button(self):
 
101
                """
 
102
                Create the replace button.
 
103
 
 
104
                @param self: Reference to the ScribesReplaceButton instance.
 
105
                @type self: A ScribesReplaceButton object.
 
106
                """
 
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)
 
111
                self.add(hbox)
 
112
                return
 
113
 
 
114
        def __button_clicked_cb(self, button):
 
115
                """
 
116
                Handles callback when the "activate" signal is emitted.
 
117
 
 
118
                @param self: Reference to the ScribesReplaceButton instance.
 
119
                @type self: A ScribesReplaceButton object.
 
120
 
 
121
                @param button: The replace bar's replace text entry widget.
 
122
                @type button: A ScribesReplaceButton object.
 
123
                """
 
124
                self.__replacemanager.replace(self.__replacebar.replace_entry.get_text())
 
125
                return True
 
126
 
 
127
        def __button_show_bar_cb(self, editor, bar):
 
128
                """
 
129
                Handles callback when the "show-bar" signal is emitted.
 
130
 
 
131
                @param self: Reference to the ScribesReplaceButton instance.
 
132
                @type self: A ScribesReplaceButton object.
 
133
 
 
134
                @param editor: Reference to the text editor.
 
135
                @type editor: An Editor object.
 
136
 
 
137
                @param bar: The text editor's replace bar.
 
138
                @type bar: A ScribesReplaceBar object.
 
139
                """
 
140
                self.set_property("sensitive", False)
 
141
                return
 
142
 
 
143
        def __button_searching_cb(self, searchmanager):
 
144
                """
 
145
                Handles callback when the "searching" signal is emitted.
 
146
 
 
147
                @param self: Reference to the ScribesReplaceButton instance.
 
148
                @type self: A ScribesReplaceButton object.
 
149
 
 
150
                @param searchmanager: The text editor's search processing object.
 
151
                @type searchmanager: A SearchProcessor object.
 
152
                """
 
153
                self.set_property("sensitive", False)
 
154
                return
 
155
 
 
156
        def __button_matches_found_cb(self, searchmanager):
 
157
                """
 
158
                Handles callback when the "matches-found" signal is emitted.
 
159
 
 
160
                @param self: Reference to the ScribesReplaceButton instance.
 
161
                @type self: A ScribesReplaceButton object.
 
162
 
 
163
                @param searchmanager: The text editor's search processing object.
 
164
                @type searchmanager: A SearchProcessor object.
 
165
                """
 
166
                self.set_property("sensitive", True)
 
167
                return
 
168
 
 
169
        def __button_no_matches_found_cb(self, searchmanager):
 
170
                """
 
171
                Handles callback when the "no-matches-found" signal is emitted.
 
172
 
 
173
                @param self: Reference to the ScribesReplaceButton instance.
 
174
                @type self: A ScribesReplaceButton object.
 
175
 
 
176
                @param searchmanager: The text editor's search processing object.
 
177
                @type searchmanager: A SearchProcessor object.
 
178
                """
 
179
                self.set_property("sensitive", False)
 
180
                return
 
181
 
 
182
        def __button_cancel_cb(self, searchmanager):
 
183
                """
 
184
                Handles callback when the "cancel" signal is emitted.
 
185
 
 
186
                @param self: Reference to the ScribesReplaceButton instance.
 
187
                @type self: A ScribesReplaceButton object.
 
188
 
 
189
                @param searchmanager: The text editor's search processing object.
 
190
                @type searchmanager: A SearchProcessor object.
 
191
                """
 
192
                self.set_property("sensitive", False)
 
193
                return
 
194
 
 
195
        def __button_changed_cb(self, entry):
 
196
                """
 
197
                Handles callback when the find entry's "changed" signal is emitted.
 
198
 
 
199
                @param self: Reference to the ScribesReplaceButton instance.
 
200
                @type self: A ScribesReplaceButton object.
 
201
 
 
202
                @param entry: The text editor's replace bar's find entry.
 
203
                @type entry: A ScribesFindEntry object.
 
204
                """
 
205
                self.set_property("sensitive", False)
 
206
                return True
 
207
 
 
208
        def __button_toggled_cb(self, checkbutton):
 
209
                """
 
210
                Handles callback when the "toggled" signal is emitted.
 
211
 
 
212
                @param self: Reference to the ScribesReplaceButton instance.
 
213
                @type self: A ScribesReplaceButton object.
 
214
 
 
215
                @param checkbutton: Either checkbutton on the replace bar.
 
216
                @type checkbutton: A gtk.CheckButton object.
 
217
                """
 
218
                self.set_property("sensitive", False)
 
219
                return True
 
220
 
 
221
        def __button_replacing_cb(self, replacemanager):
 
222
                """
 
223
                Handles callback when the "replacing" signal is emitted.
 
224
 
 
225
                @param self: Reference to the ScribesReplaceButton instance.
 
226
                @type self: A ScribesReplaceButton object.
 
227
 
 
228
                @param replacemanager: The text editor's replace object.
 
229
                @type replacemanager: A Replace object.
 
230
                """
 
231
                self.set_property("sensitive", False)
 
232
                return
 
233
 
 
234
        def __button_replaced_cb(self, replacemanager):
 
235
                """
 
236
                Handles callback when the "replacing" signal is emitted.
 
237
 
 
238
                @param self: Reference to the ScribesReplaceButton instance.
 
239
                @type self: A ScribesReplaceButton object.
 
240
 
 
241
                @param replacemanager: The text editor's replace object.
 
242
                @type replacemanager: A Replace object.
 
243
                """
 
244
                find_text = self.__replacebar.find_text_entry.get_text()
 
245
                replace_text = self.__replacebar.replace_entry.get_text()
 
246
                return
 
247
 
 
248
        def __destroy_cb(self, replacebar):
 
249
                """
 
250
                Handles callback when the "delete" signal is emitted.
 
251
 
 
252
                @param self: Reference to the ReplaceButton instance.
 
253
                @type self: A ReplaceButton object.
 
254
 
 
255
                @param replacebar: Reference to the ReplaceButton instance.
 
256
                @type replacebar: A ReplaceButton object.
 
257
                """
 
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)
 
272
                self.destroy()
 
273
                delete_attributes(self)
 
274
                del self
 
275
                self = None
 
276
                return