Skip to content
This repository has been archived by the owner on Apr 28, 2023. It is now read-only.

Commit

Permalink
Untested Commit
Browse files Browse the repository at this point in the history
Removed useless files, compressed and rewrote most of tkdesigner code to be more efficient
  • Loading branch information
Emaryllis committed Apr 28, 2023
1 parent 1ee3925 commit 5e261f7
Show file tree
Hide file tree
Showing 16 changed files with 317 additions and 880 deletions.
37 changes: 12 additions & 25 deletions Main Project/battleGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,15 @@ def battleGUI(player):
window = Tk()
window.geometry('600x600')
window.configure(bg='#FFFFFF')
canvas = Canvas(window, bg='#FFFFFF', height=600, width=600,
bd=0, highlightthickness=0, relief='ridge')
canvas = Canvas(window, bg='#FFFFFF', height=600, width=600,bd=0, highlightthickness=0, relief='ridge')
canvas.place(x=0, y=0)

# Background
background = PhotoImage(file=path('bg.png', ['assets']))
canvas.create_image(300, 300, image=background)

# Render pokemon images
playerPokemonImg = flipImg(imgCreator(
playerPokemons[playerPokeCount-1].name, True))
playerPokemonImg = flipImg(imgCreator(playerPokemons[playerPokeCount-1].name, True))
playerPokemonId = canvas.create_image(107, 107, image=playerPokemonImg)
compPokemonImg = imgCreator(compPokemons[compPokeCount-1].name)
compPokemonId = canvas.create_image(492, 107, image=compPokemonImg)
Expand All @@ -58,10 +56,8 @@ def battleGUI(player):
fill='#000', font=('Inter', -28))
# HP variables
hp = {
'player': canvas.create_text(228, 61, anchor='nw', text='100/100',
fill='#040243', font=('Inter', -30)),
'comp': canvas.create_text(228, 153, anchor='nw', text='100/100',
fill='#040243', font=('Inter', -30))
'player': canvas.create_text(228, 61, anchor='nw', text='100/100', fill='#040243', font=('Inter', -30)),
'comp': canvas.create_text(228, 153, anchor='nw', text='100/100',fill='#040243', font=('Inter', -30))
}

# Ability Buttons
Expand All @@ -80,9 +76,7 @@ def battleGUI(player):

