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 toolbar container for the text
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
33
class ScribesToolbarContainer(HBox):
35
This class creates the toolbar container object for the text editor. The
36
toolbar container houses the text editor's toolbar object.
39
def __init__(self, editor):
41
Initialize instance of this class.
43
@param self: Reference to the ScribesToolbarContainer instance.
44
@type self: A ScribesToolbarContainer object.
46
@param editor: Reference to the text editor.
47
@type editor: An Editor object.
50
self.__init_attributes(editor)
51
self.__set_properties()
52
self.resize_children()
53
self.__signal_id_1 = editor.connect("close-document", self.__close_document_cb)
54
self.__signal_id_2 = editor.connect("close-document-no-save", self.__close_document_cb)
55
self.__signal_id_3 = editor.connect("show-bar", self.__show_bar_cb)
56
self.__signal_id_4 = editor.connect("hide-bar", self.__hide_bar_cb)
57
self.__signal_id_5 = editor.connect("show-dialog", self.__show_dialog_cb)
58
self.__signal_id_6 = editor.connect("hide-dialog", self.__hide_dialog_cb)
59
self.__signal_id_7 = editor.connect("enable-fullscreen", self.__enable_fullscreen_cb)
60
self.__signal_id_8 = editor.connect("disable-fullscreen", self.__disable_fullscreen_cb)
63
def __init_attributes(self, editor):
65
Initialize the text editor's toolbar container and set its default
68
@param self: Reference to the ScribesToolbarContainer instance.
69
@type self: A ScribesToolbarContainer object.
71
@param editor: Reference to the text editor.
72
@type editor: An Editor object.
74
self.__editor = editor
75
self.__registration_id = editor.register_termination_id()
76
# Initialize the fullscreen button.
77
self.__fsbutton = None
79
self.__handler_id = None
80
self.__signal_id_1 = self.__signal_id_2 = self.__signal_id_3 = None
81
self.__signal_id_4 = self.__signal_id_5 = self.__signal_id_6 = None
82
self.__signal_id_7 = self.__signal_id_8 = None
85
def __set_properties(self):
87
Set the toolbar container's properties.
89
@param self: Reference to the ScribesToolbarContainer instance.
90
@type self: A ScribesToolbarContainer object.
92
from gtk import RESIZE_PARENT
93
self.set_property("resize-mode", RESIZE_PARENT)
94
self.set_property("name", "ScribesToolbarContainer")
99
Destroy instance of this class.
101
@param self: Reference to the Store instance.
102
@type self: A Store object.
104
# Disconnect signals.
105
from utils import disconnect_signal, delete_attributes
106
disconnect_signal(self.__signal_id_1, self.__editor)
107
disconnect_signal(self.__signal_id_2, self.__editor)
108
disconnect_signal(self.__signal_id_3, self.__editor)
109
disconnect_signal(self.__signal_id_4, self.__editor)
110
disconnect_signal(self.__signal_id_5, self.__editor)
111
disconnect_signal(self.__signal_id_6, self.__editor)
112
disconnect_signal(self.__signal_id_7, self.__editor)
113
disconnect_signal(self.__signal_id_8, self.__editor)
114
disconnect_signal(self.__handler_id, self.__editor.window)
116
self.__fsbutton.destroy()
118
# Unregister object so that editor can quit.
119
self.__editor.unregister_termination_id(self.__registration_id)
120
delete_attributes(self)
121
# Delete data attributes.
126
def __close_document_cb(self, editor):
130
def __show_dialog_cb(self, editor, dialog):
132
Handles callback when the "show-dialog" signal is emitted.
134
@param self: Reference to the ScribesToolbarContainer instance.
135
@type self: A ScribesToolbarContainer object.
137
@param editor: Reference to the text editor.
138
@type editor: An Editor object.
140
self.set_property("sensitive", False)
141
self.__editor.response()
144
def __hide_dialog_cb(self, editor, dialog):
146
Handles callback when the "hide-dialog" signal is emitted.
148
@param self: Reference to the ScribesToolbarContainer instance.
149
@type self: A ScribesToolbarContainer object.
151
@param editor: Reference to the text editor.
152
@type editor: An Editor object.
154
self.set_property("sensitive", True)
155
self.__editor.response()
158
def __show_bar_cb(self, editor, bar):
159
self.set_property("sensitive", False)
162
def __hide_bar_cb(self, editor, bar):
163
self.set_property("sensitive", True)
166
def __enable_fullscreen_cb(self, editor):
168
Handles callback when the "enable-fullscreen" signal is emitted.
170
@param self: Reference to the ScribesToolbarContainer instance.
171
@type self: A ScribesToolbarContainer object.
173
@param editor: Reference to the text editor.
174
@type editor: An Editor object.
176
from gobject import timeout_add
177
self.__timer = timeout_add(5000, self.__hide_toolbarcontainer)
179
self.__fsbutton.show_all()
180
self.pack_end(self.__fsbutton, False, False, 0)
182
from fsbutton import ScribesFullscreenButton
183
self.__fsbutton = ScribesFullscreenButton(self.__editor)
184
self.__fsbutton.show_all()
185
self.pack_end(self.__fsbutton, False, False, 0)
187
self.resize_children()
188
self.__handler_id = editor.window.connect("motion-notify-event",
189
self.__motion_notify_event_cb)
192
def __disable_fullscreen_cb(self, editor):
194
Handles callback when the "disable-fullscreen" signal is emitted.
196
@param self: Reference to the ScribesToolbarContainer instance.
197
@type self: A ScribesToolbarContainer object.
199
@param editor: Reference to the text editor.
200
@type editor: An Editor object.
202
editor.window.disconnect(self.__handler_id)
203
from gobject import source_remove
204
source_remove(self.__timer)
205
self.__fsbutton.hide_all()
206
self.remove(self.__fsbutton)
209
self.resize_children()
210
self.__handler_id = self.__timer = None
213
def __motion_notify_event_cb(self, window, event):
215
Handles callback when the "motion-notify-event" signal is emitted.
217
@param self: Reference to the ScribesToolbarContainer instance.
218
@type self: A ScribesToolbarContainer object.
220
@param window: The window for the text editor.
221
@type window: A ScribesWindow object.
223
@param event: An event that occurs when the mouse moves.
224
@type event: A gtk.Event object.
226
@return: True to propagate signals to parent widgets.
227
@type: A Boolean Object.
229
window.window.get_pointer()
231
from gobject import source_remove
232
source_remove(self.__timer)
233
from gobject import timeout_add
234
self.__timer = timeout_add(5000, self.__hide_toolbarcontainer)
237
def __hide_toolbarcontainer(self):
239
Hide the toolbar container.
241
@param self: Reference to the ScribesToolbarContainer instance.
242
@type self: A ScribesToolbarContainer object.
244
@return: True to call this function again, False otherwise.
245
@rtype: A Boolean object.
247
if self.__editor.window.is_fullscreen: