no more GTK4 only customtkinter

This commit is contained in:
admin 2024-01-20 14:03:26 +01:00
parent c1f5e027ea
commit bc4879a5c4
4 changed files with 93 additions and 203 deletions

View file

@ -8,20 +8,18 @@ sudo apt install python3 -y
# Install Python3 pip # Install Python3 pip
sudo apt install python3-pip -y sudo apt install python3-pip -y
# Install GTK4 package
sudo apt install libgtk-4-dev -y
# Install PatchELF for Nuitka (if needed) # Install PatchELF for Nuitka (if needed)
sudo apt install patchelf -y sudo apt install patchelf -y
# Install Nuitka # Install Nuitka
pip3 install nuitka pip3 install nuitka
pip3 install tqdm
# Install additional Python packages # Install additional Python packages
pip3 install requests pip3 install requests
sudo apt install libgirepository1.0-dev -y sudo apt install libgirepository1.0-dev -y
sudo apt install python3-cairo-dev -y sudo apt install python3-cairo-dev -y
pip3 install PyGObject # Install PyGObject for Gtk support
pip3 install pillow # Install Pillow for image manipulation pip3 install pillow # Install Pillow for image manipulation
pip3 install setuptools # Install setuptools for packaging pip3 install setuptools # Install setuptools for packaging

View file

@ -4,7 +4,7 @@
# install python && pip in msys2 # install python && pip in msys2
# install GTK4 according to GTK website # install customtkinter pip package
# install nuitka (in msys2) # install nuitka (in msys2)

View file

