3
This is the "gcalc" module.
5
This module provides the LDTP wrapper to make gcalc testing easier.
9
from .main import Application
10
from ..gconfwrapper import GConf
13
class Calculator(Application):
15
The Calculator class contains methods for exercising the gcalctool application
17
LAUNCHER = "gcalctool"
18
WINDOW = "frmCalculator*"
19
WINDOW_BASIC = "frmCalculator"
20
WINDOW_ADVANCED = "frmCalculator"
21
WINDOW_FINANCIAL = "frmCalculator"
22
WINDOW_SCIENTIFIC = "frmCalculator"
23
WINDOW_PROGRAMMING = "frmCalculator"
24
DLG_PREFERENCES = "dlgPreferences"
25
MNU_BASIC = "mnuBasic"
26
MNU_ADVANCED = "mnuAdvanced"
27
MNU_FINANCIAL = "mnuFinancial"
28
MNU_SCIENTIFIC = "mnuScientific"
29
MNU_PROGRAMMING = "mnuProgramming"
30
MNU_PREFERENCES = "mnuPreferences"
31
DLG_PREFERENCES = "dlgPreferences"
32
CHK_THOUSANDS = "chkShowthousandsseparators"
33
BTN_CLOSE = "btnClose"
35
VIEWS = {"BASIC" : {"WINDOW" : WINDOW_BASIC,
37
"ADVANCED" : {"WINDOW" : WINDOW_ADVANCED,
38
"MENU" : MNU_ADVANCED},
39
"FINANCIAL" : {"WINDOW" : WINDOW_FINANCIAL,
40
"MENU" : MNU_FINANCIAL},
41
"SCIENTIFIC" : {"WINDOW" : WINDOW_SCIENTIFIC,
42
"MENU" : MNU_SCIENTIFIC},
43
"PROGRAMMING" : {"WINDOW" : WINDOW_PROGRAMMING,
44
"MENU" : MNU_PROGRAMMING}}
45
BUTTONS = {"0" : "btn0",
61
"." : "btnnumeric_point",
62
"s" : "btnsquare_root",
63
"m" : "btnmodulusdivide"}
64
EDITBAR_ROLE = "edit bar"
67
GCONF_MODE_KEY = "/apps/gcalctool/button_layout"
68
GCONF_MODE_VAL = "BASIC"
71
Application.__init__(self)
78
GConf.set_item(self.GCONF_MODE_KEY, self.GCONF_MODE_VAL)
79
except GConf.GConfError:
80
raise ldtp.LdtpExecutionError, "Could not set default view in gconf"
81
Application.open(self)
83
def showing(self, button):
85
Test whether the specified button is showing
87
@param button: Specify the button to test
89
@return: Value indicating whether the button is showing in the view
93
>>> c.open() # Calculator opens in BASIC view
94
>>> c.showing("Reciprocal")
96
>>> c.set_view("ADVANCED")
97
>>> c.showing("Reciprocal")
100
calculator = ooldtp.context(self.name)
102
children = calculator.getchild(button,'push button')
103
for child in children:
104
childName=child.getName()
105
if calculator.hasstate(childName, ldtp.state.SHOWING):
110
def push(self, buttons):
112
Push the specified buttons in the calculator window.
118
@param buttons: Specify the buttons to push.
119
@type buttons: string
121
calculator = ooldtp.context(self.name)
122
for button in buttons:
123
children = calculator.getchild(self.BUTTONS[button],'push button')
124
for child in children:
129
Get the current view of the calculator.
136
@return: The current view: BASIC, ADVANCED, FINANCIAL, SCIENTIFIC,
140
windowname = self.name
141
for view in self.VIEWS:
142
if self.VIEWS[view]['WINDOW'] == windowname:
144
raise LookupError, "Could not identify the current calculator view"
146
def set_view(self, new_view):
148
Change to the specified view in the calculator
152
>>> c.set_view('ADVANCED')
154
@param new_view: Specify the new view. Valid values are:
155
BASIC, ADVANCED, FINANCIAL, SCIENTIFIC, PROGRAMMING
156
@type new_view: string
158
new_window_name = self.VIEWS[new_view]["WINDOW"]
159
new_view_menu_name = self.VIEWS[new_view]["MENU"]
160
calculator = ooldtp.context(self.name)
161
mnu_new_view = calculator.getchild(new_view_menu_name)
163
mnu_new_view.selectmenuitem()
165
self.set_name(new_window_name)
167
time.sleep(self.SLEEP_DELAY) # need to give mago some time to catch up to calc ui
171
Read the value from the calculator screen
179
@return: The contents of the calculator's screen
182
calculator = ooldtp.context(self.name)
183
editBar = calculator.getchild(role=self.EDITBAR_ROLE)
184
value = editBar[0].gettextvalue()
187
def set_thousands_separator(self, option = True):
189
Sets the thousands separator to true or false
191
@param option: set the thousands separator to true or false
195
calculator = ooldtp.context(self.name)
197
preferences_mnu = calculator.getchild(self.MNU_PREFERENCES)
198
preferences_mnu.selectmenuitem()
200
ldtp.waittillguiexist(self.DLG_PREFERENCES)
202
preferences_dlg = ooldtp.context(self.DLG_PREFERENCES)
204
chk_thousands = preferences_dlg.getchild(self.CHK_THOUSANDS)
207
chk_thousands.check()
209
chk_thousands.uncheck()
211
preferences_dlg.getchild(self.BTN_CLOSE).click()