5
This is the "gedit" module.
7
This module provides a wrapper for LDTP to make writing GEdit tests easier.
12
from .main import Application
13
from ..gconfwrapper import GConf
14
from ..cmd import globals
18
gettext.install (True)
19
gettext.bindtextdomain (PACKAGE, globals.LOCALE_SHARE)
20
gettext.textdomain (PACKAGE)
21
t = gettext.translation(PACKAGE, globals.LOCALE_SHARE, fallback = True)
25
class GEdit(Application):
27
GEdit manages the Gedit application.
29
WINDOW = _("frm*gedit")
32
SAVE_DLG = _("dlgSave*")
33
SAVE_DLG_TXT_NAME = _("txtName")
34
SAVE_DLG_BTN_SAVE = _("btnSave")
35
QUESTION_DLG = _("dlgQuestion")
36
QUESTION_DLG_BTN_SAVE = _("btnSave")
37
QUESTION_DLG_BTN_SAVE_AS = _("btnSaveAs")
38
QUESTION_DLG_BTN_CLOSE = _("btnClosewithoutSaving")
39
MNU_QUIT = _("mnuQuit")
40
MNU_CLOSE = _("mnuClose")
42
MNU_SAVE = _("mnuSave")
45
Application.__init__(self)
48
def write_text(self, text):
50
It writes text to the current buffer of the Gedit window.
53
@param text: The text string to be written to the current buffer.
55
Application.write_text(self, text, self.TXT_FIELD)
57
def save(self, filename):
59
It tries to save the current opened buffer to the filename passed as parameter.
61
TODO: It does not manage the overwrite dialog yet.
63
@type filename: string
64
@param filename: The name of the file to save the buffer to.
66
Application.save(self, self.MNU_SAVE)
67
ooldtp.context(self.name)
70
ldtp.waittillguiexist(self.SAVE_DLG)
71
save_dialog = ooldtp.context(self.SAVE_DLG)
72
except ldtp.LdtpExecutionError:
73
raise ldtp.LdtpExecutionError, "The Gedit save dialog was not found."
75
save_dlg_txt_filename = save_dialog.getchild(self.SAVE_DLG_TXT_NAME)
76
except ldtp.LdtpExecutionError:
77
raise ldtp.LdtpExecutionError, "The filename txt field in Gedit save dialog was not found."
80
save_dlg_txt_filename.settextvalue(filename)
81
except ldtp.LdtpExecutionError:
82
raise ldtp.LdtpExecutionError, "We couldn't write text."
85
save_dlg_btn_save = save_dialog.getchild(self.SAVE_DLG_BTN_SAVE)
86
except ldtp.LdtpExecutionError:
87
raise ldtp.LdtpExecutionError, "The button Save in Gedit save dialog was not found."
90
save_dlg_btn_save.click()
91
except ldtp.LdtpExecutionError:
92
raise ldtp.LdtpExecutionError, "There was an error when pushing the Save button."
94
ldtp.waittillguinotexist(self.SAVE_DLG)
97
def close(self, save=False, filename=''):
99
Given a gedit window, it tries to close the application.
100
By default, it closes without saving. This behaviour can be changed to save (or save as) on close.
103
@param save: If True, the edited file will be saved on close.
105
@type filename: string
106
@param filename: The file name to save the buffer to
109
# Exit using the Quit menu
111
gedit = ooldtp.context(self.name)
113
quit_menu = gedit.getchild(self.MNU_QUIT)
114
except ldtp.LdtpExecutionError:
115
raise ldtp.LdtpExecutionError, "The quit menu was not found."
116
quit_menu.selectmenuitem()
117
except ldtp.LdtpExecutionError:
118
raise ldtp.LdtpExecutionError, "Mmm, something went wrong when closing the application."
120
question_dialog = None
122
while not gedit.waittillguinotexist(guiTimeOut=1) and \
125
question_dialog = ooldtp.context(self.QUESTION_DLG)
131
# If the text has changed, the save dialog will appear
133
# Test if the file needs to be saved
136
question_dlg_btn_save = question_dialog.getchild(self.QUESTION_DLG_BTN_SAVE)
137
question_dlg_btn_save.click()
138
except ldtp.LdtpExecutionError:
139
# If the Save button was not found, we will try to find the Save As
141
question_dlg_btn_save = question_dialog.getchild(self.QUESTION_DLG_BTN_SAVE_AS)
142
question_dlg_btn_save.click()
143
except ldtp.LdtpExecutionError:
144
raise ldtp.LdtpExecutionError, "The save or save as buttons in Gedit question dialog were not found."
147
ldtp.waittillguiexist(self.SAVE_DLG)
148
save_dialog = ooldtp.context(self.SAVE_DLG)
149
except ldtp.LdtpExecutionError:
150
raise ldtp.LdtpExecutionError, "The Gedit save dialog was not found."
152
save_dlg_txt_filename = save_dialog.getchild(self.SAVE_DLG_TXT_NAME)
153
except ldtp.LdtpExecutionError:
154
raise ldtp.LdtpExecutionError, "The filename txt field in Gedit save dialog was not found."
157
save_dlg_txt_filename.settextvalue(filename)
158
except ldtp.LdtpExecutionError:
159
raise ldtp.LdtpExecutionError, "There was an error when writing the text."
162
save_dlg_btn_save = save_dialog.getchild(self.SAVE_DLG_BTN_SAVE)
163
except ldtp.LdtpExecutionError:
164
raise ldtp.LdtpExecutionError, "The save button in Gedit save dialog was not found."
167
save_dlg_btn_save.click()
168
except ldtp.LdtpExecutionError:
169
raise ldtp.LdtpExecutionError, "There was an error when pushing the Save button."
171
ldtp.waittillguinotexist(self.SAVE_DLG)
175
question_dlg_btn_close = question_dialog.getchild(self.QUESTION_DLG_BTN_CLOSE)
176
question_dlg_btn_close.click()
177
except ldtp.LdtpExecutionError:
178
raise ldtp.LdtpExecutionError, "It was not possible to click the close button."
180
gedit.waittillguinotexist(guiTimeOut=20)