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

« back to all changes in this revision

Viewing changes to plugins/ReplaceBar/Manager.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 creates the text editor's replace bar.
 
22
 
 
23
@author: Lateef Alabi-Oki
 
24
@organization: The Scribes Project
 
25
@copyright: Copyright © 2005 Lateef Alabi-Oki
 
26
@license: GNU GPLv2 or Later
 
27
@contact: mystilleef@gmail.com
 
28
"""
 
29
 
 
30
from SCRIBES.bar import ScribesBar
 
31
from gtk import SHRINK, FILL, EXPAND
 
32
from gobject import SIGNAL_RUN_LAST, TYPE_NONE
 
33
 
 
34
class ReplaceBar(ScribesBar):
 
35
        """
 
36
        This class creates the text editor's replace bar object. The class defines
 
37
        the behavior and default properties of the replace bar object.
 
38
        """
 
39
 
 
40
        __gsignals__ = {
 
41
                "delete": (SIGNAL_RUN_LAST, TYPE_NONE, ()),
 
42
        }
 
43
 
 
44
        def __init__(self, editor):
 
45
                """
 
46
                Initialize the replace bar object.
 
47
 
 
48
                @param self: Reference to the ScribesReplaceBar instance.
 
49
                @type self: A ScribesReplaceBar object.
 
50
 
 
51
                @param editor: Reference to the text editor.
 
52
                @type editor: An Editor object.
 
53
                """
 
54
                ScribesBar.__init__(self, editor)
 
55
                self.__init_attributes()
 
56
                self.__set_properties()
 
57
                self.__arrange_widgets()
 
58
                self.__signal_id_1 = self.__manager.connect("replacing", self.__replacebar_replacing_cb)
 
59
                self.__signal_id_2 = self.__manager.connect("replaced", self.__replacebar_replaced_cb)
 
60
                self.__signal_id_3 = self.__manager.connect("replaced-all", self.__replacebar_replaced_cb)
 
61
                self.__signal_id_4 = self.__manager.connect("cancel", self.__replacebar_cancel_cb)
 
62
                self.__signal_id_5 = self.__manager.connect("searching", self.__replacebar_searching_cb)
 
63
                self.__signal_id_6 = self.__manager.connect("matches-found", self.__replacebar_matches_found_cb)
 
64
                self.__signal_id_7 = self.__manager.connect("no-matches-found",
 
65
                                                                self.__replacebar_no_matches_found_cb)
 
66
                self.__signal_id_8 = self.__entry.connect("activate", self.__replacebar_activate_cb)
 
67
                self.__signal_id_9 = self.__entry.connect("changed", self.__replacebar_changed_cb)
 
68
                self.__signal_id_10 = self.__matchcase_check_button.connect("toggled", self.__replacebar_toggled_cb)
 
69
                self.__signal_id_11 = self.__matchword_check_button.connect("toggled", self.__replacebar_toggled_cb)
 
70
                self.__signal_id_12 = self.__incremental_check_button.connect("toggled", self.__replacebar_toggled_cb)
 
71
                self.__signal_id_13 = self.__editor.connect("show-bar", self.__replacebar_show_bar_cb)
 
72
                self.__signal_id_14 = self.__editor.connect("hide-bar", self.__replacebar_hide_bar_cb)
 
73
                self.__signal_id_15 = self.connect("delete", self.__destroy_cb)
 
74
                self.__block_search_replace_signals()
 
75
 
 
76
########################################################################
 
77
#
 
78
#                                               Accessors
 
79
#
 
80
########################################################################
 
81
 
 
82
        def __get_search_replace_manager(self):
 
83
                return self.__search_replace_manager
 
84
 
 
85
        def __get_entry(self):
 
86
                return self.__entry
 
87
 
 
88
        def __get_match_case_button(self):
 
89
                return self.__matchcase_check_button
 
90
 
 
91
        def __get_match_word_button(self):
 
92
                return self.__matchword_check_button
 
93
 
 
94
        def __get_search_button(self):
 
95
                return self.__search_button
 
96
 
 
97
        def __get_next_button(self):
 
98
                return self.__next_button
 
99
 
 
100
        def __get_previous_button(self):
 
101
                return self.__previous_button
 
102
 
 
103
        def __get_stop_button(self):
 
104
                return self.__stop_button
 
105
 
 
106
        def __get_replace_entry(self):
 
107
                return self.__replace_entry
 
108
 
 
109
        def __get_replace_button(self):
 
110
                return self.__replace_button
 
111
 
 
112
        def __get_replace_all_button(self):
 
113
                return self.__replace_all_button
 
114
 
 
115
        def __get_incremental_check_button(self):
 
116
                return self.__incremental_check_button
 
117
 
 
118
########################################################################
 
119
#
 
120
#                                       Public API properties
 
121
#
 
122
########################################################################
 
123
 
 
124
        # Public API properties.
 
125
        search_replace_manager = property(__get_search_replace_manager, doc="Search and replace object.")
 
126
        find_text_entry = property(__get_entry, doc="Entry for the findbar.")
 
127
        match_case_button = property(__get_match_case_button, doc="")
 
128
        match_word_button = property(__get_match_word_button, doc="")
 
129
        next_button = property(__get_next_button, doc="")
 
130
        previous_button = property(__get_previous_button, doc="")
 
131
        search_button = property(__get_search_button, doc="")
 
132
        find_stop_button = property(__get_stop_button, doc="")
 
133
        replace_entry = property(__get_replace_entry, doc="")
 
134
        replace_button = property(__get_replace_button, doc="")
 
135
        replace_all_button = property(__get_replace_all_button, doc="")
 
136
        incremental_button = property(__get_incremental_check_button, doc="")
 
137
 
 
138
        def __init_attributes(self):
 
139
                """
 