@ -1,216 +1,107 @@
import gi
gi.require_version('Gtk', '4.0')
from gi.repository import Gtk, Gio, GLib, GdkPixbuf
import threading import threading
from customtkinter import *
import download_main import download_main
number_of_tabs = 4 def run_installer(download_folder_tmp):
download_folder = "." global visible_widgets # Declare visible_widgets as a global variable
class InstallerGUI: app = CTk()
def __init__(self): app.geometry("600x600")
self.app = Gtk.Application(application_id="com.spitfire.launcher",
flags=Gio.ApplicationFlags.FLAGS_NONE)
self.app.connect("activate", self.activate)
def run(self): set_default_color_theme("dark-blue")
self.app.run() set_appearance_mode("dark")
def activate(self, app): # Function to print "ahoj"
app_window = MainWindow(application=app) def print_ahoj():
app_window.present() print("ahoj")
class UpdaterGUI(Gtk.Box): # Dictionary to store tabs and their widgets
def __init__(self): tabs = {
super().__init__(orientation=Gtk.Orientation.VERTICAL) "Tab1": [
CTkButton,
CTkCheckBox,
CTkComboBox,
CTkEntry,
CTkProgressBar,
CTkRadioButton,
CTkSlider,
CTkSwitch
],
"Tab2": [
CTkButton,
CTkCheckBox,
CTkComboBox,
CTkEntry,
CTkProgressBar
],
"Tab3": [
CTkButton,
CTkCheckBox,
CTkComboBox
]
}
# Create a progress bar and a label # List to store the currently visible widgets
self.progress_bar = Gtk.ProgressBar() visible_widgets = []
self.progress_label = Gtk.Label()
# # Set up the layout # Function to switch to the next tab
# logo_path = "./data/icon.png" def switch_to_next_tab():
# logo_pixbuf = GdkPixbuf.Pixbuf.new_from_file(logo_path) global visible_widgets
# logo_image = Gtk.Image.new_from_pixbuf(logo_pixbuf) # Remove currently visible widgets
for widget in visible_widgets:
widget.pack_forget()
# Get the next tab's widgets
current_tab_index = list(tabs.keys()).index(tab_combobox.get())
next_tab_index = (current_tab_index + 1) % len(tabs)
if next_tab_index == 0:
# We reached the last tab, so do not switch
next_tab_index = current_tab_index
tab_combobox.set(list(tabs.keys())[next_tab_index])
visible_widgets = create_widgets_for_current_tab()
# self.append(logo_image) # Function to switch to the previous tab
self.append(self.progress_bar) def switch_to_previous_tab():
self.append(self.progress_label) global visible_widgets
# Remove currently visible widgets
for widget in visible_widgets:
widget.pack_forget()
# Get the previous tab's widgets
current_tab_index = list(tabs.keys()).index(tab_combobox.get())
previous_tab_index = (current_tab_index - 1) % len(tabs)
if previous_tab_index == len(tabs) - 1:
# We reached the first tab, so do not switch
previous_tab_index = current_tab_index
tab_combobox.set(list(tabs.keys())[previous_tab_index])
visible_widgets = create_widgets_for_current_tab()
# Connect to the "realize" signal to run the function when the widget becomes visible # Function to create widgets for the currently selected tab
self.connect("realize", self.on_realize) def create_widgets_for_current_tab():
current_tab = tab_combobox.get()
widget_classes = tabs.get(current_tab, [])
widgets = [widget_class(master=container) for widget_class in widget_classes]
for widget in widgets:
widget.pack(pady=20, padx=20)
return widgets
def on_realize(self, widget): # Create a container frame for widgets
# Run the install_all_packages function in a separate thread when the widget becomes visible container = CTkFrame(app)
print(download_folder) container.pack()
threading.Thread(target=self.run_installation(download_folder)).start()
def run_installation(self,download_folder): # Create a combobox to select the current tab
# Pass the progress bar and label to the install_all_packages function tab_combobox = CTkComboBox(master=app, values=list(tabs.keys()))
download_main.download_all_packages(self.progress_bar, self.progress_label, download_folder,"./data/") tab_combobox.set(list(tabs.keys())[0])
# Glib.idle_add() ? tab_combobox.pack_forget() # Hide the combobox
# Initialize the visible widgets with the widgets from the initial tab
visible_widgets = create_widgets_for_current_tab()
class CustomizationTab(Gtk.Box): # Button to trigger the gradual slide-to-right effect
def __init__(self, button_box): CTkButton(master=app, text="Next", command=switch_to_next_tab).pack(pady=10)
super().__init__(orientation=Gtk.Orientation.VERTICAL, spacing=6) # Button to trigger the gradual slide-to-left effect
self.create_ui(button_box) CTkButton(master=app, text="Previous", command=switch_to_previous_tab).pack(pady=10)
def create_ui(self, button_box): # Button to print "ahoj" when pressed
# Add elements for customization tab in the future CTkButton(master=app, text="Print Ahoj", command=print_ahoj).pack(pady=10)
# Add back and next buttons at the bottom app.mainloop()
self.bottom_buttons(button_box)
def bottom_buttons(self, button_box):
self.append(Gtk.Box(hexpand=True, vexpand=True)) # Expandable empty box to push buttons to the bottom
self.append(button_box)
class MainWindow(Gtk.ApplicationWindow):
def __init__(self, application, **kwargs):
super().__init__(application=application, **kwargs)
# # Set Adwaita theme
# settings = Gtk.Settings.get_default()
# settings.set_property("gtk-application-prefer-dark-theme", True)
# settings.set_property("gtk-theme-name", "Adwaita")
self.set_default_size(600, 400)
self.set_title("Spitfire Installer Nightly")
self.child_names = ["Main", "Customization", "Tab 2", "Tab 3", "Tab 4","UpdaterGUI"]
self.stack = Gtk.Stack(transition_type=Gtk.StackTransitionType.SLIDE_LEFT_RIGHT)
self.stack.set_transition_duration(1000) # Set the duration of the transition in milliseconds
# Create a HeaderBar
header_bar = Gtk.HeaderBar()
header_bar.set_show_title_buttons(True)
self.set_titlebar(header_bar)
# First tab
self.add_first_tab()
# Second tab (Customization tab)
button_box = self.create_button_box(0)
self.customization_tab = CustomizationTab(button_box)
self.stack.add_titled(self.customization_tab, "Customization", "Customization")
# Third to Fifth tabs (empty for now)
for i in range(3):
self.add_tab(i + 1)
# Last tab (Installer tab)
self.updater_tab = UpdaterGUI()
self.stack.add_titled(self.updater_tab, "UpdaterGUI", "UpdaterGUI")
self.set_child(self.stack)
self.show()
def create_button_box(self, current_tab):
button_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6)
left_button = Gtk.Button(label="Back")
left_button.connect("clicked", self.on_back_clicked)
right_button = Gtk.Button(label="Next")
right_button.connect("clicked", self.on_next_clicked)
label = Gtk.Label(label=f"{current_tab + 1} / {number_of_tabs}") # Display current tab number
label.set_halign(Gtk.Align.CENTER) # Center-align the label
# Add an empty box to act as a flexible space
button_box.append(Gtk.Box(hexpand=True))
# Add left button, label, and right button to the button box
button_box.append(left_button)
button_box.append(label)
button_box.append(right_button)
return button_box
def add_first_tab(self):
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
self.stack.add_titled(box, "Main", "Main")
label = Gtk.Label(label=f"\nThis is an experimental (Nightly) build.")
box.append(label)
empty_space = Gtk.Box(vexpand=True)
box.append(empty_space) # Expandable empty box to push buttons to the bottom
skip_button = Gtk.Button(label="Install")
skip_button.connect("clicked", self.on_skip_clicked)
box.append(skip_button) # Use append to add child widgets
customize_button = Gtk.Button(label="Customize")
customize_button.connect("clicked", self.on_next_clicked)
box.append(customize_button) # Use append to add child widget
empty_space = Gtk.Box(vexpand=True)
box.append(empty_space) # Expandable empty box to push buttons to the bottom
def add_tab(self, current_tab):
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
self.stack.add_titled(box, f"Tab {current_tab + 1}", f"Tab {current_tab + 1}")
# Add back and next buttons at the bottom
self.bottom_buttons(box, current_tab)
def bottom_buttons(self, box, current_tab):
button_box = self.create_button_box(current_tab)
box.append(Gtk.Box(hexpand=True, vexpand=True)) # Expandable empty box to push buttons to the bottom
box.append(button_box)
def on_skip_clicked(self, button):
current_page_name = "UpdaterGUI"
current_page_index = self.child_names.index(current_page_name)
next_page_index = number_of_tabs+1
if next_page_index < len(self.child_names):
next_page_name = self.child_names[next_page_index]
next_page = self.stack.get_child_by_name(next_page_name)
self.stack.set_visible_child(next_page)
def on_next_clicked(self, button):
current_page_name = self.stack.get_visible_child_name()
current_page_index = self.child_names.index(current_page_name)
next_page_index = current_page_index + 1
if next_page_index < len(self.child_names):
next_page_name = self.child_names[next_page_index]
next_page = self.stack.get_child_by_name(next_page_name)
self.stack.set_visible_child(next_page)
def on_back_clicked(self, button):
current_page_name = self.stack.get_visible_child_name()
current_page_index = self.child_names.index(current_page_name)
prev_page_index = current_page_index - 1
if prev_page_index >= 0:
prev_page_name = self.child_names[prev_page_index]
prev_page = self.stack.get_child_by_name(prev_page_name)
self.stack.set_visible_child(prev_page)
def update_logo_and_title(self, page_name):
# Update title label text
self.title_label.set_label(page_name)
# Update logo image based on the page name
logo_path = f"./data/{page_name.lower()}_icon.png" # Assuming you have different icons for each page
logo_pixbuf = GdkPixbuf.Pixbuf.new_from_file(logo_path)
self.logo_and_title_box.get_children()[0].set_from_pixbuf(logo_pixbuf)
# Make the MainWindow class callable as a function
def run_installer(download_foler_tmp):
global download_folder
download_folder = download_foler_tmp
app = Gtk.Application(application_id="com.spitfire.launcher",
flags=Gio.ApplicationFlags.FLAGS_NONE)
app.connect("activate", lambda app: MainWindow(application=app))
app.run()
# # Run the installer when this script is executed directly
# if __name__ == "__main__":
# run_installer()

View file

@ -8,3 +8,4 @@ def install_all_packages(data):
print("installing!") print("installing!")
def install_package(): def install_package():
print("Installing package")