4
main module contains the definition of the main Application class
5
that is used to wrap applications functionality
9
from ..cmd import globals
12
gettext.install (True)
13
gettext.bindtextdomain (PACKAGE, globals.LOCALE_SHARE)
14
gettext.textdomain (PACKAGE)
15
t = gettext.translation(PACKAGE, globals.LOCALE_SHARE, fallback = True)
20
Superclass for the rest of the applications
22
Constants that should be defined in the classes that inherit from this class
23
LAUNCHER: Command to launching the application through ldtp.launchapp
24
LAUNCHER_ARGS: Arguments to pass when launching the application through
26
WINDOW: Top application frame pattern using ldtp syntax
27
CLOSE_TYPE: Close object type (one of 'menu' or 'button')
28
CLOSE_NAME: Close object name
31
CLOSE_NAME = _('mnuQuit')
34
TOP_PANEL = _('frmTopExpandedEdgePanel')
37
def __init__(self, name = None, close_type= None, close_name= None):
39
@type close_type: string
40
@param close_type: The type of close widget of the application. Types: menu, button.
41
@type close_name: string
42
@param close_name: The name of the close widget of the application. If not mentioned the default will be used ("Quit")
47
self.name = self.WINDOW
50
self.close_type = close_type
52
self.close_type = self.CLOSE_TYPE
55
self.close_name = close_name
57
self.close_name = self.CLOSE_NAME
60
def set_name(self, name):
64
def set_close_type(self, close_type):
65
if close_type is not None:
66
self.close_type = close_type
68
def set_close_name(self, close_name):
69
if close_name is not None:
70
self.close_name = close_name
74
It reloads the application map for the given ooldtp.context.
80
Given an application, it tries to open it.
82
self._enable_a11y(True)
83
ldtp.launchapp(self.LAUNCHER, args=self.LAUNCHER_ARGS)
84
self._enable_a11y(False)
87
response = ldtp.waittillguiexist(self.name, '', 20)
90
raise ldtp.LdtpExecutionError, "The " + self.name + " window was not found."
94
Returns 1, if the application is opened. 0, otherwise
96
return ldtp.guiexist(self.name)
100
Given an application, it tries to close it.
102
app = ooldtp.context(self.name)
103
close_widget = app.getchild(self.close_name)
105
if self.close_type == 'menu':
106
close_widget.selectmenuitem()
107
elif self.close_type == 'button':
110
raise ldtp.LdtpExecutionError, "Wrong close item type."
112
response = ldtp.waittillguinotexist(self.name, '', 20)
114
raise ldtp.LdtpExecutionError, "Mmm, something went wrong when closing the application."
116
def save(self, save_menu=_('mnuSave')):
118
Given an application, it tries to save the current document.
119
This method gives very basic functionality. Please, override this method in the subclasses for error checking.
121
@type save_menu: string
122
@param save_menu: The name of the Save menu of the application. If not mentioned the default will be used ("Save").
124
app = ooldtp.context(self.name)
125
actualMenu = app.getchild(save_menu)
127
actualMenu.selectmenuitem()
129
def write_text(self, text, txt_field=''):
131
Given an application it tries to write text to its current buffer.
133
app = ooldtp.context(self.name)
136
ldtp.enterstring(text)
138
app_txt_fields = app.getchild(txt_field, "text")
139
for field in app_txt_fields:
140
field.settextvalue(text)
142
def _enable_a11y(self, enable):
143
os.environ['NO_GAIL'] = str(int(not enable))
144
os.environ['NO_AT_BRIDGE'] = str(int(not enable))