PYQT5 Series Tutorial (v) Making FastBoot burner _php tutorial

Source: Internet
Author: User

PYQT5 Series Tutorial (v) Making FastBoot burner


Hardware and Software Environment

  • Windows 7
  • Python 3.4.2
  • PyQt 5.5.1
  • Pycharm 5.0.2

Objective

FastBoot is a kind of brush machine for Android device, it is lower than recovery, the speed of the brush machine is faster. This article is to complete this project is to use PYQT5 to add a GUI layer to the fastboot, make the operation more simple and convenient.

Demand analysis

The first thing to know is what fastboot can do, and you can see its help by entering FastBoot in CMD.

The main realization of this project is the fastboot of the burning function, other like access, settings related information is not involved, there is a need to add their own.

There is a more special need is the burning of the image needs to be modified, I call it a bit BBCB, it is part of the data by the user input.

Interface design

Designed with Qtdesigner, it's just a label, a pushbutton, a lineedit, a horizontal layout, a vertical layout, a menu bar, or a simple one.

Code writing

Updating the UI in Qthread

Use signal and slot mechanisms. Start by creating a class that inherits from Qthread and sends a signal when the UI needs to be updated

Class Detectdevicethread (Qthread):    detectsignal = Pyqtsignal (object)    def __int__ (self):        qthread.__init __ (self),    def run (self): when        True:            devicenum = lj_list_device_id (self            ) self.detectSignal.emit ( Devicenum)            

At the UI level, bind signals and slots, then implement the slot, and the UI updates are executed in the slot.

def ondevicedetected (Self,data): "Detected the operation of Android device on line: return: ' Font = Qtgui.qfont () font.setfamily ("Microsoft Jas Light") font.setpointsize () font.setbold (True) Self.textbrowser_devi Ce_id.setfont (font) if (common. Previous_data! = DATA): Common. Previous_data = Data Self.textBrowser_device_id.setText (data) if not Data.strip (): Co Mmon. Flag_device_online = False Else:common.        Flag_device_online = Truedef Startdetectdevice (self): ' Open thread, detect Android device online: return: ' Self.detectthread = Detectdevicethread () self.detectThread.detectSignal.connect (self.ondevicedetected) se Lf.detectThread.start ()

struct Processing binary data

I need to change the data for a certain number of bytes of the BBCB image (similar to the struct data type in C), which needs to be used to the struct module. See section Code

fp = open ("Toc\\nvram.toc", "rb+") fp.seek (common. Bbcb_offset + 2,os. Seek_set)        manufacturer_id = Fp.read (1)        manufacturer_id_new = Int (Self.lineEdit_manu_id.text ())        if ( manufacturer_id! = manufacturer_id_new):            logging.debug ("newmanufacturer_id:" + str (manufacturer_id_new))            Fp.seek ( -1,os. Seek_cur)            Fp.write (Struct.pack ("B", Manufacturer_id_new))            

The first is to open the file, locate the file, and then write the data to the file in a specific format. The supported formats in a struct are shown in the following table

In the above example, the value of Manufacturer_id_new is written to the file in the form "B", which is the unsigned char in the C language. According to the table above, if it is a string of length 5, the format should be "5s"

Use of the logging module

This uses Python's own logging as the log system. Because it needs to be used within multiple modules (multiple files), we do a global initialization at the project entrance

Def initlogconfiguration ():    '    initialize log configuration    ' '    logging.basicconfig (level = logging. DEBUG,                        filename = common. LOGFILE,                        FileMode = ' A + ',                        format = '% (asctime) s-% (filename) s-line% (Lineno) -4d-% (levelname) s-% (message) s ',                        

Here is the output to the file, you can also output to the console, specified by the stream parameter, if both filename and stream,logging are specified, the stream is ignored. Once the initialization is complete, the other modules that need to output the log will be used directly.

Cross-platform

The main thing is to judge the current platform and then handle it in different ways. Use the Platform library here

Source Address

Https://github.com/djstava/PyQt5Fastboot

http://www.bkjia.com/PHPjc/1084017.html www.bkjia.com true http://www.bkjia.com/PHPjc/1084017.html techarticle PYQT5 Series Tutorial (v) making the fastboot burner hardware and software Environment Windows 7 Python 3.4.2 PyQt 5.5.1 pycharm 5.0.2 Preface fastboot is a kind of brush machine for Android devices, it is more than rec. ..

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.