Skip to content

Commit

Permalink
Refactor backup
Browse files Browse the repository at this point in the history
Just a backup of my progress so far

Ignore, it doesn't work
  • Loading branch information
kleidis committed Oct 14, 2024
1 parent 5909ef2 commit 0d80929
Show file tree
Hide file tree
Showing 10 changed files with 355 additions and 306 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ citra_util.spec
troppical.spec
.old
*.spec
/ui/__pycache__
15 changes: 15 additions & 0 deletions imports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from PyQt6.QtWidgets import QMainWindow, QApplication, QLabel, QPushButton, QVBoxLayout, QWidget, QCheckBox, QStackedLayout, QHBoxLayout, QGroupBox, QComboBox, QProgressBar, QLineEdit, QMessageBox, QFileDialog, QInputDialog, QTreeWidget, QTreeWidgetItem
from PyQt6.QtGui import QPixmap, QIcon, QImage
from PyQt6.QtCore import Qt, QThread, pyqtSignal, QByteArray, QFile, pyqtSlot
import requests
import os
import subprocess
import sys
import json
from zipfile import ZipFile
import shutil
import tempfile
from icons import styledark_rc
import win32com.client
import winreg
from pathlib import Path
366 changes: 60 additions & 306 deletions main.py

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions ui/finish_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

from imports import *
from main import Logic as main
from header import Header

# Finish page
class FinishPage(QWidget):
def __init__(self):
super().__init__()
self.Header = Header.header(self)
self.finishPage = QWidget()
## Layout and groups
finishLayout = QVBoxLayout()
self.finishPage.setLayout(finishLayout)
## Widgets
finishLabel = QLabel("<b>Installation Complete!")
finishLabel.setAlignment(Qt.AlignmentFlag.AlignCenter) # Center the text horizontally
finishButton = QPushButton("Finish")
finishButton.clicked.connect(self.close)
installAnotherButton = QPushButton("Install another emulator")
installAnotherButton.clicked.connect(lambda: (
self.layout.setCurrentIndex(0),
self.downloadProgressBar.setValue(0),
self.extractionProgressBar.setValue(0),
setattr(main, 'install_mode', None),
setattr(main, 'selection', None)
))
## Add widgets / layouts
finishLayout.addLayout(self.Header) # Add the icon self.header
finishLayout.addWidget(finishLabel)
# Create a horizontal layout for the buttons
buttonLayout = QHBoxLayout()
buttonLayout.addWidget(finishButton)
buttonLayout.addWidget(installAnotherButton)
finishLayout.addLayout(buttonLayout)
19 changes: 19 additions & 0 deletions ui/header.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from imports import *

class Header():
def header(self):
# Header Layout
self.headerLayout = QVBoxLayout()
self.headerLayout.setContentsMargins(0, 20, 0, 0)
# Icon Widget
iconLabel = QLabel()
# icon_path = os.path.join(sys._MEIPASS, 'icon.ico')
# icon = QIcon(icon_path)
# pixmap = icon.pixmap(180, 180) # Specify the size directly
# iconLabel.setPixmap(pixmap)
# Text Widget
label = QLabel("<b><font size='10'>Troppical</font></b>")
# Set Widgets
self.headerLayout.addWidget(iconLabel, alignment=Qt.AlignmentFlag.AlignCenter)
self.headerLayout.addWidget(label, alignment=Qt.AlignmentFlag.AlignCenter)
return self.headerLayout
39 changes: 39 additions & 0 deletions ui/install_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Install page
from imports import *
from main import Logic as main
from header import Header

