added settings file plus auto save path feature
This commit is contained in:
parent
beadd27490
commit
5ac5aa361e
@ -11,6 +11,4 @@ Added task bar.
|
|||||||
<ul>
|
<ul>
|
||||||
<li>Detect window title changes</li>
|
<li>Detect window title changes</li>
|
||||||
<li>Set taskbar menu option based on window options.</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>
|
</ul>
|
||||||
|
Binary file not shown.
@ -18,7 +18,7 @@ class GridSignals:
|
|||||||
selectDirDialog = self.builder.get_object("selectDirDialog")
|
selectDirDialog = self.builder.get_object("selectDirDialog")
|
||||||
filefilter = self.builder.get_object("Folders")
|
filefilter = self.builder.get_object("Folders")
|
||||||
|
|
||||||
self.currentPath = self.settings.returnDesktopPath()
|
self.currentPath = self.settings.returnSettings()[0]
|
||||||
self.copyCutArry = []
|
self.copyCutArry = []
|
||||||
self.selectedFiles = []
|
self.selectedFiles = []
|
||||||
self.gridClss = None
|
self.gridClss = None
|
||||||
@ -27,6 +27,7 @@ class GridSignals:
|
|||||||
# Add filter to allow only folders to be selected
|
# Add filter to allow only folders to be selected
|
||||||
selectDirDialog.add_filter(filefilter)
|
selectDirDialog.add_filter(filefilter)
|
||||||
selectDirDialog.set_filename(self.currentPath)
|
selectDirDialog.set_filename(self.currentPath)
|
||||||
|
print(selectDirDialog.get_filename())
|
||||||
self.setNewDirectory(selectDirDialog)
|
self.setNewDirectory(selectDirDialog)
|
||||||
|
|
||||||
|
|
||||||
@ -35,6 +36,9 @@ class GridSignals:
|
|||||||
self.gridClss = Grid(self.gridObj, self.settings)
|
self.gridClss = Grid(self.gridObj, self.settings)
|
||||||
self.gridClss.setNewDirectory(newPath)
|
self.gridClss.setNewDirectory(newPath)
|
||||||
|
|
||||||
|
if not "~/Desktop/" in newPath:
|
||||||
|
self.settings.saveSettings(newPath)
|
||||||
|
|
||||||
|
|
||||||
# File control events
|
# File control events
|
||||||
def create(self, wdget):
|
def create(self, wdget):
|
||||||
|
@ -7,7 +7,7 @@ from gi.repository import Gtk as gtk
|
|||||||
from gi.repository import Gdk as gdk
|
from gi.repository import Gdk as gdk
|
||||||
|
|
||||||
# Python imports
|
# Python imports
|
||||||
import os
|
import os, json
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
|
|
||||||
@ -52,6 +52,12 @@ class Settings:
|
|||||||
self.MPV_WH = " -geometry 50%:50% ";
|
self.MPV_WH = " -geometry 50%:50% ";
|
||||||
self.GTK_ORIENTATION = 1 # HORIZONTAL (0) VERTICAL (1)
|
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:
|
if os.path.isdir(self.TRASHFOLDER) == False:
|
||||||
os.mkdir(TRASHFILESFOLDER)
|
os.mkdir(TRASHFILESFOLDER)
|
||||||
os.mkdir(TRASHINFOFOLDER)
|
os.mkdir(TRASHINFOFOLDER)
|
||||||
@ -62,6 +68,10 @@ class Settings:
|
|||||||
if os.path.isdir(self.TRASHINFOFOLDER) == False:
|
if os.path.isdir(self.TRASHINFOFOLDER) == False:
|
||||||
os.mkdir(TRASHINFOFOLDER)
|
os.mkdir(TRASHINFOFOLDER)
|
||||||
|
|
||||||
|
if os.path.isfile(self.configFile) == False:
|
||||||
|
open(self.configFile, 'a').close()
|
||||||
|
self.saveSettings(self.desktopPath)
|
||||||
|
|
||||||
|
|
||||||
def attachBuilder(self, builder):
|
def attachBuilder(self, builder):
|
||||||
self.builder = builder
|
self.builder = builder
|
||||||
@ -102,6 +112,36 @@ class Settings:
|
|||||||
return monitors
|
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 returnBuilder(self): return self.builder
|
||||||
def returnUserHome(self): return self.usrHome
|
def returnUserHome(self): return self.usrHome
|
||||||
def returnDesktopPath(self): return self.usrHome + "/Desktop"
|
def returnDesktopPath(self): return self.usrHome + "/Desktop"
|
||||||
|
@ -48,7 +48,6 @@ class Grid:
|
|||||||
self.grid.connect("item-activated", self.iconDblLeftClick)
|
self.grid.connect("item-activated", self.iconDblLeftClick)
|
||||||
self.grid.connect("button_release_event", self.iconSingleClick, (self.grid,))
|
self.grid.connect("button_release_event", self.iconSingleClick, (self.grid,))
|
||||||
|
|
||||||
# @threaded
|
|
||||||
def setNewDirectory(self, path):
|
def setNewDirectory(self, path):
|
||||||
self.store.clear()
|
self.store.clear()
|
||||||
self.currentPath = path
|
self.currentPath = path
|
||||||
@ -131,9 +130,11 @@ class Grid:
|
|||||||
parentDir = os.path.abspath(os.path.join(dir, os.pardir))
|
parentDir = os.path.abspath(os.path.join(dir, os.pardir))
|
||||||
self.currentPath = parentDir
|
self.currentPath = parentDir
|
||||||
self.setNewDirectory(parentDir)
|
self.setNewDirectory(parentDir)
|
||||||
|
self.settings.saveSettings(parentDir)
|
||||||
elif isdir(file):
|
elif isdir(file):
|
||||||
self.currentPath = file
|
self.currentPath = file
|
||||||
self.setNewDirectory(self.currentPath)
|
self.setNewDirectory(self.currentPath)
|
||||||
|
self.settings.saveSettings(self.currentPath)
|
||||||
elif isfile(file):
|
elif isfile(file):
|
||||||
self.fileHandler.openFile(file)
|
self.fileHandler.openFile(file)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
Loading…
Reference in New Issue
Block a user