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

« back to all changes in this revision

Viewing changes to SCRIBES/ModificationDialog.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 © 2007 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 defines the behavior of a modification
 
23
dialog.
 
24
 
 
25
@author: Lateef Alabi-Oki
 
26
@organization: The Scribes Project
 
27
@copyright: Copyright © 2007 Lateef Alabi-Oki
 
28
@license: GNU GPLv2 or Later
 
29
@contact: mystilleef@gmail.com
 
30
"""
 
31
 
 
32
class ModificationDialog(object):
 
33
        """
 
34
        This class defines the behavior of a modification dialog. The dialog
 
35
        provides options to reload, overwrite or ignore changes made to
 
36
        a document opened by Scribes by another application.
 
37
        """
 
38
 
 
39
        def __init__(self, filesaver, editor):
 
40
                """
 
41
                Initialize object.
 
42
 
 
43
                @param self: Reference to the ModificationDialog instance.
 
44
                @type self: A ModificationDialog object.
 
45
 
 
46
                @param filesaver: An object that saves documents.
 
47
                @type filesaver: A FileSaver object.
 
48
 
 
49
                @param editor: Reference to the text editor.
 
50
                @type editor: An Editor object.
 
51
                """
 
52
                self.__init_attributes(filesaver, editor)
 
53
                self.__set_properties()
 
54
                self.__signal_id_1 = self.__ignore_button.connect("clicked", self.__ignore_clicked_cb)
 
55
                self.__signal_id_2 = self.__overwrite_button.connect("clicked", self.__overwrite_clicked_cb)
 
56
                self.__signal_id_3 = self.__reload_button.connect("clicked", self.__reload_clicked_cb)
 
57
                self.__signal_id_4 = self.__window.connect("delete-event", self.__delete_event_cb)
 
58
                self.__signal_id_5 = self.__window.connect("key-press-event", self.__key_press_event_cb)
 
59
 
 
60
        def __init_attributes(self, filesaver, editor):
 
61
                """
 
62
                Initialize data attributes.
 
63
 
 
64
                @param self: Reference to the ModificationDialog instance.
 
65
                @type self: A ModificationDialog object.
 
66
 
 
67
                @param filesaver: An object that saves documents.
 
68
                @type filesaver: A FileSaver object.
 
69
 
 
70
                @param editor: Reference to the text editor.
 
71
                @type editor: An Editor object.
 
72
                """
 
73
                self.__editor = editor
 
74
                self.__filesaver = filesaver
 
75
                from os.path import join
 
76
                from info import scribes_data_folder
 
77
                glade_file = join(scribes_data_folder, "ModificationDialog.glade")
 
78
                from gtk.glade import XML
 
79
                glade = XML(glade_file, "Window")
 
80
                self.__window = glade.get_widget("Window")
 
81
                self.__ignore_button = glade.get_widget("IgnoreButton")
 
82
                self.__overwrite_button = glade.get_widget("OverwriteButton")
 
83
                self.__reload_button = glade.get_widget("ReloadButton")
 
84
                self.__label = glade.get_widget("MessageLabel")
 
85
                return
 
86
 
 
87
        def __set_properties(self):
 
88
                """
 
89
                Set default properties.
 
90
 
 
91
                @param self: Reference to the ModificationDialog instance.
 
92
                @type self: A ModificationDialog object.
 
93
                """
 
94
                self.__window.set_transient_for(self.__editor.window)
 
95
                self.__window.set_property("icon-name", "gtk-dialog-warning")
 
96
                return
 
97
 
 
98
        def destroy(self):
 
99
                """
 
100
                Destroy object.
 
101
 
 
102
                @param self: Reference to the ModificationDialog instance.
 
103
                @type self: A ModificationDialog object.
 
