2019-05-06 03:25:06 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
class SaveState:
|
|
|
|
def __init__(self):
|
|
|
|
self.fileWriter = None
|
2019-05-14 02:54:16 +00:00
|
|
|
self.toSavePath = None
|
2019-05-06 03:25:06 +00:00
|
|
|
self.useXSvrn = None
|
|
|
|
self.xScreenVal = None
|
|
|
|
self.sveFileLoc = None
|
|
|
|
self.resolution = None
|
|
|
|
|
2019-05-14 02:54:16 +00:00
|
|
|
def saveToFile(self, toSavePath, resolution,
|
|
|
|
saveLoc, useXSvrn, xScreenVal):
|
2019-05-06 03:25:06 +00:00
|
|
|
|
2019-05-14 02:54:16 +00:00
|
|
|
self.toSavePath = toSavePath
|
2019-05-06 03:25:06 +00:00
|
|
|
self.useXSvrn = useXSvrn
|
|
|
|
self.xScreenVal = xScreenVal
|
|
|
|
self.resolution = resolution
|
|
|
|
userPth = os.path.expanduser('~')
|
|
|
|
|
|
|
|
# Saves to file with selected and needed settings
|
2019-05-14 02:54:16 +00:00
|
|
|
if toSavePath:
|
|
|
|
if toSavePath.lower().endswith(('.png', '.jpg', '.jpeg', '.gif')):
|
2019-05-06 03:25:06 +00:00
|
|
|
self.sveFileLoc = userPth + "/" + ".config/nitrogen/bg-saved.cfg"
|
|
|
|
else:
|
|
|
|
self.sveFileLoc = userPth + "/" + saveLoc
|
2019-05-14 02:54:16 +00:00
|
|
|
elif useXSvrn and xScreenVal:
|
|
|
|
self.sveFileLoc = userPth + "/" + saveLoc
|
2019-05-06 03:25:06 +00:00
|
|
|
else:
|
2019-05-14 02:54:16 +00:00
|
|
|
return -1
|
|
|
|
|
2019-05-06 03:25:06 +00:00
|
|
|
if self.sveFileLoc:
|
|
|
|
self.fileWriter = open(self.sveFileLoc, "w")
|
|
|
|
|
|
|
|
return self.startSave()
|
|
|
|
|
|
|
|
def startSave(self):
|
|
|
|
applyType = 1
|
|
|
|
output = None
|
|
|
|
|
2019-05-14 02:54:16 +00:00
|
|
|
print("XScreen: " + str(self.useXSvrn))
|
|
|
|
print(self.fileWriter)
|
|
|
|
|
2019-05-06 03:25:06 +00:00
|
|
|
# XSCREENSAVER
|
|
|
|
if self.useXSvrn:
|
|
|
|
output = "xwinwrap -ov -g " + self.resolution + " -st -sp -b -nf -s -ni -- /usr/lib/xscreensaver/" + self.xScreenVal + " -window-id WID -root";
|
|
|
|
# GIF
|
2019-05-14 02:54:16 +00:00
|
|
|
elif self.toSavePath.lower().endswith(('.gif')):
|
|
|
|
output = "xwinwrap -ov -g " + self.resolution + " -st -sp -b -nf -s -ni -- gifview -a -w WID " + self.toSavePath;
|
2019-05-06 03:25:06 +00:00
|
|
|
# Standard images using nitrogen
|
2019-05-14 02:54:16 +00:00
|
|
|
elif self.toSavePath.lower().endswith(('.png', 'jpg', '.jpeg')):
|
|
|
|
output = "[xin_0] \n file=" + self.toSavePath + "\nmode=0 \nbgcolor=#000000\n[xin_1] \nfile=" + self.toSavePath + "\nmode=0 \nbgcolor=#000000";
|
2019-05-06 03:25:06 +00:00
|
|
|
applyType = 2;
|
|
|
|
# VIDEO
|
|
|
|
else:
|
2019-05-14 02:54:16 +00:00
|
|
|
output = "xwinwrap -ov -g " + self.resolution + " -st -sp -b -nf -s -ni -- mplayer -wid WID -really-quiet -ao null -loop 0 " + self.toSavePath;
|
2019-05-06 03:25:06 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
if self.fileWriter:
|
|
|
|
self.fileWriter.write(output)
|
|
|
|
self.fileWriter.close()
|
|
|
|
|
|
|
|
return applyType;
|