class InstallPage(QWidget):
def __init__(self):
super().__init__()
self.header = Header.header(self)
self.installPage = QWidget()
## Layout and gorup
installLayout = QVBoxLayout()
checkboxLayout = QVBoxLayout()
checkboxGroup = QGroupBox("Do you want to create shortcuts?") # Checkboxes
checkboxGroup.setLayout(checkboxLayout) # Set the layout of Checkboxes
pathSelectorLayout = QHBoxLayout() # Browse widget layout
self.installPage.setLayout(installLayout) # Set the installpage layout
## Widgets
InstalOpt = QLabel('<b>Installation Options')
InstalOpt.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.installationSourceComboBox = QComboBox() # Dropdown menu
self.desktopShortcutCheckbox = QCheckBox("Create a desktop shortcut") # Checkboxes
self.startMenuShortcutCheckbox = QCheckBox("Create a start menu shortcut")
self.installationPathLineEdit = QLineEdit() # Browse for installation path widget
self.browseButton = QPushButton("Browse")
self.browseButton.clicked.connect(main.InstallPath)
self.install_emu_button = QPushButton('Install') # Install button
self.install_emu_button.clicked.connect(main.qt_button_click)
## Add widgets / layouts
installLayout.addLayout(self.header) ### Icon self.header
installLayout.addWidget(InstalOpt) ### Instalation Option Label
installLayout.addWidget(self.installationSourceComboBox) ## Install Sorce Widget
pathSelectorLayout.addWidget(self.installationPathLineEdit) ## Browse Widget
pathSelectorLayout.addWidget(self.browseButton)
installLayout.addLayout(pathSelectorLayout)
checkboxLayout.addWidget(self.desktopShortcutCheckbox) # Checkboxes
checkboxLayout.addWidget(self.startMenuShortcutCheckbox)
installLayout.addWidget(checkboxGroup)
installLayout.addWidget(self.install_emu_button)
25 changes: 25 additions & 0 deletions ui/progress_bar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from imports import *
from header import Header

# Progress bar page
class ProgressBarPage(QWidget):
def __init__(self):
super().__init__()
self.Header = Header.header(self)
self.progressBarPage = QWidget()
## Layout and groups
progressBarLayout = QVBoxLayout()
self.progressBarPage.setLayout(progressBarLayout)
## Widgets
self.downloadProgressBar = QProgressBar()
self.downloadProgressBar.setRange(0, 100) # Progress bar Widgets
self.extractionProgressBar = QProgressBar()
self.extractionProgressBar.setRange(0, 100)
self.labeldown = QLabel("Downloading: ")
self.labelext = QLabel("Extracting: ")
## Add widgets / layouts
progressBarLayout.addLayout(self.Header) # Add the icon self.header
progressBarLayout.addWidget(self.labeldown)
progressBarLayout.addWidget(self.downloadProgressBar)
progressBarLayout.addWidget(self.labelext)
progressBarLayout.addWidget(self.extractionProgressBar)
82 changes: 82 additions & 0 deletions ui/selection_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
from imports import *
from main import Online
from main import Logic

# Emulator Select Page

class SelectionPage(QWidget):
def __init__(self):
super().__init__()
self.troppical_database = Online.fetch_data(self)
self.emulatorSelectPage = QWidget()
emulatorSelectLayout = QVBoxLayout()
emulatorSelectGroup = QGroupBox("Select your emulator from the list")
emulatorSelectGroupLayout = QVBoxLayout()

# Create a QTreeWidget
self.emulatorTreeWidget = QTreeWidget()
self.emulatorTreeWidget.setHeaderHidden(True)
self.emulatorTreeWidget.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOn)

emulatorSelectGroupLayout.addWidget(self.emulatorTreeWidget)

# Keep track of emulator systems
system_items = {}

for troppical_api_data in self.troppical_database:
emulator_system = troppical_api_data['emulator_system']
emulator_name = troppical_api_data['emulator_name']
emulator_desc = troppical_api_data.get('emulator_desc', '')

# Fetch and decode the logo
logo_url = troppical_api_data['emulator_logo']
response = requests.get(logo_url)
if response.status_code == 200:
image_bytes = response.content
qimage = QImage.fromData(QByteArray(image_bytes))
pixmap = QPixmap.fromImage(qimage).scaled(32, 32, Qt.AspectRatioMode.KeepAspectRatio, Qt.TransformationMode.SmoothTransformation)
icon = QIcon(pixmap)
print(logo_url)
else:
QMessageBox.critical(self, "Failed to fetch logo", f"Failed to fetch logo for {emulator_name}. Status code: {response.status_code}")
icon = QIcon()

# Check if the emulator system already has a tree item, if not create one
if emulator_system not in system_items:
system_item = QTreeWidgetItem(self.emulatorTreeWidget)
system_item.setText(0, emulator_system)
system_item.setExpanded(True) # Uncollapse the category by default
system_items[emulator_system] = system_item
else:
system_item = system_items[emulator_system]

# Add the emulator to the appropriate tree item
emulator_item = QTreeWidgetItem(system_item)
emulator_item.setText(0, emulator_name)
emulator_item.setIcon(0, icon)
emulator_item.setToolTip(0, emulator_desc)

