Initial commit with README
This commit is contained in:
152
sys/lib/explorer/__init__.mia
Normal file
152
sys/lib/explorer/__init__.mia
Normal file
@@ -0,0 +1,152 @@
|
||||
import tkinter as tk
|
||||
try:
|
||||
#绝对会报错,只是用于高亮提示,可以删除,真正的导入部分在Kernel
|
||||
import sys.kernel.UI as UI
|
||||
from sys.kernel.tools import *
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
def Omit(s):
|
||||
return s[:15] + '...' if len(s) > 15 else s
|
||||
|
||||
class DesktopFile:
|
||||
def __init__(self,c,username,i,desktop_imgs,nx,ny,dx,dy,global_dict,f,startapp):
|
||||
self.root=c.master
|
||||
self.username=username
|
||||
self.new_x=nx
|
||||
self.new_y=ny
|
||||
self.desktop_x=dx
|
||||
self.desktop_y=dy
|
||||
self.global_dict=global_dict
|
||||
self.f=f
|
||||
self.c=c
|
||||
self.i=i
|
||||
self.StartSysApp=startapp
|
||||
self.suffix=i.split(".")[-1].lower()
|
||||
if os.path.isfile(OperatingSystemHandle.UsersSite+self.username+"/Desktop/"+self.i):
|
||||
if self.suffix != i:
|
||||
if self.suffix in OperatingSystemHandle.suffixs:
|
||||
self.desktop_img = Image.open(OperatingSystemHandle.images_mik+OperatingSystemHandle.suffixs[self.suffix]+".ico")
|
||||
else:
|
||||
self.desktop_img = Image.open(OperatingSystemHandle.images_mik+OperatingSystemHandle.suffixs["[None]*"]+".ico")
|
||||
else:
|
||||
if i in OperatingSystemHandle.filesuffixs:
|
||||
self.desktop_img = Image.open(OperatingSystemHandle.images_mik+OperatingSystemHandle.filesuffixs[self.suffix]+".ico")
|
||||
else:
|
||||
self.desktop_img = Image.open(OperatingSystemHandle.images_mik+OperatingSystemHandle.suffixs["[None]*"]+".ico")
|
||||
if os.path.isdir(OperatingSystemHandle.UsersSite+self.username+"/Desktop/"+self.i):
|
||||
self.desktop_img = Image.open(OperatingSystemHandle.images_mik+OperatingSystemHandle.suffixs["[Dir]*"]+".ico")
|
||||
self.desktop_img = self.desktop_img.resize((90,90))
|
||||
if os.path.isfile(OperatingSystemHandle.UsersSite+self.username+"/Desktop/"+self.i):
|
||||
if self.suffix == "miksc":
|
||||
try:
|
||||
self.json=json.loads(openr(OperatingSystemHandle.UsersSite+self.username+"/Desktop/"+self.i))
|
||||
if "display-ico" in self.json:
|
||||
if "App" in self.json and "Start" in self.json:
|
||||
self.desktop_img = self.resize_and_return(Image.open(OperatingSystemHandle.NorAppSite+"/"+self.json["App"]+"/"+self.json["display-ico"]))
|
||||
if "SApp" in self.json and "Start" in self.json:
|
||||
self.desktop_img = self.resize_and_return(Image.open(OperatingSystemHandle.SysAppSite+"/"+self.json["SApp"]+"/"+self.json["display-ico"]))
|
||||
except:
|
||||
pass
|
||||
self.desktop_img = ImageTk.PhotoImage(self.desktop_img)
|
||||
desktop_imgs.append(self.desktop_img)
|
||||
self.desktop_btn = self.c.create_image((self.new_x-1)*100+50, 50+self.new_y*100, image=self.desktop_img)
|
||||
self.c.create_text((self.new_x-1)*100+50, (self.new_y+1)*100, text=Omit(i),font=('arial',10),fill="white")
|
||||
#self.layer.move(text, self.width//2-(self.layer.bbox(text)[2] - self.layer.bbox(text)[0])+27.5+add_xy, 0+add_xy)
|
||||
self.c.tag_bind(self.desktop_btn,'<Button-1>',self.Start)
|
||||
self.c.tag_bind(self.desktop_btn, '<Enter>', self.mouse_hand)
|
||||
self.c.tag_bind(self.desktop_btn, '<Leave>', self.mouse_arrow)
|
||||
if self.new_y < self.desktop_y-1:self.new_y+=1
|
||||
else:
|
||||
self.new_y=0
|
||||
self.new_x+=1
|
||||
if self.new_x >= self.desktop_x-1:
|
||||
self.f.ERROR("Desktop Draw","File Across Desktop Max","Main",[["0x00","0x00"]],"0x00")
|
||||
def mouse_hand(self,*args):
|
||||
self.root.config(cursor = 'hand2')
|
||||
def mouse_arrow(self,*args):
|
||||
self.root.config(cursor = 'arrow')
|
||||
def Start(self,event):
|
||||
OperatingSystemHandle.StartFile(OperatingSystemHandle.UsersSite+self.username+"/Desktop/"+self.i)
|
||||
def resize_and_return(self,image):
|
||||
width, height = image.size
|
||||
ratio = 50 / width
|
||||
new_height = int(height * ratio)
|
||||
resized_image = image.resize((50, new_height))
|
||||
return resized_image
|
||||
|
||||
|
||||
|
||||
class LogoPopUp(tk.Toplevel):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.overrideredirect(True)
|
||||
self.withdraw()
|
||||
self.config(bg=OperatingSystemHandle.color["tasks"]["win"])
|
||||
self.width=int(OperatingSystemHandle.root.winfo_width()*0.35)
|
||||
self.height=int(OperatingSystemHandle.root.winfo_height()*0.9)
|
||||
self.Tasks=tk.Frame
|
||||
self.geometry(f"{self.width}x{self.height}")
|
||||
self.Is_Focus()
|
||||
self.EmbedParentWindow()
|
||||
def Draw(self,event=tk.Event):
|
||||
if self.state() == "withdrawn":
|
||||
self.deiconify()
|
||||
self.geometry(f"+{event.widget.winfo_x()}+{OperatingSystemHandle.root.winfo_height()-self.Tasks.winfo_height()-self.height}")
|
||||
self.focus()
|
||||
@asyncs
|
||||
def Is_Focus(self):
|
||||
while True:
|
||||
if self.focus_get() != self:
|
||||
self.withdraw()
|
||||
time.sleep(0.1)
|
||||
@asyncs
|
||||
def EmbedParentWindow(self):
|
||||
#while True:
|
||||
# if master:
|
||||
# u32.SetParent(u32.GetParent(self.winfo_id()),master.winfo_id())
|
||||
# time.sleep(1)
|
||||
for i in range(10):
|
||||
u32.SetParent(u32.GetParent(self.winfo_id()),OperatingSystemHandle.root.winfo_id())
|
||||
class Explorer:
|
||||
def __init__(self):
|
||||
desktop_imgs=[]
|
||||
self.c = tk.Canvas(OperatingSystemHandle.root,width=OperatingSystemHandle.root.winfo_width(),height=OperatingSystemHandle.root.winfo_height()-30,highlightthickness=0)
|
||||
self.c.pack()
|
||||
|
||||
UI.master=self.c
|
||||
self.Tasks = tk.Frame(OperatingSystemHandle.root,height=30,bg=OperatingSystemHandle.color["tasks"]["bg"])
|
||||
self.Tasks.pack(side="bottom",fill="x")
|
||||
UI.TasksFrame=self.Tasks
|
||||
self.TasksIconImg=ImageTk.PhotoImage(Image.open(OperatingSystemHandle.images_mik+'/[MICO].png').resize([30,30]))
|
||||
self.TasksIconHovImg=ImageTk.PhotoImage(Image.open(OperatingSystemHandle.images_mik+'/[EICO].png').resize([30,30]))
|
||||
|
||||
self.LPU=LogoPopUp()
|
||||
self.LPU.Tasks=self.Tasks
|
||||
|
||||
self.TasksIconButton=tk.Button(self.Tasks,image=self.TasksIconImg,bg=OperatingSystemHandle.color["tasks"]["bg"],bd=0)
|
||||
self.TasksIconButton.pack(side="left")
|
||||
self.TasksIconButton.bind("<Enter>", lambda _: self.TasksIconButton.config(image=self.TasksIconHovImg))
|
||||
self.TasksIconButton.bind("<Leave>", lambda _: self.TasksIconButton.config(image=self.TasksIconImg))
|
||||
self.TasksIconButton.bind("<Button-1>",self.LPU.Draw)
|
||||
|
||||
self.bgimg = Image.open(OperatingSystemHandle.bg)
|
||||
self.bgimg = self.bgimg.resize((OperatingSystemHandle.root.winfo_width(), OperatingSystemHandle.root.winfo_height()))
|
||||
self.bgimg = ImageTk.PhotoImage(self.bgimg)
|
||||
|
||||
self.background = self.c.create_image(0, 0, anchor='nw', image=self.bgimg)
|
||||
|
||||
self.desktop_x=OperatingSystemHandle.root.winfo_width()//90-2
|
||||
self.desktop_y=OperatingSystemHandle.root.winfo_height()//90-2
|
||||
|
||||
self.new_x=1
|
||||
self.new_y=0
|
||||
DisplayContent=tk.Canvas(OperatingSystemHandle.root,width=OperatingSystemHandle.root.winfo_width(),height=OperatingSystemHandle.root.winfo_height()-30,highlightthickness=0)
|
||||
DisplayContent.pack(fill="both",expand=True)
|
||||
for i in os.listdir(OperatingSystemHandle.UsersSite+OperatingSystemHandle.username+"/Desktop"):
|
||||
i=DesktopFile(self.c,OperatingSystemHandle.username,i,desktop_imgs,self.new_x,self.new_y,self.desktop_x,self.desktop_y,globals(),self,OperatingSystemHandle.StartSysApp)
|
||||
self.new_x,self.new_y,self.desktop_x,self.desktop_y=i.new_x,i.new_y,i.desktop_x,i.desktop_y
|
||||
|
||||
Task_Explorer=Explorer()
|
||||
Reference in New Issue
Block a user