140
                Initialize the replace bar object's attributes.
 
141
 
 
142
                @param self: Reference to the ScribesReplaceBar instance.
 
143
                @type self: A ScribesReplaceBar object.
 
144
                """
 
145
                # Findbar stuff.
 
146
                self.__editor = self.editor
 
147
                self.__editor.triggermanager.trigger("initialize_search_replace_manager")
 
148
                self.__search_replace_manager = self.__manager = self.editor.store.get_object("SearchReplaceManager")
 
149
                from CaseButton import FindCaseButton
 
150
                self.__matchcase_check_button = FindCaseButton(self)
 
151
                from WordButton import FindWordButton
 
152
                self.__matchword_check_button = FindWordButton(self)
 
153
                from Entry import FindEntry
 
154
                self.__entry = FindEntry(self)
 
155
                from PreviousButton import FindPreviousButton
 
156
                self.__previous_button = FindPreviousButton(self)
 
157
                from NextButton import FindNextButton
 
158
                self.__next_button = FindNextButton(self)
 
159
                from SearchButton import FindSearchButton
 
160
                self.__search_button = FindSearchButton(self)
 
161
                from StopButton import FindStopButton
 
162
                self.__stop_button = FindStopButton(self)
 
163
                self.__signal_id_1 = None
 
164
                self.__signal_id_2 = None
 
165
                self.__signal_id_3 = None
 
166
                self.__signal_id_4 = None
 
167
                self.__signal_id_5 = None
 
168
                self.__signal_id_6 = None
 
169
                self.__signal_id_7 = None
 
170
                self.__status_id_1 = None
 
171
                self.__signal_id_8 = self.__signal_id_9 = self.__signal_id_10 = None
 
172
                self.__signal_id_11 = self.__signal_id_12 = self.__signal_id_13 = None
 
173
                self.__signal_id_14 = self.__signal_id_15 = None
 
174
                from i18n import msg0005
 
175
                from gtk import Label
 
176
                self.__label = Label(msg0005)
 
177
                self.__show_stop_button = True
 
178
                self.__bar_is_visible = False
 
179
                # Replacebar stuff.
 
180
                self.__show_replace_stop_button = True
 
181
                from gtk import Label
 
182
                from i18n import msg0008
 
183
                self.__replace_label = Label(msg0008)
 
184
                self.__replace_label.set_use_underline(True)
 
185
                from ReplaceButton import ReplaceButton
 
186
                self.__replace_button = ReplaceButton(self)
 
187
                from ReplaceAllButton import ReplaceAllButton
 
188
                self.__replace_all_button = ReplaceAllButton(self)
 
189
                from ReplaceEntry import ReplaceEntry
 
190
                self.__replace_entry = ReplaceEntry(self)
 
191
                from ReplaceStopButton import ReplaceStopButton
 
192
                self.__replace_stop_button = ReplaceStopButton(self)
 
193
                from IncrementalButton import ReplaceIncrementalButton
 
194
                self.__incremental_check_button = ReplaceIncrementalButton(self)
 
195
                return
 
196
 
 
197
        def __set_properties(self):
 
198
                """
 
199
                Define the default properties for the bar.
 
200
 
 
201
                @param self: Reference to the ScribesReplaceBar instance.
 
202
                @type self: A ScribesReplaceBar object.
 
203
                """
 
204
                self.set_property("name", "scribes replacebar")
 
205
                self.resize(rows=2, columns=7)
 
206
                self.set_col_spacings(5)
 
207
                self.set_row_spacings(1)
 
208
                self.set_property("border-width", 1)
 
209
                self.__label.set_use_underline(True)
 
210
                return
 
211
 
 
212
        def __arrange_widgets(self):
 
213
                """
 
214
                Arrange the widgets of the replace bar.
 
215
 
 
216
                @param self: Reference to the ScribesReplaceBar instance.
 
217
                @type self: A ScribesReplaceBar object.
 
