基于 Python 3.12.4 和 PySide 6 的 假用户操作系统【0-0】虚拟终端框架

基本目标

  • 实现工作目录的切换;
  • 实现非退出命令下的无限循环;

到目前为止还不能实现的功能

  • 动态导入 py 文件中的模块
  • 缺少组件

定义虚拟进程类

command.py

from ctypes import windll
from PySide6.QtWidgets import QWidget
from sys import exit as sys_exit
from os import path, chdir
from warnings import filterwarnings
from command_version import CommandVersion


class Command:
    def __init__(self, UI: QWidget = None):
        windll.kernel32.SetConsoleTitleW("FalseOS Command")
        filterwarnings("ignore", category=SyntaxWarning)

    def run(self, command: str):
        if command == "":
            return
        command += " "
        conlist = command.split(" ")
        if "exit" == conlist[0].strip():
            self.exit()
        elif "#" in conlist[0].strip():
            print(f"'{conlist[0].strip()}' 不是可导入的模块。")
            return
        try:
            exec(f"self.{conlist[0].strip()}(conlist[1:])")
        except:
            print(f"'{conlist[0].strip()}' 不是可导入的模块。")

    def path(self) -> str:
        return path.abspath(".")

    @staticmethod
    def exit():
        sys_exit(0)

    @staticmethod
    def about(args):
        print(f"应用程序名称:{CommandVersion.name}\n"
              f"应用程序版本:{CommandVersion.version}\n"
              f"应用程序内部版本:{CommandVersion.build_ver}\n"
              f"应用程序证书发行机构:{CommandVersion.creater}")

    def cwd(self, args: list[str]):
        args0 = args[0]
        try:
            try:
                args0 = args[0].replace("*", " ")
            except:
                args0 = args[0]
            try:
                args0 = args0.replace("/", "\\")
            except:
                pass
            chdir(args0)
        except:
            if not self.is_non_str(args0):
                print(f"指定的路径无效:\n\tcwd {self.addlist(args)}\n\t    {"^" * len(args0)}")
            else:
                print(f"指定的路径无效:路径为空")
            return

    @staticmethod
    def is_non_str(string: str) -> bool:
        for i in string:
            if i != " " and i != " " and i != "":
                return False
        return True

    @staticmethod
    def addlist(list0: list[str]):
        re0 = ""
        for i in list0:
            re0 += i
            re0 +=" "
        return re0

定义应用程序信息

command_version.py

class CommandVersion:
    name = "FalseOS Command"
    version = "0.0.1"
    build_ver = "240.00001"
    creater = "YX 6223"

定义在 真 操作系统下的终端测试文件

command_loop.py

from command import Command
from command_version import CommandVersion
print(f"{CommandVersion.name} {CommandVersion.version} (内部构建版本:{CommandVersion.build_ver})\n"
      f"Created By {CommandVersion.creater},保留所有权利。")
cmd = Command()
while True:
    try:
        a = input(f"FC {cmd.path()} >>> ")
        cmd.run(a)
    except KeyboardInterrupt:
        print("\n终端进程被终止。")
        exit(-1)
    except SystemExit:
        exit(0)
    except OSError:
        print("\n系统错误。")
        exit(-1)

  • 8
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python 3.12.4 是 Python 3 系列的一个特定版本,它属于 Python 的稳定发行版。作为持续发展的编程语言Python 每次更新版本都会包含一系列的新功能、改进、错误修复以及安全补丁。以下是针对 Python 3.12.4 特点的一般描述: ### 新功能和改进 尽管具体的细节需要参考官方发布说明,但通常新版本的 Python 包含了以下几类更新: - **语言特性**:包括语法变更、函数库的增强、错误处理机制的改进等,旨在提高编程效率和用户体验。 - **性能提升**:通过内部优化,提高程序的运行速度和资源利用效率。 - **安全修复**:解决潜在的安全漏洞,增强整体的安全性。 - **稳定性加强**:对先前版本中存在的问题进行修正,增加软件的整体可靠性。 ### 使用场景 Python 3.12.4 可用于各种应用场景,从 Web 开发到数据分析、人工智能研究、自动化脚本编写等。它的广泛兼容性和丰富的第三方库使其成为跨行业解决方案的首选之一。 ### 安装和升级 为了使用 Python 3.12.4,您需要首先确认您的系统上是否已经安装有 Python。如果没有,可以从 Python 官方网站下载最新的 Python 发行包并按照说明进行安装。如果您已经安装了一个较早的版本,可以使用命令行工具 `pip` 来升级至特定版本。例如,在终端或命令提示符下输入: ```bash pip install --upgrade python=3.12.4 ``` 这会将您当前的 Python 版本更新到 3.12.4。 ### 相关问题: 1. 我如何查找我的计算机上已安装的 Python 版本? 2. Python 3.12.4 中的主要改进是什么? 3. 对于特定的 Python 应用项目,为什么需要使用特定版本的 Python 而不是其他版本?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值