# History box
canvas.create_rectangle(0, 394, 600, 600, fill='#D9D9D9', outline='')
history = [
canvas.create_text(1, 372.5 + 22.5 * i, anchor='nw', text=f'History line {i}',
fill='#000000', font=('Inter', -22))for i in range(1, 10)
history = [canvas.create_text(1, 372.5 + 22.5 * i, anchor='nw', text=f'History line {i}', fill='#000000', font=('Inter', -22))for i in range(1, 10)
]
window.resizable(False, False)

Expand All @@ -102,10 +96,8 @@ def useAbility(no: int):
# Player damage algorithm
dmgDealt = int(playerAbilities[playerPokeCount-1][no-1]['power']) + randint(0, int(playerPokemons[playerPokeCount-1].stats[1])*int(
playerPokemons[playerPokeCount-1].stats[3])) if random() < int(playerAbilities[playerPokeCount-1][no-1]['accuracy'])/100 else 0
info(
f"(Player) {playerPokemons[playerPokeCount-1].name}'s {playerAbilities[playerPokeCount-1][no-1]['name']} dealt {dmgDealt} dmg!")
historyUpdate(
f"(Player) {playerPokemons[playerPokeCount-1].name}'s {playerAbilities[playerPokeCount-1][no-1]['name']} dealt {dmgDealt} dmg!")
info(f"(Player) {playerPokemons[playerPokeCount-1].name}'s {playerAbilities[playerPokeCount-1][no-1]['name']} dealt {dmgDealt} dmg!")
historyUpdate(f"(Player) {playerPokemons[playerPokeCount-1].name}'s {playerAbilities[playerPokeCount-1][no-1]['name']} dealt {dmgDealt} dmg!")
compCurrHp = int(canvas.itemcget(
hp['comp'], 'text').split('/')[0])-dmgDealt
# If computer hp goes below 0
Expand All @@ -116,8 +108,7 @@ def useAbility(no: int):
f'(Comp) {compPokemons[compPokeCount-1].name} has fainted.')
if compPokeCount >= 3:
gameOver = True
canvas.itemconfig(
hp['comp'], text=f"0/{int(canvas.itemcget(hp['comp'], 'text').split('/')[1])}")
canvas.itemconfig(hp['comp'], text=f"0/{int(canvas.itemcget(hp['comp'], 'text').split('/')[1])}")
info('(Comp) Computer has no usable pokemon. Player wins!')
return historyUpdate('(Comp) Computer has no usable pokemon. Player wins!')
compPokeCount += 1 # Increase counter by 1
Expand All @@ -133,8 +124,7 @@ def useAbility(no: int):
if random() < int(compAbilities[compPokeCount-1][randomAbility-1]['accuracy'])/100:
dmgDealt = int(compAbilities[compPokeCount-1][randomAbility-1]['power']) + randint(0, int(compPokemons[compPokeCount-1].stats[1])*int(
compPokemons[compPokeCount-1].stats[3]))
else:
dmgDealt = 0
else:dmgDealt = 0
info(f"(Comp) {compPokemons[compPokeCount-1].name}'s {compAbilities[compPokeCount-1][randomAbility-1]['name']} dealt {dmgDealt} dmg!")
historyUpdate(
f"(Comp) {compPokemons[compPokeCount-1].name}'s {compAbilities[compPokeCount-1][randomAbility-1]['name']} dealt {dmgDealt} dmg!")
Expand All @@ -148,8 +138,7 @@ def useAbility(no: int):
f'(Player) {playerPokemons[playerPokeCount-1].name} has fainted.')
if playerPokeCount >= 3:
gameOver = True
canvas.itemconfig(
hp['player'], text=f"0/{int(canvas.itemcget(hp['player'], 'text').split('/')[1])}")
canvas.itemconfig(hp['player'], text=f"0/{int(canvas.itemcget(hp['player'], 'text').split('/')[1])}")
info('(Player) Player has no usable pokemon. Computer wins!')
return historyUpdate('(Player) Player has no usable pokemon. Computer wins!')
playerPokeCount += 1 # Increase counter by 1
Expand All @@ -169,14 +158,12 @@ def initPokemon(no: int, trainer: str): # sourcery skip: remove-pass-elif, swit
# Set current hp to max hp
playerCurrHp = int(playerPokemons[no-1].stats[0])*100
# Update hp text
canvas.itemconfig(
hp['player'], text=f'{playerCurrHp}/{playerCurrHp}')
canvas.itemconfig(hp['player'], text=f'{playerCurrHp}/{playerCurrHp}')
canvas.update()

elif trainer == 'comp':
compCurrHp = int(compPokemons[no-1].stats[0])*100
canvas.itemconfig(
hp['comp'], text=f'{compCurrHp}/{compCurrHp}')
canvas.itemconfig(hp['comp'], text=f'{compCurrHp}/{compCurrHp}')
canvas.update()


Expand Down
5 changes: 1 addition & 4 deletions Main Project/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,5 @@
logging.info(f'Pokemon Trainer Name: {playerName}')
startGUI(playerName, time(), pokemons)
player=getPlayer()
# player = Player('John Doe')
# player.pokemons = [pokemons[1], pokemons[2], pokemons[3]]
logging.info(
f'Player {player.name} has chosen {player.pokemons[0].name}, {player.pokemons[1].name}, {player.pokemons[2].name} as their pokemons.')
logging.info(f'Player {player.name} has chosen {player.pokemons[0].name}, {player.pokemons[1].name}, {player.pokemons[2].name} as their pokemons.')
battleGUI(player)
24 changes: 0 additions & 24 deletions Main Project/info.txt