218
                """
 
219
                from gtk import SHRINK, FILL, EXPAND, Alignment, VSeparator
 
220
                from gtk import VSeparator, SHRINK, FILL, EXPAND, Alignment
 
221
                self.__find_alignment = Alignment(xalign=1.0, yalign=0.5)
 
222
                self.__find_alignment.add(self.__label)
 
223
                self.__label.set_mnemonic_widget(self.__entry)
 
224
                self.attach(child=self.__find_alignment,
 
225
                                        left_attach=0,
 
226
                                        right_attach=1,
 
227
                                        top_attach=0,
 
228
                                        bottom_attach=1,
 
229
                                        xoptions=SHRINK|FILL,
 
230
                                        yoptions=EXPAND|FILL,
 
231
                                        xpadding=7,
 
232
                                        ypadding=0)
 
233
 
 
234
                self.attach(child=self.__entry,
 
235
                                        left_attach=1,
 
236
                                        right_attach=2,
 
237
                                        top_attach=0,
 
238
                                        bottom_attach=1,
 
239
                                        xoptions=SHRINK|FILL,
 
240
                                        yoptions=EXPAND|FILL,
 
241
                                        xpadding=0,
 
242
                                        ypadding=0)
 
243
 
 
244
                self.attach(child=self.__previous_button,
 
245
                                        left_attach=2,
 
246
                                        right_attach=3,
 
247
                                        top_attach=0,
 
248
                                        bottom_attach=1,
 
249
                                        xoptions=SHRINK|FILL,
 
250
                                        yoptions=EXPAND|FILL,
 
251
                                        xpadding=0,
 
252
                                        ypadding=0)
 
253
 
 
254
                self.attach(child=self.__search_button,
 
255
                                        left_attach=3,
 
256
                                        right_attach=4,
 
257
                                        top_attach=0,
 
258
                                        bottom_attach=1,
 
259
                                        xoptions=SHRINK|FILL,
 
260
                                        yoptions=EXPAND|FILL,
 
261
                                        xpadding=0,
 
262
                                        ypadding=0)
 
263
 
 
264
                self.attach(child=VSeparator(),
 
265
                                        left_attach=4,
 
266
                                        right_attach=5,
 
267
                                        top_attach=0,
 
268
                                        bottom_attach=1,
 
269
                                        xoptions=SHRINK|FILL,
 
270
                                        yoptions=SHRINK|FILL,
 
271
                                        xpadding=0,
 
272
                                        ypadding=0)
 
273
 
 
274
                self.attach(child=self.__matchcase_check_button,
 
275
                                        left_attach=5,
 
276
                                        right_attach=6,
 
277
                                        top_attach=0,
 
278
                                        bottom_attach=1,
 
279
                                        xoptions=SHRINK|FILL,
 
280
                                        yoptions=EXPAND|FILL,
 
281
                                        xpadding=0,
 
282
                                        ypadding=0)
 
283
 
 
284
                self.attach(child=self.__matchword_check_button,
 
285
                                        left_attach=6,
 
286
                                        right_attach=7,
 
287
                                        top_attach=0,
 
288
                                        bottom_attach=1,
 
289
                                        xoptions=SHRINK|FILL,
 
290
                                        yoptions=EXPAND|FILL,
 
291
                                        xpadding=0,
 
292
                                        ypadding=0)
 
293
 
 
294
                # Replacebar
 
295
                self.__replace_alignment = Alignment(xalign=1.0, yalign=0.5)
 
296
                self.__replace_alignment.add(self.__replace_label)
 
297
                self.__replace_label.set_mnemonic_widget(self.__replace_entry)
 
298
                self.attach(child=self.__replace_alignment,
 
299
                                        left_attach=0,
 
300
                                        right_attach=1,
 
301
                                        top_attach=1,
 
302
                                        bottom_attach=2,
 
303
                                        xoptions=SHRINK|FILL,
 
304
                                        yoptions=EXPAND|FILL,
 
305
                                        xpadding=7,
 
306
                                        ypadding=0)
 
307
 
 
308
                self.attach(child=self.__replace_entry,
 
309
                                        left_attach=1,
 
310
                                        right_attach=2,
 
311
                                        top_attach=1,
 
312
                                        bottom_attach=2,
 
313
                                        xoptions=SHRINK|FILL,
 
314
                                        yoptions=EXPAND|FILL,
 
315
                                        xpadding=0,
 
316
                                        ypadding=0)
 
317
 
 
318
                self.attach(child=self.__replace_button,
 
319
                                        left_attach=2,
 
320
                                        right_attach=3,
 
321
                                        top_attach=1,
 
322
                                        bottom_attach=2,
 
323
                                        xoptions=SHRINK|FILL,
 
324
                                        yoptions=EXPAND|FILL,
 
325
                                        xpadding=0,
 
326
                                        ypadding=0)
 
327
 
 
328
                self.attach(child=self.__replace_all_button,
 
329
                                        left_attach=3,
 
330
                                        right_attach=4,
 
331
                                        top_attach=1,
 
332
                                        bottom_attach=2,
 
333
                                        xoptions=SHRINK|FILL,
 
334
                                        yoptions=EXPAND|FILL,
 
335
                                        xpadding=0,
 
336
                                        ypadding=0)
 
337
 
 
338
                self.attach(child=VSeparator(),
 
339
                                        left_attach=4,
 
340
                                        right_attach=5,
 
341
                                        top_attach=1,
 
342
                                        bottom_attach=2,
 
343
                                        xoptions=SHRINK|FILL,
 
344
                                        yoptions=SHRINK|FILL,
 
345
                                        xpadding=0,
 
346
                                        ypadding=0)
 
347
 
 
348
                self.attach(child=self.__incremental_check_button,
 
349
                                        left_attach=5,
 
350
                                        right_attach=6,
 
351
                                        top_attach=1,
 
352
                                        bottom_attach=2,
 
353
                                        xoptions=SHRINK|FILL,
 
354
                                        yoptions=EXPAND|FILL,
 
355
                                        xpadding=0,
 
356
                                        ypadding=0)
 
357
                return
 
358
 
 
359
        def show_bar(self):
 
360
                """
 
