fix loading from file
This commit is contained in:
parent
6d16f5bf88
commit
06d98bfc61
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1 +1 @@
|
|||||||
{"dd": {"name": "dd", "country": "ff"}}
|
{"s": {"name": "s", "country": "s"}, "df": {"name": "df", "country": "fa"}, "dfdsfaf": {"name": "dfdsfaf", "country": "fa"}, "aaaaa": {"name": "aaaaa", "country": "ssss"}, "": {"name": "", "country": ""}}
|
32
main.py
32
main.py
@ -1,21 +1,23 @@
|
|||||||
import team
|
import team
|
||||||
import scenario
|
import scenario
|
||||||
import terrain
|
import terrain
|
||||||
from tkinter import *
|
import tkinter as tk
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
|
|
||||||
# for child in container.winfo_children():
|
Screen = (
|
||||||
# child.grid_configure(padx=4, pady=5)
|
team.TeamsPage,
|
||||||
|
team.EditTeamPage,
|
||||||
|
terrain.TerrainsPage,
|
||||||
|
scenario.ScenarioPage
|
||||||
|
)
|
||||||
|
|
||||||
Screen = (team.TeamsPage, team.EditTeamPage, terrain.TerrainsPage, scenario.ScenarioPage)
|
class App(tk.Tk):
|
||||||
|
|
||||||
class App(Tk):
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
Tk.__init__(self, *args, **kwargs)
|
tk.Tk.__init__(self, *args, **kwargs)
|
||||||
Tk.wm_title(self, "AoS Worlds Pairing Assistant")
|
tk.Tk.wm_title(self, "AoS Worlds Pairing Assistant")
|
||||||
Tk.option_add(self, "*tearOff", False)
|
tk.Tk.option_add(self, "*tearOff", False)
|
||||||
|
|
||||||
container = ttk.Frame(self, padding="100 100 100 100")
|
container = ttk.Frame(self)#, padding="100 100 100 100")
|
||||||
container.pack()
|
container.pack()
|
||||||
container.columnconfigure(0, minsize=500, weight=1)
|
container.columnconfigure(0, minsize=500, weight=1)
|
||||||
container.rowconfigure(0, minsize=300, weight=1)
|
container.rowconfigure(0, minsize=300, weight=1)
|
||||||
@ -25,23 +27,23 @@ class App(Tk):
|
|||||||
for F in Screen:
|
for F in Screen:
|
||||||
frame = F(container, self)
|
frame = F(container, self)
|
||||||
self.frames[F] = frame
|
self.frames[F] = frame
|
||||||
frame.grid(column=0, row=0, sticky=(N, W, E, S))
|
frame.grid(column=0, row=0, sticky="nsew")
|
||||||
for child in frame.winfo_children():
|
for child in frame.winfo_children():
|
||||||
child.grid_configure(padx=4, pady=5)
|
child.grid_configure(padx=5, pady=5)
|
||||||
|
|
||||||
self.makeMenu()
|
self.makeMenu()
|
||||||
self.showFrame(team.TeamsPage)
|
self.showFrame(team.TeamsPage)
|
||||||
|
|
||||||
def makeMenu(self):
|
def makeMenu(self):
|
||||||
menubar = Menu(self)
|
menubar = tk.Menu(self)
|
||||||
|
|
||||||
menuScenarios = Menu(menubar)
|
menuScenarios = tk.Menu(menubar)
|
||||||
menubar.add_cascade(menu=menuScenarios, label="Scenarios")
|
menubar.add_cascade(menu=menuScenarios, label="Scenarios")
|
||||||
menuScenarios.add_command(label="New")#, command=scenario.getScreen)
|
menuScenarios.add_command(label="New")#, command=scenario.getScreen)
|
||||||
menuScenarios.add_command(label="New from CSV")#, command=scenario.getScreen)
|
menuScenarios.add_command(label="New from CSV")#, command=scenario.getScreen)
|
||||||
menuScenarios.add_command(label="Load")#, command=scenario.getScreen)
|
menuScenarios.add_command(label="Load")#, command=scenario.getScreen)
|
||||||
|
|
||||||
menuConfig = Menu(menubar)
|
menuConfig = tk.Menu(menubar)
|
||||||
menubar.add_cascade(menu=menuConfig, label="Configuration")
|
menubar.add_cascade(menu=menuConfig, label="Configuration")
|
||||||
menuConfig.add_command(label="Teams", command=lambda: self.showFrame(team.TeamsPage))
|
menuConfig.add_command(label="Teams", command=lambda: self.showFrame(team.TeamsPage))
|
||||||
menuConfig.add_command(label="Terrains", command=lambda: self.showFrame(terrain.TerrainsPage))
|
menuConfig.add_command(label="Terrains", command=lambda: self.showFrame(terrain.TerrainsPage))
|
||||||
|
11
scenario.py
11
scenario.py
@ -1,13 +1,10 @@
|
|||||||
from tkinter import *
|
import tkinter as tk
|
||||||
from tkinter import ttk
|
|
||||||
|
|
||||||
class ScenarioPage(Frame):
|
class ScenarioPage(tk.Frame):
|
||||||
def __init__(self, parent, controller):
|
def __init__(self, parent, controller):
|
||||||
Frame.__init__(self, parent)
|
tk.Frame.__init__(self, parent)
|
||||||
|
|
||||||
label = ttk.Label(self, text="Teams")
|
tk.Label(self, text="Teams").grid(column=1, row=1)
|
||||||
label.grid(column=1, row=1, sticky=E)
|
|
||||||
label.pack()
|
|
||||||
|
|
||||||
# button = ttk.Button(self, text="Import")
|
# button = ttk.Button(self, text="Import")
|
||||||
# button.grid(column=2, row=1, sticky=(W, E))
|
# button.grid(column=2, row=1, sticky=(W, E))
|
||||||
|
93
team.py
93
team.py
@ -1,69 +1,64 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
# import data
|
import tkinter as tk
|
||||||
from tkinter import *
|
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
|
|
||||||
|
path = "data/team.json"
|
||||||
|
|
||||||
def loadTeams():
|
def loadTeams():
|
||||||
path = "data/teams.json"
|
|
||||||
teams = {}
|
teams = {}
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
teams = json.loads("data/teams.json")
|
file = open(path, "r")
|
||||||
|
teams = json.loads(file.read())
|
||||||
|
file.close()
|
||||||
return teams
|
return teams
|
||||||
|
|
||||||
class TeamsPage(Frame):
|
def saveTeam(name, country):
|
||||||
def __init__(self, parent, controller):
|
|
||||||
Frame.__init__(self, parent)
|
|
||||||
|
|
||||||
teams = loadTeams()
|
|
||||||
|
|
||||||
teamKey = StringVar()
|
|
||||||
teamSelector = ttk.Combobox(self, textvariable=teamKey, values=list(teams.keys()))
|
|
||||||
teamSelector.grid(column=1, row=1, sticky=(E, W))
|
|
||||||
if len(teams) == 0:
|
|
||||||
teamSelector.state(["readonly"])
|
|
||||||
|
|
||||||
ttk.Button(self, text="New Team").grid(column=1, row=2, sticky=(E, W))
|
|
||||||
|
|
||||||
class EditTeamPage(Frame):
|
|
||||||
def __init__(self, parent, controller, team=None):
|
|
||||||
Frame.__init__(self, parent)
|
|
||||||
|
|
||||||
teamName = StringVar()
|
|
||||||
teamCountry = StringVar()
|
|
||||||
|
|
||||||
if (team != None):
|
|
||||||
teamName.set(team.name)
|
|
||||||
teamCountry.set(team.value)
|
|
||||||
# teamName.trace_add("write", callback=lambda val: team.__setattr__("name", val))
|
|
||||||
# teamCountry.trace_add("write", callback=lambda val: team.__setattr__("country", val))
|
|
||||||
|
|
||||||
ttk.Label(parent, text="Name:").grid(column=1, row=1, sticky=(E, W))
|
|
||||||
ttk.Entry(parent, textvariable=teamName).grid(column=2, row=1, sticky=(E, W))
|
|
||||||
ttk.Label(parent, text="Country:").grid(column=1, row=2, sticky=(E, W))
|
|
||||||
ttk.Entry(parent, textvariable=teamCountry).grid(column=2, row=2, sticky=(E, W))
|
|
||||||
|
|
||||||
ttk.Button(parent, text="Save", command=lambda: self.save(teamName.get(), teamCountry.get())).grid(column=2, row=3, sticky=(E, W))
|
|
||||||
|
|
||||||
def save(self, name, country):
|
|
||||||
teams = loadTeams()
|
teams = loadTeams()
|
||||||
team = {
|
team = {
|
||||||
"name": name,
|
"name": name,
|
||||||
"country": country
|
"country": country
|
||||||
}
|
}
|
||||||
|
|
||||||
# existing = False
|
|
||||||
# for t in teams:
|
|
||||||
# if t.name == teams.name:
|
|
||||||
# t = team
|
|
||||||
# existing = True
|
|
||||||
# if not existing:
|
|
||||||
# teams.append(team)
|
|
||||||
|
|
||||||
teams[name] = team
|
teams[name] = team
|
||||||
|
|
||||||
file = open("data/team.json", "w")
|
file = open(path, "w")
|
||||||
file.write(json.dumps(teams))
|
file.write(json.dumps(teams))
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
|
class TeamsPage(tk.Frame):
|
||||||
|
def __init__(self, parent, controller):
|
||||||
|
tk.Frame.__init__(self, parent)
|
||||||
|
|
||||||
|
teams = loadTeams()
|
||||||
|
|
||||||
|
teamKey = tk.StringVar()
|
||||||
|
teamSelector = ttk.Combobox(self, textvariable=teamKey, values=list(teams.keys()))
|
||||||
|
teamSelector.grid(column=1, row=1)#, sticky="ew")
|
||||||
|
if len(teams) == 0:
|
||||||
|
teamSelector.state(["readonly"])
|
||||||
|
|
||||||
|
tk.Button(self, text="New Team", command=lambda: controller.showFrame(EditTeamPage)).grid(column=1, row=2)#, sticky="ew")
|
||||||
|
|
||||||
|
class EditTeamPage(tk.Frame):
|
||||||
|
def __init__(self, parent, controller, team=None):
|
||||||
|
tk.Frame.__init__(self, parent)
|
||||||
|
|
||||||
|
teamName = tk.StringVar()
|
||||||
|
teamCountry = tk.StringVar()
|
||||||
|
|
||||||
|
if (team != None):
|
||||||
|
teamName.set(team.name)
|
||||||
|
teamCountry.set(team.value)
|
||||||
|
|
||||||
|
label = tk.Label(parent, text="Name:")
|
||||||
|
# .grid(column=0, row=1)
|
||||||
|
label.pack()
|
||||||
|
entry = tk.Entry(parent, textvariable=teamName)
|
||||||
|
# .grid(column=0, row=0)
|
||||||
|
entry.pack()
|
||||||
|
tk.Label(parent, text="Country:").grid(column=0, row=2)
|
||||||
|
tk.Entry(parent, textvariable=teamCountry).grid(column=0, row=2)
|
||||||
|
|
||||||
|
tk.Button(parent, text="Save", command=lambda: saveTeam(teamName.get(), teamCountry.get()))#.grid(column=2, row=3)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
from tkinter import *
|
import tkinter as tk
|
||||||
from tkinter import ttk
|
|
||||||
|
|
||||||
class TerrainsPage(Frame):
|
class TerrainsPage(tk.Frame):
|
||||||
def __init__(self, parent, controller):
|
def __init__(self, parent, controller):
|
||||||
Frame.__init__(self, parent)
|
tk.Frame.__init__(self, parent)
|
||||||
|
|
||||||
ttk.Label(self, text="New Terrain").grid(column=1, row=1, sticky=E)
|
tk.Label(self, text="New Terrain").grid(column=1, row=1)
|
Loading…
Reference in New Issue
Block a user