设为首页 加入收藏

TOP

Python实现的基于ADB的Android远程工具(八)
2015-04-07 15:30:41 来源: 作者: 【 】 浏览:227
Tags:Python 实现 基于 ADB Android 远程 工具
)
? ? ? ? ? ? sender.start()


# Kaypad Tkinter-Based GUI application
class ttkKeypadApplication(ttk.Frame):
? ? def __init__(self, master=None):
? ? ? ? if master == None:
? ? ? ? ? ? master = ttk.Tk()
? ? ? ? ttk.Frame.__init__(self, master, class_='ttkKeypadApplication')
? ? ? ? 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 = ttk.Button(self, name = btn_name, text=btn_name)
? ? ? ? ? ? else:
? ? ? ? ? ? ? ? self.tbutton = ttk.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)
? ? ? ? ? ? sender.start()


# LCD Tkinter-Based GUI application
class LcdApplication(tk.Frame):
? ? __img_factor = 1.00 # image resize rate
? ? __lcd = None # the label widget
? ? __keepupdate = True
? ? __im = None
? ? __rotate = 0


? ? # record mouse start & end point location
? ? __start = [0, 0]
? ? __end = [0, 0]


? ? def __init__(self, master=None):
? ? ? ? if DEBUG:
? ? ? ? ? ? print 'LcdApplication: __init__'
? ? ? ? if master == None:
? ? ? ? ? ? master = tk.Tk()
? ? ? ? tk.Frame.__init__(self, master, class_='LcdApplication')
? ? ? ? self.__rotate = 0
? ? ? ? self.createlcd()
? ? ? ? self.grid()


? ? def createlcd(self):
? ? ? ? # creat label as lcd
? ? ? ? if DEBUG:
? ? ? ? ? ? print 'LcdApplication: createlcd'


? ? ? ? # make default image display on label
? ? ? ? image = Image.new(mode = 'RGB', size = (240, 320), color = '#000000')
? ? ? ? draw = ImageDraw.Draw(image)
? ? ? ? draw.text((80, 100), 'Connecting...')
? ? ? ? self.__im = ImageTk.PhotoImage(image)


? ? ? ? # create label with image option
? ? ? ? self.__lcd = tk.Label(self, image=self.__im)
? ? ? ? self.__lcd.bind('', self.click_label)
? ? ? ? self.__lcd.bind('', self.click_label)
? ? ? ? self.__lcd.bind('', self.rightclick_label)


? ? ? ? # disply label on frame
? ? ? ? self.__lcd.grid()


? ? # To serve right click on label widget
? ? def rightclick_label(self, event=None):
? ? ? ? if DEBUG:
? ? ? ? ? ? print 'Type: %s' % event.type
? ? ? ? self.__rotate = (self.__rotate + 90) % 360
? ? ? ? print "rotate: %d" % self.__rotate


? ? # To serve left click on label widget
? ? def click_label(self, event=None):
? ? ? ? if DEBUG:
? ? ? ? ? ? print 'Type: %s' % event.type
? ? ? ? if event.type == '4':
? ? ? ? ? ? # record mouse left button down
? ? ? ? ? ? if DEBUG:
? ? ? ? ? ? ? ? print 'Click at: (%d, %d)' % (event.x, event.y)
? ? ? ? ? ? self.__start[0] = int(float(event.x) / float(self.__img_factor))
? ? ? ? ? ? self.__start[1] = int(float(event.y) / float(self.__img_factor))
? ? ? ? ? ? self.__end = None
? ? ? ? elif event.type == '5':
? ? ? ? ? ? # record mouse left button up
? ? ? ? ? ? if DEBUG:
? ? ? ? ? ? ? ? print 'Release at: (%d, %d)' % (event.x, event.y)
? ? ? ? ? ? self.__end = [0, 0]
? ? ? ? ? ? self.__end[0]

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

评论

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