Skip to content

Commit 79bb438

Browse files
authored
Merge pull request #21 from ChocoScaff/setting_color
Setting color
2 parents 0d791c5 + 47eadb7 commit 79bb438

File tree

5 files changed

+162
-25
lines changed

5 files changed

+162
-25
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
html/
1111
latex/
1212
.mdmp
13+
*.ini

assetsBrowser.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from caption import Caption
2323
from download import Download
2424
from decompiler import Decompiler
25+
from setting import Setting
2526

2627
class AssetsBrowser():
2728
"""
@@ -202,13 +203,13 @@ def label_init(self):
202203
self.button.display()
203204

204205
if self.sdk.first_init == 0:
205-
self.sdk.texture_menu = tk.Menu(self.sdk.menu_bar, tearoff=0,background="#4c5844",fg="white")
206+
self.sdk.texture_menu = tk.Menu(self.sdk.menu_bar, tearoff=0,background=self.sdk.background_color,fg=self.sdk.foreground_color)
206207
self.sdk.menu_bar.add_cascade(label="Texture", menu=self.sdk.texture_menu)
207-
self.sdk.map_menu = tk.Menu(self.sdk.menu_bar, tearoff=0,background="#4c5844",fg="white")
208+
self.sdk.map_menu = tk.Menu(self.sdk.menu_bar, tearoff=0,background=self.sdk.background_color,fg=self.sdk.foreground_color)
208209
self.sdk.menu_bar.add_cascade(label="Map", menu=self.sdk.map_menu)
209-
self.sdk.model_menu = tk.Menu(self.sdk.menu_bar, tearoff=0,background="#4c5844",fg="white")
210+
self.sdk.model_menu = tk.Menu(self.sdk.menu_bar, tearoff=0,background=self.sdk.background_color,fg=self.sdk.foreground_color)
210211
self.sdk.menu_bar.add_cascade(label="Model", menu=self.sdk.model_menu)
211-
self.sdk.other_menu = tk.Menu(self.sdk.menu_bar, tearoff=0,background="#4c5844",fg="white")
212+
self.sdk.other_menu = tk.Menu(self.sdk.menu_bar, tearoff=0,background=self.sdk.background_color,fg=self.sdk.foreground_color)
212213
self.sdk.menu_bar.add_cascade(label="Other", menu=self.sdk.other_menu)
213214

214215
self.sdk.map_menu.add_command(label="Build Map", command=self.map.build_map)
@@ -483,7 +484,9 @@ def open_file_explorer(self):
483484
repo_name = "SourceSDK-"
484485

485486
# Replace this with the version of your local software
486-
local_version = "1.0.0"
487+
local_version = "1.1.0"
488+
489+
setting = Setting(test.sdk)
487490

488491
github_version = test.get_latest_release_version(repo_owner, repo_name)
489492

@@ -501,15 +504,15 @@ def open_file_explorer(self):
501504
test.sdk.root = tk.Tk()
502505
test.sdk.root.title("Source SDK : assetsBrowser " + local_version)
503506

504-
test.sdk.root.tk_setPalette(background="#4c5844", foreground="white")
507+
test.sdk.root.tk_setPalette(background=test.sdk.background_color, foreground=test.sdk.foreground_color)
505508

506-
test.sdk.root.configure(background="#3e4637")
509+
test.sdk.root.configure(background=test.sdk.secondary_background_color)
507510

508511
test.sdk.menu_bar = tk.Menu(test.sdk.root)
509-
test.sdk.root.config(menu=test.sdk.menu_bar,background="#3e4637")
512+
test.sdk.root.config(menu=test.sdk.menu_bar,background=test.sdk.secondary_background_color)
510513

511514
# Create a "File" menu
512-
file_menu = tk.Menu(test.sdk.menu_bar, tearoff=0,background="#4c5844",fg="white")
515+
file_menu = tk.Menu(test.sdk.menu_bar, tearoff=0,background=test.sdk.background_color,fg=test.sdk.foreground_color)
513516
test.sdk.menu_bar.add_cascade(label="File", menu=file_menu)
514517

515518
# Add "Open" option to the "File" menu
@@ -519,10 +522,11 @@ def open_file_explorer(self):
519522
#file_menu.add_cascade(label="Previous Projects", menu=previous_projects_menu)
520523
file_menu.add_command(label="Exit", command=test.launch_exit)
521524

522-
help_menu = tk.Menu(test.sdk.menu_bar, tearoff=0,background="#4c5844",fg="white")
525+
help_menu = tk.Menu(test.sdk.menu_bar, tearoff=0,background=test.sdk.background_color,fg=test.sdk.foreground_color)
523526
test.sdk.menu_bar.add_cascade(label="Help", menu=help_menu)
524527
help_menu.add_command(label="sdk Doc", command=test.sdk_Doc)
525528
help_menu.add_command(label="About", command=test.open_about_window)
529+
help_menu.add_command(label="Settings", command=setting.create_gui)
526530

527531
# Create a Text widget to display terminal output
528532
test.terminal = Terminal(test.sdk.root, wrap=tk.WORD, height=30, width=120)
@@ -536,7 +540,7 @@ def open_file_explorer(self):
536540
test.sdk.root.bind("<Control-n>", test.handle_shortcut)
537541
test.sdk.root.bind("<Control-o>", test.handle_shortcut)
538542

539-
lbl_result = tk.Label(test.sdk.root, text="Tools", wraplength=400, background="#3e4637",fg='white')
543+
lbl_result = tk.Label(test.sdk.root, text="Tools", wraplength=400, background=test.sdk.secondary_background_color,fg=test.sdk.foreground_color)
540544
lbl_result.pack()
541545

542546
# Start the GUI event loop

button.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,56 +99,56 @@ def display(self):
9999
"""
100100

