Skip to content

Commit

Permalink
Merge pull request #2 from delington/create_gui
Browse files Browse the repository at this point in the history
Create gui
  • Loading branch information
delington authored Oct 1, 2023
2 parents 9241a1a + 8376da0 commit 58b1eb0
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 78 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/build/
/dist/
main.spec
/myenv/
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

The Double Commander Theme Changer is a Python application that allows you to easily change the theme of the Double Commander file manager. With this app, you can select a theme from a list, preview the theme picture, and apply the selected theme to Double Commander.

## GUI

<img src="img/main_window.png" height="300" width="350"/>

## Themes

| `Dark` | `Light` |
|-----------------|--------------------|
| <img src="themes/dark_theme.png" height="230" width="400"/> | <img src="themes/light_theme.png" height="230" width="400"/> |
Expand Down
Binary file added img/main_window.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
150 changes: 72 additions & 78 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
import service.read_manager as read_manager
import service.xml_manager as xml_manager
import service.folder_selector_manager as folder_selector_manager
from tkinter import Tk
from tkinter import Tk, Button, Label, Listbox, Scrollbar, messagebox

INPUT_THEME_JSON = "themes.json"
SEPARATOR_LINE = "----------------------------------------------"

def show_picture(picture_path):

if picture_path is not None:
system = platform.system()
if system == "Darwin": # macOS
Expand All @@ -23,86 +21,82 @@ def show_picture(picture_path):
else:
print("No picture found for the selected theme.")

def get_input_folder_location():
input_folder_location = folder_selector_manager.find_db_commander_property_file()

while True:
if os.path.isfile(input_folder_location):
print("✔️ Folder location is valid.")
return input_folder_location
else:
print("Invalid input folder location.")

def create_root_tinkter():
root = Tk()
root.withdraw() # Hide the root window
def apply_theme(theme_option, db_folder_location, listbox):
xml_manager.apply_changes(db_folder_location, theme_option["file_path"])
messagebox.showinfo("Theme Applied", f"{theme_option['name']} applied successfully.")

def main():
def create_root_tkinter():
root = Tk()
root.withdraw() # Hide the root window

create_root_tkinter()
last_applied_theme = ""
create_root_tinkter()
theme_list = read_manager.read_themes_as_list(INPUT_THEME_JSON)

print(SEPARATOR_LINE)
print("⚠️ If you've never opened Double Commander before, please do so, and close it.\n(It creates doublecmd.xml which is essential!)")
print(SEPARATOR_LINE)
print("Please select Double Commander installation location.")
print("0. Exit")
print("1. OK")

if (input() == "0"):
print("Exiting...")
return
root = Tk()
root.title("Double Commander Theme Selector")

def get_input_folder_location():
input_folder_location = folder_selector_manager.find_db_commander_property_file()
while True:
if os.path.isfile(input_folder_location):
return input_folder_location
else:
messagebox.showerror("Invalid Input Folder", "Invalid input folder location. Please select again.")

def on_quit():
root.quit()

def on_theme_select():
selected_index = themes_listbox.curselection()
if not selected_index:
messagebox.showwarning("No Theme Selected", "Please select a theme from the list.")
return

selected_theme = theme_list[selected_index[0]]
show_picture(selected_theme["picture_path"])

def on_theme_apply():
selected_index = themes_listbox.curselection()
if not selected_index:
messagebox.showwarning("No Theme Selected", "Please select a theme from the list.")
return

selected_theme = theme_list[selected_index[0]]
apply_theme(selected_theme, db_folder_location, themes_listbox)
nonlocal last_applied_theme
last_applied_theme = selected_theme["name"]

def refresh_theme_list():
themes_listbox.delete(0, "end")
for theme in theme_list:
themes_listbox.insert("end", theme["name"])

messagebox.showinfo("Installation folder", "Please select Double Commander installation folder");
db_folder_location = get_input_folder_location()

while True:
print(SEPARATOR_LINE)
print("Theme Options:")
print("0. Exit")

for i, theme in enumerate(theme_list, start=1):
list_item_name = f"{i}. {theme['name']}"

if theme["name"] == last_applied_theme:
list_item_name += "⭐*"
print(list_item_name)

theme_size = len(theme_list)
print(SEPARATOR_LINE)
print(f"Select a theme option (1-{theme_size}): ")
theme_input = int(input())

if theme_input == 0:
print("Exiting...")
break

for i in range(theme_size):
if theme_input - 1 == i:
theme_option = theme_list[i]
print("✔️ *", theme_list[i]["name"], "selected.")
break

while True:
print(SEPARATOR_LINE)
print("0. Back to main menu")
print("1. Apply theme")
print("2. Show picture")
apply_input = int(input())

if (apply_input == 0):
print("Back to main menu.")
break

if (apply_input == 1):
xml_manager.apply_changes(db_folder_location, theme_option["file_path"])
print(SEPARATOR_LINE)
print(f"*** {theme_option['name']} applied. ***")
last_applied_theme = theme_option["name"]
break

if (apply_input == 2):
print("Showing picture...")
show_picture(theme_option["picture_path"])
continue

main()
# Theme List
themes_listbox = Listbox(root, selectmode="SINGLE", height=10, width=50)
themes_listbox.grid(row=0, column=0, padx=10, pady=10)
refresh_theme_list()

scrollbar = Scrollbar(root, orient="vertical")
scrollbar.grid(row=0, column=1, sticky="ns")
themes_listbox.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=themes_listbox.yview)

# Buttons
show_button = Button(root, text="Show Picture", command=on_theme_select)
show_button.grid(row=1, column=0, padx=10, pady=5, sticky="w")

apply_button = Button(root, text="Apply Theme", command=on_theme_apply)
apply_button.grid(row=1, column=0, padx=10, pady=5, sticky="e")

quit_button = Button(root, text="Quit", command=on_quit)
quit_button.grid(row=2, column=0, padx=10, pady=10, sticky="e")

root.mainloop()

if __name__ == "__main__":
main()

0 comments on commit 58b1eb0

Please sign in to comment.