361
                Show the findbar.
 
362
 
 
363
                @param self: Reference to the ScribesFindBar instance.
 
364
                @type self: A ScribesFindBar object.
 
365
                """
 
366
                if self.__bar_is_visible:
 
367
                        return
 
368
                ScribesBar.show_bar(self)
 
369
                return
 
370
 
 
371
        def hide_bar(self):
 
372
                """
 
373
                Hide the findbar.
 
374
 
 
375
                @param self: Reference to the ScribesFindBar instance.
 
376
                @type self: A ScribesFindBar object.
 
377
                """
 
378
                if self.__bar_is_visible is False:
 
379
                        return
 
380
                ScribesBar.hide_bar(self)
 
381
                return
 
382
 
 
383
        def __show_replace_stop_button_cb(self):
 
384
                if self.__show_replace_stop_button is False:
 
385
                        return False
 
386
                self.__replace_stop_button.set_property("sensitive", True)
 
387
                self.__replace_stop_button.grab_focus()
 
388
                return False
 
389
 
 
390
        def __show_stop_button_cb(self):
 
391
                """
 
392
                Show the stop button.
 
393
 
 
394
                The stop button is shown if a searching operation is more than 1 second
 
395
                long.
 
396
 
 
397
                @param self: Reference to the ScribesFindBar instance.
 
398
                @type self: A ScribesFindBar object.
 
399
 
 
400
                @return: True to call this function again, False otherwise.
 
401
                @rtype: A Boolean object.
 
402
                """
 
403
                if self.__show_stop_button is False:
 
404
                        return False
 
405
                self.__stop_button.set_property("sensitive", True)
 
406
                self.__stop_button.grab_focus()
 
407
                return False
 
408
 
 
409
########################################################################
 
410
#
 
411
#                                                       (Un)Block Callbacks
 
412
#
 
413
########################################################################
 
414
 
 
415
        def __block_search_replace_signals(self):
 
416
                """
 
417
                Block signals for the search and replace manager.
 
418
 
 
419
                The search and replace manager is used multiple widgets and
 
420
                functions. Thus when the find bar is hidden, these signals need
 
421
                to be blocked. Otherwise, the find bar traps these signals and
 
422
                handles them which can lead to unwanted behavior.
 
423
 
 
424
                @param self: Reference to the ScribesFindBar instance.
 
425
                @type self: A ScribesFindBar object.
 
426
                """
 
427
                self.__search_replace_manager.handler_block(self.__signal_id_1)
 
428
                self.__search_replace_manager.handler_block(self.__signal_id_2)
 
429
                self.__search_replace_manager.handler_block(self.__signal_id_3)
 
430
                self.__search_replace_manager.handler_block(self.__signal_id_4)
 
431
                self.__search_replace_manager.handler_block(self.__signal_id_5)
 
432
                self.__search_replace_manager.handler_block(self.__signal_id_6)
 
433
                self.__search_replace_manager.handler_block(self.__signal_id_7)
 
434
                return
 
435
 
 
436
        def __unblock_search_replace_signals(self):
 
437
                """
 
438
                Unblock signals for the search and replace manager.
 
439
 
 
440
                The search and replace manager is used multiple widgets and
 
441
                functions. Thus when the find bar is hidden, these signals need
 
442
                to be blocked. Otherwise, the find bar traps these signals and
 
443
                handles them. This can lead to unwanted behavior.
 
444
 
 
445
                @param self: Reference to the ScribesFindBar instance.
 
446
                @type self: A ScribesFindBar object.
 