101101
file = File(self.sdk)
102-
self.btn_file_explorer = tk.Button(self.sdk.root, text="Files", command=file.display_files_tree,image=self.iconExplorer,compound=tk.LEFT, background="#4c5844",fg="white")
102+
self.btn_file_explorer = tk.Button(self.sdk.root, text="Files", command=file.display_files_tree,image=self.iconExplorer,compound=tk.LEFT, background=self.sdk.background_color,fg=self.sdk.foreground_color)
103103
self.btn_file_explorer.pack(side="left")
104104

105105
if os.path.isfile(self.sdk.bin_folder + "/hammer.exe"):
106-
self.btn_hammer = tk.Button(self.sdk.root, text="hammer", command=self.open_hammer,image=self.iconHammer,compound=tk.LEFT, background="#4c5844",fg="white")
106+
self.btn_hammer = tk.Button(self.sdk.root, text="hammer", command=self.open_hammer,image=self.iconHammer,compound=tk.LEFT, background=self.sdk.background_color,fg=self.sdk.foreground_color)
107107
self.btn_hammer.pack(side="left")
108108

109109
if os.path.isfile(self.sdk.bin_folder + "/hammerplusplus.exe"):
110-
self.btn_hammer_plus_plus = tk.Button(self.sdk.root, text="hammer++", command=self.open_hammer_plus_plus, image=self.iconHpp, compound=tk.LEFT, background="#4c5844",fg="white")
110+
self.btn_hammer_plus_plus = tk.Button(self.sdk.root, text="hammer++", command=self.open_hammer_plus_plus, image=self.iconHpp, compound=tk.LEFT, background=self.sdk.background_color,fg=self.sdk.foreground_color)
111111
self.btn_hammer_plus_plus.pack(side="left")
112112

113113
if os.path.isfile(self.sdk.bin_folder + "/hlmv.exe"):
114-
self.btn_hlmv = tk.Button(self.sdk.root, text="hlmv", command=self.model.open_hlmv, image=self.iconHLMV, compound=tk.LEFT, background="#4c5844",fg="white")
114+
self.btn_hlmv = tk.Button(self.sdk.root, text="hlmv", command=self.model.open_hlmv, image=self.iconHLMV, compound=tk.LEFT, background=self.sdk.background_color,fg=self.sdk.foreground_color)
115115
self.btn_hlmv.pack(side="left")
116116

