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

« back to all changes in this revision

Viewing changes to plugins/IncrementalBar/WordButton.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 match word
 
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 FindWordButton(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 FindWordButton instance.
 
44
                @type self: A FindWordButton object.
 
45
 
 
46
                @param findbar: The text editor's findbar.
 
47
                @type findbar: A ScribesFindBar object.
 
48
                """
 
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)
 
59
 
 
60
        def __init_attributes(self, findbar):
 
61
                """
 
62
                Initialize the check button's attributes.
 
63
 
 
64
                @param self: Reference to the FindWordButton instance.
 
65
                @type self: A FindWordButton 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 = self.__signal_id_3 = None
 
75
                self.__signal_id_4 = self.__signal_id_5 = self.__signal_id_6 = None
 
76
                return
 
77
 
 
78
        def __wordbutton_toggled_cb(self, togglebutton):
 
79
                """
 
80
                Handles callback when the "toggled" signal is emitted.
 
81
 
 
82
                @param self: Reference to the FindWordButton instance.
 
83
                @type self: A FindWordButton object.
 
84
 
 
85
                @param togglebutton: The findbar's case check button.
 
86
                @type togglebutton: A CheckButton object.
 
87
                """
 
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")
 
92
                return True
 
93
 
 
94
        def __wordbutton_show_bar_cb(self, editor, bar):
 
95
                """
 
96
                Handles callback when the "show-bar" signal is emitted.
 
97
 
 
98
                @param self: Reference to the FindWordButton instance.
 
99
                @type self: A FindWordButton object.
 
100
 
 
101
                @param editor: Reference to the text editor.
 
102
                @type editor: An Editor object.
 
103
 
 
104
                @param bar: One of the text editor's bars.
 
105
                @type bar: A ScribesBar object.
 
106
                """
 
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)
 
111
                return
 
112
 
 
113
        def __wordbutton_searching_cb(self, searchmanager):
 
114
                """
 
115
                Handles callback when the "searching" signal is emitted.
 
116
 
 
117
                @param self: Reference to the FindWordButton instance.
 
118
                @type self: A FindWordButton object.
 
119
 
 
120
                @param searchmanager: The text editor's search processor.
 
121
                @type searchmanager: A SearchProcessor object.
 
122
                """
 
123
                self.set_property("sensitive", False)
 
124
                return
 
125
 
 
126
        def __wordbutton_matches_found_cb(self, searchmanager):
 
127
                """
 
128
                Handles callback when the "matches-found" signal is emitted.
 
129
 
 
130
                @param self: Reference to the FindWordButton instance.
 
131
                @type self: A FindWordButton object.
 
132
 
 
133
                @param searchmanager: The text editor's search processor.
 
134
                @type searchmanager: A SearchProcessor object.
 
135
                """
 
136
                self.set_property("sensitive", True)
 
137
                return
 
138
 
 
139
        def __wordbutton_no_matches_found_cb(self, searchmanager):
 
140
                """
 
141
                Handles callback when the "no-matches-found" signal is emitted.
 
142
 
 
143
                @param self: Reference to the FindWordButton instance.
 
144
                @type self: A FindWordButton object.
 
145
 
 
146
                @param searchmanager: The text editor's search processor.
 
147
                @type searchmanager: A SearchProcessor object.
 
148
                """
 
149
                self.set_property("sensitive", True)
 
150
                return
 
151
 
 
152
        def __wordbutton_cancel_cb(self, searchmanager):
 
153
                """
 
154
                Handles callback when the "cancel" signal is emitted.
 
155
 
 
156
                @param self: Reference to the FindWordButton instance.
 
157
                @type self: A FindWordButton object.
 
158
 
 
159
                @param searchmanager: The text editor's search processor.
 
160
                @type searchmanager: A SearchProcessor object.
 
161
                """
 
162
                self.set_property("sensitive", True)
 
163
                return
 
164
 
 
165
        def __destroy_cb(self, findbar):
 
166
                """
 
167
                Handles callback when the "destroy" signal is emitted.
 
168
 
 
169
                @param self: Reference to the FindWordButton instance.
 
170
                @type self: A FindWordButton object.
 
171
 
 
172
                @param findbar: Reference to the FindBar instance.
 
173
                @type findbar: A FindBar object.
 
174
                """
 
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)
 
183
                self.destroy()
 
184
                delete_attributes(self)
 
185
                del self
 
186
                self = None
 
187
                return