【ANSI】汉字转机内码工具

这是一个介绍汉字转机内码工具GbToANSI的博客,该工具能将输入的汉字内容转化为机内码。文章提供了工具的最新版本下载链接,GitHub和百度网盘两个途径,并附有源代码。工具使用Tkinter库创建GUI界面,支持创建快捷方式功能。同时,文章包含免责声明,提醒读者自行承担可能的错误风险。
摘要由CSDN通过智能技术生成

PS:该工具已经进行重制,新版本工具请看这篇博文

工具介绍

工具名称:汉字转机内码工具(GbToANSI)

工具版本:1.01

功能介绍:输入汉字内容,即可将对应内容转为机内码

工具截图:

PS:使用过程中若出现Bug可告知作者进行修复

下载链接:GitHub下载链接  百度网盘下载链接(提取码:1314)

源代码:

from tkinter import *
from Tool.ico import gtaIco
from Tool import PackTool as pt
from ctypes import windll
import os
from sys import executable as EXECUTABLE
from subprocess import Popen, PIPE, STDOUT
from win32api import SetFileAttributes
from win32con import FILE_ATTRIBUTE_HIDDEN
import Tool.MyLogger as ml


class GbToANSI:
    __log = ml.IMyLogger()

    def _createShortcut(self):
        execpath = os.path.dirname(EXECUTABLE)
        batpath = execpath + "\\init.bat"
        if os.path.exists(batpath):
            self.__log.InLog("Create shortcut successful!")
            startcmd = "start " + "shortcut.bat"
            startpath = execpath + "\\shortcut.bat"
            cmd = "cd " + execpath + " && " + startcmd
            pop = Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT)
            pop.wait()
            if pop.returncode == 0:
                pop.terminate()
                pop.kill()
                SetFileAttributes(startpath, FILE_ATTRIBUTE_HIDDEN)

    def __init__(self):
        self._createShortcut()
        self.__cIPT = pt.IPackTool(False)
        # 告诉操作系统使用程序自身的dpi适配
        windll.shcore.SetProcessDpiAwareness(1)
        # 获取屏幕的缩放因子
        ScaleFactor = windll.shcore.GetScaleFactorForDevice(0)
        self.__root = Tk()
        self.__root.title("汉字机内码")
        self.__cIPT.IcoBase64Decoder('gta', gtaIco)
        self.__cIPT.IcoSetToTk(self.__root, 'gta')
        # 获取屏幕宽高
        self.__screenWidth = self.__root.winfo_screenwidth()
        self.__screenHeight = self.__root.winfo_screenheight()
        # 设置窗口大小
        self.__root.geometry(self._windowSize(int(self.__screenWidth * 0.35), int(self.__screenHeight * 0.625)))
        self.__root.wm_minsize(int(self.__screenWidth * 0.31), int(self.__screenHeight * 0.56))
        # 设置程序缩放
        self.__root.tk.call('tk', 'scaling', ScaleFactor / 75)

        self.__Lb_1 = Label(self.__root, text='汉字内容:', foreground='red')
        self.__Lb_1.place(relx=0.1, rely=0, relwidth=0.8, relheight=0.1)
        self.__Et_1 = Entry(self.__root)
        self.__Et_1.place(relx=0.1, rely=0.1, relwidth=0.8, relheight=0.1)
        self.__Lb_2 = Label(self.__root, text='机内码如下:', foreground='red')
        self.__Lb_2.place(relx=0.1, rely=0.2, relwidth=0.8, relheight=0.1)
        self.__Et_3 = Entry(self.__root)
        self.__Et_3.place(relx=0.1, rely=0.3, relwidth=0.8, relheight=0.1)
        self.__Bt_1 = Button(self.__root, text='转化', command=lambda: self._run(str(self.__Et_1.get())))
        self.__Bt_1.place(relx=0.4, rely=0.45, relwidth=0.2, relheight=0.1)
        self.__root.mainloop()

    def _windowSize(self, p_width, p_height):
        size = '%dx%d+%d+%d' % (
            p_width, p_height, (self.__screenWidth - p_width) / 2, (self.__screenHeight - p_height) / 2)
        return size

    def _toUnicode(self, p_str):
        r_str = ""
        for v_char in p_str:
            r_str = r_str + hex(ord(v_char)).replace("0x", "") + " "
        return r_str

    def _toGb2312(self, p_bytes):
        r_str = ""
        count = 2
        for v_byte in p_bytes:
            r_str += hex(int(v_byte)).replace("0x", "")
            count -= 1
            if count == 0:
                r_str += " "
                count = 2
        return r_str

    def _run(self, p_context):
        try:
            Str1 = self._toGb2312(p_context.encode("gb2312")).strip()
            self.__Et_3.insert(0, Str1)
        except IOError:
            print("Error:转换失败!")
        else:
            print("Success:转换成功!")


class IGbToANSI:
    def __init__(self):
        self.__gta = GbToANSI()


mIGTA = IGbToANSI()

免责声明:由于本文内容未经过正规和严格的测试,可能存在错误,因此造成的损失均由使用者自行承担,对本文内容复制、下载、参考等引用行为即默认悉知并同意该声明。

如果这篇文章对你有帮助,请给作者点个赞吧!

  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值