def test_gcalctool1(self): self.p = EasyProcess('gnome-calculator').start() self.wait() focus_wnd() send_key('ctrl+q') time.sleep(1) # img_debug(grab(), 'ctrl+q') self.assertFalse(getbbox(grab()))
def check_edges(horiz): if horiz: r1 = bbox.left r2 = bbox.right else: r1 = bbox.top r2 = bbox.bottom ls = [] for c in xrange(int(r1), int(r2)): if horiz: p1 = (c, bbox.top) p2 = (c, bbox.bottom) else: p1 = (bbox.left, c) p2 = (bbox.right, c) color1 = sum(img_diff_filtered.getpixel(p1)) color2 = sum(img_diff_filtered.getpixel(p2)) ls += [int(bool(color1 + color2))] if not 0 in ls: log.debug('split pos not found') return i = ls.index(0) if i == 0: ls.reverse() i = ls.index(0) i = len(ls) - i - 1 pos = i + r1 log.debug('split pos found:%s' % pos) if horiz: rsegment1 = ScreenRect(0, 0, pos, img_orig.size[1]) rsegment2 = ScreenRect(pos, 0, img_orig.size[0], img_orig.size[1]) else: rsegment1 = ScreenRect(0, 0, img_orig.size[0], pos) rsegment2 = ScreenRect(0, pos, img_orig.size[0], img_orig.size[1]) box1 = getbbox(img_diff.crop(rsegment1)) box1.move(rsegment1.topleft) box2 = getbbox(img_diff.crop(rsegment2)) box2.move(rsegment2.topleft) return box1, box2
def test_zenity(self): self.p = EasyProcess('zenity --warning').start() self.wait() send_key('\n') self.assertFalse(getbbox(grab())) self.p = EasyProcess('zenity --warning').start() self.wait() send_key_list(['\n']) self.assertFalse(getbbox(grab())) self.p = EasyProcess('zenity --warning').start() self.wait() send_key(' ') self.assertFalse(getbbox(grab())) self.p = EasyProcess('zenity --warning').start() self.wait() send_key('x') self.assertTrue(getbbox(grab()))
def tab_rect_pair(img_orig, im_next): ''' ''' img_diff = ImageChops.difference(img_orig, im_next) img_log(img_diff, 'img_diff') # can be dotted -> filter + enhance color img_diff_filtered = img_diff.filter(ImageFilter.MaxFilter(5)) img_diff_filtered = img_diff_filtered.point(lambda x: 255 * bool(x)) img_log(img_diff_filtered, 'img_diff_filtered') bbox = getbbox(img_diff) if not bbox: return None def check_edges(horiz): if horiz: r1 = bbox.left r2 = bbox.right else: r1 = bbox.top r2 = bbox.bottom ls = [] for c in xrange(int(r1), int(r2)): if horiz: p1 = (c, bbox.top) p2 = (c, bbox.bottom) else: p1 = (bbox.left, c) p2 = (bbox.right, c) color1 = sum(img_diff_filtered.getpixel(p1)) color2 = sum(img_diff_filtered.getpixel(p2)) ls += [int(bool(color1 + color2))] if not 0 in ls: log.debug('split pos not found') return i = ls.index(0) if i == 0: ls.reverse() i = ls.index(0) i = len(ls) - i - 1 pos = i + r1 log.debug('split pos found:%s' % pos) if horiz: rsegment1 = ScreenRect(0, 0, pos, img_orig.size[1]) rsegment2 = ScreenRect(pos, 0, img_orig.size[0], img_orig.size[1]) else: rsegment1 = ScreenRect(0, 0, img_orig.size[0], pos) rsegment2 = ScreenRect(0, pos, img_orig.size[0], img_orig.size[1]) box1 = getbbox(img_diff.crop(rsegment1)) box1.move(rsegment1.topleft) box2 = getbbox(img_diff.crop(rsegment2)) box2.move(rsegment2.topleft) return box1, box2 r = check_edges(0) if r is None: r = check_edges(1) if r is None: # in new styles the textbox is not changing return [bbox] box1, box2 = r d1 = darker(img_orig, im_next, box1) d2 = darker(img_orig, im_next, box2) if d1==d2: log.warning( 'd1 == d2 %s %s %s %s', d1, d2, box1, box2) if d1 == 1: boxes = (box1, box2) else: boxes = (box2, box1) return boxes