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 creates the text editor's findbar's match word
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 CheckButton
33
class FindWordButton(CheckButton):
35
This class creates a check button for the text editor's findbar. The class
36
defines the behavior and default properties of the check button.
39
def __init__(self, findbar):
41
Initialize the check button.
43
@param self: Reference to the FindWordButton instance.
44
@type self: A FindWordButton object.
46
@param findbar: The text editor's findbar.
47
@type findbar: A ScribesFindBar object.
49
from i18n import msg0002
50
CheckButton.__init__(self, msg0002, use_underline=True)
51
self.__init_attributes(findbar)
52
self.__signal_id_1 = self.connect("toggled", self.__wordbutton_toggled_cb)
53
self.__signal_id_2 = self.__editor.connect("show-bar", self.__wordbutton_show_bar_cb)
54
self.__signal_id_3 = self.__searchmanager.connect("searching", self.__wordbutton_searching_cb)
55
self.__signal_id_4 = self.__searchmanager.connect("matches-found", self.__wordbutton_matches_found_cb)
56
self.__signal_id_5 = self.__searchmanager.connect("no-matches-found", self.__wordbutton_no_matches_found_cb)
57
self.__signal_id_6 = self.__searchmanager.connect("cancel", self.__wordbutton_cancel_cb)
58
self.__signal_id_7 = findbar.connect("delete", self.__destroy_cb)
60
def __init_attributes(self, findbar):
62
Initialize the check button's attributes.
64
@param self: Reference to the FindWordButton instance.
65
@type self: A FindWordButton object.
67
@param findbar: The text editor's findbar.
68
@type findbar: A ScribesFindBar object.
70
self.__editor = findbar.editor
71
self.__searchmanager = findbar.search_replace_manager
72
from gconf import client_get_default
73
self.__client = client_get_default()
74
self.__signal_id_1 = self.__signal_id_2 = self.__signal_id_3 = None
75
self.__signal_id_4 = self.__signal_id_5 = self.__signal_id_6 = None
78
def __wordbutton_toggled_cb(self, togglebutton):
80
Handles callback when the "toggled" signal is emitted.
82
@param self: Reference to the FindWordButton instance.
83
@type self: A FindWordButton object.
85
@param togglebutton: The findbar's case check button.
86
@type togglebutton: A CheckButton object.
88
self.__searchmanager.reset()
89
value = self.get_property("active")
90
self.__client.set_bool("/apps/scribes/match_word", value)
91
self.__client.notify("/apps/scribes/match_word")
94
def __wordbutton_show_bar_cb(self, editor, bar):
96
Handles callback when the "show-bar" signal is emitted.
98
@param self: Reference to the FindWordButton instance.
99
@type self: A FindWordButton object.
101
@param editor: Reference to the text editor.
102
@type editor: An Editor object.
104
@param bar: One of the text editor's bars.
105
@type bar: A ScribesBar object.
107
self.set_property("sensitive", True)
108
value = self.__client.get_bool("/apps/scribes/match_word")
109
if not self.get_property("active") is value:
110
self.set_property("active", value)
113
def __wordbutton_searching_cb(self, searchmanager):
115
Handles callback when the "searching" signal is emitted.
117
@param self: Reference to the FindWordButton instance.
118
@type self: A FindWordButton object.
120
@param searchmanager: The text editor's search processor.
121
@type searchmanager: A SearchProcessor object.
123
self.set_property("sensitive", False)
126
def __wordbutton_matches_found_cb(self, searchmanager):
128
Handles callback when the "matches-found" signal is emitted.
130
@param self: Reference to the FindWordButton instance.
131
@type self: A FindWordButton object.
133
@param searchmanager: The text editor's search processor.
134
@type searchmanager: A SearchProcessor object.
136
self.set_property("sensitive", True)
139
def __wordbutton_no_matches_found_cb(self, searchmanager):
141
Handles callback when the "no-matches-found" signal is emitted.
143
@param self: Reference to the FindWordButton instance.
144
@type self: A FindWordButton object.
146
@param searchmanager: The text editor's search processor.
147
@type searchmanager: A SearchProcessor object.
149
self.set_property("sensitive", True)
152
def __wordbutton_cancel_cb(self, searchmanager):
154
Handles callback when the "cancel" signal is emitted.
156
@param self: Reference to the FindWordButton instance.
157
@type self: A FindWordButton object.
159
@param searchmanager: The text editor's search processor.
160
@type searchmanager: A SearchProcessor object.
162
self.set_property("sensitive", True)
165
def __destroy_cb(self, findbar):
167
Handles callback when the "destroy" signal is emitted.
169
@param self: Reference to the FindWordButton instance.
170
@type self: A FindWordButton object.
172
@param findbar: Reference to the FindBar instance.
173
@type findbar: A FindBar object.
175
from SCRIBES.utils import disconnect_signal, delete_attributes
176
disconnect_signal(self.__signal_id_1, self)
177
disconnect_signal(self.__signal_id_2, self.__editor)
178
disconnect_signal(self.__signal_id_3, self.__searchmanager)
179
disconnect_signal(self.__signal_id_4, self.__searchmanager)
180
disconnect_signal(self.__signal_id_5, self.__searchmanager)
181
disconnect_signal(self.__signal_id_6, self.__searchmanager)
182
disconnect_signal(self.__signal_id_7, findbar)
184
delete_attributes(self)