Python調(diào)用adb截圖凶硅、推送扫皱、屏幕操作程序

https://github.com/scsd3211/AndroidPythonTools


主界面截圖
獲取設(shè)備信息截圖

#-*- coding: UTF-8 -*-
__author__ = 'chenzhuo'
__date__ = '2018/12/7'

from tkinter import *

from PIL import Image, ImageTk
import os
import time

import _thread
import json
PATH = lambda p: os.path.abspath(p)

adbpush = "adb push "
global label_img
global img_pngl
adbpushwhere = " /system/framework/arm64/"

aline = "\n__________________________________________________________________________________________\n"
#______________________________________________________________________________________________________
root = Tk() # 初始化Tk()
root.title("僅陳卓-用來調(diào)試Android")    # 設(shè)置窗口標題
root.geometry()    # 設(shè)置窗口大小 注意:是x 不是*
def printline():
    print("__________________________________________________________________________________________\n")


def printhello():
    t.insert(END,"hello\n")
    t.see(END)

def printSomeWords(inputString):
    t.insert(END,inputString + '\n')
    t.see(END)


def testGetCapture():

    print("testGEt")

#獲取截圖
def getCapture():

    print("getCapture START")
    printSomeWords("截圖-")
    tempImage = screenshot();
    print("getImageName is " + tempImage)
    time.sleep(2.5)
    showAimage(tempImage);

    print("getCapture END")
# 為線程定義一個函數(shù)
def print_time( threadName, delay):
   count = 0
   while count < 5:
      time.sleep(delay)
      count += 1
      print ("%s: %s" % ( threadName, time.ctime(time.time()) ))

def throwThreadgetCapture():
    # 創(chuàng)建兩個線程
    try:
        _thread.start_new_thread(getCapture,())
        #_thread.start_new_thread(print_time, ("Thread-1", 2,))
    except:
        print("Error: 無法啟動線程")

#獲取設(shè)備信息
def getDevices():


    printSomeWords("獲取設(shè)備信息-")
    deviceInfo =  androidDevice();

    printSomeWords(str(deviceInfo))


#獲取SCCARD/LOGS 的日志

def getSDCARDLOGS():
    printSomeWords("獲取設(shè)備的SDCARD/LOGS日志")
    path = PATH(os.getcwd() + "/SDCARDLOGS")



    if not os.path.isdir(PATH(os.getcwd() + "/SDCARDLOGS")):
        os.makedirs(path)


    time.sleep(3.5)
    #tempopen = os.popen(r"adb pull /sdcard/logs/ " + PATH(path),"r",).readlines()
    tempopen = os.popen(r"adb pull /sdcard/logs/ " + PATH(path), "r", )
    #;;;;
    tempString = tempopen.read()
    print("getSOme",tempString)
    print(tempopen)
    #printSomeWords(str(tempString))

#截圖CMD命令
def screenshot():
    path = PATH(os.getcwd() + "/screenshot")

    timestamp = time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime(time.time()))
    #os.popen("adb wait-for-device")
    os.popen("adb shell screencap -p /data/local/tmp/tmp.png")
    if not os.path.isdir(PATH(os.getcwd() + "/screenshot")):
        os.makedirs(path)


    time.sleep(3.5)
    tempopen = os.popen("adb pull /data/local/tmp/tmp.png " + PATH(path + "/" + timestamp + ".png"))

    print(tempopen)
    #time.sleep(2)
    os.popen("adb shell rm /data/local/tmp/tmp.png")
    print("success")
    return PATH(path + "/" + timestamp + ".png")
#設(shè)備信息CMD命令
def androidDevice():
    tempopen = os.popen("adb devices")
    haha =tempopen.read()
    print("haha="+ haha);
    return haha



def slimUp():
    stringSwipe = "adb shell input swipe 500 300 500 1300 100"
    os.popen(stringSwipe)
    printSomeWords("向上滑動——————————————————————————————————")

def slimDown():
    stringSwipe = "adb shell input swipe 500 1300 500 300 100"
    os.popen(stringSwipe)
    printSomeWords("向下滑動——————————————————————————————————")

def resize(w, h, w_box, h_box, pil_image):
  '''
  resize a pil_image object so it will fit into
  a box of size w_box times h_box, but retain aspect ratio
  對一個pil_image對象進行縮放,讓它在一個矩形框內(nèi)段多,還能保持比例
  '''
  f1 = 1.0*w_box/w # 1.0 forces float division in Python2
  f2 = 1.0*h_box/h
  factor = min([f1, f2])
  #print(f1, f2, factor) # test
  # use best down-sizing filter
  width = int(w*factor)
  height = int(h*factor)
  return pil_image.resize((width, height), Image.ANTIALIAS)


