diff --git a/install-linux.sh b/install-linux.sh index f90e065..16737a8 100755 --- a/install-linux.sh +++ b/install-linux.sh @@ -8,20 +8,18 @@ sudo apt install python3 -y # Install Python3 pip sudo apt install python3-pip -y -# Install GTK4 package -sudo apt install libgtk-4-dev -y - # Install PatchELF for Nuitka (if needed) sudo apt install patchelf -y # Install Nuitka pip3 install nuitka +pip3 install tqdm + # Install additional Python packages pip3 install requests sudo apt install libgirepository1.0-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 setuptools # Install setuptools for packaging diff --git a/install-windows.txt b/install-windows.txt index b66c8d2..ea0cb50 100755 --- a/install-windows.txt +++ b/install-windows.txt @@ -4,7 +4,7 @@ # install python && pip in msys2 -# install GTK4 according to GTK website +# install customtkinter pip package # install nuitka (in msys2) diff --git a/src/gui_main.py b/src/gui_main.py index 5c492a3..0ff63e4 100644 --- a/src/gui_main.py +++ b/src/gui_main.py @@ -1,216 +1,107 @@ -import gi -gi.require_version('Gtk', '4.0') -from gi.repository import Gtk, Gio, GLib, GdkPixbuf import threading +from customtkinter import * import download_main -number_of_tabs = 4 -download_folder = "." +def run_installer(download_folder_tmp): + global visible_widgets # Declare visible_widgets as a global variable -class InstallerGUI: - def __init__(self): - self.app = Gtk.Application(application_id="com.spitfire.launcher", - flags=Gio.ApplicationFlags.FLAGS_NONE) - self.app.connect("activate", self.activate) + app = CTk() + app.geometry("600x600") - def run(self): - self.app.run() + set_default_color_theme("dark-blue") + set_appearance_mode("dark") - def activate(self, app): - app_window = MainWindow(application=app) - app_window.present() + # Function to print "ahoj" + def print_ahoj(): + print("ahoj") -class UpdaterGUI(Gtk.Box): - def __init__(self): - super().__init__(orientation=Gtk.Orientation.VERTICAL) + # Dictionary to store tabs and their widgets + tabs = { + "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 - self.progress_bar = Gtk.ProgressBar() - self.progress_label = Gtk.Label() + # List to store the currently visible widgets + visible_widgets = [] - # # Set up the layout - # logo_path = "./data/icon.png" - # logo_pixbuf = GdkPixbuf.Pixbuf.new_from_file(logo_path) - # logo_image = Gtk.Image.new_from_pixbuf(logo_pixbuf) + # Function to switch to the next tab + def switch_to_next_tab(): + global visible_widgets + # 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) - self.append(self.progress_bar) - self.append(self.progress_label) + # Function to switch to the previous tab + def switch_to_previous_tab(): + 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 - self.connect("realize", self.on_realize) + # Function to create widgets for the currently selected tab + 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): - # Run the install_all_packages function in a separate thread when the widget becomes visible - print(download_folder) - threading.Thread(target=self.run_installation(download_folder)).start() + # Create a container frame for widgets + container = CTkFrame(app) + container.pack() - def run_installation(self,download_folder): - # Pass the progress bar and label to the install_all_packages function - download_main.download_all_packages(self.progress_bar, self.progress_label, download_folder,"./data/") - # Glib.idle_add() ? + # Create a combobox to select the current tab + tab_combobox = CTkComboBox(master=app, values=list(tabs.keys())) + tab_combobox.set(list(tabs.keys())[0]) + 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): - def __init__(self, button_box): - super().__init__(orientation=Gtk.Orientation.VERTICAL, spacing=6) - self.create_ui(button_box) + # Button to trigger the gradual slide-to-right effect + CTkButton(master=app, text="Next", command=switch_to_next_tab).pack(pady=10) + # Button to trigger the gradual slide-to-left effect + CTkButton(master=app, text="Previous", command=switch_to_previous_tab).pack(pady=10) - def create_ui(self, button_box): - # Add elements for customization tab in the future + # Button to print "ahoj" when pressed + CTkButton(master=app, text="Print Ahoj", command=print_ahoj).pack(pady=10) - # Add back and next buttons at the bottom - 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() \ No newline at end of file + app.mainloop() \ No newline at end of file diff --git a/src/install_main.py b/src/install_main.py index 14214ec..0a0995b 100644 --- a/src/install_main.py +++ b/src/install_main.py @@ -8,3 +8,4 @@ def install_all_packages(data): print("installing!") def install_package(): + print("Installing package") \ No newline at end of file