format data tool version_2
#!/usr/bin/env python """PyQt4 port of the dialogs/findfiles example from Qt v4.x""" import sys,os from PySide import QtCore, QtGui from PySide.QtCore import * from PySide.QtGui import * #codeing=utf-8 class MainWindow(QtGui.QDialog): def __init__(self, parent=None): super(MainWindow, self).__init__(parent) print "1" self.originalPalette = QtGui.QApplication.palette() print "1" self.native = QtGui.QCheckBox() print "1" self.native.setText("@@@@@@@") print "1" self.native.setChecked(True) if sys.platform not in ("win32", "darwin"): self.native.hide() print "1" self.setWindowTitle("TOOL") print "2" self.globalInit() self.initUI() self.createInputArea() print "12" self.createSwapArea() print "22" self.createResultArea() print "21" mainLayout = QtGui.QGridLayout() print "22" mainLayout.addWidget(self.tpInputEdit,1,0) print "212" mainLayout.addWidget(self.tpSwap,2,0) print "217" mainLayout.addWidget(self.tpResBox,3,0) print "222" self.setLayout(mainLayout) print "252" def globalInit(self): self.title = "" def initUI(self): self.aa = "" def createInputArea(self): self.tpInputEdit = QtGui.QGroupBox("InputArea:") self.tpInputEdit.resEdit = QtGui.QTextEdit(self.tpInputEdit) #self.tpInputEdit.resEdit.setReadOnly(True) self.tpInputEdit.resEdit.setFixedSize(450,200) self.tpInputEdit.resEdit.show() print "555" #layout = QtGui.QGridLayout() print "5" self.tpInputEdit.freshButton = QPushButton("fresh",self.tpInputEdit) self.tpInputEdit.freshButton.clicked.connect(self.formatString) self.tpInputEdit.freshButton.setFixedSize(80,200) self.tpInputEdit.freshButton.show() #self.tpSwap = QtGui.QGroupBox("SwapArea:") print "5" self.tpInputEdit.swapButton32 = QPushButton("swap32",self.tpInputEdit) self.tpInputEdit.swapButton32.clicked.connect(self.formatStringswap32) self.tpInputEdit.swapButton32.setFixedSize(80,45) self.tpInputEdit.swapButton32.show() self.tpInputEdit.swapButton64 = QPushButton("swap64",self.tpInputEdit) self.tpInputEdit.swapButton64.clicked.connect(self.formatStringswap64) self.tpInputEdit.swapButton64.setFixedSize(80,45) self.tpInputEdit.swapButton64.show() self.tpInputEdit.swapButton128 = QPushButton("swap128",self.tpInputEdit) self.tpInputEdit.swapButton128.clicked.connect(self.formatStringswap128) self.tpInputEdit.swapButton128.setFixedSize(80,45) self.tpInputEdit.swapButton128.show() self.layout = QtGui.QHBoxLayout() layout1 = QtGui.QHBoxLayout() print "3" layout1.addWidget(self.tpInputEdit.resEdit) print "2" layout1.addWidget(self.tpInputEdit.freshButton) print "111" layout3 = QtGui.QVBoxLayout() print "3" layout3.addWidget(self.tpInputEdit.swapButton32) print "2" layout3.addWidget(self.tpInputEdit.swapButton64) print "4" layout3.addWidget(self.tpInputEdit.swapButton128) print "9" self.layout.addLayout(layout1) #self.layout.addStretch(1) self.layout.addLayout(layout3) print "8" self.tpInputEdit.setLayout(self.layout) def createSwapArea(self): self.tpSwap = QtGui.QGroupBox("ResultArea:") self.tpSwap.resEdit = QtGui.QTextEdit(self.tpSwap) self.tpSwap.resEdit.setReadOnly(True) self.tpSwap.resEdit.setFixedSize(720,30) #self.tpSwap.resEdit.move(100,100) self.tpSwap.resEdit.show() layout = QtGui.QVBoxLayout() layout.addWidget(self.tpSwap.resEdit) self.tpSwap.setLayout(layout) def createResultArea(self): self.tpResBox = QtGui.QGroupBox("ResultArea:") self.tpResBox.resEdit = QtGui.QTextEdit(self.tpResBox) #self.tpResBox.resEdit.setReadOnly(True) self.tpResBox.resEdit.setFixedSize(720,300) self.tpResBox.resEdit.show() layout = QtGui.QVBoxLayout() layout.addWidget(self.tpResBox.resEdit) self.tpResBox.setLayout(layout) def formatString(self): print "format" data = self.tpInputEdit.resEdit.toPlainText() print data len_data = len(data) temp = "" print len_data num = 0; for i in range(0,len_data,2): temp += "0x"+data[i:i+2]+", " num = num + 1 if num == 16: num = 0 temp += "\n" print temp self.tpResBox.resEdit.setText(temp) def formatStringswap32(self): print "format32" data = self.tpInputEdit.resEdit.toPlainText() print data len_data = len(data) temp = "" print len_data num = 0; array = []; j=0; for i in range(0,len_data,2): temp = "0x"+data[i:i+2] #print temp b= hex(eval(temp)) print b array.append(b) len_data = len(array) array_res = []; print len_data len_list = len_data/4 print len_list j=0; lists = [[] for i in range(len_list)] for i in range(0,len_data,1): lists[j].append(array[i]) if (i+1)%4 == 0: j = j+1 print lists finial_str = "" for i in range(len_list): for j in range(4)[::-1]: finial_str += str(lists[i][j])+", " j=0 print finial_str self.tpSwap.resEdit.setText(finial_str) def formatStringswap64(self): print "format64" data = self.tpInputEdit.resEdit.toPlainText() print data len_data = len(data) temp = "" print len_data num = 0; array = []; j=0; for i in range(0,len_data,2): temp = "0x"+data[i:i+2] #print temp b= hex(eval(temp)) print b array.append(b) len_data = len(array) #array_res = []; # #print array # temp_str = "" # if len_data == 8: # for i in range(0,len_data,1)[::-1]: # array_res.append(array[i]) # for i in range(0,len_data,1): # temp_str+=str(array_res[i])+", " # #print temp_str # if len_data == 16: # for i in range(0,8,1)[::-1]: # array_res.append(array[i]) # for i in range(0,8,1): # temp_str+=str(array_res[i])+", " # #print temp_str # # for i in range(8,16,1)[::-1]: # array_res.append(array[i]) # for i in range(8,16,1): # temp_str+=str(array_res[i])+", " # #print temp_str # print temp_str # self.tpSwap.resEdit.setText(temp_str) print len_data len_list = len_data/8 print len_list j=0; lists = [[] for i in range(len_list)] for i in range(0,len_data,1): lists[j].append(array[i]) if (i+1)%8 == 0: j = j+1 print lists finial_str = "" for i in range(len_list): for j in range(8)[::-1]: finial_str += str(lists[i][j])+", " j=0 print finial_str self.tpSwap.resEdit.setText(finial_str) def formatStringswap128(self): print "format128" data = self.tpInputEdit.resEdit.toPlainText() print data len_data = len(data) temp = "" print len_data num = 0; array = []; j=0; for i in range(0,len_data,2): temp = "0x"+data[i:i+2] #print temp b= hex(eval(temp)) print b array.append(b) len_data = len(array) array_res = []; #print array # for i in range(0,len_data,1)[::-1]: # array_res.append(array[i]) # temp_str = "" # for i in range(0,len_data,1): # temp_str+=str(array_res[i])+", " # #print temp_str # print temp_str print len_data len_list = len_data/16 print len_list j=0; lists = [[] for i in range(len_list)] for i in range(0,len_data,1): lists[j].append(array[i]) if (i+1)%16 == 0: j = j+1 print lists finial_str = "" for i in range(len_list): for j in range(16)[::-1]: finial_str += str(lists[i][j])+", " j=0 print finial_str self.tpSwap.resEdit.setText(finial_str) if __name__ == '__main__': import sys try: app = QtGui.QApplication(sys.argv) print("MainWindow") window = MainWindow() print("setGeometry") window.setGeometry(330,200,750,575) print("show") window.show() sys.exit(app.exec_()) except: print("Error: new MainWwindow error.") pass #11111222222222333333333333444444 #33333333344444467