forked from scsd3211/AndroidPythonTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtkinterAndroid.py
More file actions
211 lines (149 loc) · 5.69 KB
/
tkinterAndroid.py
File metadata and controls
211 lines (149 loc) · 5.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#-*- coding: UTF-8 -*-
__author__ = '007'
__date__ = '2016/4/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("仅陈卓-用来调试Android") # 设置窗口标题
root.geometry() # 设置窗口大小 注意:是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")
# 为线程定义一个函数
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():
# 创建两个线程
try:
_thread.start_new_thread(getCapture,())
#_thread.start_new_thread(print_time, ("Thread-1", 2,))
except:
print("Error: 无法启动线程")
#获取设备信息
def getDevices():
printSomeWords("获取设备信息-")
deviceInfo = androidDevice();
printSomeWords(str(deviceInfo))
#获取SCCARD/LOGS 的日志
def getSDCARDLOGS():
printSomeWords("获取设备的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")
#设备信息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对象进行缩放,让它在一个矩形框内,还能保持比例
'''
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="设备信息", 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="设备信息", 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() # 进入消息循环