KernelChan/main.py

143 lines
3.8 KiB
Python
Raw Normal View History

2021-05-02 07:14:44 +02:00
from PySide2.QtWidgets import QWidget, QPushButton, QListWidget, QApplication, QListWidgetItem, QMessageBox, QLabel, QVBoxLayout
2021-05-01 22:41:48 +02:00
from PySide2.QtGui import QGuiApplication, QIcon, QFont
2021-05-01 21:02:46 +02:00
from getKernelInfo import KernelVerList, KernelURL
2021-05-02 07:14:44 +02:00
import sys,os,time
2021-04-30 02:47:06 +02:00
2021-05-02 07:29:27 +02:00
#!!! If you run it as Sudo it will install you the Kernel
#! Base
# TODO: Fix InstallationWindow wired behavior.
2021-05-01 22:26:47 +02:00
# TODO: Implement resizable Windows
2021-05-01 14:43:58 +02:00
# TODO: Clean the code.
2021-05-02 07:29:27 +02:00
# TODO: Fix KernelVer sorting
# TODO: First Release 1.0
# TODO: Aur Package
#! Features
# TODO: Being able to se what is currently installed.
# TODO: Being able to choose download destination?
# TODO: Add Linux Headers, as optional download.
# TODO: Asking for Sudo
#! Unrealistic Features
# TODO: Seeing Terminal output in a Window
# TODO: Installing multiple Kernels
# TODO: Installing Custom Kernel
2021-05-01 00:41:15 +02:00
2021-04-30 04:14:55 +02:00
## Creating the MainWindow
2021-04-30 02:47:06 +02:00
class Window(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("KernelChan")
self.setFixedSize(600,600)
self.center()
self.setIcon()
2021-05-02 02:40:52 +02:00
setList(self,25,20)
2021-04-30 02:47:06 +02:00
Button.setButton(self,"Install",400,540,self.installKernel)
Button.setButton(self,"Exit",490,540,self.exitApp)
2021-05-02 02:40:52 +02:00
aList.itemSelectionChanged.connect(selected)
2021-04-30 02:47:06 +02:00
def center(self):
qRect = self.frameGeometry()
2021-05-01 22:24:33 +02:00
centerPoint = QGuiApplication.primaryScreen().availableGeometry().center()
2021-04-30 02:47:06 +02:00
qRect.moveCenter(centerPoint)
self.move(qRect.topLeft())
def setIcon(self):
appIcon = QIcon('icon.png')
self.setWindowIcon(appIcon)
def installKernel(self):
self.install = InstallProcess()
self.install.show()
2021-05-02 07:14:44 +02:00
self.install.Installation()
self.install.hide()
2021-05-01 00:41:15 +02:00
2021-04-30 04:14:55 +02:00
## Application Quit Popup
2021-04-30 02:47:06 +02:00
def exitApp(self):
askUser = QMessageBox.question(self, "Quit", "Are you Sure?", QMessageBox.Yes | QMessageBox.No)
if askUser == QMessageBox.Yes:
App.quit()
elif askUser == QMessageBox.No:
pass
2021-05-01 22:02:52 +02:00
## Making an Button
class Button(QPushButton):
def setButton(self, name, x, y,function):
button = QPushButton(name,self)
button.move(x,y)
2021-05-02 02:40:52 +02:00
button.clicked.connect(function)
2021-05-01 22:02:52 +02:00
2021-04-30 02:47:06 +02:00
class InstallProcess(QWidget):
2021-04-30 04:14:55 +02:00
def __init__(self, *args):
QWidget.__init__(self, *args)
2021-04-30 02:47:06 +02:00
self.setWindowTitle("Kernel Installation")
2021-05-02 07:14:44 +02:00
self.setFixedSize(400,120)
self.center()
2021-05-01 00:41:15 +02:00
2021-04-30 04:14:55 +02:00
# create objects
2021-05-02 07:14:44 +02:00
self.te = QLabel()
2021-05-01 00:41:15 +02:00
# puts the Terminal output into InstallWindow
2021-05-02 07:14:44 +02:00
pic = 'Installing.png'
self.te.setPixmap(pic)
2021-04-30 04:14:55 +02:00
# layout
2021-05-02 07:14:44 +02:00
self.layout = QVBoxLayout(self)
self.layout.addWidget(self.te)
self.setLayout(self.layout)
def Installation(self):
2021-05-02 07:29:27 +02:00
#! It works
os.system("wget "+ URL + " -P ~/ && pacman -U "+ URL + " --noconfirm")
os.system("echo it works!")
2021-05-02 07:14:44 +02:00
print("done")
2021-04-30 04:14:55 +02:00
2021-04-30 02:47:06 +02:00
def center(self):
qRect = self.frameGeometry()
2021-05-01 22:24:33 +02:00
centerPoint = QGuiApplication.primaryScreen().availableGeometry().center()
2021-04-30 02:47:06 +02:00
qRect.moveCenter(centerPoint)
self.move(qRect.topLeft())
2021-05-02 02:40:52 +02:00
def setList(self,x,y):
global aList
aList = QListWidget(self)
aList.resize(550,500)
aList.move(x,y)
font = QFont()
font.setPixelSize(16)
aList.setFont(font)
for i in KernelVerList:
item = QListWidgetItem()
item.setText(str(i))
aList.addItem(item)
def selected():
global TheSelect, URL
TheSelect = str([item.text() for item in aList.selectedItems()])
TheSelect = TheSelect.strip("'['']'")
URL = [name for name in KernelURL if TheSelect in name]
URL = '+'.join(URL).strip("'['']'").split("+", 1)[0]
print(URL)
2021-05-01 14:52:55 +02:00
def main():
2021-05-02 02:40:52 +02:00
global App,window
2021-05-01 14:52:55 +02:00
App = QApplication(sys.argv)
window = Window()
window.show()
2021-05-01 22:02:52 +02:00
2021-05-01 14:52:55 +02:00
App.exec_()
sys.exit(0)
2021-04-30 02:47:06 +02:00
2021-05-02 07:14:44 +02:00
if __name__ == '__main__':
main()