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

« back to all changes in this revision

Viewing changes to plugins/RemoteDialog/Window.py

  • Committer: goldenmyst
  • Date: 2008-03-05 15:49:42 UTC
  • Revision ID: goldenmyst@goldenmyst-desktop-20080305154942-lu3eqminvhjfs14d
Ported remote dialog to glade. The open/save dialog still crash scribes occassionally. May be as a result of the new gio libraries. More investigation is needed

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
# Copyright © 2006 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
 
19
# USA
 
20
 
 
21
"""
 
22
This module documents a class that creates the window for the document
 
23
browser.
 
24
 
 
25
@author: Lateef Alabi-Oki
 
26
@organization: The Scribes Project
 
27
@copyright: Copyright © 2006 Lateef Alabi-Oki
 
28
@license: GNU GPLv2 or Later
 
29
@contact: mystilleef@gmail.com
 
30
"""
 
31
 
 
32
class Window(object):
 
33
        """
 
34
        This class creates the window for the document browser window.
 
35
        """
 
36
 
 
37
        def __init__(self, editor, manager):
 
38
                """
 
39
                Initialize an instance of this class.
 
40
 
 
41
                @param self: Reference to the BrowserWindow instance.
 
42
                @type self: A BrowserWindow object.
 
43
 
 
44
                @param manager: Reference to the Manager instance
 
45
                @type manager: A Manager object.
 
46
 
 
47
                @param editor: Reference to the text editor.
 
48
                @type editor: An Editor object.
 
49
                """
 
50
                self.__init_attributes(editor, manager)
 
51
                self.__set_properties()
 
52
                self.__sig_id1 = self.__manager.connect("destroy", self.__destroy_cb)
 
53
                self.__sig_id2 = self.__manager.connect("show-window", self.__show_window_cb)
 
54
                self.__sig_id3 = self.__manager.connect("hide-window", self.__hide_window_cb)
 
55
                self.__sig_id4 = self.__window.connect("delete-event", self.__delete_event_cb)
 
56
                self.__sig_id5 = self.__window.connect("key-press-event", self.__key_press_event_cb)
 
57
                from gobject import idle_add
 
58
                idle_add(self.__show)
 
59
                self.__window.set_property("sensitive", True)
 
60
 
 
61
        def __init_attributes(self, editor, manager):
 
62
                """
 
63
                Initialize data attributes.
 
64
 
 
65
                @param self: Reference to the Window instance.
 
66
                @type self: A Window object.
 
67
 
 
68
                @param manager: Reference to the Manager instance
 
69
                @type manager: A Manager object.
 
70
 
 
71
                @param editor: Reference to the text editor.
 
72
                @type editor: An Editor object.
 
73
                """
 
74
                self.__manager = manager
 
75
                self.__editor = editor
 
76
                self.__window = manager.glade.get_widget("Window")
 
77
                self.__sig_id1 = self.__status_id = None
 
78
                return
 
79
 
 
80
        def __set_properties(self):
 
81
                """
 
82
                Define the default behavior of the dialog.
 
83
 
 
84
                @param self: Reference to the Window instance.
 
85
                @type self: A Window object.
 
86
                """
 
87
                self.__window.set_transient_for(self.__editor.window)
 
88
                return
 
89
 
 
90
        def __show(self):
 
91
                """
 
92
                Show the document browser.
 
93
 
 
94
                @param self: Reference to the Window instance.
 
95
                @type self: A Window object.
 
96
                """
 
97
                self.__editor.emit("show-dialog", self.__window)
 
98
                from i18n import msg0001
 
99
                self.__status_id = self.__editor.feedback.set_modal_message(msg0001, "open")
 
100
                self.__window.show_all()
 
101
                return False
 
102
 
 
103
        def __hide(self):
 
104
                """
 
105
                Hide the document browser.
 
106
 
 
107
                @param self: Reference to the Window instance.
 
108
                @type self: A Window object.
 
109
                """
 
110
                self.__editor.emit("hide-dialog", self.__window)
 
111
                self.__editor.feedback.unset_modal_message(self.__status_id)
 
112
                self.__window.hide()
 
113
                return False
 
114
 
 
115
        def __destroy(self):
 
116
                """
 
117
                Destroy object.
 
118
 
 
119
                @param self: Reference to the Window instance.
 
120
                @type self: A Window object.
 
121
                """
 
122
                self.__editor.disconnect_signal(self.__sig_id1, self.__manager)
 
123
                self.__editor.disconnect_signal(self.__sig_id2, self.__manager)
 
124
                self.__editor.disconnect_signal(self.__sig_id3, self.__manager)
 
125
                self.__editor.disconnect_signal(self.__sig_id4, self.__window)
 
126
                self.__editor.disconnect_signal(self.__sig_id5, self.__window)
 
127
                self.__window.destroy()
 
128
                del self
 
129
                self = None
 
130
                return
 
131
 
 
132
        def __destroy_cb(self, *args):
 
133
                """
 
134
                Handles callback when "destroy" signal is emitted.
 
135
 
 
136
                @param self: Reference to the Window instance.
 
137
                @type self: An Window object.
 
138
                """
 
139
                self.__destroy()
 
140
                return
 
141
 
 
142
        def __hide_window_cb(self, *args):
 
143
                """
 
144
                Handles callback when "destroy" signal is emitted.
 
145
 
 
146
                @param self: Reference to the Window instance.
 
147
                @type self: An Window object.
 
148
                """
 
149
                self.__hide()
 
150
                return
 
151
 
 
152
        def __show_window_cb(self, *args):
 
153
                """
 
154
                Handles callback when "destroy" signal is emitted.
 
155
 
 
156
                @param self: Reference to the Window instance.
 
157
                @type self: An Window object.
 
158
                """
 
159
                from gobject import idle_add
 
160
                idle_add(self.__show)
 
161
                return
 
162
 
 
163
        def __delete_event_cb(self, *args):
 
164
                """
 
165
                Handles callback when "destroy" signal is emitted.
 
166
 
 
167
                @param self: Reference to the Window instance.
 
168
                @type self: An Window object.
 
169
                """
 
170
                self.__hide()
 
171
                return True
 
172
 
 
173
        def __key_press_event_cb(self, window, event):
 
174
                """
 
175
                Handles callback when "destroy" signal is emitted.
 
176
 
 
177
                @param self: Reference to the Window instance.
 
178
                @type self: An Window object.
 
179
                """
 
180
                from gtk import keysyms
 
181
                if event.keyval != keysyms.Escape: return False
 
182
                self.__hide()
 
183
                return True