117117
if os.path.isfile(self.sdk.bin_folder + "/qc_eyes.exe"):
118-
self.btn_qc_eyes= tk.Button(self.sdk.root, text="qc_eyes", command=self.open_qc_eyes, image=self.iconQc_eyes, compound=tk.LEFT, background="#4c5844",fg="white")
118+
self.btn_qc_eyes= tk.Button(self.sdk.root, text="qc_eyes", command=self.open_qc_eyes, image=self.iconQc_eyes, compound=tk.LEFT, background=self.sdk.background_color,fg=self.sdk.foreground_color)
119119
self.btn_qc_eyes.pack(side="left")
120120

121121
if os.path.isfile(self.sdk.bin_folder + "/hlfaceposer.exe"):
122-
self.btn_hlfaceposer = tk.Button(self.sdk.root, text="hlfaceposer", command=self.open_hlfaceposer, image=self.iconHlposer, compound=tk.LEFT, background="#4c5844",fg="white")
122+
self.btn_hlfaceposer = tk.Button(self.sdk.root, text="hlfaceposer", command=self.open_hlfaceposer, image=self.iconHlposer, compound=tk.LEFT, background=self.sdk.background_color,fg=self.sdk.foreground_color)
123123
self.btn_hlfaceposer.pack(side="left")
124124

125125
if os.path.isfile(os.getcwd() + "/VTfEdit/x64/VTFEdit.exe") or os.path.exists(r"C:\Program Files\Nem's Tools\VTFEdit\VTFEdit.exe"):
126-
self.btn_vtf_edit = tk.Button(self.sdk.root, text="vtfEdit", command=self.texture.open_VTF, image=self.iconVTFEdit, compound=tk.LEFT, background="#4c5844",fg="white")
126+
self.btn_vtf_edit = tk.Button(self.sdk.root, text="vtfEdit", command=self.texture.open_VTF, image=self.iconVTFEdit, compound=tk.LEFT, background=self.sdk.background_color,fg=self.sdk.foreground_color)
127127
self.btn_vtf_edit.pack(side="left")
128128
else:
129129
Download.download_VTF_Edit()
130-
self.btn_vtf_edit = tk.Button(self.sdk.root, text="vtfEdit", command=self.texture.open_VTF, image=self.iconVTFEdit, compound=tk.LEFT, background="#4c5844",fg="white")
130+
self.btn_vtf_edit = tk.Button(self.sdk.root, text="vtfEdit", command=self.texture.open_VTF, image=self.iconVTFEdit, compound=tk.LEFT, background=self.sdk.background_color,fg=self.sdk.foreground_color)
131131
self.btn_vtf_edit.pack(side="left")
132132

133133
if os.path.isfile(os.getcwd() +"/VPKEdit-Windows-Standalone-GUI-msvc-Release/vpkedit.exe"):
134-
self.btn_vpk_edit = tk.Button(self.sdk.root, text="vtfEdit", command=self.LaunchVPKEdit, image=self.iconVPKEdit, compound=tk.LEFT, background="#4c5844",fg="white")
134+
self.btn_vpk_edit = tk.Button(self.sdk.root, text="vtfEdit", command=self.LaunchVPKEdit, image=self.iconVPKEdit, compound=tk.LEFT, background=self.sdk.background_color,fg=self.sdk.foreground_color)
135135
self.btn_vpk_edit.pack(side="left")
136136

137137
if os.path.exists(self.sdk.selected_folder + "/src/games.sln"):
138-
self.btn_games = tk.Button(self.sdk.root, text="games", command=self.open.open_games, image=self.iconVisualStudio, compound=tk.LEFT, background="#4c5844",fg="white")
138+
self.btn_games = tk.Button(self.sdk.root, text="games", command=self.open.open_games, image=self.iconVisualStudio, compound=tk.LEFT, background=self.sdk.background_color,fg=self.sdk.foreground_color)
139139
self.btn_games.pack(side="left")
140140

