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

« back to all changes in this revision

Viewing changes to plugins/ReplaceBar/CaseButton.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 findbar's case
 
22
check button.
 
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 CheckButton
 
32
 
 
33
class FindCaseButton(CheckButton):
 
34
        """
 
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.
 
37
        """
 
38
 
 
39
        def __init__(self, findbar):
 
40
                """
 
41
                Initialize the check button.
 
42
 
 
43
                @param self: Reference to the FindCaseButton instance.
 
44
                @type self: A FindCaseButton object.
 
45
 
 
46
                @param findbar: The text editor's findbar.
 
47
                @type findbar: A ScribesFindBar object.
 
48
                """
 
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)
 
59
 
 
60
        def __init_attributes(self, findbar):
 
61
                """
 
62
                Initialize the check button's attributes.
 
63
 
 
64
                @param self: Reference to the FindCaseButton instance.
 
65
                @type self: A FindCaseButton object.
 
66
 
 
67
                @param findbar: The text editor's findbar.
 
68
                @type findbar: A ScribesFindBar object.
 
69
                """
 
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
 
78
                return
 
79
 
 
80
        def __casebutton_toggled_cb(self, togglebutton):
 
81
                """
 
82
                Handles callback when the "toggled" signal is emitted.
 
83
 
 
84
                @param self: Reference to the FindCaseButton instance.
 
85
                @type self: A FindCaseButton object.
 
86
 
 
87
                @param togglebutton: The findbar's case check button.
 
88
                @type togglebutton: A CheckButton object.
 
89
                """
 
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")
 
94
                return True
 
95
 
 
96
        def __casebutton_show_bar_cb(self, editor, bar):
 
97
                """
 
98
                Handles callback when the "show-bar" signal is emitted.
 
99
 
 
100
                @param self: Reference to the FindCaseButton instance.
 
101
                @type self: A FindCaseButton object.
 
102
 
 
103
                @param editor: Reference to the text editor.
 
104
                @type editor: An Editor object.
 
105
 
 
106
                @param bar: One of the text editor's bars.
 
107
                @type bar: A ScribesBar object.
 
108
                """
 
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)
 
113
                return
 
114
 
 
115
        def __casebutton_searching_cb(self, searchmanager):
 
116
                """
 
117
                Handles callback when the "searching" signal is emitted.
 
118
 
 
119
                @param self: Reference to the FindCaseButton instance.
 
120
                @type self: A FindCaseButton object.
 
121
 
 
122
                @param searchmanager: The text editor's search processor.
 
123
                @type searchmanager: A SearchProcessor object.
 
124
                """
 
125
                self.set_property("sensitive", False)
 
126
                return
 
127
 
 
128
        def __casebutton_matches_found_cb(self, searchmanager):
 
129
                """
 
130
                Handles callback when the "matches-found" signal is emitted.
 
131
 
 
132
                @param self: Reference to the FindCaseButton instance.
 
133
                @type self: A FindCaseButton object.
 
134
 
 
135
                @param searchmanager: The text editor's search processor.
 
136
                @type searchmanager: A SearchProcessor object.
 
137
                """
 
138
                self.set_property("sensitive", True)
 
139
                return
 
140
 
 
141
        def __casebutton_no_matches_found_cb(self, searchmanager):
 
142
                """
 
143
                Handles callback when the "no-matches-found" signal is emitted.
 
144
 
 
145
                @param self: Reference to the FindCaseButton instance.
 
146
                @type self: A FindCaseButton object.
 
147
 
 
148
                @param searchmanager: The text editor's search processor.
 
149
                @type searchmanager: A SearchProcessor object.
 
150
                """
 
151
                self.set_property("sensitive", True)
 
152
                return
 
153
 
 
154
        def __casebutton_cancel_cb(self, searchmanager):
 
155
                """
 
156
                Handles callback when the "cancel" signal is emitted.
 
157
 
 
158
                @param self: Reference to the FindCaseButton instance.
 
159
                @type self: A FindCaseButton object.
 
160
 
 
161
                @param searchmanager: The text editor's search processor.
 
162
                @type searchmanager: A SearchProcessor object.
 
163
                """
 
164
                self.set_property("sensitive", True)
 
165
                return
 
166
 
 
167
        def __destroy_cb(self, findbar):
 
168
                """
 
169
                Handles callback when the "destroy" signal is emitted.
 
170
 
 
171
                @param self: Reference to the FindCaseButton instance.
 
172
                @type self: A FindCaseButton object.
 
173
 
 
174
                @param findbar: Reference the Findbar instance.
 
175
                @type findbar: A Findbar object.
 
176
                """
 
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)
 
185
                self.destroy()
 
186
                delete_attributes(self)
 
187
                del self
 
188
                self = None
 
189
                return