""" GUI Automated Testing This module contains interface to the ListBox component. """ __author__ = "Lukas Cenovsky (cenovsky@bakalari.cz)" __version__ = "0.3" __date__ = "August 2008" __copyright__ = "Copyright (c) 2008 Lukas Cenovsky" from time import sleep from Win32API import Win32API from BaseComponent import BaseComponent class ListBox(BaseComponent): """ interface to the ListBox component """ # the following methods are considered private # the following methods are considered public def Select(self, aItem): """ select an item from list box @aItem - string with item to select """ if aItem not in self.items: raise Exception("Item '%s' not in list box" % aItem) self.guiat.Activate() self._CheckVisibility() pos = self.location # click on the first item to focus the list box Win32API.MouseClick(pos[0] + (pos[2]/2), pos[1] + 3) # send Home to be sure we are on the first item # (we could be scrolled down a little) Win32API.SendKey(Win32API.VK_HOME) # simulate pressing down arrow until we find the item # we should find it because it is among self.items while self.value != aItem: Win32API.SendKey(Win32API.VK_DOWN) # properties items = property(lambda self: [i for i in self._control.Items], doc="list of items in the list box {R}") value = property(lambda self: self._control.SelectedItem, Select, doc="get or set the selected item in the list box {R/W}")