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 case
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 FindCaseButton(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 FindCaseButton instance.
44
@type self: A FindCaseButton object.
46
@param findbar: The text editor's findbar.
47
@type findbar: A ScribesFindBar object.
49
from i18n import msg0001
50
CheckButton.__init__(self, msg0001, use_underline=True)
51
self.__init_attributes(findbar)
52
self.__signal_id_7 = self.connect("toggled", self.__casebutton_toggled_cb)
53
self.__signal_id_1 = self.__editor.connect("show-bar", self.__casebutton_show_bar_cb)
54
self.__signal_id_2 = self.__searchmanager.connect("searching", self.__casebutton_searching_cb)
55
self.__signal_id_3 = self.__searchmanager.connect("matches-found", self.__casebutton_matches_found_cb)
56
self.__signal_id_4 = self.__searchmanager.connect("no-matches-found", self.__casebutton_no_matches_found_cb)
57
self.__signal_id_5 = self.__searchmanager.connect("cancel", self.__casebutton_cancel_cb)
58
self.__signal_id_6 = 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 FindCaseButton instance.
65
@type self: A FindCaseButton 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 = None
75
self.__signal_id_3 = self.__signal_id_4 = None
76
self.__signal_id_5 = self.__signal_id_6 = None
77
self.__signal_id_7 = None
80
def __casebutton_toggled_cb(self, togglebutton):
82
Handles callback when the "toggled" signal is emitted.
84
@param self: Reference to the FindCaseButton instance.
85
@type self: A FindCaseButton object.
87
@param togglebutton: The findbar's case check button.
88
@type togglebutton: A CheckButton object.
90
self.__searchmanager.reset()
91
value = self.get_property("active")
92
self.__client.set_bool("/apps/scribes/match_case", value)
93
self.__client.notify("/apps/scribes/match_case")
96
def __casebutton_show_bar_cb(self, editor, bar):
98
Handles callback when the "show-bar" signal is emitted.
100
@param self: Reference to the FindCaseButton instance.
101
@type self: A FindCaseButton object.
103
@param editor: Reference to the text editor.
104
@type editor: An Editor object.
106
@param bar: One of the text editor's bars.
107
@type bar: A ScribesBar object.
109
self.set_property("sensitive", True)
110
value = self.__client.get_bool("/apps/scribes/match_case")
111
if not self.get_property("active") is value:
112
self.set_property("active", value)
115
def __casebutton_searching_cb(self, searchmanager):
117
Handles callback when the "searching" signal is emitted.
119
@param self: Reference to the FindCaseButton instance.
120
@type self: A FindCaseButton object.
122
@param searchmanager: The text editor's search processor.
123
@type searchmanager: A SearchProcessor object.
125
self.set_property("sensitive", False)
128
def __casebutton_matches_found_cb(self, searchmanager):
130
Handles callback when the "matches-found" signal is emitted.
132
@param self: Reference to the FindCaseButton instance.
133
@type self: A FindCaseButton object.
135
@param searchmanager: The text editor's search processor.
136
@type searchmanager: A SearchProcessor object.
138
self.set_property("sensitive", True)
141
def __casebutton_no_matches_found_cb(self, searchmanager):
143
Handles callback when the "no-matches-found" signal is emitted.
145
@param self: Reference to the FindCaseButton instance.
146
@type self: A FindCaseButton object.
148
@param searchmanager: The text editor's search processor.
149
@type searchmanager: A SearchProcessor object.
151
self.set_property("sensitive", True)
154
def __casebutton_cancel_cb(self, searchmanager):
156
Handles callback when the "cancel" signal is emitted.
158
@param self: Reference to the FindCaseButton instance.
159
@type self: A FindCaseButton object.
161
@param searchmanager: The text editor's search processor.
162
@type searchmanager: A SearchProcessor object.
164
self.set_property("sensitive", True)
167
def __destroy_cb(self, findbar):
169
Handles callback when the "destroy" signal is emitted.
171
@param self: Reference to the FindCaseButton instance.
172
@type self: A FindCaseButton object.
174
@param findbar: Reference the Findbar instance.
175
@type findbar: A Findbar object.
177
from SCRIBES.utils import disconnect_signal, delete_attributes
178
disconnect_signal(self.__signal_id_1, self.__editor)
179
disconnect_signal(self.__signal_id_2, self.__searchmanager)
180
disconnect_signal(self.__signal_id_3, self.__searchmanager)
181
disconnect_signal(self.__signal_id_4, self.__searchmanager)
182
disconnect_signal(self.__signal_id_5, self.__searchmanager)
183
disconnect_signal(self.__signal_id_6, findbar)
184
disconnect_signal(self.__signal_id_7, self)
186
delete_attributes(self)