GWinWrap/src/versions/0.0.1/GWinWrap/utils/SaveStateToXWinWarp.py

70 lines
2.4 KiB
Python
Raw Normal View History

2019-05-06 03:25:06 +00:00
#!/usr/bin/env python
import os
class SaveStateToXWinWarp:
2019-05-06 03:25:06 +00:00
def __init__(self):
self.fileWriter = None
2022-01-24 06:06:11 +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
2022-01-24 06:06:11 +00:00
self.player = None
2019-05-06 03:25:06 +00:00
2019-05-14 02:54:16 +00:00
def saveToFile(self, toSavePath, resolution,
2022-01-24 06:06:11 +00:00
saveLoc, useXSvrn, xScreenVal, player):
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
2022-01-24 06:06:11 +00:00
self.player = player
2019-05-06 03:25:06 +00:00
userPth = os.path.expanduser('~')
# Saves to file with selected and needed settings
2019-05-14 02:54:16 +00:00
if toSavePath:
2022-01-24 06:06:11 +00:00
if toSavePath.lower().endswith(('.png', '.jpg', '.jpeg')):
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
# 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')):
2022-01-24 06:06:11 +00:00
output = "[xin_0] \nfile=" + self.toSavePath + "\nmode=0 \nbgcolor=#000000\n\n[xin_1] \nfile=" + self.toSavePath + "\nmode=0 \nbgcolor=#000000";
2019-05-06 03:25:06 +00:00
applyType = 2;
# VIDEO
else:
2022-01-24 06:06:11 +00:00
output = "xwinwrap -ov -g " + self.resolution + " -st -sp -b -nf -s -ni -- " + self.player + " -wid WID -really-quiet -ao null -loop 0 '" + self.toSavePath + "'";
2019-05-06 03:25:06 +00:00
pass
2022-01-24 06:06:11 +00:00
try:
if self.fileWriter:
self.fileWriter.write(output)
self.fileWriter.close()
except Exception as e:
print(":: Write failed! ::")
print(e)
2019-05-06 03:25:06 +00:00
return applyType;