from PySide2.QtWidgets import QApplication,QMainWindow,QPushButton,QPlainTextEdit,QMessageBox
from PySide2.QtUiTools import QUiLoader
from PySide2.QtCore import QFile
Rmdiction1 = {'a':'01','b':'02','c':'03','d':'04','e':'05','f':'10','g':'11','h':'12','i':'13','j':'14','k':'15','l':'20','m':'21','n':'22','o':'23','p':'24','q':'25','r':'30','s':'31','t':'32','u':'33','v':'34','w':'35','x':'40','y':'41','z':'42',' ':'43',',':'44','.':'45',':':'50',';':'51','<':'52','>':'53','?':'54','/':'55','[':'0001',']':'0010','{':'0100','}':'1000','-':'0011','':'0111','~':'1111','!':'0101','@':'0110','#':'1001','$':'1011','%':'1010','^':'1100','&':'1101','*':'1111','(':'60',')':'61','=':'62','+':'63','|':'64','`':'65','0':'70','1':'71','2':'72','3':'73','4':'74','5':'75','6':'80','7':'81','8':'82','9':'83','\':'84',''':'85','"':'90'}
Rmdiction = {value:key for key,value in Rmdiction1.items()}
def decode(x):
for i in Rmdiction:
if i == x:
print(Rmdiction[i])
return Rmdiction[i]
def encode(x1):
for i1 in Rmdiction1:
if i1 == x1:
print(Rmdiction1[i1])
return Rmdiction1[i1]
class Codec:
def _init(self):
# 从文件中加载UI定义
qfile_stats = QFile(r'C:\Users\Administrator\Desktop\jsr\程序及数据\ui文件\R编解码.ui')
qfile_stats.open(QFile.ReadOnly)
qfile_stats.close()
# 从 UI 定义中动态 创建一个相应的窗口对象
# 注意:里面的控件对象也成为窗口对象的属性了
# 比如 self.ui.button , self.ui.textEdit
self.ui = QUiLoader().load(qfile_stats)
self.ui.button.clicked.connect(self.coding)
self.ui.pushButton.clicked.connect(self.decoding)
self.ui.pushButton_2.clicked.connect(self.PUSH_BUTTON2)
self.ui.pushButton_3.clicked.connect(self.PUSH_BUTTON3)
def coding(self):
replied = self.ui.textedit.toPlainText()
ip = self.ui.textedit1.toPlainText()
message1 = open(replied,'r')
message2 = message1.read()
i3 = 0
receivelist1 = []
Message = message2.lower()
MESSAGE = Message.replace('\n','')
while i3 < len(MESSAGE):
a1 = encode(MESSAGE[i3])
receivelist1.append(a1)
i3 += 1
if i3 == len(MESSAGE):
orderedlist = '\n'.join(receivelist1)
f = open(ip,'w+')
f.writelines(orderedlist)
f.close()
QMessageBox.about(self.ui,'','编码成功')
def decoding(self):
replied = self.ui.textedit.toPlainText()
ip = self.ui.textedit1.toPlainText()
Filehandle = open(replied,'r')
n = Filehandle.read()
Filehandle.close()
v = n.split('\n')
i2 = 0
receivelist = []
while i2 < len(v):
a = decode(v[i2])
receivelist.append(a)
i2 += 1
if i2 == len(v):
orderedlist1 = ''.join(receivelist)
f = open(ip,'w+')
f.writelines(orderedlist1)
f.close()
QMessageBox.about(self.ui,'','解码成功')
def PUSH_BUTTON2(self):
version = '''**********使用说明**********
此程序可以将英文进行编码操作,对R码数字进行解码操作。
本程序不支持不使用英文字母的语言,请确保文件的内容正确。
以及关于文件的路径问题:
例如Jenny想要进行编码或解码的文件在桌面上,
而且她使用的是widowsXP系统,那么如果文件的名字为01.txt的话,
01.txt的路径就为C:\Documents and Settings\Administrator\桌面\01.txt
(特别提醒:目前只支持txt文件,即记事本文件)'''
QMessageBox.about(self.ui,'使用说明',version)
def PUSH_BUTTON3(self):
instructions = '''
R编解码版本:1.2 修改时间:2020.2.25 19:44:31.69
相比1.1版本,此次更新修复、添加了
1.增强了图形用户界面
2.删除了编解码时会逐一打印的值对的功能
3.修复了编解码时文件里字符串空行造成编解码操作出错的情况'''
QMessageBox.about(self.ui,'版本介绍',instructions)
app = QApplication([])
codec =Codec()
codec.ui.show()