447
                """
 
448
                self.__search_replace_manager.handler_unblock(self.__signal_id_1)
 
449
                self.__search_replace_manager.handler_unblock(self.__signal_id_2)
 
450
                self.__search_replace_manager.handler_unblock(self.__signal_id_3)
 
451
                self.__search_replace_manager.handler_unblock(self.__signal_id_4)
 
452
                self.__search_replace_manager.handler_unblock(self.__signal_id_5)
 
453
                self.__search_replace_manager.handler_unblock(self.__signal_id_6)
 
454
                self.__search_replace_manager.handler_unblock(self.__signal_id_7)
 
455
                return
 
456
 
 
457
########################################################################
 
458
#
 
459
#                                       Signal and Event Handlers
 
460
#
 
461
########################################################################
 
462
 
 
463
        def __replacebar_replacing_cb(self, replacemanager):
 
464
                """
 
465
                Handles callback when the "replacing" signal is emitted.
 
466
 
 
467
                @param self: Reference to the ScribesReplaceBar instance.
 
468
                @type self: A ScribesReplaceBar object.
 
469
 
 
470
                @param replacemanager: The text editor's replace object.
 
471
                @type replacemanager: A ScribesReplaceBar object.
 
472
                """
 
473
                self.__show_replace_stop_button = True
 
474
                self.__entry.set_property("sensitive", False)
 
475
                self.__search_button.set_property("sensitive", False)
 
476
                self.__matchcase_check_button.set_property("sensitive", False)
 
477
                self.__matchword_check_button.set_property("sensitive", False)
 
478
                from gobject import timeout_add
 
479
                timeout_add(1000, self.__show_replace_stop_button_cb)
 
480
                self.__previous_button.set_property("sensitive", False)
 
481
                if self.__next_button in self.get_children():
 
482
                        self.remove(self.__next_button)
 
483
                        from gtk import SHRINK, FILL, EXPAND
 
484
                        self.attach(child=self.__search_button,
 
485
                                        left_attach=3,
 
486
                                        right_attach=4,
 
487
                                        top_attach=0,
 
488
                                        bottom_attach=1,
 
489
                                        xoptions=SHRINK|FILL,
 
490
                                        yoptions=EXPAND|FILL,
 
491
                                        xpadding=0,
 
492
                                        ypadding=0)
 
493
                        self.__search_button.show_all()
 
494
                if self.__replace_all_button in self.get_children():
 
495
                        self.remove(self.__replace_all_button)
 
496
                        from gtk import SHRINK, FILL, EXPAND
 
497
                        self.attach(child=self.__replace_stop_button,
 
498
                                                left_attach=3,
 
499
                                                right_attach=4,
 
500
                                                top_attach=1,
 
501
                                                bottom_attach=2,
 
502
                                                xoptions=SHRINK|FILL,
 
503
                                                yoptions=EXPAND|FILL,
 
504
                                                xpadding=0,
 
505
                                                ypadding=0)
 
506
                        self.__replace_stop_button.set_property("sensitive", False)
 
507
                        self.__replace_stop_button.show_all()
 
508
                return
 
509
 
 
510
        def __replacebar_replaced_cb(self, replacemanager):
 
511
                """
 
512
                Handles callback when the "replaced" signal is emitted.
 
513
 
 
514
                @param self: Reference to the ScribesReplaceBar instance.
 
515
                @type self: A ScribesReplaceBar object.
 
516
 
 
517
                @param replacemanager: The text editor's replace object.
 
518
                @type replacemanager: A ScribesReplaceBar object.
 
519
                """
 
520
                self.__show_replace_stop_button = False
 
521
                self.__entry.set_property("sensitive", True)
 
522
                self.__search_button.set_property("sensitive", True)
 
523
                self.__matchcase_check_button.set_property("sensitive", True)
 
524
                self.__matchword_check_button.set_property("sensitive", True)
 
525
                if self.__replace_stop_button in self.get_children():
 
526
                        self.remove(self.__replace_stop_button)
 
527
                        from gtk import SHRINK, FILL, EXPAND
 
528
                        self.attach(child=self.__replace_all_button,
 
529
                                                left_attach=3,
 
530
                                                right_attach=4,
 
531
                                                top_attach=1,
 
532
                                                bottom_attach=2,
 
533
                                                xoptions=SHRINK|FILL,
 
534
                                                yoptions=EXPAND|FILL,
 
535
                                                xpadding=0,
 
536
                                                ypadding=0)
 
537
                        self.__replace_all_button.show_all()
 
538
                self.__entry.grab_focus()
 
539
                return
 
540
 
 
541
        def __replacebar_cancel_cb(self, searchmanager):
 
542
                """
 
543
                Handles callback when the "cancel" signal is emitted.
 
544
 
 
545
                @param self: Reference to the ScribesReplaceBar instance.
 
546
                @type self: A ScribesReplaceBar object.
 
547
 
 
548
                @param searchmanager: An object that performs search and replace operations.
 
549
                @type searchmanager: A SearchReplaceManager object.
 
