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 used to create statusbar objects for the text
22
editor. The statusbar object are customized for the text editor.
24
@author: Lateef Alabi-Oki
25
@organiation: 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 Statusbar
33
class ScribesStatusbar(Statusbar):
35
This class creates instances of statusbar objects for the text editor.
38
def __init__(self, editor):
40
Initialize a statusbar objects for the text editor and set its
43
@param self: Reference to the ScribesStatusbar instance.
44
@type self: A ScribesStatusbar object.
46
@param width: The width size of the statusbar object.
47
@type width: An Integer object.
49
@param height: The height size of the statusbar object.
50
@type height: An Integer object.
52
Statusbar.__init__(self)
53
self.__init_attributes(editor)
54
self.set_reallocate_redraws(False)
55
self.set_redraw_on_allocate(False)
56
from gtk import RESIZE_PARENT
57
self.set_property("resize-mode", RESIZE_PARENT)
58
self.resize_children()
59
self.__signal_id_1 = editor.connect("close-document", self.__close_document_cb)
60
self.__signal_id_2 = editor.connect("close-document-no-save", self.__close_document_cb)
62
def __init_attributes(self, editor):
64
Initialize data attributes.
66
@param self: Reference to the ScribesMainContainer instance.
67
@type self: A ScribesMainContainer object.
69
@param editor: Reference to the text editor.
70
@type editor: An Editor object.
72
self.__editor = editor
73
self.__registration_id = editor.register_termination_id()
74
self.__signal_id_1 = self.__signal_id_2 = None
79
Destroy instance of this class.
81
@param self: Reference to the Store instance.
82
@type self: A Store object.
85
from utils import disconnect_signal, delete_attributes
86
disconnect_signal(self.__signal_id_1, self.__editor)
87
disconnect_signal(self.__signal_id_2, self.__editor)
89
# Unregister object so that editor can quit.
90
self.__editor.unregister_termination_id(self.__registration_id)
91
delete_attributes(self)
92
# Delete data attributes.
97
def __close_document_cb(self, editor):
99
Handles callback when the "close-document" signal is emitted.
101
@param self: Reference to the Store instance.
102
@type self: A Store object.
104
@param editor: Reference to the text editor.
105
@type editor: An Editor object.
110
class StatusOne(ScribesStatusbar):
112
The class instantiates a statusbar object for the text editor that informs
113
the user of the status of the text editor or the operations they are
114
currently performing.
117
def __init__(self, editor):
118
ScribesStatusbar.__init__(self, editor)
120
self.set_has_resize_grip(False)
121
# Initialize the first statusbar context identification.
124
self.connect("text-popped", self.__statusone_text_popped_cb)
125
self.connect("text-pushed", self.__statusone_text_pushed_cb)
127
def __statusone_text_popped_cb(self, statusbar, context_id, text):
129
Handles callback when messages are removed from the statusbar.
131
@param self: Reference to the StatusOne instance.
132
@type self: A StatusOne object.
134
@param statusbar: The first statusbar object for the text editor.
135
@type statusbar: A gtk.Statusbar object.
137
@param context_id: A number associated with a message on the statusbar.
138
@type context_id: An Integer object.
140
@param text: The message removed from the statusbar.
141
@type text: A String object.
143
@return: True to propagate signals to parent widgets.
144
@type: A Boolean Object.
146
self.context_id = context_id
150
def __statusone_text_pushed_cb(self, statusbar, context_id, text):
152
@param self: Reference to the StatusOne instance.
153
@type self: A StatusOne object.
155
@param statusbar: The first statusbar object for the text editor.
156
@type statusbar: A gtk.Statusbar object.
158
@param context_id: A number associated with a message on the statusbar.
159
@type context_id: An Integer object.
161
@param text: The message removed from the statusbar.
162
@type text: A String object.
164
@return: True to propagate signals to parent widgets.
165
@type: A Boolean Object.
167
self.context_id = context_id
171
class StatusTwo(ScribesStatusbar):
173
This class instantiates the second statusbar object of the text editor. This
174
statusbar bar displays the position of the cursor in the text editor's
178
def __init__(self, editor):
179
ScribesStatusbar.__init__(self, editor)
182
self.set_property("width-request", 160)
183
self.set_has_resize_grip(False)
184
# Initialize the second statusbar context identification.
186
self.editor.connect("gui-created", self.__statustwo_gui_created_cb)
187
self.editor.connect("enable-readonly", self.__statustwo_enable_readonly_cb)
188
self.editor.connect("disable-readonly", self.__statustwo_disable_readonly_cb)
190
def __statustwo_gui_created_cb(self, editor):
192
Handles callback when the "gui-created" signal is emitted
194
@param self: Reference to the StatusTwo instance.
195
@type self: An StatusTwo object.
197
@param editor: Reference to the text editor.
198
@type editor: An Editor object.
200
# Update the cursor position on the statusbar.
201
from gobject import idle_add, PRIORITY_LOW
202
idle_add(self.__update_cursor_position, editor.textview, priority=PRIORITY_LOW)
203
editor.connect("cursor-moved", self.__statustwo_cursor_moved_cb)
206
def __statustwo_cursor_moved_cb(self, editor):
208
Handles callback when the editor's buffer's "mark-set" signal is emitted.
210
This function updates the cursor position and reflects the changes of
213
@param self: Reference to the StatusTwo instance.
214
@type self: A StatusTwo object.
216
@param editor: Reference to the text editor.
217
@type editor: An Editor object.
219
# Update the cursor position on the statusbar.
220
from gobject import idle_add, PRIORITY_LOW
221
self.__stop_idle_add()
222
self.__id = idle_add(self.__update_cursor_position, editor.textview, priority=PRIORITY_LOW)
225
def __stop_idle_add(self):
227
from gobject import source_remove
228
source_remove(self.__id)
233
def __update_cursor_position(self, textview):
235
from cursor import update_cursor_position
236
update_cursor_position(self, textview)
237
except AttributeError:
241
def __statustwo_enable_readonly_cb(self, editor):
243
Handles callback when the "enable-readonly" signal is emitted.
245
@param self: Reference to the StatusTwo instance.
246
@type self: A StatusTwo object.
248
@param editor: Reference to the text editor.
249
@type editor: An Editor object.
254
def __statustwo_disable_readonly_cb(self, editor):
256
Handles callback when the "disable-readonly" signal is emitted.
258
@param self: Reference to the StatusTwo instance.
259
@type self: A StatusTwo object.
261
@param editor: Reference to the text editor.
262
@type editor: An Editor object.
267
class StatusThree(ScribesStatusbar):
269
This class instantiates the third statusbar object of the text editor. This
270
statusbar indicates whether the text editor is in "insert", or "overwrite"
274
def __init__(self, editor):
276
Initialize the third statusbar object of the text editor.
278
@param self: Reference to the StatusThree instance.
279
@type self: A StatusThree object.
281
ScribesStatusbar.__init__(self, editor)
283
self.set_has_resize_grip(True)
284
self.set_property("width-request", 80)
285
# Let status bar reflect correct textview mode
286
from internationalization import msg0354
287
self.context_id = self.get_context_id(msg0354)
288
self.push(self.context_id, msg0354)
289
self.editor.connect("gui-created", self.__statusthree_gui_created_cb)
290
self.editor.connect("enable-readonly", self.__statusthree_enable_readonly_cb)
291
self.editor.connect("disable-readonly", self.__statusthree_disable_readonly_cb)
293
def __statusthree_gui_created_cb(self, editor):
295
Handles callback when the "gui-created" signal is emitted
297
@param self: Reference to the StatusTwo instance.
298
@type self: An StatusTwo object.
300
@param editor: Reference to the text editor.
301
@type editor: An Editor object.
303
editor.textview.connect("toggle-overwrite", self.__statusthree_toggle_overwrite_cb)
306
def __statusthree_toggle_overwrite_cb(self, textview):
308
Handles callback when the textview's "toggle-overwrite" signal is
311
@param self: Reference to the StatusThree instance.
312
@type self: A StatusThree object.
314
@param textview: The text editor's buffer container, view.
315
@type textview: A gtksourceview.SourceView object.
317
@return: True to propagate signals to parent widgets.
318
@type: A Boolean Object.
320
# Set textview overwrite mode
321
if not textview.get_overwrite():
322
from internationalization import msg0355
325
from internationalization import msg0354
327
# Let status bar reflect correct textview mode
328
self.pop(self.context_id)
329
self.context_id = self.get_context_id(mode)
330
self.push(self.context_id, mode)
333
def __statusthree_enable_readonly_cb(self, editor):
335
Handles callback when the "enable-readonly" signal is emitted.
337
@param self: Reference to the StatusThree instance.
338
@type self: A StatusThree object.
340
@param editor: Reference to the text editor.
341
@type editor: An Editor object.
346
def __statusthree_disable_readonly_cb(self, editor):
348
Handles callback when the "disable-readonly" signal is emitted.
350
@param self: Reference to the StatusThree instance.
351
@type self: A StatusThree object.
353
@param editor: Reference to the text editor.
354
@type editor: An Editor object.