#C:\Users\chenzhuo\PycharmProjects\AndroidS\screenshot\2018-11-30-10-02-50.png


def showAimage(filename):
    pass
    global label_img
    global img_pngl
    img_pngl = PhotoImage(file=str(filename))

    img_pngl = img_pngl.subsample(3, 3)
    # 獲取圖像的原始大小


    label_img.configure(image = img_pngl)

    # pil_image_resized = img_png.zoom( w_box,h_box)

    # label_img = Label(root, image = img_png )


    #global  label_img.configure(img_png)
    #
img_png = PhotoImage(file='''haha.png''')

img_png = img_png.subsample(3,3)
#獲取圖像的原始大小




#pil_image_resized = img_png.zoom( w_box,h_box)

#label_img = Label(root, image = img_png )

label_img = Label(root, image = img_png ,width = 480 ,height = 680 )
label_img.grid(row = 0, column = 3 ,columnspan =2)



t = Text()
# t.pack()   # 這里的side可以賦值為LEFT  RTGHT TOP  BOTTOM
# Button(root, text="press", command=printhello).pack()
#
#
# Button(root, text="截圖", command=getCapture).pack()
# Button(root, text="設(shè)備信息", command=getDevices).pack()
t.grid(row = 0, column = 0 ,columnspan =3)
Button(root, text="打印一個Hello", command=printhello).grid(row = 1, column = 0)
Button(root, text="截圖", command=throwThreadgetCapture).grid(row = 1, column = 1)

Button(root, text="向上滑動屏幕", command=slimUp).grid(row = 1, column = 2)


Button(root, text="設(shè)備信息", command=getDevices).grid(row = 2, column = 0)
Button(root, text="獲取/SCARD/LOGS的日志", command=getSDCARDLOGS).grid(row = 2, column = 1)

Button(root, text="向下滑動屏幕", command=slimDown).grid(row = 2, column = 2)
root.mainloop() # 進入消息循環(huán)
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末加缘,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子生百,更是在濱河造成了極大的恐慌柄延,老刑警劉巖,帶你破解...
    沈念sama閱讀 222,104評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件市俊,死亡現(xiàn)場離奇詭異滤奈,居然都是意外死亡,警方通過查閱死者的電腦和手機蜒程,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,816評論 3 399
  • 文/潘曉璐 我一進店門昭躺,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人领炫,你說我怎么就攤上這事。” “怎么了脚猾?”我有些...
    開封第一講書人閱讀 168,697評論 0 360
  • 文/不壞的土叔 我叫張陵砚哗,是天一觀的道長。 經(jīng)常有香客問我泌参,道長常空,這世上最難降的妖魔是什么盖溺? 我笑而不...
    開封第一講書人閱讀 59,836評論 1 298
  • 正文 為了忘掉前任,我火速辦了婚禮烘嘱,結(jié)果婚禮上昆禽,老公的妹妹穿的比我還像新娘蝇庭。我一直安慰自己,他們只是感情好盗棵,可當我...
    茶點故事閱讀 68,851評論 6 397
  • 文/花漫 我一把揭開白布北发。 她就那樣靜靜地躺著,像睡著了一般琳拨。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上惊畏,一...
    開封第一講書人閱讀 52,441評論 1 310
  • 那天密任,我揣著相機與錄音,去河邊找鬼农曲。 笑死,一個胖子當著我的面吹牛乳规,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播暮的,決...
    沈念sama閱讀 40,992評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼冻辩,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了恨闪?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,899評論 0 276
  • 序言:老撾萬榮一對情侶失蹤老玛,失蹤者是張志新(化名)和其女友劉穎钧敞,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體溉苛,經(jīng)...
    沈念sama閱讀 46,457評論 1 318
  • 正文 獨居荒郊野嶺守林人離奇死亡愚战,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,529評論 3 341
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了寂玲。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,664評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡佑淀,死狀恐怖彰檬,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情逢倍,我是刑警寧澤,帶...
    沈念sama閱讀 36,346評論 5 350
  • 正文 年R本政府宣布碉哑,位于F島的核電站,受9級特大地震影響扣典,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜笛粘,卻給世界環(huán)境...
    茶點故事閱讀 42,025評論 3 334
  • 文/蒙蒙 一湿硝、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧关斜,春花似錦、人聲如沸例诀。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,511評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至秉沼,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間唬复,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,611評論 1 272
  • 我被黑心中介騙來泰國打工棘捣, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留休建,地道東北人。 一個月前我還...
    沈念sama閱讀 49,081評論 3 377
  • 正文 我出身青樓茵烈,卻偏偏與公主長得像砌些,于是被迫代替她去往敵國和親呜投。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 45,675評論 2 359

推薦閱讀更多精彩內(nèi)容