设为首页 加入收藏

TOP

Python实现的基于ADB的Android远程工具(七)
2015-04-07 15:30:41 来源: 作者: 【 】 浏览:220
Tags:Python 实现 基于 ADB Android 远程 工具
d_str)


? ? ? ? ? ? # up
? ? ? ? ? ? cmd_str = ''
? ? ? ? ? ? cmd_str = cmd_str + 'sendevent %s %d %d %d;' % (tp[1], 1, 330, 0)
? ? ? ? ? ? cmd_str = cmd_str + 'sendevent %s %d %d %d;' % (tp[1], 0, 2, 0)
? ? ? ? ? ? cmd_str = cmd_str + 'sendevent %s %d %d %d' % (tp[1], 0, 0, 0)
? ? ? ? ? ? if DEBUG:
? ? ? ? ? ? ? ? print cmd_str
? ? ? ? ? ? adbshellcommand(cmd_str)


# Framebuffer Class
# Only record framebuffer attributs
class fb:
? ? fb_bpp = 0
? ? fb_size = 0
? ? fb_width = 0
? ? fb_height = 0
? ? red_offset = 0
? ? red_length = 0
? ? blue_offset = 0
? ? blue_length = 0
? ? green_offset = 0
? ? green_length = 0
? ? alpha_offset = 0
? ? alpha_length = 0
? ? fb_data = None


? ? def __init__(self):
? ? ? ? fb_bpp = 0
? ? ? ? fb_size = 0
? ? ? ? fb_width = 0
? ? ? ? fb_height = 0
? ? ? ? red_offset = 0
? ? ? ? red_length = 0
? ? ? ? blue_offset = 0
? ? ? ? blue_length = 0
? ? ? ? green_offset = 0
? ? ? ? green_length = 0
? ? ? ? alpha_offset = 0
? ? ? ? alpha_length = 0
? ? ? ? fb_data = None


# send key thread
class send_key_thread(threading.Thread):
? ? __tkapp = None
? ? __root = None
? ? __key = None
? ?
? ? def __init__(self, key):
? ? ? ? if DEBUG:
? ? ? ? ? ? print 'send_key_thread init'
? ? ? ? threading.Thread.__init__(self)
? ? ? ? self.thread_stop = False
? ? ? ? self.__key = key


? ? def devexist(self):
? ? ? ? p = subprocess.Popen("adb devices", shell=True, stdout=subprocess.PIPE)
? ? ? ? p.wait()
? ? ? ? devList = p.communicate()
? ? ? ? devList = devList[0].splitlines()
? ? ? ? if 'device' in devList[1]:
? ? ? ? ? ? if DEBUG:
? ? ? ? ? ? ? ? print devList[1]
? ? ? ? ? ? return True
? ? ? ? else:
? ? ? ? ? ? if DEBUG:
? ? ? ? ? ? ? ? print 'No adb device found'
? ? ? ? ? ? return False


? ? def sendKey(self):
? ? ? ? if DEBUG:
? ? ? ? ? ? print 'send_key: %s' % self.__key
? ? ? ? if self.__key in keynames:
? ? ? ? ? ? if self.devexist():
? ? ? ? ? ? ? ? if self.__key != 'none':
? ? ? ? ? ? ? ? ? ? adbshellcommand('input keyevent %s' % str(keyvalues[keynames.index(self.__key)]))


? ? def run(self):
? ? ? ? if DEBUG:
? ? ? ? ? ? print 'send_key_thread run'
? ? ? ? self.sendKey()


? ? def stop(self):
? ? ? ? if DEBUG:
? ? ? ? ? ? print 'stop send_key_thread'
? ? ? ? self.thread_stop = True


# Kaypad Tkinter-Based GUI application
class KeypadApplication(tk.Frame):
? ? def __init__(self, master=None):
? ? ? ? if master == None:
? ? ? ? ? ? master = tk.Tk()
? ? ? ? tk.Frame.__init__(self, master, class_='KeypadApplication')
? ? ? ? self.createkeypad()
? ? ? ? self.grid()


? ? def createkeypad(self):
? ? ? ? # creat buttons from keymap with 4 buttons each row
? ? ? ? for btn_name in keynames:
? ? ? ? ? ? row_id = keynames.index(btn_name) / 4
? ? ? ? ? ? col_id = keynames.index(btn_name) % 4


? ? ? ? ? ? if btn_name != 'none':
? ? ? ? ? ? ? ? self.tbutton = tk.Button(self, name = btn_name, text=btn_name)
? ? ? ? ? ? ? ? self.tbutton['activebackground'] = '#BBBBBB'
? ? ? ? ? ? ? ? #self.tbutton['highlightcolor'] = '#BBBB00'
? ? ? ? ? ? else:
? ? ? ? ? ? ? ? self.tbutton = tk.Button(self, name = btn_name, text='')


? ? ? ? ? ? self.tbutton['width'] = 10
? ? ? ? ? ? if btn_name != 'none':
? ? ? ? ? ? ? ? self.tbutton.bind('', self.sendKey)
? ? ? ? ? ? ? ? self.tbutton.grid(padx = 5, pady = 1, column = col_id, row = row_id)


? ? def devexist(self):
? ? ? ? p = subprocess.Popen("adb devices", shell=True, stdout=subprocess.PIPE)
? ? ? ? p.wait()
? ? ? ? devList = p.communicate()
? ? ? ? devList = devList[0].splitlines()
? ? ? ? if 'device' in devList[1]:
? ? ? ? ? ? if DEBUG:
? ? ? ? ? ? ? ? print devList[1]
? ? ? ? ? ? return True
? ? ? ? else:
? ? ? ? ? ? if DEBUG:
? ? ? ? ? ? ? ? print 'No adb device found'
? ? ? ? ? ? return False


? ? def sendKey(self, event=None):
? ? ? ? if DEBUG:
? ? ? ? ? ? print event.widget.winfo_name()
? ? ? ? keyname = event.widget.winfo_name()
? ? ? ? if keyname in keynames:
? ? ? ? ? ? sender = send_key_thread(keyname

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

评论

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