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('<ButtonRelease-1>', 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()
# 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