added favorites functionality
This commit is contained in:
parent
fad7b6a31d
commit
e30ae34f97
|
@ -1,6 +1,5 @@
|
||||||
# Python imports
|
# Python imports
|
||||||
import subprocess
|
import os, subprocess, json
|
||||||
import os
|
|
||||||
|
|
||||||
from os.path import isdir, isfile, join
|
from os.path import isdir, isfile, join
|
||||||
from os import listdir
|
from os import listdir
|
||||||
|
@ -25,6 +24,7 @@ class Main(Context):
|
||||||
paths = ["/opt/", "/usr/share/applications/", HOME_APPS]
|
paths = ["/opt/", "/usr/share/applications/", HOME_APPS]
|
||||||
baseOptions = ["[ TO MAIN MENU ]", "Favorites"]
|
baseOptions = ["[ TO MAIN MENU ]", "Favorites"]
|
||||||
self.menuData = self.getDesktopFilesInfo(paths)
|
self.menuData = self.getDesktopFilesInfo(paths)
|
||||||
|
self.faves = self.loadFaves()
|
||||||
query = ""
|
query = ""
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
@ -35,8 +35,15 @@ class Main(Context):
|
||||||
|
|
||||||
if "Search..." in group:
|
if "Search..." in group:
|
||||||
query = self.call_method("searchMenu")["query"]
|
query = self.call_method("searchMenu")["query"]
|
||||||
if "Favorites" in group:
|
if "[ Set Favorites ]" in group:
|
||||||
query = self.call_method("favoritesMenu")["faves"]
|
progsList = self.getSubgroup("Search...", "")
|
||||||
|
fixedProgsList = []
|
||||||
|
|
||||||
|
for prog in progsList:
|
||||||
|
fixedProgsList.append({'name': prog})
|
||||||
|
|
||||||
|
self.faves = self.call_method("setFavoritesMenu", [fixedProgsList])["setFaves"]
|
||||||
|
self.saveFaves(self.faves)
|
||||||
continue
|
continue
|
||||||
if "[ Exit ]" in group:
|
if "[ Exit ]" in group:
|
||||||
break
|
break
|
||||||
|
@ -59,6 +66,35 @@ class Main(Context):
|
||||||
return method(data) if data else method()
|
return method(data) if data else method()
|
||||||
|
|
||||||
|
|
||||||
|
def loadFaves(self, data = None):
|
||||||
|
configFolder = os.getenv("HOME") + "/.config/shellmen"
|
||||||
|
configFile = configFolder + "/favorites.json"
|
||||||
|
self.logger.info("[Opening saved favorites file: {}".format(configFile))
|
||||||
|
faves = []
|
||||||
|
|
||||||
|
if os.path.isdir(configFolder) == False:
|
||||||
|
os.mkdir(configFolder)
|
||||||
|
if os.path.isfile(configFile) == False:
|
||||||
|
open(configFile, 'a').close()
|
||||||
|
|
||||||
|
with open(configFile) as infile:
|
||||||
|
try:
|
||||||
|
faves = json.load(infile)
|
||||||
|
except Exception as e:
|
||||||
|
pass
|
||||||
|
|
||||||
|
infile.close()
|
||||||
|
|
||||||
|
return faves
|
||||||
|
|
||||||
|
|
||||||
|
def saveFaves(self, data = None):
|
||||||
|
configFolder = os.getenv("HOME") + "/.config/shellmen"
|
||||||
|
configFile = configFolder + "/favorites.json"
|
||||||
|
with open(configFile, 'w') as outfile:
|
||||||
|
json.dump(data, outfile)
|
||||||
|
|
||||||
|
|
||||||
def getDesktopFilesInfo(self, paths):
|
def getDesktopFilesInfo(self, paths):
|
||||||
menuObjs = {
|
menuObjs = {
|
||||||
"Accessories": [],
|
"Accessories": [],
|
||||||
|
@ -143,7 +179,7 @@ class Main(Context):
|
||||||
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:
|
elif "Favorites" in group:
|
||||||
pass
|
desktopObjs = self.faves
|
||||||
else:
|
else:
|
||||||
for opt in self.menuData[group]:
|
for opt in self.menuData[group]:
|
||||||
keys = opt.keys()
|
keys = opt.keys()
|
||||||
|
|
|
@ -17,7 +17,7 @@ from .mixins import StylesMixin
|
||||||
|
|
||||||
GROUPS = [ "Search...", "Favorites", "Accessories", "Multimedia", "Graphics", "Office",
|
GROUPS = [ "Search...", "Favorites", "Accessories", "Multimedia", "Graphics", "Office",
|
||||||
"Development", "Internet", "Settings", "System", "Game", "Wine",
|
"Development", "Internet", "Settings", "System", "Game", "Wine",
|
||||||
"Other", "[ Exit ]"
|
"Other", "[ Set Favorites ]", "[ Exit ]"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,13 +53,14 @@ class Context(StylesMixin):
|
||||||
return prompt(menu, style=self.theme)
|
return prompt(menu, style=self.theme)
|
||||||
|
|
||||||
|
|
||||||
def favoritesMenu(self, _grouplist = None):
|
def setFavoritesMenu(self, _grouplist = None):
|
||||||
GROUPS = ["[ TO MAIN MENU ]", "This is a stub method for Favorites..."]
|
GROUPS = [{'name': '[ TO MAIN MENU ]'}, {'name': 'This is a stub method for Favorites...'}]
|
||||||
grouplist = GROUPS if not _grouplist else _grouplist
|
grouplist = GROUPS if not _grouplist[0] else _grouplist[0]
|
||||||
menu = {
|
menu = {
|
||||||
'type': 'list',
|
'type': 'checkbox',
|
||||||
'name': 'faves',
|
'qmark': '>',
|
||||||
'message': '[ Favorites ]',
|
'message': 'Select Favorites',
|
||||||
|
'name': 'setFaves',
|
||||||
'choices': grouplist
|
'choices': grouplist
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue