# 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 'stop arobot_keys'
if self.__tkapp != None:
self.__tkapp.quit()
self.thread_stop = True
# screen windows thread
class arobot_lcd(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_lcd'
self.__root = tk.Tk()
self.__tkapp = LcdApplication(master=self.__root)
self.__tkapp.master.title('ARobot3.0-Lcd')
t = threading.Timer(1, self.__tkapp.updatelcd_sock)
t.start()
self.__tkapp.grid()
self.__tkapp.mainloop()
if DEBUG:
print 'exit arobot_lcd mainloop'
self.__tkapp.stop()
def stop(self):
if DEBUG:
print 'stop arobot_lcd'
self.thread_stop = True
if self.__tkapp != None:
self.__tkapp.stop()
self.__tkapp.quit()
def arobot_main(prog):
if prog == None:
return
if prog == 'lcd':
lcd_thread = arobot_lcd()
lcd_thread.start()
if prog == 'keypad':
keypad_thread = arobot_keys()
keypad_thread.start()
def usage():
print '--------------------------------------------'
print 'Arobot 3.1'
print 'This is a tool to control Android device via ADB'
print 'usage: python %s [option]' % sys.argv[0]
print 'option:'
print ' -keypad run keypad'
print ' -lcd run lcd'
print '--------------------------------------------'
if __name__ == '__main__':
prog_name = sys.argv[0]
if '--debug' in sys.argv:
DEBUG = True