# Sort the systems and emulators alphabetically
self.emulatorTreeWidget.sortItems(0, Qt.SortOrder.AscendingOrder)
for i in range(self.emulatorTreeWidget.topLevelItemCount()):
system_item = self.emulatorTreeWidget.topLevelItem(i)
system_item.sortChildren(0, Qt.SortOrder.AscendingOrder)

# Set layout for the group and add to the main layout
emulatorSelectGroup.setLayout(emulatorSelectGroupLayout)
emulatorSelectLayout.addWidget(emulatorSelectGroup)
self.emulatorSelectPage.setLayout(emulatorSelectLayout) # Set the layout for the emulator selection page

# Next button to confirm selection
self.nextButton = QPushButton("Next")
self.nextButton.clicked.connect(Logic.set_emulator)
emulatorSelectLayout.addWidget(self.nextButton)

def get_selected_emulator(self):
selected_item = self.emulatorTreeWidget.currentItem()
print(selected_item)
if not selected_item or not selected_item.parent():
QMessageBox.warning(self, "Selection Error", "Please select an emulator.")
print("Please select an emulator.")
return None
return selected_item
38 changes: 38 additions & 0 deletions ui/welcome_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from imports import *
from main import Logic as main
from header import Header

class WelcomePage(QWidget,):
def __init__(self):
super().__init__()
self.header = Header.header(self)
# Welcome page
self.welcomePage = QWidget()
## Layout and gorup
welcomerLayout = QVBoxLayout()
welcomerGroup = QGroupBox("")
welcomerGroupLayout = QVBoxLayout()
buttonsLayout = QHBoxLayout()
welcomerGroup.setLayout(welcomerGroupLayout)
self.welcomePage.setLayout(welcomerLayout) # Set the welcomepage layout
## Widgets
self.welcomerLabel = QLabel()
self.welcomerLabel.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.installButton = QPushButton('Install')
self.installButton.clicked.connect(main.qt_button_click)
self.updateButton = QPushButton('Check for Updates')
self.updateButton.clicked.connect(main.qt_button_click)
self.uninstallButton = QPushButton('Uninstall')
self.uninstallButton.clicked.connect(main.qt_button_click)
self.backButton = QPushButton("Back")
self.backButton.setFixedSize(80, 30)
self.backButton.clicked.connect(main.qt_button_click)
## Add widgets / layouts
welcomerLayout.addLayout(self.header)
welcomerLayout.addWidget(welcomerGroup)
welcomerGroupLayout.addWidget(self.welcomerLabel)
buttonsLayout.addWidget(self.installButton)
buttonsLayout.addWidget(self.updateButton)
buttonsLayout.addWidget(self.uninstallButton)
welcomerLayout.addLayout(buttonsLayout)
welcomerLayout.insertWidget(0, self.backButton)
41 changes: 41 additions & 0 deletions ui_init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Page imports
from imports import *
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "ui"))
from selection_page import SelectionPage
from welcome_page import WelcomePage
from install_page import InstallPage
from progress_bar import ProgressBarPage
from finish_page import FinishPage
from stylesheet import Style

class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle(f'Troppical - {"version"}') # Window name with version
self.setCentralWidget(QWidget(self)) # Set a central widget
self.layout = QStackedLayout(self.centralWidget()) # Set the layout on the central widget
self.setMaximumSize(1000, 720) # Set the maximum window size to 1280x720
self.setMinimumSize(1000, 720) # Set the minimum window size to 800x600
# Set the window icon
# icon_path = os.path.join(sys._MEIPASS, 'icon.ico')
# self.setWindowIcon(QIcon(icon_path))
self.selection_page = SelectionPage()
self.welcome_page = WelcomePage()
self.install_page = InstallPage()
self.progress_bar_page = ProgressBarPage()
self.finish_page = FinishPage()
self.widget_2_layout()
self.load_stylesheet()

def widget_2_layout(self):
self.layout.addWidget(self.selection_page.emulatorSelectPage)
self.layout.addWidget(self.welcome_page.welcomePage)
self.layout.addWidget(self.install_page.installPage)
self.layout.addWidget(self.progress_bar_page.progressBarPage)
self.layout.addWidget(self.finish_page.finishPage)

def load_stylesheet(app):
app.setStyleSheet(Style.dark_stylesheet)



0 comments on commit 0d80929

Please sign in to comment.