This file was deleted.

231 changes: 62 additions & 169 deletions Tkinter Designer/gui/gui.py
Original file line number Diff line number Diff line change
@@ -1,183 +1,76 @@
import webbrowser
import re
import sys
import os
import tkinter as tk
import tkinter.messagebox as tk1
import tkinter.filedialog
from pathlib import Path

# Add tkdesigner to path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
try:
from tkdesigner.designer import Designer
except ModuleNotFoundError:
raise RuntimeError("Couldn't add tkdesigner to the PATH.")


# Path to asset files for this GUI window.
ASSETS_PATH = Path(__file__).resolve().parent / "assets"

# Required in order to add data files to Windows executable
path = getattr(sys, '_MEIPASS', os.getcwd())
import re,sys,os,tkinter as tk,tkinter.messagebox as tk1,tkinter.filedialog;from pathlib import Path
sys.path.insert(0,str(Path(__file__).resolve().parent.parent)),
try:from tkdesigner.designer import Designer
except ModuleNotFoundError:raise RuntimeError('Couldn\'t add tkdesigner to the PATH.')
ASSETS_PATH=Path(__file__).resolve().parent/'assets'
path=getattr(sys,'_MEIPASS',os.getcwd())
os.chdir(path)

output_path = ""


output_path=''
def btn_clicked():
token = token_entry.get()
URL = URL_entry.get()
output_path = path_entry.get()
output_path = output_path.strip()

token=token_entry.get()
URL=URL_entry.get()
output_path=path_entry.get()
output_path=output_path.strip()
if not token:
tk.messagebox.showerror(
title="Empty Fields!", message="Please enter Token.")
tk.messagebox.showerror(title='Empty Fields!',message='Please enter Token.')
return
if not URL:
tk.messagebox.showerror(
title="Empty Fields!", message="Please enter URL.")
tk.messagebox.showerror(title='Empty Fields!',message='Please enter URL.')
return
if not output_path:
tk.messagebox.showerror(
title="Invalid Path!", message="Enter a valid output path.")
tk.messagebox.showerror( title='Invalid Path!',message='Enter a valid output path.')
return

match = re.search(
r'https://www.figma.com/file/([0-9A-Za-z]+)', URL.strip())
match=re.search(r'https://www.figma.com/file/([0-9A-Za-z]+)',URL.strip())
if match is None:
tk.messagebox.showerror(
"Invalid URL!", "Please enter a valid file URL.")
tk.messagebox.showerror('Invalid URL!','Please enter a valid file URL.')
return

file_key = match.group(1).strip()
token = token.strip()
output = Path(output_path + "/build").expanduser().resolve()

if output.exists() and not output.is_dir():
tk1.showerror(
"Exists!",
f"{output} already exists and is not a directory.\n"
"Enter a valid output directory.")
elif output.exists() and output.is_dir() and tuple(output.glob('*')):
response = tk1.askyesno(
"Continue?",
f"Directory {output} is not empty.\n"
"Do you want to continue and overwrite?")
if not response:
return

designer = Designer(token, file_key, output)
designer.design()

tk.messagebox.showinfo(
"Success!", f"Project successfully generated at {output}.")


file_key=match[1].strip()
token=token.strip()
output=Path(output_path+'/build').expanduser().resolve()
if output.exists() and not output.is_dir():tk1.showerror(f'Exists! {output} already exists and is not a directory.\nEnter a valid output directory.')
elif output.exists()and output.is_dir()and tuple(output.glob('*')):
if not tk1.askyesno(f'Continue? Directory {output} is not empty.\nDo you want to continue and overwrite?'): return
Designer(token,file_key,output).design()
tk.messagebox.showinfo('Success!',f'Project successfully generated at {output}.')
def select_path():
global output_path

