Pre favorites additions

This commit is contained in:
Maxim Stewart 2020-10-24 20:13:26 -05:00
parent 968fda6f68
commit 5f783ac320
2 changed files with 40 additions and 27 deletions

View File

@ -8,8 +8,6 @@ from os import listdir
# Gtk imports # Gtk imports
from xdg.DesktopEntry import DesktopEntry from xdg.DesktopEntry import DesktopEntry
# Application imports # Application imports
from core import Context from core import Context
@ -25,16 +23,18 @@ class Main(Context):
super().__init__(args) super().__init__(args)
HOME_APPS = os.path.expanduser('~') + "/.local/share/applications/" HOME_APPS = os.path.expanduser('~') + "/.local/share/applications/"
paths = ["/opt/", "/usr/share/applications/", HOME_APPS] paths = ["/opt/", "/usr/share/applications/", HOME_APPS]
self.menuData = self.getDesktopFilesInfo(paths)
baseOptions = ["[ TO MAIN MENU ]", "[ Favorites ]"]
query = "" query = ""
while True: while True:
try:
self.clear() self.clear()
if not self.menuData:
self.menuData = self.getDesktopFilesInfo(paths)
group = self.call_method("mainMenu")["group"] group = self.call_method("mainMenu")["group"]
if "[ Search ]" in group: if "Search..." in group:
query = self.call_method("searchMenu")["query"] query = self.call_method("searchMenu")["query"]
if "Favorites" in group:
query = self.call_method("favoritesMenu")["faves"]
if "[ Exit ]" in group: if "[ Exit ]" in group:
break break
@ -42,8 +42,10 @@ class Main(Context):
progsList = ["[ TO MAIN MENU ]"] progsList = ["[ TO MAIN MENU ]"]
progsList += self.getSubgroup(group, query) progsList += self.getSubgroup(group, query)
entry = self.call_method("subMenu", [group, progsList])["prog"] entry = self.call_method("subMenu", [group, progsList])["prog"]
if not "[ TO MAIN MENU ]" is entry: if entry not in baseOptions:
self.executeProgram(group, entry) self.executeProgram(group, entry)
except Exception as e:
pass
def call_method(self, method_name, data = None): def call_method(self, method_name, data = None):
@ -123,11 +125,9 @@ class Main(Context):
}) })
def getSubgroup(self, group, query = ""): def getSubgroup(self, group, query = ""):
desktopObjs = [] desktopObjs = []
if "[ Search ]" in group: if "Search..." in group:
gkeys = self.menuData.keys() gkeys = self.menuData.keys()
for gkey in gkeys: for gkey in gkeys:
for opt in self.menuData[gkey]: for opt in self.menuData[gkey]:
@ -135,9 +135,10 @@ class Main(Context):
if "comment" in keys and len(opt["comment"]) > 0 : if "comment" in keys and len(opt["comment"]) > 0 :
if query.lower() in opt["comment"].lower(): if query.lower() in opt["comment"].lower():
desktopObjs.append( opt["title"] + " || " + opt["comment"] ) desktopObjs.append( opt["title"] + " || " + opt["comment"] )
continue
if query.lower() in opt["title"].lower() or query.lower() in opt["fileName"].lower(): if query.lower() in opt["title"].lower() or query.lower() in opt["fileName"].lower():
desktopObjs.append( opt["title"] + " || " + opt["fileName"].replace(".desktop", "") ) desktopObjs.append( opt["title"] + " || " + opt["fileName"].replace(".desktop", "") )
elif "Favorites" in group:
pass
else: else:
for opt in self.menuData[group]: for opt in self.menuData[group]:
keys = opt.keys() keys = opt.keys()

View File

@ -15,9 +15,10 @@ from .mixins import StylesMixin
GROUPS = ["[ Search ]", "Accessories", "Multimedia", "Graphics", "Game", GROUPS = [ "Favorites", "Accessories", "Multimedia", "Graphics", "Office",
"Office", "Development", "Internet", "Settings", "System", "Development", "Internet", "Settings", "System", "Game", "Wine",
"Wine", "Other", "[ Exit ]"] "Other", "Search...", "[ Exit ]"
]
class Context(StylesMixin): class Context(StylesMixin):
@ -51,6 +52,17 @@ class Context(StylesMixin):
return prompt(menu, style=self.theme) return prompt(menu, style=self.theme)
def favoritesMenu(self, _grouplist = None):
grouplist = GROUPS if not _grouplist else _grouplist
menu = {
'type': 'list',
'name': 'faves',
'message': '[ Favorites ]',
'choices': grouplist
}
def subMenu(self, data = ["NO GROUP NAME", "NO PROGRAMS PASSED IN"]): def subMenu(self, data = ["NO GROUP NAME", "NO PROGRAMS PASSED IN"]):
group = data[0] group = data[0]
progList = data[1] progList = data[1]