104
                """
 
105
                from utils import delete_attributes, disconnect_signal
 
106
                disconnect_signal(self.__signal_id_1, self.__ignore_button)
 
107
                disconnect_signal(self.__signal_id_2, self.__overwrite_button)
 
108
                disconnect_signal(self.__signal_id_3, self.__reload_button)
 
109
                disconnect_signal(self.__signal_id_4, self.__window)
 
110
                disconnect_signal(self.__signal_id_5, self.__window)
 
111
                self.__ignore_button.destroy()
 
112
                self.__overwrite_button.destroy()
 
113
                self.__reload_button.destroy()
 
114
                self.__window.destroy()
 
115
                delete_attributes(self)
 
116
                self = None
 
117
                del self
 
118
                return
 
119
 
 
120
        def show(self):
 
121
                """
 
122
                Show dialog.
 
123
 
 
124
                @param self: Reference to the ModificationDialog instance.
 
125
                @type self: A ModificationDialog object.
 
126
                """
 
127
                self.__editor.response()
 
128
                from internationalization import msg0490
 
129
                message = "<b>" + msg0490 + "</b>"
 
130
                from gnomevfs import get_local_path_from_uri
 
131
                message = message % (get_local_path_from_uri(self.__editor.uri))
 
132
                self.__label.set_markup(message)
 
133
                self.__ignore_button.grab_focus()
 
134
                self.__editor.emit("show-dialog", self.__window)
 
135
                self.__window.show_all()
 
136
                self.__editor.response()
 
137
                return
 
138
 
 
139
        def __hide(self):
 
140
                """
 
141
                Hide dialog.
 
142
 
 
143
                @param self: Reference to the ModificationDialog instance.
 
144
                @type self: A ModificationDialog object.
 
145
                """
 
146
                self.__editor.response()
 
147
                self.__editor.emit("hide-dialog", self.__window)
 
148
                self.__window.hide()
 
149
                self.__editor.response()
 
150
                return
 
151
 
 
152
        def __ignore_clicked_cb(self, *args):
 
153
                """
 
154
                Handles callback when the ignore button is clicked.
 
155
 
 
156
                @param self: Reference to the ModificationDialog instance.
 
157
                @type self: A ModificationDialog object.
 
158
                """
 
159
                self.__filesaver.reset_save_flag()
 
160
                self.__hide()
 
161
                return True
 
162
 
 
163
        def __overwrite_clicked_cb(self, *args):
 
164
                """
 
165
                Handles callback when the overwrite button is clicked.
 
166
 
 
167
                @param self: Reference to the ModificationDialog instance.
 
168
                @type self: A ModificationDialog object.
 
169
                """
 
170
                self.__filesaver.reset_save_flag()
 
171
                self.__editor.trigger("save_file")
 
172
                self.__hide()
 
173
                return True
 
174
 
 
175
        def __reload_clicked_cb(self, *args):
 
176
                """
 
177
                Handles callback when the reload button is clicked.
 
178
 
 
179
                @param self: Reference to the ModificationDialog instance.
 
180
                @type self: A ModificationDialog object.
 
181
                """
 
182
                self.__filesaver.reset_save_flag()
 
183
                self.__editor.emit("reload-document")
 
184
                self.__hide()
 
185
                return True
 
186
 
 
187
        def __delete_event_cb(self, *args):
 
188
                """
 
189
                Handles callback when the window is closed.
 
190
 
 
191
                @param self: Reference to the ModificationDialog instance.
 
192
                @type self: A ModificationDialog object.
 
193
                """
 
194
                self.__ignore_button.activate()
 
195
                return True
 
196
 
 
197
        def __key_press_event_cb(self, window, event):
 
198
                """
 
199
                Handles callback when the "Esc" key is pressed.
 
200
 
 
201
                @param self: Reference to the ModificationDialog instance.
 
202
                @type self: A ModificationDialog object.
 
203
 
 
204
                @param window: Reference to the dialog.
 
205
                @type window: A ModificationDialog object.
 
206
 
 
207
                @param event: A key press event.
 
208
                @type event: A gtk.Event object.
 
209
 
 
210
                @return: True to propagate signals to parent widgets.
 
211
                @type: A Boolean Object.
 
212
                """
 
213
                from gtk import keysyms
 
214
                from operator import ne
 
215
                if ne(event.keyval, keysyms.Escape): return False
 
216
                self.__ignore_button.activate()
 
217
                return True