1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# -*- coding: utf-8 -*-
# Copyright © 2005 Lateef Alabi-Oki
#
# This file is part of Scribes.
#
# Scribes is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Scribes is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Scribes; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
"""
This module exposes a base class for all dialogs used by the text editor.
@author: Lateef Alabi-Oki
@organization: The Scribes Project
@copyright: Copyright © 2005 Lateef Alabi-Oki
@license: GNU GPLv2 or Later
@contact: mystilleef@gmail.com
"""
from gtk import Dialog
class ScribesDialog(Dialog):
"""
This class defines the basic properties and behavior for all dialogs of the
text editor. Its primary objective is for inheritance. It inherits from the
gtk.Dialog. See the GTK+ manual for the properties gtk.Dialog exposes.
Ideally all dialogs should inherits from this class. Dialogs are shown or
hidden but never destroyed.
"""
def __init__(self, editor):
"""
Initialize basic dialog attributes and properties.
@param self: Reference to the ScribesDialog instance.
@type self: A ScribesDialog object.
@param window: An optional parent window.
@type window: A gtk.Window object.
"""
Dialog.__init__(self)
self.__init_attributes(editor)
self.__set_dialog_properties()
self.__signal_id_1 = self.connect("close", self.__close_cb)
self.__signal_id_2 = self.connect("response", self.__close_cb)
self.__signal_id_3 = self.editor.connect("close-document", self.__destroy_cb)
self.__signal_id_4 = self.editor.connect("close-document-no-save", self.__destroy_cb)
def __init_attributes(self, editor):
"""
Initialize the dialog attributes.
@param self: Reference to the ScribesDialog instance.
@type self: A ScribesDialog object.
@param window: A optional parent window.
@type window: A gtk.Window object.
"""
self.editor = editor
return
def __set_dialog_properties(self):
"""
Set the default dialog properties.
@param self: Reference to the ScribesDialog instance.
@type self: A ScribesDialog object.
"""
self.set_property("has-separator", False)
self.set_property("skip-pager-hint", True)
self.set_property("skip-taskbar-hint", True)
self.set_property("urgency-hint", False)
self.set_property("modal", True)
from gtk import WIN_POS_CENTER_ON_PARENT
self.set_property("window-position", WIN_POS_CENTER_ON_PARENT)
self.set_property("resizable", True)
try:
self.set_transient_for(self.editor.window)
except:
pass
return
def show_dialog(self):
"""
Show the dialog.
@param self: Reference to the ScribesDialog instance.
@type self: A ScribesDialog object.
"""
self.editor.emit("show-dialog", self)
self.run()
return
def hide_dialog(self):
"""
Hide the dialog.
@param self: Reference to the ScribesDialog instance.
@type self: A ScribesDialog object.
"""
self.editor.emit("hide-dialog", self)
self.hide()
# Feedback to the text editor's statusbar indication the dialog window
# has just been closed.
try:
from internationalization import msg0187
self.editor.feedback.update_status_message(msg0187, "info", 1)
except:
pass
return
def __destroy(self):
"""
Handles callback when the "delete" signal is emitted.
@param self: Reference to the OpenDialog instance.
@type self: An OpenDialog object.
@param dialog: Reference to the OpenDialog instance.
@type dialog: An OpenDialog object.
"""
self.editor.disconnect_signal(self.__signal_id_1, self)
self.editor.disconnect_signal(self.__signal_id_2, self)
self.editor.disconnect_signal(self.__signal_id_3, self.editor)
self.editor.disconnect_signal(self.__signal_id_4, self.editor)
self.destroy()
del self
self = None
return
################################################################################
#
# Dialog Callbacks
#
################################################################################
def __close_cb(self, *args):
self.hide_dialog()
return True
def __destroy_cb(self, *args):
self.__destroy()
return False
|