141141
if os.path.exists(self.sdk.selected_folder + "/src/everything.sln"):
142-
self.btn_everything = tk.Button(self.sdk.root, text="everything", command=self.open.open_everything, image=self.iconVisualStudio, compound=tk.LEFT, background="#4c5844",fg="white")
142+
self.btn_everything = tk.Button(self.sdk.root, text="everything", command=self.open.open_everything, image=self.iconVisualStudio, compound=tk.LEFT, background=self.sdk.background_color,fg=self.sdk.foreground_color)
143143
self.btn_everything.pack(side="left")
144144

145-
self.btn_particle = tk.Button(self.sdk.root, text="Particle", command=self.particle, image=self.iconSource, compound=tk.LEFT, background="#4c5844",fg="white")
145+
self.btn_particle = tk.Button(self.sdk.root, text="Particle", command=self.particle, image=self.iconSource, compound=tk.LEFT, background=self.sdk.background_color,fg=self.sdk.foreground_color)
146146
self.btn_particle.pack(side="left")
147147

148-
self.btn_Launch_dev = tk.Button(self.sdk.root, text="Launch Dev", command=self.Launch_dev, image=self.iconSource, compound=tk.LEFT, background="#4c5844",fg="white")
148+
self.btn_Launch_dev = tk.Button(self.sdk.root, text="Launch Dev", command=self.Launch_dev, image=self.iconSource, compound=tk.LEFT, background=self.sdk.background_color,fg=self.sdk.foreground_color)
149149
self.btn_Launch_dev.pack(side="left")
150150

151-
self.btn_Launch = tk.Button(self.sdk.root, text="Launch", command=self.Launch, image=self.iconSource, compound=tk.LEFT, background="#4c5844",fg="white")
151+
self.btn_Launch = tk.Button(self.sdk.root, text="Launch", command=self.Launch, image=self.iconSource, compound=tk.LEFT, background=self.sdk.background_color,fg=self.sdk.foreground_color)
152152
self.btn_Launch.pack(side="left")
153153

154154
def open_hammer(self):

