added settings file plus auto save path feature

This commit is contained in:
Maxim Stewart 2019-10-28 00:16:15 -05:00
parent beadd27490
commit 5ac5aa361e
5 changed files with 48 additions and 5 deletions

View File

@ -11,6 +11,4 @@ Added task bar.
<ul>
<li>Detect window title changes</li>
<li>Set taskbar menu option based on window options.</li>
<li>Attach copy, cut, and paste signals to the controls menu.</li>
<li>Add a settings file to store values.</li>
</ul>

Binary file not shown.

View File

@ -18,7 +18,7 @@ class GridSignals:
selectDirDialog = self.builder.get_object("selectDirDialog")
filefilter = self.builder.get_object("Folders")
self.currentPath = self.settings.returnDesktopPath()
self.currentPath = self.settings.returnSettings()[0]
self.copyCutArry = []
self.selectedFiles = []
self.gridClss = None
@ -27,6 +27,7 @@ class GridSignals:
# Add filter to allow only folders to be selected
selectDirDialog.add_filter(filefilter)
selectDirDialog.set_filename(self.currentPath)
print(selectDirDialog.get_filename())
self.setNewDirectory(selectDirDialog)
@ -35,6 +36,9 @@ class GridSignals:
self.gridClss = Grid(self.gridObj, self.settings)
self.gridClss.setNewDirectory(newPath)
if not "~/Desktop/" in newPath:
self.settings.saveSettings(newPath)
# File control events
def create(self, wdget):

View File

@ -7,7 +7,7 @@ from gi.repository import Gtk as gtk
from gi.repository import Gdk as gdk
# Python imports
import os
import os, json
# Application imports
@ -52,6 +52,12 @@ class Settings:
self.MPV_WH = " -geometry 50%:50% ";
self.GTK_ORIENTATION = 1 # HORIZONTAL (0) VERTICAL (1)
configFolder = os.path.expanduser('~') + "/.config/pytop/"
self.configFile = configFolder + "settings.ini"
if os.path.isdir(configFolder) == False:
os.mkdir(configFolder)
if os.path.isdir(self.TRASHFOLDER) == False:
os.mkdir(TRASHFILESFOLDER)
os.mkdir(TRASHINFOFOLDER)
@ -62,6 +68,10 @@ class Settings:
if os.path.isdir(self.TRASHINFOFOLDER) == False:
os.mkdir(TRASHINFOFOLDER)
if os.path.isfile(self.configFile) == False:
open(self.configFile, 'a').close()
self.saveSettings(self.desktopPath)
def attachBuilder(self, builder):
self.builder = builder
@ -102,6 +112,36 @@ class Settings:
return monitors
def saveSettings(self, startPath):
data = {}
data['pytop_settings'] = []
data['pytop_settings'].append({
'startPath' : startPath
})
with open(self.configFile, 'w') as outfile:
json.dump(data, outfile)
def returnSettings(self):
returnData = []
with open(self.configFile) as infile:
try:
data = json.load(infile)
for obj in data['pytop_settings']:
returnData = [obj['startPath']]
except Exception as e:
returnData = ['~/Desktop/']
if returnData[0] == '':
returnData[0] = '~/Desktop/'
return returnData
def returnBuilder(self): return self.builder
def returnUserHome(self): return self.usrHome
def returnDesktopPath(self): return self.usrHome + "/Desktop"

View File

@ -48,7 +48,6 @@ class Grid:
self.grid.connect("item-activated", self.iconDblLeftClick)
self.grid.connect("button_release_event", self.iconSingleClick, (self.grid,))
# @threaded
def setNewDirectory(self, path):
self.store.clear()
self.currentPath = path
@ -131,9 +130,11 @@ class Grid:
parentDir = os.path.abspath(os.path.join(dir, os.pardir))
self.currentPath = parentDir
self.setNewDirectory(parentDir)
self.settings.saveSettings(parentDir)
elif isdir(file):
self.currentPath = file
self.setNewDirectory(self.currentPath)
self.settings.saveSettings(self.currentPath)
elif isfile(file):
self.fileHandler.openFile(file)
except Exception as e: