-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Zhou-Shilin/main
Add GUI support and fix some bugs
- Loading branch information
Showing
7 changed files
with
144 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
projects/* | ||
!projects/template/ | ||
generated/* | ||
|
||
logs/* | ||
test.py | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import sys | ||
import tkinter as tk | ||
import tkinter.messagebox as msgbox | ||
|
||
from log_writer import logger | ||
import core | ||
import config | ||
|
||
def get_schematic(description): | ||
""" | ||
Generates a schematic based on the given description. | ||
Args: | ||
description (str): The description of the schematic. | ||
Returns: | ||
str: The generated schematic. | ||
Raises: | ||
SystemExit: If the schematic generation fails. | ||
""" | ||
response = core.askgpt(config.SYS_GEN, config.USR_GEN.replace("%DESCRIPTION%", description), config.GENERATE_MODEL) | ||
|
||
schem = core.text_to_schem(response) | ||
|
||
if schem is None: | ||
msgbox.showerror("Error", "Failed to generate the schematic. We recommend you to change the generating model to gpt-4-turbo-preview or other smarter models.") | ||
sys.exit(1) | ||
|
||
return schem | ||
|
||
def generate_schematic(): | ||
""" | ||
Generates a schematic file based on user input. | ||
This function retrieves the version, name, and description from the user interface, | ||
initializes the core functionality, and generates a plugin based on the provided description. | ||
It then saves the generated schematic file in the 'generated' folder. | ||
Returns: | ||
None | ||
""" | ||
generate_button.config(state=tk.DISABLED, text="Generating...") | ||
|
||
version = version_entry.get() | ||
name = name_entry.get() | ||
description = description_entry.get() | ||
|
||
logger(f"console: input version {version}") | ||
logger(f"console: input name {name}") | ||
logger(f"console: input description {description}") | ||
|
||
schem = get_schematic(description) | ||
|
||
logger(f"console: Saving {name}.schem to generated/ folder.") | ||
version_tag = core.input_version_to_mcs_tag(version) | ||
|
||
while version_tag is None: | ||
msgbox.showerror("Error", "Invalid version number. Please retype the version number.") | ||
version = version_entry.get() | ||
version_tag = core.input_version_to_mcs_tag(version) | ||
|
||
schem.save("generated", name, version_tag) | ||
|
||
msgbox.showinfo("Success", "Generated. Get your schem file in folder generated.") | ||
|
||
generate_button.config(state=tk.NORMAL, text="Generate") | ||
|
||
def Application(): | ||
global version_entry, name_entry, description_entry, generate_button | ||
|
||
window = tk.Tk() | ||
window.title("BuilderGPT") | ||
|
||
logo = tk.PhotoImage(file="logo.png") | ||
logo = logo.subsample(4) | ||
logo_label = tk.Label(window, image=logo) | ||
logo_label.pack() | ||
|
||
version_label = tk.Label(window, text="What's your minecraft version? (eg. 1.20.1):") | ||
version_label.pack() | ||
version_entry = tk.Entry(window) | ||
version_entry.pack() | ||
|
||
name_label = tk.Label(window, text="What's the name of your structure? It will be the name of the generated *.schem file:") | ||
name_label.pack() | ||
name_entry = tk.Entry(window) | ||
name_entry.pack() | ||
|
||
description_label = tk.Label(window, text="What kind of structure would you like to generate? Describe as clear as possible:") | ||
description_label.pack() | ||
description_entry = tk.Entry(window) | ||
description_entry.pack() | ||
|
||
generate_button = tk.Button(window, text="Generate", command=generate_schematic) | ||
generate_button.pack() | ||
|
||
window.mainloop() | ||
|
||
if __name__ == "__main__": | ||
core.initialize() | ||
Application() | ||
else: | ||
print("Error: Please run ui.py as the main program instead of importing it from another program.") |