updated install windows, clean gui_main

This commit is contained in:
dez 2024-01-30 15:11:44 +01:00
parent 05e2cdc23f
commit 8a78272238
7 changed files with 122 additions and 132 deletions

View file

@ -1,13 +1,18 @@
# install msys2
https://www.msys2.org/
# update msys2
pacman -Suy
# install python && pip in msys2
pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-python3 mingw-w64-x86_64-python3-pip mingw-w64-x86_64-python3-setuptools
# install customtkinter pip package
# install packages from requirements.txt (in msys2 mingw64)
pip install -r requirements.txt
# install nuitka (in msys2)
# if it does not work by pip, install python-pillow in msys2
pacman -S mingw-w64-x86_64-python-pillow
# add python (usually: C:\msys2\bin) to system variable PATH
# add python (default: C:\msys2\mingw64\bin) to system variable PATH
# restart computer, and if done well you should be able to build and run this app
# restart computer to refresh system variables, and if done well you should be able to build and run this app

View file

@ -1,6 +1,7 @@
tkinter
tk
tkintertable
customtkinter
Pillow
tqdm
requests
requests
nuitka
pillow

View file

@ -1,3 +1,3 @@
python3 ./src/main.py
python.exe ./src/main.py
:: --clean-cache=all --disable-console --windows-icon-from-ico=./data/icon.ico
pause

View file