550
                """
 
551
                self.__show_replace_stop_button = False
 
552
                self.__entry.set_property("sensitive", True)
 
553
                self.__search_button.set_property("sensitive", True)
 
554
                self.__matchword_check_button.set_property("sensitive", True)
 
555
                self.__matchcase_check_button.set_property("sensitive", True)
 
556
                if self.__stop_button in self.get_children():
 
557
                        self.remove(self.__stop_button)
 
558
                if self.__replace_stop_button in self.get_children():
 
559
                        self.remove(self.__replace_stop_button)
 
560
                        from gtk import SHRINK, FILL, EXPAND
 
561
                        self.attach(child=self.__replace_all_button,
 
562
                                                left_attach=3,
 
563
                                                right_attach=4,
 
564
                                                top_attach=1,
 
565
                                                bottom_attach=2,
 
566
                                                xoptions=SHRINK|FILL,
 
567
                                                yoptions=EXPAND|FILL,
 
568
                                                xpadding=0,
 
569
                                                ypadding=0)
 
570
                        self.__replace_all_button.show_all()
 
571
                if not self.__search_button in self.get_children():
 
572
                        from gtk import EXPAND, SHRINK, FILL
 
573
                        self.attach(child=self.__search_button,
 
574
                                                left_attach=3,
 
575
                                                right_attach=4,
 
576
                                                top_attach=0,
 
577
                                                bottom_attach=1,
 
578
                                                xoptions=SHRINK|FILL,
 
579
                                                yoptions=EXPAND|FILL,
 
580
                                                xpadding=0,
 
581
                                                ypadding=0)
 
582
                        self.__search_button.show_all()
 
583
                self.__entry.grab_focus()
 
584
                return
 
585
 
 
586
        def __replacebar_searching_cb(self, searchmanager):
 
587
                """
 
588
                Handles callback when the "searching" signal is emitted.
 
589
 
 
590
                @param self: Reference to the ScribesFindBar instance.
 
591
                @type self: A ScribesFindBar object.
 
592
 
 
593
                @param searchmanager: The text editor's searchmanager
 
594
                @type searchmanager: A SearchProcessor object.
 
595
                """
 
596
                self.__search_replace_manager.reset()
 
597
                self.__show_stop_button = True
 
598
                from gobject import timeout_add
 
599
                timeout_add(1000, self.__show_stop_button_cb)
 
600
                if self.__search_button in self.get_children():
 
601
                        self.remove(self.__search_button)
 
602
                if not self.__stop_button in self.get_children():
 
603
                        from gtk import EXPAND, SHRINK, FILL
 
604
                        self.attach(child=self.__stop_button,
 
605
                                        left_attach=3,
 
606
                                        right_attach=4,
 
607
                                        top_attach=0,
 
608
                                        bottom_attach=1,
 
609
                                        xoptions=SHRINK|FILL,
 
610
                                        yoptions=EXPAND|FILL,
 
611
                                        xpadding=0,
 
612
                                        ypadding=0)
 
613
                self.__stop_button.set_property("sensitive", False)
 
614
                self.__stop_button.show_all()
 
615
                return
 
616
 
 
617
        def __replacebar_matches_found_cb(self, searchmanager):
 
618
                """
 
619
                Handles callback when the "matches-found" signal is emitted.
 
620
 
 
621
                @param self: Reference to the ScribesFindBar instance.
 
622
                @type self: A ScribesFindBar object.
 
623
 
 
624
                @param searchmanager: The text editor's searchmanager
 
625
                @type searchmanager: A SearchProcessor object.
 
626
                """
 
627
                self.__show_stop_button = False
 
628
                if self.__stop_button in self.get_children():
 
629
                        self.remove(self.__stop_button)
 
630
                from gtk import EXPAND, SHRINK, FILL
 
631
                if self.__search_replace_manager.number_of_matches > 1:
 
632
                        self.attach(child=self.__next_button,
 
633
                                                left_attach=3,
 
634
                                                right_attach=4,
 
635
                                                top_attach=0,
 
636
                                                bottom_attach=1,
 
637
                                                xoptions=SHRINK|FILL,
 
638
                                                yoptions=EXPAND|FILL,
 
639
                                                xpadding=0,
 
640
                                                ypadding=0)
 
641
                        self.__next_button.show_all()
 
642
                else:
 
643
                        self.attach(child=self.__search_button,
 
644
                                                left_attach=3,
 
645
                                                right_attach=4,
 
646
                                                top_attach=0,
 
647
                                                bottom_attach=1,
 
648
                                                xoptions=SHRINK|FILL,
 
649
                                                yoptions=EXPAND|FILL,
 
650
                                                xpadding=0,
 
651
                                                ypadding=0)
 
652
                        self.__search_button.set_property("sensitive", False)
 
653
                        self.__search_button.show_all()
 
654
                return
 
655
 
 
656
        def __replacebar_no_matches_found_cb(self, searchmanager):
 
657
                """
 
658
                Handles callback when the "no-matches-found" signal is emitted.
 
659
 
 
660
                @param self: Reference to the ScribesFindBar instance.
 
661
                @type self: A ScribesFindBar object.
 
662
 
 
663
                @param searchmanager: The text editor's searchmanager
 
