1
# -*- coding: utf-8 -*-
2
# Copyright © 2007 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
22
This module documents a class that defines the behavior of a modification
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
32
class ModificationDialog(object):
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.
39
def __init__(self, filesaver, editor):
43
@param self: Reference to the ModificationDialog instance.
44
@type self: A ModificationDialog object.
46
@param filesaver: An object that saves documents.
47
@type filesaver: A FileSaver object.
49
@param editor: Reference to the text editor.
50
@type editor: An Editor object.
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)
60
def __init_attributes(self, filesaver, editor):
62
Initialize data attributes.
64
@param self: Reference to the ModificationDialog instance.
65
@type self: A ModificationDialog object.
67
@param filesaver: An object that saves documents.
68
@type filesaver: A FileSaver object.
70
@param editor: Reference to the text editor.
71
@type editor: An Editor object.
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")
87
def __set_properties(self):
89
Set default properties.
91
@param self: Reference to the ModificationDialog instance.
92
@type self: A ModificationDialog object.
94
self.__window.set_transient_for(self.__editor.window)
95
self.__window.set_property("icon-name", "gtk-dialog-warning")
102
@param self: Reference to the ModificationDialog instance.
103
@type self: A ModificationDialog object.
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)
124
@param self: Reference to the ModificationDialog instance.
125
@type self: A ModificationDialog object.
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()
143
@param self: Reference to the ModificationDialog instance.
144
@type self: A ModificationDialog object.
146
self.__editor.response()
147
self.__editor.emit("hide-dialog", self.__window)
149
self.__editor.response()
152
def __ignore_clicked_cb(self, *args):
154
Handles callback when the ignore button is clicked.
156
@param self: Reference to the ModificationDialog instance.
157
@type self: A ModificationDialog object.
159
self.__filesaver.reset_save_flag()
163
def __overwrite_clicked_cb(self, *args):
165
Handles callback when the overwrite button is clicked.
167
@param self: Reference to the ModificationDialog instance.
168
@type self: A ModificationDialog object.
170
self.__filesaver.reset_save_flag()
171
self.__editor.trigger("save_file")
175
def __reload_clicked_cb(self, *args):
177
Handles callback when the reload button is clicked.
179
@param self: Reference to the ModificationDialog instance.
180
@type self: A ModificationDialog object.
182
self.__filesaver.reset_save_flag()
183
self.__editor.emit("reload-document")
187
def __delete_event_cb(self, *args):
189
Handles callback when the window is closed.
191
@param self: Reference to the ModificationDialog instance.
192
@type self: A ModificationDialog object.
194
self.__ignore_button.activate()
197
def __key_press_event_cb(self, window, event):
199
Handles callback when the "Esc" key is pressed.
201
@param self: Reference to the ModificationDialog instance.
202
@type self: A ModificationDialog object.
204
@param window: Reference to the dialog.
205
@type window: A ModificationDialog object.
207
@param event: A key press event.
208
@type event: A gtk.Event object.
210
@return: True to propagate signals to parent widgets.
211
@type: A Boolean Object.
213
from gtk import keysyms
214
from operator import ne
215
if ne(event.keyval, keysyms.Escape): return False
216
self.__ignore_button.activate()