setting.py

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
2+
import os
3+
import tkinter as tk
4+
from tkinter import colorchooser
5+
6+
class Setting():
7+
"""
8+
"""
9+
def __init__(self,SourceSDK):
10+
"""
11+
Initialize settings class.
12+
"""
13+
self.source_sdk = SourceSDK
14+
self.setting_file = os.path.join(os.getcwd(), "setting.ini")
15+
16+
if os.path.exists(os.getcwd() + "/setting.ini"):
17+
self.load_settings()
18+
else:
19+
self.createSettingIni()
20+
self.load_settings()
21+
22+
23+
def createSettingIni(self):
24+
"""
25+
Create default setting.ini file if it doesn't exist.
26+
"""
27+
settings_content = """
28+
background_color=#4c5844
29+
foreground_color=white
30+
secondary_background_color=#3e4637
31+
"""
32+
try:
33+
with open(self.setting_file, 'w') as file:
34+
file.write(settings_content)
35+
print(f"Settings file created successfully at '{self.setting_file}'.")
36+
except Exception as e:
37+
print(f"Error: {e}")
38+
39+
def load_settings(self):
40+
"""
41+
Load settings from the setting.ini file and apply them to SourceSDK.
42+
"""
43+
try:
44+
with open(self.setting_file, 'r') as file:
45+
settings = {}
46+
for line in file:
47+
if '=' in line:
48+
key, value = line.strip().split('=')
49+
settings[key.strip()] = value.strip()
50+
51+
# Apply settings to SourceSDK
52+
self.source_sdk.background_color = settings.get('background_color', '#4c5844')
53+
self.source_sdk.foreground_color = settings.get('foreground_color', 'white')
54+
self.source_sdk.secondary_background_color = settings.get('secondary_background_color', '#3e4637')
55+
print("Settings loaded successfully.")
56+
except Exception as e:
57+
print(f"Error loading settings: {e}")
58+
59+
def create_gui(self):
60+
# Window title and size
61+
self.root = tk.Toplevel(self.source_sdk.root)
62+
self.root.title("Settings")
63+
self.root.geometry("500x300")
64+
65+
# Label and entry for Background Color
66+
tk.Label(self.root, text="Background Color:").grid(row=0, column=0, padx=10, pady=10)
67+
self.bg_color_entry = tk.Entry(self.root, width=30)
68+
self.bg_color_entry.grid(row=0, column=1)
69+
self.bg_color_entry.insert(0, self.source_sdk.background_color)
70+
71+
# Button to pick background color
72+
tk.Button(self.root, text="Pick Color", command=self.pick_bg_color).grid(row=0, column=2)
73+
74+
# Label and entry for Foreground Color
75+
tk.Label(self.root, text="Foreground Color:").grid(row=1, column=0, padx=10, pady=10)
76+
self.fg_color_entry = tk.Entry(self.root, width=30)
77+
self.fg_color_entry.grid(row=1, column=1)
78+
self.fg_color_entry.insert(0, self.source_sdk.foreground_color)
79+
80+
81+
# Label and entry for Secondary Background Color
82+
tk.Label(self.root, text="Secondary Background Color:").grid(row=2, column=0, padx=10, pady=10)
83+
self.sec_bg_color_entry = tk.Entry(self.root, width=30)
84+
self.sec_bg_color_entry.grid(row=2, column=1)
85+
self.sec_bg_color_entry.insert(0, self.source_sdk.secondary_background_color)
86+
87+
# Button to pick secondary background color
88+
tk.Button(self.root, text="Pick Color", command=self.pick_sec_bg_color).grid(row=2, column=2)
89+
90+
# Save button
91+
tk.Button(self.root, text="Save Settings", command=self.save_settings).grid(row=3, column=1, pady=20)
92+
93+
def pick_bg_color(self):
94+
# Color chooser for background color
95+
color_code = colorchooser.askcolor(title="Choose Background Color")[1]
96+
if color_code:
97+
self.bg_color_entry.delete(0, tk.END)
98+
self.bg_color_entry.insert(0, color_code)
99+
100+
def pick_fg_color(self):
101+
# Color chooser for foreground color
102+
color_code = colorchooser.askcolor(title="Choose Foreground Color")[1]
103+
if color_code:
104+
self.fg_color_entry.delete(0, tk.END)
105+
self.fg_color_entry.insert(0, color_code)
106+
107+
def pick_sec_bg_color(self):
108+
# Color chooser for secondary background color
109+
color_code = colorchooser.askcolor(title="Choose Secondary Background Color")[1]
110+
if color_code:
111+
self.sec_bg_color_entry.delete(0, tk.END)
112+
self.sec_bg_color_entry.insert(0, color_code)
113+
114+
def save_settings(self):
115+
# Save the settings from the input fields into the SDK
116+
self.source_sdk.background_color = self.bg_color_entry.get()
117+
self.source_sdk.foreground_color = self.fg_color_entry.get()
118+
self.source_sdk.secondary_background_color = self.sec_bg_color_entry.get()
119+
120+
# Save settings to file
121+
try:
122+
with open(self.setting_file, 'w') as file:
123+
file.write(f"background_color={self.source_sdk.background_color}\n")
124+
file.write(f"foreground_color={self.source_sdk.foreground_color}\n")
125+
file.write(f"secondary_background_color={self.source_sdk.secondary_background_color}\n")
126+
print("Settings saved successfully.")
127+
print("Need restart to take effect.")
128+
except Exception as e:
129+
print(f"Error while saving settings: {e}")

sourceSDK.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ class SourceSDK():
2020
root : tk.Tk
2121
game_path = []
2222
parent_folder : string
23+
background_color : string
24+
foreground_color : string
25+
secondary_background_color : string

0 commit comments

Comments
 (0)