implement teams and terrains
This commit is contained in:
parent
06d98bfc61
commit
1868150e73
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1 +1 @@
|
||||
{"s": {"name": "s", "country": "s"}, "df": {"name": "df", "country": "fa"}, "dfdsfaf": {"name": "dfdsfaf", "country": "fa"}, "aaaaa": {"name": "aaaaa", "country": "ssss"}, "": {"name": "", "country": ""}}
|
||||
{"dfd": {"name": "dfd", "country": "fa", "members": []}, "dfaaa": {"name": "dfaaa", "country": "fa", "members": [{"name": "d", "army": "a"}, {"name": "fds", "army": "adfs"}]}, "Daniel": {"name": "Daniel", "country": "Austria", "members": []}, "Sarah": {"name": "Sarah", "country": "s", "members": []}, "dfg": {"name": "dfg", "country": "fdsa", "members": []}, "Test": {"name": "Test", "country": "asd", "members": []}}
|
1
data/terrain.json
Normal file
1
data/terrain.json
Normal file
@ -0,0 +1 @@
|
||||
{"fgddgfd": {"name": "fgddgfd"}}
|
3
main.py
3
main.py
@ -6,7 +6,6 @@ from tkinter import ttk
|
||||
|
||||
Screen = (
|
||||
team.TeamsPage,
|
||||
team.EditTeamPage,
|
||||
terrain.TerrainsPage,
|
||||
scenario.ScenarioPage
|
||||
)
|
||||
@ -17,7 +16,7 @@ class App(tk.Tk):
|
||||
tk.Tk.wm_title(self, "AoS Worlds Pairing Assistant")
|
||||
tk.Tk.option_add(self, "*tearOff", False)
|
||||
|
||||
container = ttk.Frame(self)#, padding="100 100 100 100")
|
||||
container = ttk.Frame(self, padding="100 100")
|
||||
container.pack()
|
||||
container.columnconfigure(0, minsize=500, weight=1)
|
||||
container.rowconfigure(0, minsize=300, weight=1)
|
||||
|
151
team.py
151
team.py
@ -5,60 +5,121 @@ from tkinter import ttk
|
||||
|
||||
path = "data/team.json"
|
||||
|
||||
def loadTeams():
|
||||
teams = {}
|
||||
if os.path.exists(path):
|
||||
file = open(path, "r")
|
||||
teams = json.loads(file.read())
|
||||
file.close()
|
||||
return teams
|
||||
|
||||
def saveTeam(name, country):
|
||||
teams = loadTeams()
|
||||
team = {
|
||||
"name": name,
|
||||
"country": country
|
||||
}
|
||||
teams[name] = team
|
||||
|
||||
file = open(path, "w")
|
||||
file.write(json.dumps(teams))
|
||||
file.close()
|
||||
|
||||
class TeamsPage(tk.Frame):
|
||||
def __init__(self, parent, controller):
|
||||
tk.Frame.__init__(self, parent)
|
||||
self.activeTeam = None
|
||||
|
||||
teams = loadTeams()
|
||||
self.teamKey = tk.StringVar()
|
||||
self.teamName = tk.StringVar()
|
||||
self.teamCountry = tk.StringVar()
|
||||
self.teamMembers = []
|
||||
|
||||
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"])
|
||||
self.teamSelector = ttk.Combobox(self, textvariable=self.teamKey)
|
||||
self.loadTeams()
|
||||
|
||||
self.teamSelector.grid(column=1, row=1, sticky="ew")
|
||||
self.teamSelector.bind("<<ComboboxSelected>>", self.setActiveTeam)
|
||||
|
||||
if len(self.teams) == 0:
|
||||
self.teamSelector.state(["readonly"])
|
||||
|
||||
tk.Button(self, text="New Team", command=lambda: controller.showFrame(EditTeamPage)).grid(column=1, row=2)#, sticky="ew")
|
||||
tk.Button(self, text="New Team", command=self.createTeam).grid(column=4, row=1, sticky="ew")
|
||||
|
||||
class EditTeamPage(tk.Frame):
|
||||
def __init__(self, parent, controller, team=None):
|
||||
tk.Frame.__init__(self, parent)
|
||||
tk.Label(self, text="Name:").grid(column=1, row=3)
|
||||
tk.Entry(self, textvariable=self.teamName).grid(column=2, row=3, sticky="ew")
|
||||
tk.Label(self, text="Country:").grid(column=1, row=4)
|
||||
tk.Entry(self, textvariable=self.teamCountry).grid(column=2, row=4, sticky="ew")
|
||||
tk.Label(self, text="Members:").grid(column=1, row=5)
|
||||
self.teamMembersGrid = ttk.Frame(self)
|
||||
self.teamMembersGrid.grid(column=2, row=5)
|
||||
|
||||
tk.Button(self, text="Save", command=self.saveTeam).grid(column=2, row=6)
|
||||
|
||||
def createTeam(self):
|
||||
self.activeTeam = None
|
||||
self.teamSelector.selection_clear()
|
||||
|
||||
self.teamName.set("")
|
||||
self.teamCountry.set("")
|
||||
self.teamMembers = []
|
||||
self.renderTeamMembers()
|
||||
|
||||
def loadTeams(self):
|
||||
self.teams = {}
|
||||
self.teamSelector["values"] = []
|
||||
if os.path.exists(path):
|
||||
file = open(path, "r")
|
||||
self.teams = json.loads(file.read())
|
||||
file.close()
|
||||
self.teamSelector["values"] = list(self.teams.keys())
|
||||
|
||||
def saveTeam(self):
|
||||
key = self.teamKey.get()
|
||||
name = self.teamName.get()
|
||||
country = self.teamCountry.get()
|
||||
members = self.teamMembers
|
||||
|
||||
if name != "" and country != "":
|
||||
self.loadTeams()
|
||||
team = {
|
||||
"name": name,
|
||||
"country": country,
|
||||
"members": members
|
||||
}
|
||||
|
||||
if key != "" and key != name:
|
||||
del self.teams[key]
|
||||
self.teamKey.set(name)
|
||||
|
||||
self.teams[name] = team
|
||||
|
||||
file = open(path, "w")
|
||||
file.write(json.dumps(self.teams))
|
||||
file.close()
|
||||
self.loadTeams()
|
||||
|
||||
def setActiveTeam(self, event):
|
||||
if self.teamKey.get() != "":
|
||||
self.activeTeam = self.teams[self.teamKey.get()]
|
||||
self.teamName.set(self.activeTeam["name"])
|
||||
self.teamCountry.set(self.activeTeam["country"])
|
||||
self.teamMembers = self.activeTeam["members"]
|
||||
|
||||
self.renderTeamMembers()
|
||||
else:
|
||||
self.teamSelector.selection_clear()
|
||||
|
||||
teamName = tk.StringVar()
|
||||
teamCountry = tk.StringVar()
|
||||
def renderTeamMembers(self):
|
||||
self.teamMembersGrid.destroy()
|
||||
self.teamMembersGrid = ttk.Frame(self)
|
||||
self.teamMembersGrid.grid(column=2, row=5)
|
||||
|
||||
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)
|
||||
row = 1
|
||||
for m in self.teamMembers:
|
||||
tk.Label(self.teamMembersGrid, text=m["name"]).grid(column=1, row=row)
|
||||
tk.Label(self.teamMembersGrid, text=m["army"]).grid(column=2, row=row)
|
||||
tk.Button(self.teamMembersGrid, text="X", command=lambda: self.removeTeamMember(m)).grid(column=3, row=row)
|
||||
row += 1
|
||||
|
||||
tk.Button(parent, text="Save", command=lambda: saveTeam(teamName.get(), teamCountry.get()))#.grid(column=2, row=3)
|
||||
self.newTeamMemberName = tk.StringVar()
|
||||
self.newTeamMemberArmy = tk.StringVar()
|
||||
|
||||
tk.Entry(self.teamMembersGrid, textvariable=self.newTeamMemberName).grid(column=1, row=row)
|
||||
tk.Entry(self.teamMembersGrid, textvariable=self.newTeamMemberArmy).grid(column=2, row=row)
|
||||
tk.Button(self.teamMembersGrid, text="+", command=self.addTeamMember).grid(column=3, row=row)
|
||||
|
||||
def addTeamMember(self):
|
||||
name = self.newTeamMemberName.get()
|
||||
army = self.newTeamMemberArmy.get()
|
||||
if name != "" and army != "":
|
||||
self.teamMembers.append({
|
||||
"name": name,
|
||||
"army": army,
|
||||
})
|
||||
|
||||
self.renderTeamMembers()
|
||||
|
||||
def removeTeamMember(self, member):
|
||||
self.teamMembers.remove(member)
|
||||
self.renderTeamMembers()
|
68
terrain.py
68
terrain.py
@ -1,7 +1,73 @@
|
||||
import json
|
||||
import os
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
|
||||
path = "data/terrain.json"
|
||||
|
||||
class TerrainsPage(tk.Frame):
|
||||
def __init__(self, parent, controller):
|
||||
tk.Frame.__init__(self, parent)
|
||||
self.activeTerrain = None
|
||||
|
||||
self.terrainKey = tk.StringVar()
|
||||
self.terrainName = tk.StringVar()
|
||||
|
||||
self.terrainSelector = ttk.Combobox(self, textvariable=self.terrainKey)
|
||||
self.loadTerrains()
|
||||
|
||||
self.terrainSelector.grid(column=1, row=1, sticky="ew")
|
||||
self.terrainSelector.bind("<<ComboboxSelected>>", self.setActiveTerrain)
|
||||
|
||||
if len(self.terrains) == 0:
|
||||
self.terrainSelector.state(["readonly"])
|
||||
|
||||
tk.Label(self, text="New Terrain").grid(column=1, row=1)
|
||||
tk.Button(self, text="New Terrain", command=self.createTerrain).grid(column=4, row=1, sticky="ew")
|
||||
|
||||
tk.Label(self, text="Name:").grid(column=1, row=3)
|
||||
tk.Entry(self, textvariable=self.terrainName).grid(column=2, row=3, sticky="ew")
|
||||
|
||||
tk.Button(self, text="Save", command=self.saveTerrain).grid(column=2, row=6)
|
||||
|
||||
def createTerrain(self):
|
||||
self.activeTerrain = None
|
||||
self.terrainSelector.selection_clear()
|
||||
self.terrainName.set("")
|
||||
|
||||
def loadTerrains(self):
|
||||
self.terrains = {}
|
||||
self.terrainSelector["values"] = []
|
||||
if os.path.exists(path):
|
||||
file = open(path, "r")
|
||||
self.terrains = json.loads(file.read())
|
||||
file.close()
|
||||
self.terrainSelector["values"] = list(self.terrains.keys())
|
||||
|
||||
def saveTerrain(self):
|
||||
key = self.terrainKey.get()
|
||||
name = self.terrainName.get()
|
||||
|
||||
if name != "":
|
||||
self.loadTerrains()
|
||||
terrain = {
|
||||
"name": name
|
||||
}
|
||||
|
||||
if key != "" and key != name:
|
||||
del self.terrains[key]
|
||||
self.terrainKey.set(name)
|
||||
|
||||
self.terrains[name] = terrain
|
||||
|
||||
file = open(path, "w")
|
||||
file.write(json.dumps(self.terrains))
|
||||
file.close()
|
||||
self.loadTerrains()
|
||||
|
||||
def setActiveTerrain(self, event):
|
||||
if self.terrainKey.get() != "":
|
||||
self.activeTerrain = self.terrains[self.terrainKey.get()]
|
||||
self.terrainName.set(self.activeTerrain["name"])
|
||||
|
||||
else:
|
||||
self.terrainSelector.selection_clear()
|
Loading…
Reference in New Issue
Block a user