设为首页 加入收藏

TOP

Python实现的基于ADB的Android远程工具(十)
2015-04-07 15:30:41 来源: 作者: 【 】 浏览:226
Tags:Python 实现 基于 ADB Android 远程 工具
t
? ? ? ? ? ? ? ? ? ? ? ? print 'red_length: %d' % myfb.red_length
? ? ? ? ? ? ? ? ? ? ? ? print 'blue_offset: %d' % myfb.blue_offset
? ? ? ? ? ? ? ? ? ? ? ? print 'blue_length: %d' % myfb.blue_length
? ? ? ? ? ? ? ? ? ? ? ? print 'green_offset: %d' % myfb.green_offset
? ? ? ? ? ? ? ? ? ? ? ? print 'green_length: %d' % myfb.green_length
? ? ? ? ? ? ? ? ? ? ? ? print 'alpha_offset: %d' % myfb.alpha_offset
? ? ? ? ? ? ? ? ? ? ? ? print 'alpha_length: %d' % myfb.alpha_length


? ? ? ? ? ? ? ? ? ? # read fb buffer
? ? ? ? ? ? ? ? ? ? rcvcnt = 0
? ? ? ? ? ? ? ? ? ? readbyte = 0
? ? ? ? ? ? ? ? ? ? imagebuff = []
? ? ? ? ? ? ? ? ? ? while True:
? ? ? ? ? ? ? ? ? ? ? ? if (rcvcnt < myfb.fb_size):
? ? ? ? ? ? ? ? ? ? ? ? ? ? readbyte = myfb.fb_size - rcvcnt
? ? ? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ? ? ? break
? ? ? ? ? ? ? ? ? ? ? ? resp = s.recv(readbyte)
? ? ? ? ? ? ? ? ? ? ? ? if DEBUG:
? ? ? ? ? ? ? ? ? ? ? ? ? ? print 'read byte: %d' % len(resp)
? ? ? ? ? ? ? ? ? ? ? ? rcvcnt = rcvcnt + len(resp);
? ? ? ? ? ? ? ? ? ? ? ? imagebuff.extend(resp)
? ? ? ? ? ? ? ? ? ? ? ? if len(resp) == 0:
? ? ? ? ? ? ? ? ? ? ? ? ? ? break


? ? ? ? ? ? ? ? ? ? if DEBUG:
? ? ? ? ? ? ? ? ? ? ? ? print 'total rcv byte: %d' % rcvcnt
? ? ? ? ? ? ? ? ? ? reply = s.recv(10)
? ? ? ? ? ? ? ? ? ? s.close()
? ? ? ? ? ? ? ? ? ? myfb.fb_data = bytearray(imagebuff)


? ? ? ? ? ? ? ? ? ? if len(imagebuff) < myfb.fb_size:
? ? ? ? ? ? ? ? ? ? ? ? continue


? ? ? ? ? ? ? ? ? ? # convert raw-rgb to image
? ? ? ? ? ? ? ? ? ? image = Image.frombuffer('RGBA',
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? (myfb.fb_width, myfb.fb_height),
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? myfb.fb_data,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 'raw',
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 'RGBA',
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 1)


? ? ? ? ? ? ? ? ? ? lcd_w = image.size[0]
? ? ? ? ? ? ? ? ? ? lcd_h = image.size[1]
? ? ? ? ? ? ? ? ? ? if DEBUG:
? ? ? ? ? ? ? ? ? ? ? ? print 'LCD size: %d x %d' % (lcd_w,lcd_h)
? ? ? ? ? ? ? ? ? ? factor_w = 1.00
? ? ? ? ? ? ? ? ? ? factor_h = 1.00
? ? ? ? ? ? ? ? ? ? if lcd_w > max_lcd_w:
? ? ? ? ? ? ? ? ? ? ? ? img_w = max_lcd_w
? ? ? ? ? ? ? ? ? ? ? ? factor_w = float(img_w)/float(lcd_w)
? ? ? ? ? ? ? ? ? ? if lcd_h > max_lcd_h:
? ? ? ? ? ? ? ? ? ? ? ? img_h = max_lcd_h
? ? ? ? ? ? ? ? ? ? ? ? factor_h = float(img_h)/float(lcd_h)
? ? ? ? ? ? ? ? ? ? factor = min([factor_w, factor_h])
? ? ? ? ? ? ? ? ? ? self.__img_factor = factor


? ? ? ? ? ? ? ? ? ? # Keep the rate of w:h
? ? ? ? ? ? ? ? ? ? img_w = int(lcd_w * factor)
? ? ? ? ? ? ? ? ? ? img_h = int(lcd_h * factor)
? ? ? ? ? ? ? ? ? ? if DEBUG:
? ? ? ? ? ? ? ? ? ? ? ? print 'Image size: %d x %d' % (img_w, img_h)


? ? ? ? ? ? ? ? ? ? # resize image
? ? ? ? ? ? ? ? ? ? if (factor < 1.00):
? ? ? ? ? ? ? ? ? ? ? ? image = image.resize((img_w, img_h))


? ? ? ? ? ? ? ? ? ? # rotate image
? ? ? ? ? ? ? ? ? ? if self.__rotate != 0:
? ? ? ? ? ? ? ? ? ? ? ? image = image.rotate(self.__rotate)


? ? ? ? ? ? ? ? ? ? if self.__lcd != None:
? ? ? ? ? ? ? ? ? ? ? ? try:
? ? ? ? ? ? ? ? ? ? ? ? ? ? # save image to local path
? ? ? ? ? ? ? ? ? ? ? ? ? ? if DEBUG:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? refresh_count = refresh_count + 1
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? image_name = 'image_%d.png' % refresh_count
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? image.save(image_name, format='PNG')
? ? ? ? ? ? ? ? ? ? ? ? ? ? new_image = ImageTk.PhotoImage(image)
? ? ? ? ? ? ? ? ? ? ? ? ? ? self.__im = new_image
? ? ? ? ? ? ? ? ? ? ? ? ? ? self.__lcd['image'] = self.__im
? ? ? ? ? ? ? ? ? ? ? ? except:
? ? ? ? ? ? ? ? ? ? ? ? ? ? continue


# keypad window thread
class arobot_keys(threading.Thread):
? ? __tkapp = None
? ? __root = None
? ?
? ? def __init__(self):
? ? ? ? threading.Thread.__init__(self)
? ? ? ? self.thread_stop = False


? ? def run(self):
? ? ? ? if DEBUG:
? ? ? ? ? ? print 'run arobot_keys'
? ? ? ? self.__root = tk.Tk()
? ? ? ? if USE_TTK:
? ? ? ? ? ? self.__tkapp = ttkKeypadApplication(master=self.__root)
? ? ? ? else:
? ? ? ? ? ? self.__tkapp = KeypadApplication(master=self.__root)
? ? ? ? self.__tkapp.master.title('ARobot3.0-Keypad')
? ? ? ? self.__tkapp.grid()
? ? ? ? self.__tkapp.mainloop()
? ? ? ? if DEBUG:
? ? ? ? ? ? print 'exit arobot_keys mainloop'


? ? def stop(self):
? ? ? ? if DEBUG:
? ? ? ? ? ? print 's

首页 上一页 7 8 9 10 11 下一页 尾页 10/11/11
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Python基础教程 - global关键字及.. 下一篇Python基础教程 - lambda关键字

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: