Add basic web utitlities

This commit is contained in:
leha-code 2022-03-23 21:20:58 -04:00
parent ec78c25829
commit e02a5e9de9
No known key found for this signature in database
GPG Key ID: 15227A6455DDF7EE
7 changed files with 222 additions and 136 deletions

View File

@ -49,6 +49,7 @@ if os.path.exists("/usr/lib/planet-launcher/"):
# Local imports
import launcher
from splashes import SPLASHES
import web
# PyQt5 imports
from qtpy.QtCore import *
@ -71,7 +72,7 @@ USER = os.getenv("USER") # Get the username, used for later
# Create the mods directory if it does not exist
if not os.path.exists(f"/home/{USER}/.planet-launcher/mods"):
os.makedirs(f"/home/{USER}/.planet-launcher/mods")
if not os.path.exists(f"/home/{USER}/.minecraft-pi/overrides/images/mob/"):
os.makedirs(f"/home/{USER}/.minecraft-pi/overrides/images/mob/")
@ -242,7 +243,7 @@ class Planet(QMainWindow):
"hidelauncher": True,
"profile": "Modded MCPE",
"render_distance": "Short",
"theme": theme,
"theme": theme,
"discord_rpc": True,
}
@ -271,113 +272,151 @@ class Planet(QMainWindow):
tabs.setTabIcon(
play_tab, QIcon(f"{absolute_path}/assets/logo512.png")
) # Set the icon for the tab
features_tab = tabs.addTab(self.features_tab(), "Features") # Add the features tab
tabs.setTabIcon(features_tab, QIcon(f"{absolute_path}/assets/heart512.png")) # set the icon for the tab
servers_tab = tabs.addTab(self.servers_tab(), "Servers") # Servers tab
features_tab = tabs.addTab(
self.features_tab(), "Features"
) # Add the features tab
tabs.setTabIcon(
features_tab, QIcon(f"{absolute_path}/assets/heart512.png")
) # set the icon for the tab
servers_tab = tabs.addTab(self.servers_tab(), "Servers") # Servers tab
tabs.setTabIcon(
servers_tab, QIcon(f"{absolute_path}/assets/portal512.png")
) # Set the icon
) # Set the icon
# mods_tab = tabs.addTab(self.custom_mods_tab(), "Mods")
# tabs.setTabIcon(mods_tab, QIcon(f"{absolute_path}/assets/portal512.png"))
changelog_tab = tabs.addTab(self.changelog_tab(), "Changelog") # Changelog tab
tabs.setTabIcon(changelog_tab, QIcon(f"{absolute_path}/assets/git.png")) # Set the icon
changelog_tab = tabs.addTab(self.changelog_tab(), "Changelog") # Changelog tab
tabs.setTabIcon(
changelog_tab, QIcon(f"{absolute_path}/assets/git.png")
) # Set the icon
self.setCentralWidget(tabs) # Set the central widget to the tabs
self.setCentralWidget(tabs) # Set the central widget to the tabs
self.setGeometry(600, 900, 200, 200) # Set the window geometry. Doesn't do much effect from my observations, unfortunartely
self.usernameedit.setText(self.conf["username"]) # Set the username text to the configuration's variant
self.profilebox.setCurrentText(self.conf["profile"]) # See top comment
self.distancebox.setCurrentText(self.conf["render_distance"]) # See top comments
self.setGeometry(
600, 900, 200, 200
) # Set the window geometry. Doesn't do much effect from my observations, unfortunartely
self.usernameedit.setText(
self.conf["username"]
) # Set the username text to the configuration's variant
self.profilebox.setCurrentText(self.conf["profile"]) # See top comment
self.distancebox.setCurrentText(
self.conf["render_distance"]
) # See top comments
for feature in self.features:
try:
if self.conf["options"][feature]:
self.features[feature].setCheckState(Qt.Checked) # Set to checked if the configuration has it to true
self.features[feature].setCheckState(
Qt.Checked
) # Set to checked if the configuration has it to true
else:
self.features[feature].setCheckState(Qt.Unchecked) # Else, set it unchecked
except KeyError: # May happen on downgrades or upgrades of the Reborn version
self.features[feature].setCheckState(
Qt.Unchecked
) # Else, set it unchecked
except KeyError: # May happen on downgrades or upgrades of the Reborn version
pass
# Hide launcher/Show it depending on the config
self.showlauncher.setChecked(self.conf["hidelauncher"])
# Set the features
self.set_features()
def play_tab(self) -> QWidget:
"""The main tab, with the main functionality"""
layout = QGridLayout() # The layout
layout = QGridLayout() # The layout
titlelayout = QGridLayout() # The layout for the title
titlelayout = QGridLayout() # The layout for the title
# Load the logo pixmap
logopixmap = QPixmap(f"{absolute_path}/assets/logo512.png").scaled(
100, 100, Qt.KeepAspectRatio #Scale it, but keep the aspect ratio
100, 100, Qt.KeepAspectRatio # Scale it, but keep the aspect ratio
)
logolabel = QLabel() # Label for the pixmap
logolabel.setPixmap(logopixmap) # apply the pixmap onto the label
logolabel.setAlignment(Qt.AlignRight) # Align the label
logolabel = QLabel() # Label for the pixmap
logolabel.setPixmap(logopixmap) # apply the pixmap onto the label
logolabel.setAlignment(Qt.AlignRight) # Align the label
namelabel = QLabel() # Label for the title
namelabel = QLabel() # Label for the title
# Ester eggs
if date.today().month == 4 and date.today().day == 1:
namelabel.setText("Banana Launcher") # If the date is april fish, show the banana easter egg
namelabel.setText(
"Banana Launcher"
) # If the date is april fish, show the banana easter egg
else:
if random.randint(1, 100) == 1:
namelabel.setText("Pluto Launcher") # a 1/100, Pluto launcher
namelabel.setText("Pluto Launcher") # a 1/100, Pluto launcher
else:
namelabel.setText("Planet Launcher") #Else, just set it normal
namelabel.setText("Planet Launcher") # Else, just set it normal
font = namelabel.font() # Font used
font.setPointSize(30) # Set the font size
namelabel.setFont(font) # Aplly the font onto the label
namelabel.setAlignment(Qt.AlignLeft) # Align the label
font = namelabel.font() # Font used
font.setPointSize(30) # Set the font size
namelabel.setFont(font) # Aplly the font onto the label
namelabel.setAlignment(Qt.AlignLeft) # Align the label
splashlabel = QLabel(f'<font color="gold">{random.choice(SPLASHES)}</font>') # Label for splash. Uses QSS for color
splashlabel.adjustSize() # Adjust the size just in case
splashlabel.setAlignment(Qt.AlignHCenter) # Align the label
splashlabel = QLabel(
f'<font color="gold">{random.choice(SPLASHES)}</font>'
) # Label for splash. Uses QSS for color
splashlabel.adjustSize() # Adjust the size just in case
splashlabel.setAlignment(Qt.AlignHCenter) # Align the label
usernamelabel = QLabel("Username") # Label that is used to direct the line edit
usernamelabel = QLabel("Username") # Label that is used to direct the line edit
self.usernameedit = QLineEdit() # Line Edit for username
self.usernameedit.setPlaceholderText("StevePi") # Set ghost value
self.usernameedit = QLineEdit() # Line Edit for username
self.usernameedit.setPlaceholderText("StevePi") # Set ghost value
distancelabel = QLabel("Render Distance") # Label that is used to direct the combo box
distancelabel = QLabel(
"Render Distance"
) # Label that is used to direct the combo box
self.distancebox = QComboBox()
self.distancebox.addItems(["Far", "Normal", "Short", "Tiny"]) # Set the values
self.distancebox.setCurrentText("Short") # Set the default option
self.distancebox = QComboBox()
self.distancebox.addItems(["Far", "Normal", "Short", "Tiny"]) # Set the values
self.distancebox.setCurrentText("Short") # Set the default option
profilelabel = QLabel("Profile") # Label that is used to direct the combo box
profilelabel = QLabel("Profile") # Label that is used to direct the combo box
self.profilebox = QComboBox()
self.profilebox = QComboBox()
self.profilebox.addItems(
["Vanilla MCPi", "Modded MCPi", "Modded MCPE", "Optimized MCPE", "Custom"] # Add items into the combo box
[
"Vanilla MCPi",
"Modded MCPi",
"Modded MCPE",
"Optimized MCPE",
"Custom",
] # Add items into the combo box
)
self.profilebox.setCurrentText("Modded MCPE") # Set the current selection
self.profilebox.setCurrentText("Modded MCPE") # Set the current selection
self.showlauncher = QRadioButton(
"Hide Launcher"
) # RadioButton used for hiding the launcher
self.showlauncher = QRadioButton("Hide Launcher") # RadioButton used for hiding the launcher
self.skin_button = QPushButton("Select Skin")
self.skin_button.clicked.connect(self.select_skin)
self.playbutton = QPushButton("Play") # The most powerful button
self.playbutton.setCheckable(True) # Allow checking it
self.playbutton.clicked.connect(self.launch) # Connect it to the executing function
self.versionbox = QComboBox()
self.versionbox.addItems(["Far", "Normal", "Short", "Tiny"]) # Set the values
self.versionbox.setCurrentText("Short") # Set the default option
self.playbutton = QPushButton("Play") # The most powerful button
self.playbutton.setCheckable(True) # Allow checking it
self.playbutton.clicked.connect(
self.launch
) # Connect it to the executing function
# Add widgets into the title layout
titlelayout.addWidget(logolabel, 0, 0)
titlelayout.addWidget(namelabel, 0, 1)
titlewidget = QWidget()
titlewidget.setLayout(titlelayout) # Apply the layout onto a fake widget
titlewidget.setLayout(titlelayout) # Apply the layout onto a fake widget
layout.addWidget(
titlewidget, 0, 0, 2, 5
) # Apply that widget onto the main layout
layout.addWidget(titlewidget, 0, 0, 2, 5) # Apply that widget onto the main layout
# All other widgets are applied here
layout.addWidget(splashlabel, 2, 0, 1, 6)
@ -391,14 +430,16 @@ class Planet(QMainWindow):
layout.addWidget(self.profilebox, 5, 4, 1, 2)
layout.addWidget(self.showlauncher, 6, 4)
layout.addWidget(self.skin_button, 6, 0)
layout.addWidget(self.playbutton, 8, 4, 1, 2)
layout.addWidget(self.skin_button, 6, 0)
layout.addWidget(self.versionbox, 8, 0, 1, 3)
layout.addWidget(self.playbutton, 8, 4, 1, 2)
widget = QWidget()
widget.setLayout(layout) # Apply the layout onto the main widget
widget.setLayout(layout) # Apply the layout onto the main widget
return widget
@ -406,37 +447,43 @@ class Planet(QMainWindow):
layout = QVBoxLayout()
self.features = dict() # Dictionary used for storing checkboxes for features
default_features = launcher.get_features_dict( # Get default feature list
self.features = dict() # Dictionary used for storing checkboxes for features
default_features = launcher.get_features_dict( # Get default feature list
f"/home/{USER}/.planet-launcher/minecraft.AppImage"
)
for feature in default_features: # Loop in default features
checkbox = QCheckBox(feature) # For each feature, create a checkbox
for feature in default_features: # Loop in default features
checkbox = QCheckBox(feature) # For each feature, create a checkbox
# TODO: Fix the error if newer features are added here, or check for them in self.conf
if default_features[feature]: # Check if it's checked. If so, check it
if default_features[feature]: # Check if it's checked. If so, check it
checkbox.setCheckState(Qt.Checked)
else:
checkbox.setCheckState(Qt.Unchecked)
checkbox.clicked.connect(self.set_features) # Connect saving function
checkbox.clicked.connect(self.set_features) # Connect saving function
self.features[feature] = checkbox # Add the checkbox into the list
self.features[feature] = checkbox # Add the checkbox into the list
layout.addWidget(checkbox) #Add the checkbox into the layout
layout.addWidget(checkbox) # Add the checkbox into the layout
fakewidget = QWidget() # Create a fake widget to apply the layout on
fakewidget.setLayout(layout) # Apply the layoutonto
fakewidget = QWidget() # Create a fake widget to apply the layout on
fakewidget.setLayout(layout) # Apply the layoutonto
scroll = QScrollArea() # Add a scoll area
scroll = QScrollArea() # Add a scoll area
scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) # Shoe the vertical scroll bar
scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) # Hide the horizontak scroll bar
scroll.setWidgetResizable(True) # Allow window resizing and fix itt with the scrollbar
scroll.setWidget(fakewidget) # Set the main widget into the scrollbar
scroll.setVerticalScrollBarPolicy(
Qt.ScrollBarAlwaysOn
) # Shoe the vertical scroll bar
scroll.setHorizontalScrollBarPolicy(
Qt.ScrollBarAlwaysOff
) # Hide the horizontak scroll bar
scroll.setWidgetResizable(
True
) # Allow window resizing and fix itt with the scrollbar
scroll.setWidget(fakewidget) # Set the main widget into the scrollbar
fakelayout = QGridLayout()
fakelayout.addWidget(scroll, 0, 0) #Apply the scrollbar onto the layout
fakelayout.addWidget(scroll, 0, 0) # Apply the scrollbar onto the layout
widget = QWidget()
@ -447,23 +494,26 @@ class Planet(QMainWindow):
def servers_tab(self) -> QWidget:
widget = QWidget()
layout = QGridLayout()
self.serversedit = QTextEdit() # Create a text editing area
self.serversedit = QTextEdit() # Create a text editing area
if not os.path.exists(f"/home/{USER}/.minecraft-pi/servers.txt"):
with open(f"/home/{USER}/.minecraft-pi/servers.txt") as servers:
servers.write("pbptanarchy.tk")
self.serversedit.textChanged.connect(self.save_servers) # Connect on change to the save function
self.serversedit.textChanged.connect(
self.save_servers
) # Connect on change to the save function
with open(f"/home/{USER}/.minecraft-pi/servers.txt") as servers:
self.serversedit.setPlainText(servers.read()) # Set the text of the text editing area
self.serversedit.setPlainText(
servers.read()
) # Set the text of the text editing area
infolabel = QLabel( #Label with information about the server format
infolabel = QLabel( # Label with information about the server format
'Servers are stored in the format of <font color="gold">IP: </font><font color="blue">Port</font>'
)
layout.addWidget(self.serversedit, 0, 0) # Add the widgets
layout.addWidget(self.serversedit, 0, 0) # Add the widgets
layout.addWidget(infolabel, 6, 0)
widget.setLayout(layout)
@ -472,9 +522,11 @@ class Planet(QMainWindow):
def custom_mods_tab(self) -> QWidget:
layout = QVBoxLayout()
for mod in os.listdir(f"/home/{USER}/.planet-launcher/mods/"): # Loop in every mod in the mod directory
checkbox = QCheckBox(mod) # Create a checkbox with the mod name
checkbox.setCheckState(Qt.Unchecked) # Set it to unchecked
for mod in os.listdir(
f"/home/{USER}/.planet-launcher/mods/"
): # Loop in every mod in the mod directory
checkbox = QCheckBox(mod) # Create a checkbox with the mod name
checkbox.setCheckState(Qt.Unchecked) # Set it to unchecked
layout.addWidget(checkbox)
@ -498,8 +550,10 @@ class Planet(QMainWindow):
return widget
def changelog_tab(self):
web = QWebEngineView() # Create a webview object
web.load(QUrl().fromLocalFile(f"{absolute_path}/assets/changelog.html")) # Load the local file
web = QWebEngineView() # Create a webview object
web.load(
QUrl().fromLocalFile(f"{absolute_path}/assets/changelog.html")
) # Load the local file
# TODO: Use two different tabs for the webview
return web
@ -519,7 +573,7 @@ class Planet(QMainWindow):
def mouseReleaseEvent(self, event):
self.moveFlag = False
self.setCursor(Qt.ArrowCursor)
def center(self):
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
@ -547,37 +601,48 @@ class Planet(QMainWindow):
def save_servers(self):
with open(f"/home/{USER}/.minecraft-pi/servers.txt", "w") as file:
file.write(self.serversedit.toPlainText())
def select_skin(self):
filename = QFileDialog.getOpenFileName(
self, "Select skin file", "/", "PNG files (*.png)"
)
if not filename == '':
with open(f"/home/{USER}/.minecraft-pi/overrides/images/mob/char.png", "w") as skin:
if not filename == "":
with open(
f"/home/{USER}/.minecraft-pi/overrides/images/mob/char.png", "w"
) as skin:
skin.write("quick placeholder")
Image.open(filename[0]).crop((0,0,64,32)).convert('RGBA').save(f"/home/{USER}/.minecraft-pi/overrides/images/mob/char.png")
Image.open(filename[0]).crop((0, 0, 64, 32)).convert("RGBA").save(
f"/home/{USER}/.minecraft-pi/overrides/images/mob/char.png"
)
def launch(self):
self.save_profile()
if self.profilebox.currentText().lower() == "vanilla mcpi":
self.launchfeatures = launcher.get_features_dict(f"/home/{USER}/.planet-launcher/minecraft.AppImage")
self.launchfeatures = launcher.get_features_dict(
f"/home/{USER}/.planet-launcher/minecraft.AppImage"
)
for feature in self.launchfeatures:
self.launchfeatures[feature] = False
elif self.profilebox.currentText().lower() == "modded mcpi":
self.launchfeatures = launcher.get_features_dict(f"/home/{USER}/.planet-launcher/minecraft.AppImage")
self.launchfeatures = launcher.get_features_dict(
f"/home/{USER}/.planet-launcher/minecraft.AppImage"
)
self.launchfeatures["Touch GUI"] = False
elif self.profilebox.currentText().lower() == "modded mcpe":
self.launchfeatures = launcher.get_features_dict(f"/home/{USER}/.planet-launcher/minecraft.AppImage")
self.launchfeatures = launcher.get_features_dict(
f"/home/{USER}/.planet-launcher/minecraft.AppImage"
)
elif self.profilebox.currentText().lower() == "optimized mcpe":
self.launchfeatures = launcher.get_features_dict(f"/home/{USER}/.planet-launcher/minecraft.AppImage")
self.launchfeatures = launcher.get_features_dict(
f"/home/{USER}/.planet-launcher/minecraft.AppImage"
)
self.launchfeatures["Fancy Graphics"] = False
self.launchfeatures["Smooth Lightning"] = False
self.launchfeatures["Animated Water"] = False
self.launchfeatures['Disable "gui_blocks" Atlas'] = False
self.env = launcher.set_username(self.env, self.usernameedit.text())
self.env = launcher.set_options(self.env, self.launchfeatures)
self.env = launcher.set_render_distance(
@ -604,7 +669,7 @@ if __name__ == "__main__":
app.setPalette(qdarktheme.load_palette(json.loads(file.read())["theme"]))
else:
app.setPalette(qdarktheme.load_palette(theme))
if not os.path.exists(f"/home/{USER}/.planet-launcher/minecraft.AppImage"):
pluto = ConfigPluto()
pluto.show()

View File

@ -11,33 +11,34 @@ SPLASHES = [
"Robo",
"If I could, I would. But I can't, so I shan't.",
"SyntaxError: invalid syntax",
"We Fixed The Rail!",
"The World Of Notch!",
"github.com/mcpiscript/Planet!",
"Now with fly-hacks!",
"We Fixed The Rail!",
"The World Of Notch!",
"github.com/mcpiscript/Planet!",
"Now with fly-hacks!",
"Now with custom skins!",
"Now with *fancy icons*!",
"@Banana",
"BANANA!",
"To \"Na\" Or Not To \"Na\", that is the question!",
"Not Minecraft Java!",
"Oh yeah, that version...",
"Segmentation fault (core dumped)",
"It's the Segment's Fault!",
"Who is StevePi?",
"(Not) Made by Notch!",
"Open-Source!",
"RIP all MCPILs, 2020-2022",
"StevePi = Leha confirmed?",
"Watch out for StevePi!",
"Didn't remove Herobrine!",
"Check out PBPT Anarchy!",
"你好中国",
"한국 안녕하세요!",
"日本ハロー!",
"Привет Россия!",
"Підтримай Україну!",
"Supercalifragilisticexpialidocious!",
"Now with multiplayer!",
"ENGINEER GAMING",
"@Banana",
"BANANA!",
'To "Na" Or Not To "Na", that is the question!',
"Not Minecraft Java!",
"Oh yeah, that version...",
"Segmentation fault (core dumped)",
"It's the Segment's Fault!",
"Who is StevePi?",
"(Not) Made by Notch!",
"Open-Source!",
"RIP all MCPILs, 2020-2022",
"StevePi = Leha confirmed?",
"Watch out for StevePi!",
"Didn't remove Herobrine!",
"Check out PBPT Anarchy!",
"你好中国",
"한국 안녕하세요!",
"日本ハロー!",
"Привет Россия!",
"Підтримай Україну!",
"Supercalifragilisticexpialidocious!",
"Now with multiplayer!",
"ENGINEER GAMING",
"Play Minecraft Pi Edition, watch Red-Exe-Engineer, get PIG!",
]

20
planet/web.py Normal file
View File

@ -0,0 +1,20 @@
from urllib.request import Request, urlopen
import requests
def get_versions() -> str:
return str(
urlopen(
Request(
"https://gist.github.com/leha-code/3e8fea40346536b451e45fc1728ed250/raw/versions.json"
)
).read()
)
def check_internet() -> bool:
try:
requests.head("http://www.google.com/")
return True
except requests.ConnectionError:
return False

View File

@ -10,9 +10,9 @@ mkdir build/planet/usr/lib
cp -r ./planet/ ./build/planet/usr/lib/planet-launcher
mkdir build/planet/DEBIAN
cp ./scripts/control ./build/planet/DEBIAN/control
cp ./scripts/postinst ./build/planet/DEBIAN/postinst
cp ./scripts/postrm ./build/planet/DEBIAN/postrm
cp ./scripts/deb/control ./build/planet/DEBIAN/control
cp ./scripts/deb/postinst ./build/planet/DEBIAN/postinst
cp ./scripts/deb/postrm ./build/planet/DEBIAN/postrm
dpkg-deb --build ./build/planet
mkdir dist