Files
MikOS/sys/kernel/main.pyw
2026-01-25 17:01:16 +08:00

125 lines
6.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#导入模块
from tools import *
import login
import mount
import UI
#操作系统核心
class System:
def __init__(self):
#临时
self.username="root"
#将程序工作目录改到系统根目录
os.chdir(os.path.dirname(os.path.realpath(sys.argv[0])))
self.ReadConfig()
mount.endMount(self.DiskSite+":")#取消挂载虚拟磁盘,以防止过去的过期记录影响正常挂载
if not mount.Mount("\\".join(os.getcwd().split("\\")[:-2]),self.DiskSite+":"):#挂载虚拟磁盘如果返回值为False表示错误加not变为True运行If语句内容
print("EFI: Error, Mount DiskSite "+self.DiskSite+" not true")#输出虚拟磁盘挂载错误信息
os._exit(0)#补上的,如果运行失败程序需要停止运行
os.chdir(self.DiskSite+":")#将目录转移至虚拟磁盘
self.root = tk.Tk()
self.root.title('MikOS')
# 通过config.json个性化窗口
for i in self.config["res"]["set"]:
if i == "full":
self.root.state("zoomed")
elif i == "overrideredirect":
self.root.overrideredirect(True)
else:
print(f"Error: {i} no know")
UI.index(self.root,self.width,self.height)
self.root.update()
self.StartSysApp("explorer","__init__.mia")
self.root.protocol("WM_DELETE_WINDOW",self.CloseEvent)
self.root.mainloop()
def ReadConfig(self):
#获取配置文件
self.config=json.loads(openr("../config/config.json")) #全部配置句柄
self.width=self.config["res"]["width"] #窗口长
self.height=self.config["res"]["height"] #窗口宽
self.chicun=str(self.width)+"x"+str(self.height) #窗口长宽(可直接应用到self.root.geometry)
self.EFI=self.config["EFI"] #引导(EFI)配置句柄
self.Kernel=self.config["Kernel"] #内核(Kernel)配置句柄
self.DOS=self.config["DOS"] #命令行(DOS)配置句柄
self.DiskSite=self.EFI["DiskSite"] #虚拟磁盘挂载地址
self.BootSite=self.EFI["BootSite"] #操作系统程序文件所在
self.SysAppSite=self.BootSite+self.Kernel["SysAppSite"] #系统级程序文件所在
self.NorAppSite=self.Kernel["NorAppSite"] #全局用户级程序文件所在
self.ui_mik=self.BootSite+self.Kernel["ui"] #MikOs窗口图标文件所在
self.images_mik=self.BootSite+self.Kernel["images"] #MikOs桌面图标文件所在
self.tkinter_mik=self.BootSite+self.Kernel["tkinter"] #MikOs-Tkinter支持文件所在
UI.ui_mik=self.ui_mik #将MikOs窗口图标文件所在注册到UI
UI.tkinter_mik=self.tkinter_mik #将MikOs-Tkinter支持文件所在注册到UI
self.UsersSite=self.Kernel["UsersSite"] #用户组文件所在
self.bg=self.BootSite+self.config["bg"]["sys"] #桌面壁纸
self.suffixs=self.config["suffixs"] #文件图标后缀关联
self.filesuffixs=self.config["filesuffixs"] #文件名称图标关联(无后缀但需显示图标文件)(如:MakeFile)
self.color=self.config["color"] #主题色配置句柄
self.SysFileSuffixMapping=self.config["SysFileSuffixMapping"] #文件功能后缀关联
def CloseEvent(self):#关闭事件
if tm.askokcancel('MikOS:提示','确认要关闭MikOS吗?'):
os._exit(0)
def ERROR(self,WrongDevice,IOFlowErrorMessage,DebuggerApp,MemoryAddresss,EndMemoryAddress):
ERROR=tk.Frame(self.root,bg="#000")
ERROR.place(x=0,y=0)
def Text(text):
tk.Label(ERROR,text=text,fg="#FFF",bg="#000",font=("Moder DOS 437",15)).pack(anchor="sw")
def FText():
tk.Label(ERROR,text="",bg="#000",font=("Moder DOS 437",15)).pack(anchor="sw")
Text("There are some problems with your MikOS,")
Text("This may come from MikOs itself or some of its settings,")
Text("Python version problems, Or because of your own external operating system,")
Text("In short, MikOs has an error, We are not sure if the program can still run normally,")
Text("So we interrupted the program, But there may be some subprograms that have not")
Text("stopped completely, We can only do it here, the following are some error prompts")
FText()
Text(f'Error({WrongDevice}): "{IOFlowErrorMessage}"')
Text(f"Debugger Called: <{DebuggerApp}>")
Text("Specific Error Points:")
for i in MemoryAddresss:Text(f"{i[0]} : {i[1]} ()")
Text(f"Error Terminated At {{EndMemoryAddress}} Memory Pointer")
FText()
Text("Operating System Has Been Terminated")
FText()
Text("Kernel version:")
Text(f"MikOS Kernel V{self.Kernel['VerSion']} / EFI Boot System V{self.EFI['VerSion']}")
FText()
FText()
FText()
def StartSysApp(self,appname,file,*args,**kw):
self.global_dict=globals()
self.global_dict["args"]=args
self.global_dict["kw"]=kw
self.global_dict["app_info"]={"path":self.SysAppSite+"/"+appname+"/"}
self.global_dict["OperatingSystemHandle"]=self
code=openr(self.global_dict["app_info"]["path"]+file)
exec(code,self.global_dict)
def StartApp(self,appname,file,*args,**kw):
self.global_dict=globals()
self.global_dict["args"]=args
self.global_dict["kw"]=kw
self.global_dict["app_info"]={"path":self.NorAppSite+"/"+appname+"/"}
self.global_dict["OperatingSystemHandle"]=self
code=openr(self.global_dict["app_info"]["path"]+file)
exec(code,self.global_dict)
def StartFile(self,File=str,*args):
if os.path.isfile(File):
if (suffix := File.split(".")[-1].lower()) in self.SysFileSuffixMapping:
self.StartSysApp(self.SysFileSuffixMapping[suffix],"__init__.mia",f=File,*args)
#免登录
#login.login(root,bg=BootSite+config["bg"]["login"],width=root.winfo_width(),height=root.winfo_height(),callback=verifylogin)
System()
s=tk.Tk()#堵塞进程
s.withdraw()
s.mainloop()