output_path = tk.filedialog.askdirectory()
path_entry.delete(0, tk.END)
path_entry.insert(0, output_path)


def make_label(master, x, y, h, w, *args, **kwargs):
f = tk.Frame(master, height=h, width=w)
f.pack_propagate(0) # don't shrink
f.place(x=x, y=y)

label = tk.Label(f, *args, **kwargs)
label.pack(fill=tk.BOTH, expand=1)

return label


window = tk.Tk()
logo = tk.PhotoImage(file=ASSETS_PATH / "iconbitmap.gif")
window.call('wm', 'iconphoto', window._w, logo)
window.title("Tkinter Designer")

window.geometry("862x519")
window.configure(bg="#3A7FF6")
canvas = tk.Canvas(
window, bg="#3A7FF6", height=519, width=862,
bd=0, highlightthickness=0, relief="ridge")
canvas.place(x=0, y=0)
canvas.create_rectangle(431, 0, 431 + 431, 0 + 519, fill="#FCFCFC", outline="")
canvas.create_rectangle(40, 160, 40 + 60, 160 + 5, fill="#FCFCFC", outline="")

text_box_bg = tk.PhotoImage(file=ASSETS_PATH / "TextBox_Bg.png")
token_entry_img = canvas.create_image(650.5, 167.5, image=text_box_bg)
URL_entry_img = canvas.create_image(650.5, 248.5, image=text_box_bg)
filePath_entry_img = canvas.create_image(650.5, 329.5, image=text_box_bg)

token_entry = tk.Entry(bd=0, bg="#F6F7F9",fg="#000716", highlightthickness=0)
token_entry.place(x=490.0, y=137+25, width=321.0, height=35)
output_path=tk.filedialog.askdirectory()
path_entry.delete(0,tk.END)
path_entry.insert(0,output_path)
def make_label(master,x,y,h,w,*args,**kwargs):
f=tk.Frame(master,height=h,width=w)
f.pack_propagate(0)
f.place(x=x,y=y)
return tk.Label(f,*args,**kwargs).pack(fill=tk.BOTH,expand=1)
window=tk.Tk()
logo=tk.PhotoImage(file=ASSETS_PATH/'iconbitmap.gif')
window.call('wm','iconphoto',window._w,logo)
window.title('Tkinter Designer')
window.geometry('862x519')
window.configure(bg='#3A7FF6')
canvas=tk.Canvas(window,bg='#3A7FF6',height=519,width=862,bd=0,highlightthickness=0,relief='ridge')
canvas.place(x=0,y=0)
canvas.create_rectangle(431,0,862,519,fill='#FCFCFC',outline='')
canvas.create_rectangle(40,160,100,160 + 5,fill='#FCFCFC',outline='')
tk.PhotoImage(file=ASSETS_PATH/'TextBox_Bg.png')
canvas.create_image(650.5,167.5,image=text_box_bg)
canvas.create_image(650.5,248.5,image=text_box_bg)
canvas.create_image(650.5,329.5,image=text_box_bg)
token_entry=tk.Entry(bd=0,bg='#F6F7F9',fg='#000716',highlightthickness=0)
token_entry.place(x=490.0,y=137+25,width=321.0,height=35)
token_entry.focus()

URL_entry = tk.Entry(bd=0, bg="#F6F7F9", fg="#000716", highlightthickness=0)
URL_entry.place(x=490.0, y=218+25, width=321.0, height=35)

path_entry = tk.Entry(bd=0, bg="#F6F7F9", fg="#000716", highlightthickness=0)
path_entry.place(x=490.0, y=299+25, width=321.0, height=35)

path_picker_img = tk.PhotoImage(file = ASSETS_PATH / "path_picker.png")
path_picker_button = tk.Button(
image = path_picker_img,
text = '',
compound = 'center',
fg = 'white',
borderwidth = 0,
highlightthickness = 0,
command = select_path,
relief = 'flat')

path_picker_button.place(
x = 783, y = 319,
width = 24,
height = 22)