664
                @type searchmanager: A SearchProcessor object.
 
665
                """
 
666
                self.__show_stop_button = False
 
667
                if self.__stop_button in self.get_children():
 
668
                        self.remove(self.__stop_button)
 
669
                if not self.__search_button in self.get_children():
 
670
                        from gtk import EXPAND, SHRINK, FILL
 
671
                        self.attach(child=self.__search_button,
 
672
                                                left_attach=3,
 
673
                                                right_attach=4,
 
674
                                                top_attach=0,
 
675
                                                bottom_attach=1,
 
676
                                                xoptions=SHRINK|FILL,
 
677
                                                yoptions=EXPAND|FILL,
 
678
                                                xpadding=0,
 
679
                                                ypadding=0)
 
680
                        self.__search_button.set_property("sensitive", False)
 
681
                        self.__search_button.show_all()
 
682
                return
 
683
 
 
684
        def __replacebar_activate_cb(self, entry):
 
685
                """
 
686
                Handles callback when the findbar's entry "activate" signal is emitted.
 
687
 
 
688
                @param self: Reference to the ScribesFindBar instance.
 
689
                @type self: A ScribesFindBar object.
 
690
 
 
691
                @param entry: The findbar's text entry.
 
692
                @type entry: A gtk.Entry object.
 
693
 
 
694
                @return: True to propagate signals to parent widgets.
 
695
                @type: A Boolean Object.
 
696
                """
 
697
                if self.__search_button in self.get_children():
 
698
                        if entry.get_text():
 
699
                                self.__search_button.activate()
 
700
                else:
 
701
                        if entry.get_text():
 
702
                                self.__next_button.activate()
 
703
                return True
 
704
 
 
705
        def __replacebar_changed_cb(self, entry):
 
706
                """
 
707
                Handles callback when the findbar's entry "changed" signal is emitted.
 
708
 
 
709
                @param self: Reference to the ScribesFindBar instance.
 
710
                @type self: A ScribesFindBar object.
 
711
 
 
712
                @param entry: The findbar's text entry.
 
713
                @type entry: A gtk.Entry object.
 
714
 
 
715
                @return: True to propagate signals to parent widgets.
 
716
                @type: A Boolean Object.
 
717
                """
 
718
                from gtk import EXPAND, SHRINK, FILL
 
719
                self.__search_replace_manager.reset()
 
720
                if self.__next_button in self.get_children():
 
721
                        self.remove(self.__next_button)
 
722
                if not self.__search_button in self.get_children():
 
723
                        self.attach(child=self.__search_button,
 
724
                                                left_attach=3,
 
725
                                                right_attach=4,
 
726
                                                top_attach=0,
 
727
                                                bottom_attach=1,
 
728
                                                xoptions=SHRINK|FILL,
 
729
                                                yoptions=EXPAND|FILL,
 
730
                                                xpadding=0,
 
731
                                                ypadding=0)
 
732
                        self.__search_button.show_all()
 
733
                return False
 
734
 
 
735
        def __replacebar_toggled_cb(self, togglebutton):
 
736
                """
 
737
                Handles callback when the "toggled" signal is emitted.
 
738
 
 
739
                @param self: Reference to the ScribesFindBar instance.
 
740
                @type self: A ScribesFindBar object.
 
741
 
 
742
                @param togglebutton: The findbar's case check button.
 
743
                @type togglebutton: A ScribesFindCaseButton object.
 
744
                """
 
745
                if self.__next_button in self.get_children():
 
746
                        self.remove(self.__next_button)
 
747
                if not self.__search_button in self.get_children():
 
748
                        from gtk import EXPAND, SHRINK, FILL
 
749
                        self.attach(child=self.__search_button,
 
750
                                        left_attach=3,
 
751
                                        right_attach=4,
 
752
                                        top_attach=0,
 
753
                                        bottom_attach=1,
 
754
                                        xoptions=SHRINK|FILL,
 
755
                                        yoptions=EXPAND|FILL,
 
756
                                        xpadding=0,
 
757
                                        ypadding=0)
 
758
                        self.__search_button.show_all()
 
759
                self.__previous_button.set_property("sensitive", False)
 
760
                if self.__entry.get_text():
 
761
                        self.__search_button.set_property("sensitive", True)
 
762
                else:
 
763
                        self.__search_button.set_property("sensitive", False)
 
764
                self.__entry.grab_focus()
 
765
                self.__replace_button.set_property("sensitive", False)
 
766
                self.__replace_all_button.set_property("sensitive", False)
 
767
                self.__replace_entry.set_property("sensitive", False)
 
768
                return True
 
769
 
 
770
        def __replacebar_show_bar_cb(self, editor, bar):
 
771
                """
 
772
                Handles callback when the "show-bar" signal is emitted.
 
773
 
 
774
                @param self: Reference to the ScribesFindBar instance.
 
775
                @type self: A ScribesFindBar object.
 
776
 
 
777
                @param editor: Reference to the text editor.
 
