Skip to content

Commit abe2bd4

Browse files
committed
Renamed config.py to shared_globals.py as the config settings are now stored elsewhere (on Windows in appdata). Created main.py.
1 parent 913e602 commit abe2bd4

File tree

5 files changed

+133
-108
lines changed

5 files changed

+133
-108
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ This program will do most of the conversion work for you, but some conversion st
1717
## How to add your own conversion rules
1818
* Download Python 3 and this GitHub repository.
1919
* Change your directory to the `cc-legacy-mod-converter` repository in your terminal.
20-
* Run `python gui.py` when you want to convert old mods.
21-
* `conversion_rules.py` has the `conversion_rules` dictionary inside of it. The dictionary contains entries that look like `'foo': 'bar',` which means means that any time `foo` will be encountered by `convert.py`, it will replace it with `bar`. You can add extra cases to it, see the next sections on how to do this.
20+
* Run `python main.py` when you want to convert old mods.
21+
* `conversion_rules.py` has the `conversion_rules` dictionary inside of it. The dictionary contains entries that look like `'foo': 'bar',` which means means that any time `foo` is encountered in a legacy mod it will be replaced with `bar`. You can also add extra conversion cases to it; see the next sections on how to do this in detail.
2222

2323
## Tutorials on constructing conversion rules efficiently
2424
* [Fixing CCCP crashes/errors with the program Everything](https://github.com/cortex-command-community/Cortex-Command-Legacy-Mod-Converter/wiki/Fixing-CCCP-crashes-errors-with-the-program-Everything)

convert.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import os, time, pathlib, shutil, math, re, sys, shutil, zipfile
22
from playsound import playsound
3-
import config
3+
# from python import shared_globals as cfg
4+
import shared_globals as cfg
45

56
from conversion_rules import conversion_rules
67

78

89
finishSoundPath = "media/finish.wav"
910

11+
1012
progress = 0
1113
total_progress = 0
1214

@@ -20,28 +22,28 @@ def main():
2022

2123
total_progress = get_total_progress()
2224

23-
for input_folder_path, input_subfolders, full_filename_list in os.walk(config.sg.user_settings_get_entry("mods_folder")):
25+
for input_folder_path, input_subfolders, full_filename_list in os.walk(cfg.sg.user_settings_get_entry("mods_folder")):
2426
mod_subfolder = get_mod_subfolder(input_folder_path)
2527
output_folder = get_output_folder_path(mod_subfolder)
2628

2729
try_print_mod_name(mod_subfolder)
2830
create_folder(input_folder_path, output_folder)
2931
process_file(full_filename_list, input_folder_path, output_folder)
3032

31-
if config.sg.user_settings_get_entry("output_zips"):
33+
if cfg.sg.user_settings_get_entry("output_zips"):
3234
create_zips()
3335

3436
progress = 0
3537
total_progress = 0
3638

3739
elapsed = math.floor(time.time() - time_start)
38-
if config.sg.user_settings_get_entry("play_finish_sound"):
40+
if cfg.sg.user_settings_get_entry("play_finish_sound"):
3941
playsound(finishSoundPath)
4042
print("Finished in {} {}".format(elapsed, pluralize("second", elapsed)))
4143

4244

4345
def unzip():
44-
mods_folder = config.sg.user_settings_get_entry("mods_folder")
46+
mods_folder = cfg.sg.user_settings_get_entry("mods_folder")
4547
for f in os.listdir(mods_folder):
4648
zip_path = os.path.join(mods_folder, f)
4749
if zipfile.is_zipfile(zip_path):
@@ -51,17 +53,17 @@ def unzip():
5153

5254

5355
def get_total_progress():
54-
mods_folder = config.sg.user_settings_get_entry("mods_folder")
56+
mods_folder = cfg.sg.user_settings_get_entry("mods_folder")
5557
mod_count = len([name for name in os.listdir(mods_folder) if os.path.isdir(os.path.join(mods_folder, name))])
56-
return mod_count * 2 if config.sg.user_settings_get_entry("output_zips") else mod_count
58+
return mod_count * 2 if cfg.sg.user_settings_get_entry("output_zips") else mod_count
5759

5860

5961
def get_mod_subfolder(input_folder_path):
60-
return input_folder_path.replace(config.sg.user_settings_get_entry("mods_folder") + "\\", "") # TODO: Find proper replacement for removing the \\ part that will also work for Unix.
62+
return input_folder_path.replace(cfg.sg.user_settings_get_entry("mods_folder") + "\\", "") # TODO: Find proper replacement for removing the \\ part that will also work for Unix.
6163

6264

6365
def get_output_folder_path(mod_subfolder):
64-
return os.path.join(config.sg.user_settings_get_entry("output_folder"), mod_subfolder)
66+
return os.path.join(cfg.sg.user_settings_get_entry("output_folder"), mod_subfolder)
6567

6668

6769
def try_print_mod_name(mod_subfolder):
@@ -75,12 +77,12 @@ def try_print_mod_name(mod_subfolder):
7577
def update_progress():
7678
global progress, total_progress
7779
progress += 1
78-
config.progress_bar.UpdateBar(progress % total_progress, total_progress)
80+
cfg.progress_bar.UpdateBar(progress % total_progress, total_progress)
7981

8082

8183
def create_folder(input_folder_path, output_folder):
8284
# Prevents putting the mods_folder itself into the output_folder.
83-
if input_folder_path != config.sg.user_settings_get_entry("mods_folder"):
85+
if input_folder_path != cfg.sg.user_settings_get_entry("mods_folder"):
8486
try:
8587
os.makedirs(output_folder)
8688
except FileExistsError:
@@ -194,8 +196,8 @@ def regex_replace_bmps_and_wavs(all_lines):
194196

195197
def create_zips():
196198
# Get mod folder names from the mods_folder.
197-
output_folder = config.sg.user_settings_get_entry("output_folder")
198-
folder_names = [f for f in os.listdir(config.sg.user_settings_get_entry("mods_folder")) if os.path.isdir(os.path.join(output_folder, f))]
199+
output_folder = cfg.sg.user_settings_get_entry("output_folder")
200+
folder_names = [f for f in os.listdir(cfg.sg.user_settings_get_entry("mods_folder")) if os.path.isdir(os.path.join(output_folder, f))]
199201

200202
for f in folder_names:
201203
print("Zipping '{}'".format(f))

gui.py

Lines changed: 111 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
33

44
import os.path, pathlib, webbrowser
55
import PySimpleGUI as sg
6-
import config, convert
6+
# from python import shared_globals as cfg
7+
import shared_globals as cfg
8+
# from python import convert
9+
import convert
710

811

9-
no_path_set_color = "#b35858"
10-
path_set_color = "#528b30"
11-
progress_bar_color = "#17569c"
12+
def init_window_theme():
13+
path_set_color = "#528b30"
14+
progress_bar_color = "#17569c"
1215

13-
sg.theme("DarkGrey14")
14-
sg.theme_input_background_color(path_set_color)
15-
sg.theme_progress_bar_color((progress_bar_color, sg.theme_progress_bar_color()[1]))
16+
sg.theme("DarkGrey14")
17+
sg.theme_input_background_color(path_set_color)
18+
sg.theme_progress_bar_color((progress_bar_color, sg.theme_progress_bar_color()[1]))
1619

1720

1821
def get_folder_containing_mods(mods_folder):
@@ -22,93 +25,108 @@ def get_folder_containing_mods(mods_folder):
2225
return mods_folder
2326

2427

25-
paths_column = [
26-
[sg.Frame(layout=[
27-
[
28-
sg.Text("Folder with legacy mod(s)"),
29-
sg.In(
30-
sg.user_settings_get_entry("mods_folder"),
31-
size=(25, 1),
32-
enable_events=True,
33-
key="-MODS FOLDER-",
34-
background_color=sg.theme_input_background_color() if sg.user_settings_get_entry("mods_folder") else no_path_set_color
35-
),
36-
sg.FolderBrowse()
37-
],
38-
[
39-
sg.Text("Output CCCP folder"),
40-
sg.In(
41-
sg.user_settings_get_entry("output_folder"),
42-
size=(25, 1),
43-
enable_events=True,
44-
key="-OUTPUT FOLDER-",
45-
background_color=sg.theme_input_background_color() if sg.user_settings_get_entry("output_folder") else no_path_set_color
46-
),
47-
sg.FolderBrowse()
28+
def init_window():
29+
no_path_set_color = "#b35858"
30+
print(sg.user_settings_filename())
31+
32+
paths_column = [
33+
[sg.Frame(layout=[
34+
[
35+
sg.Text("Folder with legacy mod(s)"),
36+
sg.In(
37+
sg.user_settings_get_entry("mods_folder"),
38+
size=(25, 1),
39+
enable_events=True,
40+
key="-MODS FOLDER-",
41+
background_color=sg.theme_input_background_color() if sg.user_settings_get_entry("mods_folder") else no_path_set_color
42+
),
43+
sg.FolderBrowse()
44+
],
45+
[
46+
sg.Text("Output CCCP folder"),
47+
sg.In(
48+
sg.user_settings_get_entry("output_folder"),
49+
size=(25, 1),
50+
enable_events=True,
51+
key="-OUTPUT FOLDER-",
52+
background_color=sg.theme_input_background_color() if sg.user_settings_get_entry("output_folder") else no_path_set_color
53+
),
54+
sg.FolderBrowse()
55+
]
56+
], title="Paths", element_justification="right")]
4857
]
49-
], title="Paths", element_justification="right")]
50-
]
51-
52-
options_column = [
53-
[sg.Frame(layout=[
54-
[sg.Checkbox("Output zips", size=(10, 1), tooltip=" Zipping is slow ", key="-OUTPUT ZIPS-", default=sg.user_settings_get_entry("output_zips"))],
55-
[sg.Checkbox("Play finish sound", size=(12, 1), tooltip=" For when converting takes long ", key="-PLAY FINISH SOUND-", default=sg.user_settings_get_entry("play_finish_sound"))]
56-
], title="Options")],
57-
]
58-
59-
run_column = [
60-
[sg.Frame(layout=[
61-
[sg.Button("Convert", key="-CONVERT-")],
62-
[sg.ProgressBar(100, size=(17.45, 20), key="-PROGRESS BAR-")]
63-
], title="Run", element_justification="center")]
64-
]
65-
66-
info_column = [
67-
[sg.Frame(layout=[
68-
[sg.Image("media/github-icon.png", enable_events=True, key="-GITHUB-")],
69-
[sg.Image("media/discord-icon.png", enable_events=True, key="-DISCORD-")]
70-
], title="", pad=(0, (8, 0)))]
71-
]
72-
73-
layout = [
74-
[
75-
sg.Column(paths_column),
76-
],
77-
[
78-
sg.Column(options_column),
79-
sg.Column(run_column),
80-
sg.Column(info_column)
58+
59+
options_column = [
60+
[sg.Frame(layout=[
61+
[sg.Checkbox("Output zips", size=(10, 1), tooltip=" Zipping is slow ", key="-OUTPUT ZIPS-", default=sg.user_settings_get_entry("output_zips"), enable_events=True)],
62+
[sg.Checkbox("Play finish sound", size=(12, 1), tooltip=" For when converting takes long ", key="-PLAY FINISH SOUND-", default=sg.user_settings_get_entry("play_finish_sound"), enable_events=True)]
63+
], title="Options")],
64+
]
65+
66+
run_column = [
67+
[sg.Frame(layout=[
68+
[sg.Button("Convert", key="-CONVERT-")],
69+
[sg.ProgressBar(100, size=(17.45, 20), key="-PROGRESS BAR-")]
70+
], title="Run", element_justification="center")]
71+
]
72+
73+
info_column = [
74+
[sg.Frame(layout=[
75+
[sg.Image("media/github-icon.png", enable_events=True, key="-GITHUB-")],
76+
[sg.Image("media/discord-icon.png", enable_events=True, key="-DISCORD-")]
77+
], title="", pad=(0, (8, 0)))]
78+
]
79+
80+
layout = [
81+
[
82+
sg.Column(paths_column),
83+
],
84+
[
85+
sg.Column(options_column),
86+
sg.Column(run_column),
87+
sg.Column(info_column)
88+
]
8189
]
82-
]
83-
84-
config.sg = sg
85-
window = sg.Window("Legacy Mod Converter - v1.0", layout, icon="media/cclmc-icon.ico", button_color=(sg.theme_text_color(), "#2a3948"))
86-
config.progress_bar = window["-PROGRESS BAR-"]
87-
88-
89-
while True:
90-
event, values = window.read()
91-
92-
if event == "Exit" or event == sg.WIN_CLOSED:
93-
window.close()
94-
break
95-
96-
if event == "-GITHUB-":
97-
webbrowser.open("https://github.com/cortex-command-community/Cortex-Command-Legacy-Mod-Converter")
98-
elif event == "-DISCORD-":
99-
webbrowser.open("https://discord.gg/SdNnKJN")
100-
elif event == "-MODS FOLDER-":
101-
mods_folder = values[event]
102-
if mods_folder != "":
103-
sg.user_settings_set_entry("mods_folder", get_folder_containing_mods(mods_folder))
104-
window[event](background_color=sg.theme_input_background_color())
105-
elif event == "-OUTPUT FOLDER-":
106-
output_folder = values[event]
107-
if output_folder != "":
108-
sg.user_settings_set_entry("output_folder", output_folder)
109-
window[event](background_color=sg.theme_input_background_color())
110-
elif event == "-CONVERT-":
111-
if sg.user_settings_get_entry("mods_folder") not in (None, "") and sg.user_settings_get_entry("output_folder") not in (None, ""):
90+
91+
cfg.sg = sg
92+
window = sg.Window("Legacy Mod Converter - v1.0", layout, icon="media/cclmc-icon.ico", button_color=(sg.theme_text_color(), "#2a3948"))
93+
cfg.progress_bar = window["-PROGRESS BAR-"]
94+
95+
return window
96+
97+
98+
def run_window(window):
99+
while True:
100+
event, values = window.read()
101+
102+
if event == "Exit" or event == sg.WIN_CLOSED:
103+
window.close()
104+
break
105+
106+
# print(event, values)
107+
108+
if event == "-MODS FOLDER-":
109+
mods_folder = values[event]
110+
if mods_folder != "":
111+
sg.user_settings_set_entry("mods_folder", get_folder_containing_mods(mods_folder))
112+
window[event](background_color=sg.theme_input_background_color())
113+
elif event == "-OUTPUT FOLDER-":
114+
output_folder = values[event]
115+
if output_folder != "":
116+
sg.user_settings_set_entry("output_folder", output_folder)
117+
window[event](background_color=sg.theme_input_background_color())
118+
elif event == "-OUTPUT ZIPS-":
112119
sg.user_settings_set_entry("output_zips", values["-OUTPUT ZIPS-"])
120+
elif event == "-PLAY FINISH SOUND-":
113121
sg.user_settings_set_entry("play_finish_sound", values["-PLAY FINISH SOUND-"])
114-
convert.main()
122+
elif event == "-CONVERT-":
123+
if sg.user_settings_get_entry("mods_folder") not in (None, "") and sg.user_settings_get_entry("output_folder") not in (None, ""):
124+
convert.main()
125+
elif event == "-GITHUB-":
126+
webbrowser.open("https://github.com/cortex-command-community/Cortex-Command-Legacy-Mod-Converter")
127+
elif event == "-DISCORD-":
128+
webbrowser.open("https://discord.gg/SdNnKJN")
129+
130+
131+
# init_window_theme()
132+
# run_window(init_window())

main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# from python import gui
2+
import gui
3+
4+
gui.init_window_theme()
5+
gui.run_window(gui.init_window())
File renamed without changes.

0 commit comments

Comments
 (0)