initial commit
This commit is contained in:
commit
6d16f5bf88
BIN
__pycache__/data.cpython-310.pyc
Normal file
BIN
__pycache__/data.cpython-310.pyc
Normal file
Binary file not shown.
BIN
__pycache__/menu.cpython-310.pyc
Normal file
BIN
__pycache__/menu.cpython-310.pyc
Normal file
Binary file not shown.
BIN
__pycache__/scenario.cpython-310.pyc
Normal file
BIN
__pycache__/scenario.cpython-310.pyc
Normal file
Binary file not shown.
BIN
__pycache__/team.cpython-310.pyc
Normal file
BIN
__pycache__/team.cpython-310.pyc
Normal file
Binary file not shown.
BIN
__pycache__/terrain.cpython-310.pyc
Normal file
BIN
__pycache__/terrain.cpython-310.pyc
Normal file
Binary file not shown.
38
data.py
Normal file
38
data.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
|
class Team:
|
||||||
|
def __init__(self, name, country):
|
||||||
|
self.name = name
|
||||||
|
self.country = country
|
||||||
|
self.players = []
|
||||||
|
|
||||||
|
def get_json_state(self):
|
||||||
|
return [self.name, self.country, self.players]
|
||||||
|
|
||||||
|
def addPlayer(self, name, army):
|
||||||
|
self.players.append(Player(name, army))
|
||||||
|
|
||||||
|
class TeamEncoder(json.JSONEncoder):
|
||||||
|
def default(self, obj):
|
||||||
|
if isinstance(obj, Team):
|
||||||
|
return obj.get_json_state()
|
||||||
|
else:
|
||||||
|
return json.JSONEncoder.default(self, obj)
|
||||||
|
|
||||||
|
class Player:
|
||||||
|
def __init__(self, name, army):
|
||||||
|
self.name = name
|
||||||
|
self.army = army
|
||||||
|
|
||||||
|
class Terrain:
|
||||||
|
def __init__(self, name):
|
||||||
|
self.name = name
|
||||||
|
|
||||||
|
class Scenario:
|
||||||
|
def __init__(self, defender, opponent):
|
||||||
|
self.defender = defender
|
||||||
|
self.opponent = opponent
|
||||||
|
self.terrains = []
|
||||||
|
|
||||||
|
def addTerrain(self, name):
|
||||||
|
self.terrains.append(Terrain(name))
|
1
data/team.json
Normal file
1
data/team.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"dd": {"name": "dd", "country": "ff"}}
|
56
main.py
Normal file
56
main.py
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
import team
|
||||||
|
import scenario
|
||||||
|
import terrain
|
||||||
|
from tkinter import *
|
||||||
|
from tkinter import ttk
|
||||||
|
|
||||||
|
# for child in container.winfo_children():
|
||||||
|
# child.grid_configure(padx=4, pady=5)
|
||||||
|
|
||||||
|
Screen = (team.TeamsPage, team.EditTeamPage, terrain.TerrainsPage, scenario.ScenarioPage)
|
||||||
|
|
||||||
|
class App(Tk):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
Tk.__init__(self, *args, **kwargs)
|
||||||
|
Tk.wm_title(self, "AoS Worlds Pairing Assistant")
|
||||||
|
Tk.option_add(self, "*tearOff", False)
|
||||||
|
|
||||||
|
container = ttk.Frame(self, padding="100 100 100 100")
|
||||||
|
container.pack()
|
||||||
|
container.columnconfigure(0, minsize=500, weight=1)
|
||||||
|
container.rowconfigure(0, minsize=300, weight=1)
|
||||||
|
|
||||||
|
self.frames = {}
|
||||||
|
|
||||||
|
for F in Screen:
|
||||||
|
frame = F(container, self)
|
||||||
|
self.frames[F] = frame
|
||||||
|
frame.grid(column=0, row=0, sticky=(N, W, E, S))
|
||||||
|
for child in frame.winfo_children():
|
||||||
|
child.grid_configure(padx=4, pady=5)
|
||||||
|
|
||||||
|
self.makeMenu()
|
||||||
|
self.showFrame(team.TeamsPage)
|
||||||
|
|
||||||
|
def makeMenu(self):
|
||||||
|
menubar = Menu(self)
|
||||||
|
|
||||||
|
menuScenarios = Menu(menubar)
|
||||||
|
menubar.add_cascade(menu=menuScenarios, label="Scenarios")
|
||||||
|
menuScenarios.add_command(label="New")#, command=scenario.getScreen)
|
||||||
|
menuScenarios.add_command(label="New from CSV")#, command=scenario.getScreen)
|
||||||
|
menuScenarios.add_command(label="Load")#, command=scenario.getScreen)
|
||||||
|
|
||||||
|
menuConfig = Menu(menubar)
|
||||||
|
menubar.add_cascade(menu=menuConfig, label="Configuration")
|
||||||
|
menuConfig.add_command(label="Teams", command=lambda: self.showFrame(team.TeamsPage))
|
||||||
|
menuConfig.add_command(label="Terrains", command=lambda: self.showFrame(terrain.TerrainsPage))
|
||||||
|
|
||||||
|
self['menu'] = menubar
|
||||||
|
|
||||||
|
def showFrame(self, screen):
|
||||||
|
frame = self.frames[screen]
|
||||||
|
frame.tkraise()
|
||||||
|
|
||||||
|
app = App()
|
||||||
|
app.mainloop()
|
30
scenario.py
Normal file
30
scenario.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
from tkinter import *
|
||||||
|
from tkinter import ttk
|
||||||
|
|
||||||
|
class ScenarioPage(Frame):
|
||||||
|
def __init__(self, parent, controller):
|
||||||
|
Frame.__init__(self, parent)
|
||||||
|
|
||||||
|
label = ttk.Label(self, text="Teams")
|
||||||
|
label.grid(column=1, row=1, sticky=E)
|
||||||
|
label.pack()
|
||||||
|
|
||||||
|
# button = ttk.Button(self, text="Import")
|
||||||
|
# button.grid(column=2, row=1, sticky=(W, E))
|
||||||
|
# button.pack
|
||||||
|
|
||||||
|
# ttk.Label(self, text="Terrains").grid(column=1, row=2, sticky=E)
|
||||||
|
# ttk.Button(self, text="Import from CSV").grid(column=2, row=2, sticky=(W, E))
|
||||||
|
|
||||||
|
# teamCount = StringVar(value=8)
|
||||||
|
# ttk.Label(self, text="Teams count").grid(column=1, row=3, sticky=E)
|
||||||
|
# teamCountEntry = ttk.Spinbox(self, textvariable=teamCount, from_=1, to=100).grid(column=2, row=3, sticky=(W, E))
|
||||||
|
|
||||||
|
# terrainCount = StringVar(value=4)
|
||||||
|
# terrainCountLabel = ttk.Label(self, text="Terrain count")
|
||||||
|
# terrainCountLabel.grid(column=1, row=4, sticky=E).pack()
|
||||||
|
|
||||||
|
|
||||||
|
# terrainCountEntry = ttk.Spinbox(self, textvariable=terrainCount, from_=1, to=100).grid(column=2, row=4, sticky=(W, E))
|
||||||
|
|
||||||
|
# ttk.Button(self, text="Test").grid(column=3, row=5, sticky=(W, E))
|
69
team.py
Normal file
69
team.py
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
import json
|
||||||
|
import os
|
||||||
|
# import data
|
||||||
|
from tkinter import *
|
||||||
|
from tkinter import ttk
|
||||||
|
|
||||||
|
def loadTeams():
|
||||||
|
path = "data/teams.json"
|
||||||
|
teams = {}
|
||||||
|
if os.path.exists(path):
|
||||||
|
teams = json.loads("data/teams.json")
|
||||||
|
return teams
|
||||||
|
|
||||||
|
class TeamsPage(Frame):
|
||||||
|
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()
|
||||||
|
team = {
|
||||||
|
"name": name,
|
||||||
|
"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
|
||||||
|
|
||||||
|
file = open("data/team.json", "w")
|
||||||
|
file.write(json.dumps(teams))
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
|
8
terrain.py
Normal file
8
terrain.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
from tkinter import *
|
||||||
|
from tkinter import ttk
|
||||||
|
|
||||||
|
class TerrainsPage(Frame):
|
||||||
|
def __init__(self, parent, controller):
|
||||||
|
Frame.__init__(self, parent)
|
||||||
|
|
||||||
|
ttk.Label(self, text="New Terrain").grid(column=1, row=1, sticky=E)
|
Loading…
Reference in New Issue
Block a user