Python PyQt 5は16進数文字ストリームの検証と計算を実現する

8532 ワード

# -*- coding:utf-8 -*-
'''      ,   ,    ,        ,    “  ”                ''' __author__ = 'TangJie'

#     
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QHBoxLayout, QPushButton, QLineEdit, QVBoxLayout, QMessageBox
from PyQt5 import QtGui, QtCore
import sys

#        Qwidget,QWidget            ,                  QWidget
class ShowWindow(QWidget):

    def __init__(self):
        super(ShowWindow, self).__init__()
        self.initCheckUI()

    def initCheckUI(self):
        #     :    ,     ,    
        self.inputLabel = QLabel("         ")
        self.editLine = QLineEdit()
        self.printButton = QPushButton("  ")
        self.clearButton = QPushButton("  ")

        #                 
        self.printButton.clicked.connect(self.printText)
        self.clearButton.clicked.connect(self.clearText)

        #         (QHBoxLayout),            
        inputLayout = QHBoxLayout()
        inputLayout.addWidget(self.inputLabel)
        inputLayout.addWidget(self.editLine)

        #           2      
        buttonLayout = QHBoxLayout()
        buttonLayout.addWidget(self.printButton)
        buttonLayout.addWidget(self.clearButton)

        #         ,           
        mainLayout = QVBoxLayout()
        mainLayout.addLayout(inputLayout)
        mainLayout.addLayout(buttonLayout)

        #  mainLayout     LayOut
        self.setLayout(mainLayout)
        self.setWindowTitle('       ')  #      
        self.setFixedSize(300, 100)
        # self.setWindowFlags(QtCore.Qt.SplashScreen)  #       ,  :https://jingyan.baidu.com/article/ac6a9a5e7a79312b653eacc0.html
        self.setFixedSize(self.width(), self.height())
        self.show()  #     

    def printText(self):
        Hexflow = self.editLine.text()  #            
        FlowLen = len(Hexflow)
        FlowSum = 0

        if (FlowLen / 4) > (FlowLen // 4):
            QMessageBox.information(self, "    ", "     4   ,    4   ")
        else:
            if Hexflow == '':   #        
                QMessageBox.information(self, "    ", "    ,     ")
            else:  #         
                n = 0
                while FlowLen > 0:
                    FlowLen -= 4
                    FlowSum += int(Hexflow[n:n+4], 16)
                    n += 4
                FlowSum = ((FlowSum & 0xffff0000) >> 16) +  (FlowSum & 0x0000ffff)
                FlowSum = (~FlowSum) & 0xffff
                QMessageBox.information(self, "    ", "%s
:%x" % (Hexflow,FlowSum)) def clearText(self): Hexflow = self.editLine.text() if Hexflow == '': return else: self.editLine.clear() # if __name__ == '__main__': app = QApplication(sys.argv) ex = ShowWindow() sys.exit(app.exec_()) #
  UI      https://blog.csdn.net/zhulove86/article/details/52387265