-
Notifications
You must be signed in to change notification settings - Fork 11
/
plymouth-creator.py
196 lines (184 loc) · 9.11 KB
/
plymouth-creator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import os
import glob
import tkinter
from tkinter import filedialog
from subprocess import call
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
setVideoInputFile = False
videoInputFile = ""
setVideoOutputDirectory = False
videoOutputDirectory = ""
setOutputDirectory = False
outputDirectory = ""
name = ""
description = ""
loopAnimation = None
scaleImages = None
root = tkinter.Tk()
root.withdraw()
class Handler:
def on_selectVideoButton_clicked(self, button):
global videoInputFile
global setVideoInputFile
videoInputFile = filedialog.askopenfilename(parent=root,initialdir="/home",title='Select your .mp4 video',filetypes = (("mp4 files","*.mp4"),("all files","*.*")))
if(isinstance(videoInputFile, str)):
setVideoInputFile = True
selectVideoDoneLabel.set_text("Done!")
def on_selectVideoOutputButton_clicked(self, button):
global videoOutputDirectory
global setVideoOutputDirectory
videoOutputDirectory = filedialog.askdirectory(parent=root,initialdir="/home",title='Select an empty output directory')
if(isinstance(videoOutputDirectory, str)):
setVideoOutputDirectory = True
selectVideoOutputDoneLabel.set_text("Done!")
def on_startVideoConvertionButton_clicked(self, button):
global setOutputDirectory
global outputDirectory
if(setVideoInputFile == True and setVideoOutputDirectory == True):
os.system("ffmpeg -i '" + videoInputFile + "' '" + videoOutputDirectory + "/image-%01d.png' -hide_banner")
videoConvertionDoneLabel.set_text("Done!")
if(isinstance(videoOutputDirectory, str)):
setOutputDirectory = True
outputDirectory = videoOutputDirectory
selectDirectoryDoneLabel.set_text("Done!")
def on_selectDirectoryButton_clicked(self, button):
global setOutputDirectory
global outputDirectory
outputDirectory = filedialog.askdirectory(parent=root,initialdir="/home",title='Select directory with .png files')
if(isinstance(outputDirectory, str)):
setOutputDirectory = True
selectDirectoryDoneLabel.set_text("Done!")
def on_generateButton_clicked(self, button):
global name
global description
global scaleImages
if(setOutputDirectory == True):
name = nameEntry.get_text()
description = descriptionEntry.get_text()
loopAnimation = loopAnimationCheckButton.get_active()
scaleImages = scaleImagesCheckButton.get_active()
amountOfPngFiles = len(glob.glob1(outputDirectory,"*.png"))
plymouthFile = open(outputDirectory + "/" + name + ".plymouth","w")
plymouthFile.write("[Plymouth Theme]\n")
plymouthFile.write("Name=" + name + "\n")
plymouthFile.write("Description=" + description + "\n")
plymouthFile.write("ModuleName=script\n")
plymouthFile.write("\n")
plymouthFile.write("[script]\n")
plymouthFile.write("ImageDir=/usr/share/plymouth/themes/" + name + "\n")
plymouthFile.write("ScriptFile=/usr/share/plymouth/themes/" + name + "/" + name + ".script")
plymouthFile.close()
scriptFile = open(outputDirectory + "/" + name + ".script","w")
scriptFile.write("Window.SetBackgroundTopColor (0, 0, 0);\n")
scriptFile.write("Window.SetBackgroundBottomColor (0, 0, 0);\n")
scriptFile.write("for(i = 1; i <= " + str(amountOfPngFiles) + "; i++)\n")
scriptFile.write("{\n")
if(scaleImages == False):
scriptFile.write(" image[i].image = Image(\"image-\" + i + \".png\");\n")
else:
scriptFile.write(" image[i].image = Image(\"image-\" + i + \".png\").Scale(Window.GetWidth(), Window.GetHeight());\n")
scriptFile.write(" image[i].sprite = Sprite(image[i].image);\n")
scriptFile.write(" image[i].sprite.SetOpacity(0);\n")
scriptFile.write(" image[i].x = Window.GetX() + Window.GetWidth() / 2 - image[i].image.GetWidth() / 2;\n")
scriptFile.write(" image[i].y = Window.GetY() + Window.GetHeight() / 2 - image[i].image.GetHeight() / 2;\n")
scriptFile.write(" image[i].sprite.SetPosition(image[i].x, image[i].y, 0);\n")
scriptFile.write("}\n")
scriptFile.write("\n")
scriptFile.write("index = 1;\n")
scriptFile.write("fun boot_callback()\n")
scriptFile.write("{\n")
scriptFile.write(" if(index >= " + str(amountOfPngFiles) + " + 1)\n")
scriptFile.write(" {\n")
if(loopAnimation == False):
scriptFile.write(" image[" + str(amountOfPngFiles) + "].sprite.SetOpacity(1);\n")
else:
scriptFile.write(" index = 1;\n")
scriptFile.write(" }\n")
scriptFile.write(" else\n")
scriptFile.write(" {\n")
scriptFile.write(" for(i = 1; i <= " + str(amountOfPngFiles) + "; i++)\n")
scriptFile.write(" {\n")
scriptFile.write(" if(index != i)\n")
scriptFile.write(" {\n")
scriptFile.write(" image[i].sprite.SetOpacity(0);\n")
scriptFile.write(" }\n")
scriptFile.write(" else\n")
scriptFile.write(" {\n")
scriptFile.write(" image[i].sprite.SetOpacity(1);\n")
scriptFile.write(" }\n")
scriptFile.write(" }\n")
scriptFile.write(" index++;\n")
scriptFile.write(" }\n")
scriptFile.write("}\n")
scriptFile.write("\n")
scriptFile.write("Plymouth.SetRefreshFunction(boot_callback);\n")
scriptFile.write("Plymouth.SetQuitFunction(boot_callback);")
scriptFile.close()
installFile = open(outputDirectory + "/install.sh","w")
installFile.write("#!/bin/bash\n")
installFile.write("echo Please enter your sudo password if you are prompted to do so.\n")
installFile.write("echo Installing the " + name + " theme...\n")
installFile.write("sudo mkdir /usr/share/plymouth/themes/" + name + "\n")
installFile.write("sudo cp -rf ./ /usr/share/plymouth/themes/" + name + "\n")
installFile.write("sudo update-alternatives --quiet --install /usr/share/plymouth/themes/default.plymouth default.plymouth /usr/share/plymouth/themes/" + name + "/" + name + ".plymouth 100\n")
installFile.write("sudo update-alternatives --quiet --set default.plymouth /usr/share/plymouth/themes/" + name + "/" + name + ".plymouth\n")
installFile.write("sudo update-initramfs -u\n")
installFile.write("echo Done!\n")
installFile.write("echo Testing...\n")
installFile.write("sudo plymouthd\n")
installFile.write("sudo plymouth --show-splash\n")
installFile.write("sleep 10\n")
installFile.write("sudo plymouth quit\n")
installFile.write("echo Done!\n")
installFile.write("echo Have a nice day!")
installFile.close()
os.system("chmod +x " + outputDirectory + "/install.sh")
testFile = open(outputDirectory + "/test.sh","w")
testFile.write("#!/bin/bash\n")
testFile.write("echo Please enter your sudo password if you are prompted to do so.\n")
testFile.write("echo Testing...\n")
testFile.write("sudo plymouthd\n")
testFile.write("sudo plymouth --show-splash\n")
testFile.write("sleep 10\n")
testFile.write("sudo plymouth quit\n")
testFile.write("echo Done!\n")
testFile.write("echo Have a nice day!")
testFile.close()
os.system("chmod +x " + outputDirectory + "/test.sh")
uninstallFile = open(outputDirectory + "/uninstall.sh","w")
uninstallFile.write("#!/bin/bash\n")
uninstallFile.write("echo Please enter your sudo password if you are prompted to do so.\n")
uninstallFile.write("echo Uninstalling the " + name + " theme...\n")
uninstallFile.write("sudo update-alternatives --quiet --remove default.plymouth /usr/share/plymouth/themes/" + name + "/" + name + ".plymouth\n")
uninstallFile.write("sudo rm -rf /usr/share/plymouth/themes/" + name + "\n")
uninstallFile.write("sudo update-alternatives --quiet --auto default.plymouth\n")
uninstallFile.write("sudo update-initramfs -u\n")
uninstallFile.write("echo Done!\n")
uninstallFile.write("echo Testing...\n")
uninstallFile.write("sudo plymouthd\n")
uninstallFile.write("sudo plymouth --show-splash\n")
uninstallFile.write("sleep 10\n")
uninstallFile.write("sudo plymouth quit\n")
uninstallFile.write("echo Done!\n")
uninstallFile.write("echo Have a nice day!")
uninstallFile.close()
os.system("chmod +x " + outputDirectory + "/uninstall.sh")
generationDoneLabel.set_text("Done!")
builder = Gtk.Builder()
builder.add_from_file("plymouth-creator.glade")
builder.connect_signals(Handler())
selectVideoDoneLabel = builder.get_object("selectVideoDoneLabel")
selectVideoOutputDoneLabel = builder.get_object("selectVideoOutputDoneLabel")
videoConvertionDoneLabel = builder.get_object("videoConvertionDoneLabel")
nameEntry = builder.get_object("nameEntry")
descriptionEntry = builder.get_object("descriptionEntry")
loopAnimationCheckButton = builder.get_object("loopAnimationCheckButton")
scaleImagesCheckButton = builder.get_object("scaleImagesCheckButton")
selectDirectoryDoneLabel = builder.get_object("selectDirectoryDoneLabel")
generationDoneLabel = builder.get_object("generationDoneLabel")
window1 = builder.get_object("window1")
window1.connect("delete-event", Gtk.main_quit)
window1.show_all()
Gtk.main()