def testMenu(): m_logger = Logger.InitLog("testMenu.log", logging.getLogger("testMenu.thread")) # init device device = Device(m_logger) device.open() data = device.getDumpData() # build View Tree vt = ViewTree(m_logger) tree_nodes_list = vt.build(data) # if current view is a system component menu = Menu(tree_nodes_list) elements_list = menu.getElementList() # if current view is not a system component, use "tree_nodes_list" directly: node.mElement #for node in tree_nodes_list: # view_element = ViewElement(node.mElement) # ...... # ...... # View Element for element in elements_list: print "begin deal with [%s]" % element.mText view_element = ViewElement(element)
def __init__(self, device_name="emulator-5554", device_port=5554, device_address="127.0.0.1", view_server_port=4939, monkey_server_port=12345): ''' Constructor ''' self.class_name = "SoloInterface" self.m_logger = Logger.InitLog( "solo-interface.log", logging.getLogger("solo-interface.thread")) self.device_name = device_name self.device_port = device_port self.device_address = device_address self.view_server_port = view_server_port self.monkey_server_port = monkey_server_port # object of Device self.device = Device(self.m_logger, self.device_name, self.device_port, self.device_address, self.view_server_port, self.monkey_server_port) # init device self.device.open() # build View Tree self.vt = ViewTree(self.m_logger) self.tree_nodes_list = None # object of View Controller self.event_controller = EventController(self.m_logger, self.device_name, self.device_port, self.device_address, self.monkey_server_port) # init event controller self.event_controller.open() try: self.device_display_width = int( self.event_controller.getDisplayWidth()) self.device_display_height = int( self.event_controller.getDisplayHeight()) # LCD density is in the build.prop: # adb shell getprop ro.sf.lcd_density # And the resolution is availble in the dumpsys of the input activity: # # windows # adb shell dumpsys window | find "DisplayWidth" # # linux # adb shell dumpsys window | grep DisplayWidth except Exception, e: print "Failed to get device display width and height: [%s]" % str( e)
"right": None, "top": None, "bottom": None} tag_list = element.split(" ") for tag in tag_list: if "mTop=" in tag: l = tag.split(",") rect["top"] = l[1] elif "mBottom=" in tag: l = tag.split(",") rect["bottom"] = l[1] elif "mLeft=" in tag: l = tag.split(",") rect["left"] = l[1] elif "mRight" in tag: l = tag.split(",") rect["right"] = l[1] if (rect["top"]!=None) and (rect["bottom"]!=None) and (rect["left"]!=None) and (rect["right"]!=None): mid_point["x"] = (str2int(rect["right"])-str2int(rect["left"]))/2.0 mid_point["y"] = (str2int(rect["bottom"])-str2int(rect["top"]))/2.0 return mid_point if __name__=="__main__": device = Device() data = device.getInfosByTelnet("DUMP -1") element_parser = ParseElement() element_parser.getStructure(data)