778
                @type editor: An Editor object.
 
779
 
 
780
                @param gotobar: The text editor's gotobar.
 
781
                @type gotobar: A ScribesFindBar object.
 
782
                """
 
783
                if bar.get_property("name") != "scribes replacebar":
 
784
                        return
 
785
                self.__bar_is_visible = True
 
786
                self.__unblock_search_replace_signals()
 
787
                from i18n import msg0009
 
788
                self.__status_id_1 = self.editor.feedback.set_modal_message(msg0009, "replace")
 
789
                self.set_property("sensitive", True)
 
790
                return
 
791
 
 
792
        def __replacebar_hide_bar_cb(self, editor, bar):
 
793
                """
 
794
                Handles callback when the "hide-bar" signal is emitted.
 
795
 
 
796
                @param self: Reference to the ScribesFindBar instance.
 
797
                @type self: A ScribesFindBar object.
 
798
 
 
799
                @param editor: Reference to the text editor.
 
800
                @type editor: An Editor object.
 
801
 
 
802
                @param gotobar: The text editor's gotobar.
 
803
                @type gotobar: A ScribesFindBar object.
 
804
                """
 
805
                if bar.get_property("name") != "scribes replacebar":
 
806
                        return
 
807
                self.__block_search_replace_signals()
 
808
                self.__bar_is_visible = False
 
809
                self.__editor.feedback.unset_modal_message(self.__status_id_1, False)
 
810
                # Remove the next button from the findbar if it is attached.
 
811
                if self.__next_button in self.get_children():
 
812
                        self.remove(self.__next_button)
 
813
                # Remove the stop button from the findbar if it is attached.
 
814
                if self.__stop_button in self.get_children():
 
815
                        self.remove(self.__stop_button)
 
816
                # Attach the search button to the findbar if it isn't attached.
 
817
                if not self.__search_button in self.get_children():
 
818
                        from gtk import SHRINK, FILL, EXPAND
 
819
                        self.attach(child=self.__search_button,
 
820
                                        left_attach=3,
 
821
                                        right_attach=4,
 
822
                                        top_attach=0,
 
823
                                        bottom_attach=1,
 
824
                                        xoptions=SHRINK|FILL,
 
825
                                        yoptions=EXPAND|FILL,
 
826
                                        xpadding=0,
 
827
                                        ypadding=0)
 
828
                        self.__search_button.show_all()
 
829
                from i18n import msg0010
 
830
                self.editor.feedback.update_status_message(msg0010, "info", 3)
 
831
                if self.__replace_stop_button in self.get_children():
 
832
                        self.remove(self.__replace_stop_button)
 
833
                        from gtk import SHRINK, FILL, EXPAND
 
834
                        self.attach(child=self.__replace_all_button,
 
835
                                                left_attach=3,
 
836
                                                right_attach=4,
 
837
                                                top_attach=1,
 
838
                                                bottom_attach=2,
 
839
                                                xoptions=SHRINK|FILL,
 
840
                                                yoptions=EXPAND|FILL,
 
841
                                                xpadding=0,
 
842
                                                ypadding=0)
 
843
                        self.__replace_all_button.show_all()
 
844
                return
 
845
 
 
846
        def __destroy_cb(self, replacebar):
 
847
                """
 
848
                Handles callback when "delete" signal is emitted.
 
849
 
 
850
                @param self: Reference to the ReplaceBar instance.
 
851
                @type self: A ReplaceBar object.
 
852
 
 
853
                @param replacebar: Reference to the ReplaceBar instance.
 
854
                @type replacebar: A ReplaceBar object.
 
855
                """
 
856
                from SCRIBES.utils import disconnect_signal, delete_attributes
 
857
                disconnect_signal(self.__signal_id_1, self.__manager)
 
858
                disconnect_signal(self.__signal_id_2, self.__manager)
 
859
                disconnect_signal(self.__signal_id_3, self.__manager)
 
860
                disconnect_signal(self.__signal_id_4, self.__manager)
 
861
                disconnect_signal(self.__signal_id_5, self.__manager)
 
862
                disconnect_signal(self.__signal_id_6, self.__manager)
 
863
                disconnect_signal(self.__signal_id_7, self.__manager)
 
864
                disconnect_signal(self.__signal_id_8, self.__entry)
 
865
                disconnect_signal(self.__signal_id_9, self.__entry)
 
866
                disconnect_signal(self.__signal_id_10, self.__matchword_check_button)
 
867
                disconnect_signal(self.__signal_id_11, self.__matchword_check_button)
 
868
                disconnect_signal(self.__signal_id_12, self.__incremental_check_button)
 
869
                disconnect_signal(self.__signal_id_13, self.__editor)
 
870
                disconnect_signal(self.__signal_id_14, self.__editor)
 
871
                disconnect_signal(self.__signal_id_15, self)
 
872
                self.destroy()
 
873
                delete_attributes(self)
 
874
                del self
 
875
                self = None
 
876
                return