@ -4,7 +4,7 @@ from tkinter import PhotoImage
from PIL import Image, ImageTk
import download_main
from star_field import StarField
from gui_starfield import StarField
def run_installer(download_folder_tmp):
global visible_widgets, tab_combobox # Declare tab_combobox as a global variable
@ -19,85 +19,32 @@ def run_installer(download_folder_tmp):
set_default_color_theme("dark-blue")
set_appearance_mode("dark")
# Function to print "ahoj"
app.resizable(False, False)
def print_ahoj():
print("ahoj")
# Function to start the installation process
def start_install():
# Switch to Tab3
switch_to_tab("Tab3")
# Create a CTkLabel for displaying progress
progress_label = CTkLabel(master=container, text="Download in progress...")
# Run download_all_packages in a separate thread
threading.Thread(
target=download_main.download_all_packages,
args=(progress_label, "your_app_name", "./", "./data")
).start()
# Pack the label to display it
progress_label.pack(pady=20, padx=20)
# Function to load and display an image
def display_image():
img = PhotoImage(file="./assets/icon.png") # Specify the path to your image
# Calculate the center position
canvas_width = canvas.winfo_width()
canvas_height = canvas.winfo_height()
image_width = img.width()
image_height = img.height()
x_center = (app.winfo_width() - image_width) // 2
y_center = (app.winfo_height() - image_height) // 2
# Display the image at the center
canvas.create_image((app.winfo_width() - 400) // 2, y_center, anchor="nw", image=img)
canvas.image = img # Keep a reference to avoid garbage collection
def display_star_field():
# Create an instance of the StarField class
global star_field # Keep a reference to avoid garbage collection
star_field = StarField(app, 400, 600)
star_field.canvas.pack(side="left", fill="y") # Pack the StarField canvas on the left side
# Dictionary to store tabs and their widgets
tabs = {
"Tab1": [
(CTkButton, {"text": "Install", "command": print_ahoj}), # Tuple containing widget class and details
CTkCheckBox,
CTkComboBox,
CTkEntry,
CTkProgressBar,
CTkRadioButton,
CTkSlider,
CTkSwitch
],
"Tab2": [
CTkButton,
CTkCheckBox,
CTkComboBox,
CTkEntry,
CTkProgressBar
],
"Tab3": [
CTkProgressBar,
(CTkButton, {"text": "Start Install", "command": start_install})
]
}
# List to store the currently visible widgets
visible_widgets = []
def display_star_field(container):
# Create an instance of the StarField class
global star_field # Keep a reference to avoid garbage collection
star_field = StarField(app, 400, 600)
star_field.canvas.pack(side="left", fill="y") # Pack the StarField canvas on the left side
global star_field
star_field = StarField(container, 400, 600)
star_field.canvas.pack(side="left", fill="y")
def create_widgets_for_current_tab(container):
def create_widgets_for_current_tab():
# Remove currently visible widgets
for widget in visible_widgets:
widget.pack_forget()
# Create wigets for current tab
current_tab = tab_combobox.get()
widget_specs = tabs.get(current_tab, [])
widgets = [create_widget(spec, container) for spec in widget_specs]
@ -105,22 +52,28 @@ def run_installer(download_folder_tmp):
widget.pack(pady=20, padx=20)
return widgets
# Function to switch to a specified tab
def switch_to_tab(tab_name):
global visible_widgets
# Remove currently visible widgets
for widget in visible_widgets:
widget.pack_forget()
# Set the specified tab as the current tab
tab_combobox.set(tab_name)
visible_widgets = create_widgets_for_current_tab()
def create_widget(spec, master):
global progress_bar
if isinstance(spec, tuple):
widget_class, widget_args = spec[0], spec[1]
if widget_class == CTkButton:
return CTkButton(master=master, **widget_args)
elif widget_class == CTkProgressBar:
progress_bar = CTkProgressBar(master=master, **widget_args)
return progress_bar
else:
return spec(master=master)
# Function to switch to a specified tab
def switch_to_tab(tabname):
global visible_widgets
# Set the specified tab as the current tab
tab_combobox.set(tabname)
visible_widgets = create_widgets_for_current_tab()
# 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)
@ -133,9 +86,6 @@ def run_installer(download_folder_tmp):
# 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)
@ -145,53 +95,47 @@ def run_installer(download_folder_tmp):
tab_combobox.set(list(tabs.keys())[previous_tab_index])
visible_widgets = create_widgets_for_current_tab()
# Function to create widgets for the currently selected tab
def create_widgets_for_current_tab():
current_tab = tab_combobox.get()
widget_specs = tabs.get(current_tab, [])
widgets = [create_widget(spec, container) for spec in widget_specs]
for widget in widgets:
widget.pack(pady=20, padx=20)
return widgets
tabs = {
"Tab1": [
(CTkButton, {"text": "Next Tab", "command": switch_to_next_tab}),
(CTkButton, {"text": "Previous Tab", "command": switch_to_previous_tab}),
CTkCheckBox,
CTkComboBox,
CTkEntry,
CTkProgressBar,
CTkRadioButton,
CTkSlider,
CTkSwitch
],
"Tab2": [
(CTkButton, {"text": "Next Tab", "command": switch_to_next_tab}),
(CTkButton, {"text": "Previous Tab", "command": switch_to_previous_tab}),
CTkButton,
CTkCheckBox,
CTkComboBox,
CTkEntry,
CTkProgressBar
],
"Tab3": [
CTkProgressBar,
(CTkButton, {"text": "Start Install", "command": start_install})
]
}
# Function to create a widget based on its specifications
def create_widget(spec, master):
global progress_bar
if isinstance(spec, tuple):
widget_class, widget_args = spec[0], spec[1]
if widget_class == CTkButton:
# If it's a CTkButton, create the button with specified details
return CTkButton(master=master, **widget_args)
elif widget_class == CTkProgressBar:
# If it's a CTkProgressBar, save the reference to update later
progress_bar = CTkProgressBar(master=master, **widget_args)
return progress_bar
else:
# For other widget classes, create them without additional details
return spec(master=master)
visible_widgets = []
def display_star_field(container):
# Create an instance of the StarField class
global star_field # Keep a reference to avoid garbage collection
star_field = StarField(container, 400, 600) # Use container as the parent
star_field.canvas.pack(side="left", fill="y") # Pack the StarField canvas on the left side
# Create a container frame for widgets
container = CTkFrame(app)
container.pack(ipadx="100") # Place the container on the right side
container.pack(ipadx="100")
# Display the StarField initially
display_star_field(container)
# 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
tab_combobox.pack_forget()
# Initialize the visible widgets with the widgets from the initial tab
visible_widgets = create_widgets_for_current_tab()
app.mainloop()
# # Example usage
# Example usage
# run_installer("your_download_folder")

View file

@ -1,7 +1,7 @@
import math
from tkinter import Canvas
from random import randrange
from PIL import Image, ImageTk # Import Image and ImageTk from PIL
from PIL import Image, ImageTk
class Star:
__slots__ = ['x', 'y', 'z', 'id', 'radius', 'fill']
@ -16,7 +16,7 @@ class Star:
self.fill = 0
class StarField:
def __init__(self, master, width, height, depth=32, num_stars=500):
def __init__(self, master, width, height, depth=32, num_stars=100):
self.master = master
self.fov = 180 * math.pi / 180
self.view_distance = 0
@ -26,16 +26,20 @@ class StarField:
self.max_depth = depth
self.center_x = width / 2
self.center_y = height / 2
self.circular_mask_radius = min(self.center_x, self.center_y) *0.95
self.canvas = Canvas(master, width=width, height=height, bg="#000000")
self.circular_mask_radius = min(self.center_x, self.center_y) * 0.95
self.canvas = Canvas(master, width=width, height=height, bg="#111111")
self.canvas.pack()
# Create a black circle as the background
self.canvas.create_oval(self.center_x - self.circular_mask_radius,
self.center_y - self.circular_mask_radius,
self.center_x + self.circular_mask_radius,
self.center_y + self.circular_mask_radius, fill='#000000')
# Load the image and resize it
original_image = Image.open("./assets/logo.png") # Specify the path to your image
original_image = Image.open("./assets/logo.png")
image_size = self.height if self.width > self.height else self.width
resized_image = original_image.resize((image_size, image_size), resample=Image.LANCZOS)
self.image = ImageTk.PhotoImage(resized_image)
self.image_item = self.canvas.create_image(self.center_x, self.center_y, anchor='center', image=self.image)

View file

@ -85,7 +85,7 @@ def set_path_variable(download_path):
print(f"Added PATH: {output_string_unique}")
def run_init():
def run_init_win():
download_path = get_temp_folder()

36
src/theme_unix.py Normal file
View file

@ -0,0 +1,36 @@
import subprocess
import re
def get_gnome_theme():
try:
output = subprocess.check_output(['gsettings', 'get', 'org.gnome.desktop.interface', 'gtk-theme'], text=True)
theme_name = output.strip().strip("'")
return theme_name
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
return None
theme_name = get_gnome_theme()
print(f"GNOME Theme: {theme_name}")
def get_gtk_theme_colors(theme_name):
theme_path = f"/usr/share/themes/{theme_name}/gtk-3.0/gtk.css" # Adjust the path based on your system
try:
with open(theme_path, 'r') as f:
css_content = f.read()
# Extract background and foreground colors from the CSS
background_color = re.search(r'background-color:\s*#(\w+);', css_content).group(1)
foreground_color = re.search(r'color:\s*#(\w+);', css_content).group(1)
return background_color, foreground_color
except FileNotFoundError:
print(f"Theme file not found: {theme_path}")
return None, None
except Exception as e:
print(f"Error: {e}")
return None, None
background, foreground = get_gtk_theme_colors(theme_name)
print(f"Background color: #{background}, Foreground color: #{foreground}")