Python学习笔记(二)----Python+Pyqt5制作ADB调试工具

一:Python+Pyqt5制作ADB调试工具

python版本:3.7.3
IDE:PyCharm
其他工具:PyQt5,pywin32,pyInstaller(主要把py文件打包成exe文件)

MainTemplete.py文件如下

import os
import sys
from datetime import datetime

from PyQt5 import QtWidgets

from test import Ui_MainWindow


class MainTemplete(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self, parent=None):
        super(MainTemplete, self).__init__(parent)
        self.setupUi(self)

        self.bind_view_event()

    ##
    # Bind view event
    # ##
    def bind_view_event(self):
        print("========bind_view_event============")
        self.btn_devices.clicked.connect(self.btn_devices_info)
        self.btn_root.clicked.connect(self.btn_root_click)
        self.btn_reboot.clicked.connect(self.btn_reboot_click)
        self.btn_export_log.clicked.connect(self.btn_export_click)
        self.btn_sys_prop.clicked.connect(self.btn_sys_prop_click)

    # 一键root
    def btn_root_click(self):
        print("========btn_devices_info============")
        self.show_log("adb root && adb remount")

    # 一键重启
    def btn_reboot_click(self):
        self.show_log("adb reboot")

    # 查看设备信息
    def btn_devices_info(self):
        print("========btn_devices_info============")
        self.show_log("adb devices")

    # 导出日志
    def btn_export_click(self):
        try:
            os.rmdir("c:/export_log")
            os.mkdir("c:/export_log")
        except:
            Exception("export dir not exists")
        print(self.le_log_export.text())
        self.show_log("adb pull data/local/log " + self.le_log_export.text())

    # 显示操作记录
    def show_log(self, cmd):
        self.te_show.append("------------------" + str(datetime.now()) + "-------------------------")
        self.te_show.append(os.popen(cmd).read())

    # 显示系统属性
    def btn_sys_prop_click(self):
        self.show_log("adb shell getprop")


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    mainTemplete = MainTemplete()
    mainTemplete.show()
    sys.exit(app.exec_())


test.py文件如下:

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'test.ui'
#
# Created by: PyQt5 UI code generator 5.11.3
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.setEnabled(True)
        MainWindow.resize(551, 304)
        MainWindow.setMinimumSize(QtCore.QSize(551, 304))
        MainWindow.setMaximumSize(QtCore.QSize(551, 304))
        MainWindow.setMouseTracking(False)
        MainWindow.setAcceptDrops(False)
        MainWindow.setUnifiedTitleAndToolBarOnMac(False)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.btn_export_log = QtWidgets.QPushButton(self.centralwidget)
        self.btn_export_log.setGeometry(QtCore.QRect(440, 230, 91, 23))
        self.btn_export_log.setObjectName("btn_export_log")
        self.btn_root = QtWidgets.QPushButton(self.centralwidget)
        self.btn_root.setGeometry(QtCore.QRect(10, 260, 91, 23))
        self.btn_root.setObjectName("btn_root")
        self.le_log_export = QtWidgets.QLineEdit(self.centralwidget)
        self.le_log_export.setGeometry(QtCore.QRect(110, 230, 301, 20))
        self.le_log_export.setReadOnly(True)
        self.le_log_export.setObjectName("le_log_export")
        self.btn_devices = QtWidgets.QPushButton(self.centralwidget)
        self.btn_devices.setGeometry(QtCore.QRect(140, 260, 121, 23))
        self.btn_devices.setObjectName("btn_devices")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(20, 230, 91, 16))
        self.label.setObjectName("label")
        self.btn_sys_prop = QtWidgets.QPushButton(self.centralwidget)
        self.btn_sys_prop.setGeometry(QtCore.QRect(300, 260, 101, 23))
        self.btn_sys_prop.setObjectName("btn_sys_prop")
        self.te_show = QtWidgets.QTextEdit(self.centralwidget)
        self.te_show.setGeometry(QtCore.QRect(10, 10, 531, 211))
        self.te_show.setReadOnly(True)
        self.te_show.setObjectName("te_show")
        self.btn_reboot = QtWidgets.QPushButton(self.centralwidget)
        self.btn_reboot.setGeometry(QtCore.QRect(440, 260, 91, 23))
        self.btn_reboot.setObjectName("btn_reboot")
        MainWindow.setCentralWidget(self.centralwidget)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "ADB调试工具1.0"))
        self.btn_export_log.setText(_translate("MainWindow", "export"))
        self.btn_root.setText(_translate("MainWindow", "一键root"))
        self.le_log_export.setText(_translate("MainWindow", "C:\\export_log"))
        self.btn_devices.setText(_translate("MainWindow", "查看设备信息"))
        self.label.setText(_translate("MainWindow", "Log保存地址:"))
        self.btn_sys_prop.setText(_translate("MainWindow", "查看系统属性"))
        self.btn_reboot.setText(_translate("MainWindow", "一键重启"))

二:运行效果

本博文只提供一种python制作软件的基本流程,请自行开发所需功能。
特别提醒:切勿制作商业非法软件。
Python学习笔记(二)----Python+Pyqt5制作ADB调试工具_第1张图片


软件及所需工具下载地址如下:
链接:https://pan.baidu.com/s/1DfxooNG_5WKpfcEyX3odWA
提取码:ret8
github地址:https://github.com/jiaxingLiu/AdbDebugTools


你可能感兴趣的:(Python)