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

« back to all changes in this revision

Viewing changes to SCRIBES/ToolbarContainer.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 toolbar container for the text
 
22
editor.
 
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 HBox
 
32
 
 
33
class ScribesToolbarContainer(HBox):
 
34
        """
 
35
        This class creates the toolbar container object for the text editor. The
 
36
        toolbar container houses the text editor's toolbar object.
 
37
        """
 
38
 
 
39
        def __init__(self, editor):
 
40
                """
 
41
                Initialize instance of this class.
 
42
 
 
43
                @param self: Reference to the ScribesToolbarContainer instance.
 
44
                @type self: A ScribesToolbarContainer object.
 
45
 
 
46
                @param editor: Reference to the text editor.
 
47
                @type editor: An Editor object.
 
48
                """
 
49
                HBox.__init__(self)
 
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)
 
61
                editor.response()
 
62
 
 
63
        def __init_attributes(self, editor):
 
64
                """
 
65
                Initialize the text editor's toolbar container and set its default
 
66
                state and properties.
 
67
 
 
68
                @param self: Reference to the ScribesToolbarContainer instance.
 
69
                @type self: A ScribesToolbarContainer object.
 
70
 
 
71
                @param editor: Reference to the text editor.
 
72
                @type editor: An Editor object.
 
73
                """
 
74
                self.__editor = editor
 
75
                self.__registration_id = editor.register_termination_id()
 
76
                # Initialize the fullscreen button.
 
77
                self.__fsbutton = None
 
78
                self.__timer = 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
 
83
                return
 
84
 
 
85
        def __set_properties(self):
 
86
                """
 
87
                Set the toolbar container's properties.
 
88
 
 
89
                @param self: Reference to the ScribesToolbarContainer instance.
 
90
                @type self: A ScribesToolbarContainer object.
 
91
                """
 
92
                from gtk import RESIZE_PARENT
 
93
                self.set_property("resize-mode", RESIZE_PARENT)
 
94
                self.set_property("name", "ScribesToolbarContainer")
 
95
                return
 
96
 
 
97
        def __destroy(self):
 
98
                """
 
99
                Destroy instance of this class.
 
100
 
 
101
                @param self: Reference to the Store instance.
 
102
                @type self: A Store object.
 
103
                """
 
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)
 
115
                if self.__fsbutton:
 
116
                        self.__fsbutton.destroy()
 
117
                self.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.
 
122
                del self
 
123
                self = None
 
124
                return
 
125
 
 
126
        def __close_document_cb(self, editor):
 
127
                self.__destroy()
 
128
                return 
 
129
 
 
130
        def __show_dialog_cb(self, editor, dialog):
 
131
                """
 
132
                Handles callback when the "show-dialog" signal is emitted.
 
133
 
 
134
                @param self: Reference to the ScribesToolbarContainer instance.
 
135
                @type self: A ScribesToolbarContainer object.
 
136
 
 
137
                @param editor: Reference to the text editor.
 
138
                @type editor: An Editor object.
 
139
                """
 
140
                self.set_property("sensitive", False)
 
141
                self.__editor.response()
 
142
                return
 
143
 
 
144
        def __hide_dialog_cb(self, editor, dialog):
 
145
                """
 
146
                Handles callback when the "hide-dialog" signal is emitted.
 
147
 
 
148
                @param self: Reference to the ScribesToolbarContainer instance.
 
149
                @type self: A ScribesToolbarContainer object.
 
150
 
 
151
                @param editor: Reference to the text editor.
 
152
                @type editor: An Editor object.
 
153
                """
 
154
                self.set_property("sensitive", True)
 
155
                self.__editor.response()
 
156
                return
 
157
 
 
158
        def __show_bar_cb(self, editor, bar):
 
159
                self.set_property("sensitive", False)
 
160
                return
 
161
 
 
162
        def __hide_bar_cb(self, editor, bar):
 
163
                self.set_property("sensitive", True)
 
164
                return
 
165
 
 
166
        def __enable_fullscreen_cb(self, editor):
 
167
                """
 
168
                Handles callback when the "enable-fullscreen" signal is emitted.
 
169
 
 
170
                @param self: Reference to the ScribesToolbarContainer instance.
 
171
                @type self: A ScribesToolbarContainer object.
 
172
 
 
173
                @param editor: Reference to the text editor.
 
174
                @type editor: An Editor object.
 
175
                """
 
176
                from gobject import timeout_add
 
177
                self.__timer = timeout_add(5000, self.__hide_toolbarcontainer)
 
178
                try:
 
179
                        self.__fsbutton.show_all()
 
180
                        self.pack_end(self.__fsbutton, False, False, 0)
 
181
                except:
 
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)
 
186
                self.queue_resize()
 
187
                self.resize_children()
 
188
                self.__handler_id = editor.window.connect("motion-notify-event",
 
189
                                                                self.__motion_notify_event_cb)
 
190
                return
 
191
 
 
192
        def __disable_fullscreen_cb(self, editor):
 
193
                """
 
194
                Handles callback when the "disable-fullscreen" signal is emitted.
 
195
 
 
196
                @param self: Reference to the ScribesToolbarContainer instance.
 
197
                @type self: A ScribesToolbarContainer object.
 
198
 
 
199
                @param editor: Reference to the text editor.
 
200
                @type editor: An Editor object.
 
201
                """
 
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)
 
207
                self.show_all()
 
208
                self.queue_resize()
 
209
                self.resize_children()
 
210
                self.__handler_id = self.__timer = None
 
211
                return
 
212
 
 
213
        def __motion_notify_event_cb(self, window, event):
 
214
                """
 
215
                Handles callback when the "motion-notify-event" signal is emitted.
 
216
 
 
217
                @param self: Reference to the ScribesToolbarContainer instance.
 
218
                @type self: A ScribesToolbarContainer object.
 
219
 
 
220
                @param window: The window for the text editor.
 
221
                @type window: A ScribesWindow object.
 
222
 
 
223
                @param event: An event that occurs when the mouse moves.
 
224
                @type event: A gtk.Event object.
 
225
 
 
226
                @return: True to propagate signals to parent widgets.
 
227
                @type: A Boolean Object.
 
228
                """
 
229
                window.window.get_pointer()
 
230
                self.show_all()
 
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)
 
235
                return False
 
236
 
 
237
        def __hide_toolbarcontainer(self):
 
238
                """
 
239
                Hide the toolbar container.
 
240
 
 
241
                @param self: Reference to the ScribesToolbarContainer instance.
 
242
                @type self: A ScribesToolbarContainer object.
 
243
 
 
244
                @return: True to call this function again, False otherwise.
 
245
                @rtype: A Boolean object.
 
246
                """
 
247
                if self.__editor.window.is_fullscreen:
 
248
                        self.hide_all()
 
249
                return False