Added Search and page mapping
This commit is contained in:
parent
1bd81a6eb0
commit
d2be227619
85
main.py
85
main.py
@ -5,37 +5,94 @@ import subprocess
|
|||||||
import os
|
import os
|
||||||
import webbrowser
|
import webbrowser
|
||||||
import json
|
import json
|
||||||
|
import math
|
||||||
|
|
||||||
|
|
||||||
class FLOappStore:
|
class FLOappStore:
|
||||||
def __init__(self, root):
|
def __init__(self, root):
|
||||||
self.root = root
|
self.root = root
|
||||||
|
self.maxRow=5
|
||||||
|
self.maxCol=2
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self.MainFrame = Frame(self.root, height=1000,width=500)
|
self.MainFrame = Frame(self.root)
|
||||||
self.MainFrame.pack()
|
self.MainFrame.pack()
|
||||||
WelcomeLabel = Label(self.MainFrame,text="FLO AppStore",font=("Arial", 20))
|
WelcomeLabel = Label(self.MainFrame,text="FLO AppStore",font=("Arial", 20))
|
||||||
WelcomeLabel.grid(column = 1, columnspan =2)
|
WelcomeLabel.grid(row=1,column = 1,columnspan=2)
|
||||||
|
self.searchBox=Entry(self.MainFrame)
|
||||||
|
self.searchBox.grid(row=2,column=1,sticky="E")
|
||||||
|
self.searchButton=Button(self.MainFrame,text="Search",command = self.searchApps)
|
||||||
|
self.searchButton.grid(row=2,column=2,sticky="W")
|
||||||
|
self.searchApps()
|
||||||
|
|
||||||
|
def searchApps(self):
|
||||||
|
self.searchResult=[]
|
||||||
|
searchText=self.searchBox.get()
|
||||||
|
for app in apps:
|
||||||
|
if (searchText.lower() in app["name"].lower()):
|
||||||
|
self.searchResult = self.searchResult + [app]
|
||||||
|
self.totalPage = math.ceil(len(self.searchResult)/(self.maxRow*self.maxCol))
|
||||||
|
self.listApps(1)
|
||||||
|
|
||||||
|
def listApps(self,pageNum):
|
||||||
|
try:
|
||||||
|
self.listFrame.destroy()
|
||||||
|
except:
|
||||||
|
None
|
||||||
|
|
||||||
|
self.listFrame = Frame(self.MainFrame)
|
||||||
|
if not len(self.searchResult):
|
||||||
|
noResultLabel = Label(self.listFrame,text="No Apps found!")
|
||||||
|
noResultLabel.grid()
|
||||||
|
self.listFrame.grid(column=1,columnspan=2)
|
||||||
|
return
|
||||||
|
|
||||||
|
if pageNum<1:
|
||||||
|
pageNum=self.totalPage
|
||||||
|
elif pageNum>self.totalPage:
|
||||||
|
pageNum=1
|
||||||
|
|
||||||
self.icon=[]
|
self.icon=[]
|
||||||
self.appButton=[]
|
self.appButton=[]
|
||||||
for i in range(len(apps)):
|
Xrow=1
|
||||||
self.icon= self.icon+[PhotoImage(file=apps[i]["icon"])]
|
Xcol=1
|
||||||
self.appButton = self.appButton + [Button(self.MainFrame,text=apps[i]["name"],image = self.icon[i],compound="left",width="500",height="50",command=lambda i=i:self.execute(i))]
|
startIndex=(pageNum-1)*(self.maxRow*self.maxCol)
|
||||||
self.appButton[i].grid(column = 1)
|
|
||||||
|
|
||||||
def execute(self,i):
|
for app in self.searchResult[startIndex:]:
|
||||||
print(apps[i]["name"])
|
self.icon= self.icon+[PhotoImage(file=app["icon"])]
|
||||||
if(apps[i]["type"] == "Gui"):
|
self.appButton = self.appButton + [Button(self.listFrame,text=app["name"],image = self.icon[-1],compound="left",width="500",height="50",command=lambda app=app:self.execute(app))]
|
||||||
subprocess.Popen(apps[i]["exec"], cwd=apps[i]["location"])
|
self.appButton[-1].grid(row = Xrow,column = Xcol)
|
||||||
elif(apps[i]["type"] == "Cmdline"):
|
Xcol=Xcol+1
|
||||||
subprocess.Popen(["mate-terminal --command %s" % (apps[i]["exec"])],cwd=apps[i]["location"],stdout=subprocess.PIPE,shell=True)
|
if (Xcol>self.maxCol):
|
||||||
elif(apps[i]["type"] == "Webapp"):
|
Xcol=1
|
||||||
webbrowser.open(apps[i]["exec"],new=1)
|
Xrow=Xrow+1
|
||||||
|
if (Xrow>self.maxRow):
|
||||||
|
break
|
||||||
|
prevButton = Button(self.listFrame,text="Prev",command=lambda :self.listApps(pageNum-1))
|
||||||
|
nextButton = Button(self.listFrame,text="Next",command=lambda :self.listApps(pageNum+1))
|
||||||
|
pageLabel = Label(self.listFrame,text=f"{pageNum}/{self.totalPage}")
|
||||||
|
prevButton.grid(row=self.maxRow+1,column=1,columnspan=self.maxCol,sticky="W")
|
||||||
|
nextButton.grid(row=self.maxRow+1,column=1,columnspan=self.maxCol,sticky="NE")
|
||||||
|
pageLabel.grid(row=self.maxRow+1,column=1,columnspan=self.maxCol,sticky="N")
|
||||||
|
self.listFrame.grid(column=1,columnspan=2)
|
||||||
|
|
||||||
|
def execute(self,app):
|
||||||
|
print(app["name"])
|
||||||
|
if(app["type"] == "Gui"):
|
||||||
|
subprocess.Popen(app["exec"], cwd=app["location"])
|
||||||
|
elif(app["type"] == "Cmdline"):
|
||||||
|
subprocess.Popen(["gnome-terminal --command %s" % (app["exec"])],cwd=app["location"],stdout=subprocess.PIPE,shell=True)
|
||||||
|
elif(app["type"] == "Webapp"):
|
||||||
|
webbrowser.open(app["exec"],new=1)
|
||||||
|
|
||||||
with open('AppData.json',encoding='utf-8') as F:
|
with open('AppData.json',encoding='utf-8') as F:
|
||||||
apps=json.loads(F.read())["Dapps"]
|
apps=json.loads(F.read())["Dapps"]
|
||||||
root = Tk()
|
root = Tk()
|
||||||
root.title("FLOappStore")
|
root.title("FLOappStore")
|
||||||
|
root.geometry("1100x500")
|
||||||
|
root.resizable(0,0)
|
||||||
gui = FLOappStore(root)
|
gui = FLOappStore(root)
|
||||||
gui.start()
|
gui.start()
|
||||||
root.mainloop()
|
root.mainloop()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user