canvas.create_text(
490.0, 156.0, text="Token ID", fill="#515486",
font=("Arial-BoldMT", int(13.0)), anchor="w")
canvas.create_text(
490.0, 234.5, text="File URL", fill="#515486",
font=("Arial-BoldMT", int(13.0)), anchor="w")
canvas.create_text(
490.0, 315.5, text="Output Path",
fill="#515486", font=("Arial-BoldMT", int(13.0)), anchor="w")
canvas.create_text(
646.5, 428.5, text="Generate",
fill="#FFFFFF", font=("Arial-BoldMT", int(13.0)))
canvas.create_text(
573.5, 88.0, text="Enter the details.",
fill="#515486", font=("Arial-BoldMT", int(22.0)))

title = tk.Label(
text="Welcome to Tkinter Designer", bg="#3A7FF6",
fg="white", font=("Arial-BoldMT", int(20.0)))
title.place(x=27.0, y=120.0)

info_text = tk.Label(
text="Tkinter Designer uses the Figma API\n"
"to analyse a design file, then creates\n"
"the respective code and files needed\n"
"for your GUI.\n\n"

"Even this GUI was created\n"
"using Tkinter Designer.",
bg="#3A7FF6", fg="white", justify="left",
font=("Georgia", int(16.0)))

info_text.place(x=27.0, y=200.0)

generate_btn_img = tk.PhotoImage(file=ASSETS_PATH / "generate.png")
generate_btn = tk.Button(
image=generate_btn_img, borderwidth=0, highlightthickness=0,
command=btn_clicked, relief="flat")
generate_btn.place(x=557, y=401, width=180, height=55)

window.resizable(False, False)
tk.Entry(bd=0,bg='#F6F7F9',fg='#000716',highlightthickness=0).place(x=490.0,y=218+25,width=321.0,height=35)
tk.Entry(bd=0,bg='#F6F7F9',fg='#000716',highlightthickness=0).place(x=490.0,y=299+25,width=321.0,height=35)
path_picker_img=tk.PhotoImage(file=ASSETS_PATH / 'path_picker.png')
tk.Button(image=path_picker_img,text='',compound='center',fg='white',borderwidth=0,highlightthickness=0,command=select_path,relief='flat').place(x=783,y=319,width=24,height=22)
canvas.create_text(490.0,156.0,text='Token ID',fill='#515486',font=('Arial-BoldMT',int(13.0)),anchor='w')
canvas.create_text(490.0,234.5,text='File URL',fill='#515486',font=('Arial-BoldMT',int(13.0)),anchor='w')
canvas.create_text(490.0,315.5,text='Output Path',fill='#515486',font=('Arial-BoldMT',int(13.0)),anchor='w')
canvas.create_text(646.5,428.5,text='Generate',fill='#FFFFFF',font=('Arial-BoldMT',int(13.0)))
canvas.create_text(573.5,88.0,text='Enter the details.',fill='#515486',font=('Arial-BoldMT',int(22.0)))
tk.Label(text='Welcome to Tkinter Designer',bg='#3A7FF6',fg='white',font=('Arial-BoldMT',int(20.0))).place(x=27.0,y=120.0)
tk.Label(text='Tkinter Designer uses the Figma API\nto analyse a design file,then creates\nthe respective code and files needed\nfor your GUI.\n\nEven this GUI was created\nusing Tkinter Designer.',bg='#3A7FF6',fg='white',justify='left',font=('Georgia',int(16.0))).place(x=27.0,y=200.0)
generate_btn_img=tk.PhotoImage(file=ASSETS_PATH / 'generate.png')
tk.Button(image=generate_btn_img,borderwidth=0,highlightthickness=0,command=btn_clicked,relief='flat').place(x=557,y=401,width=180,height=55)
window.resizable(False,False)
window.mainloop()
Loading

0 comments on commit 5e261f7

Please sign in to comment.