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

Commit

Permalink
ponies tab gui
Browse files Browse the repository at this point in the history
  • Loading branch information
Arzaroth Lekva committed Dec 27, 2014
1 parent bf6c4d8 commit 8197345
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CelestiaSunrise.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from docopt import docopt

PRGM = os.path.basename(__file__)
VERSION = "0.6.1b"
VERSION = "0.6.4a"

__doc__ = """
{prgm} {ver}
Expand Down
8 changes: 0 additions & 8 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,10 @@
# [email protected]
#

from src.savemanager import (SaveManager, SaveError,
decompress_data, compress_data)
from src.xmlhandler import XmlHandler
from src.ponyshell import PonyShell
from src.gui import Gui

__all__ = [
'SaveManager',
'SaveError',
'decompress_data',
'compress_data',
'XmlHandler',
'PonyShell',
'Gui',
]
155 changes: 155 additions & 0 deletions src/poniesframe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# File: poniesframe.py
# by Arzaroth Lekva
# [email protected]
#

from tkinter import (Frame, Canvas,
Label, Scrollbar, Scale, Checkbutton, OptionMenu,
IntVar, BooleanVar, StringVar)
from tkinter.constants import (N, S, E, W,
NW, NSEW,
VERTICAL, HORIZONTAL,
Y, LEFT, RIGHT,
ALL,
NORMAL, DISABLED)
from src.utility import Pony

class PonyFrame(object):

def __init__(self, parent,
name, level,
shards, next_game,
offset):
self.parent = parent

self._pony_label = Label(self.parent,
text=name)
self._level = Scale(self.parent,
from_=0, to=5,
orient=HORIZONTAL,
command=self._level_change)
self._level.set(level)
self._level_up = BooleanVar(self.parent,
shards == 10)
self._shards = Checkbutton(self.parent,
variable=self._level_up)
self._next_game = StringVar(self.parent,
next_game)
self._option_next = OptionMenu(self.parent,
self._next_game,
Pony.GameTypes.rmap[Pony.GameTypes.Ball],
Pony.GameTypes.rmap[Pony.GameTypes.Apple],
Pony.GameTypes.rmap[Pony.GameTypes.Book])

options = dict(padx=16, pady=2)
self._pony_label.grid(row=offset, column=0, sticky=W, **options)
self._level.grid(row=offset, column=1, sticky=NSEW, **options)
self._shards.grid(row=offset, column=2, sticky=NSEW, **options)
self._option_next.grid(row=offset, column=3, sticky=NSEW, **options)

def _level_change(self, *args):
if self.level == 5:
self._shards.configure(state=DISABLED)
self.level_up = False
else:
self._shards.configure(state=NORMAL)

@property
def level(self):
return int(self._level.get())

@level.setter
def level(self, new_val):
self._level.set(new_val)

@property
def level_up(self):
return self._level_up.get()

@level_up.setter
def level_up(self, new_val):
self._level_up.set(new_val and self.level != 5)

@property
def next_game(self):
return self._next_game.get()

@next_game.setter
def next_game(self, new_val):
self._next_game.set(new_val)


class EveryponyFrame(PonyFrame):

def __init__(self, ponies, *args):
super(EveryponyFrame, self).__init__(*args)
self._ponies = ponies
self._level_change_first_call = False
self._level_up.trace("w", self._shards_change)
self._next_game.trace("w", self._next_game_change)

def _level_change(self, *args):
super(EveryponyFrame, self)._level_change(*args)
if self._level_change_first_call:
for pony in self._ponies.values():
pony.level = self.level
self._shards_change(self)
else:
self._level_change_first_call = True

def _shards_change(self, *args):
for pony in self._ponies.values():
pony.level_up = self.level_up

def _next_game_change(self, *args):
for pony in self._ponies.values():
pony.next_game = self.next_game


class PoniesFrame(Frame):

def __init__(self, parent, xml_handle):
super(PoniesFrame, self).__init__(parent)
self._canvas = Canvas(self)
self._ponies_frame = Frame(self._canvas)

self._scrollb = Scrollbar(self, orient=VERTICAL, command=self._canvas.yview)
self._scrollb.pack(side=RIGHT, fill=Y)

self._canvas.configure(yscrollcommand=self._scrollb.set)
self._canvas.pack(side=LEFT)
self._canvas.create_window((0, 0), window=self._ponies_frame,
anchor=NW, tags="self._ponies_frame")

self._ponies_frame.bind('<Configure>', self._scroll_func)

self._xml_handle = xml_handle

options = dict(sticky=NSEW, padx=16, pady=2)
Label(self._ponies_frame, text="Level").grid(row=0, column=1, **options)
Label(self._ponies_frame, text="Trigger next level").grid(row=0, column=2, **options)
Label(self._ponies_frame, text="Next minigame").grid(row=0, column=3, **options)
self._ponies = {}
for n, pony in enumerate(self._xml_handle.ponies.values()):
self._ponies[pony.ID] = PonyFrame(self._ponies_frame,
pony.name, pony.level,
pony.shards, pony.next_game,
n + 2)
self._everypony = EveryponyFrame(self._ponies, self._ponies_frame,
"Everypony", 0,
0, Pony.GameTypes.rmap[Pony.GameTypes.Ball],
1)

def _scroll_func(self, event):
self._canvas.configure(scrollregion=self._canvas.bbox(ALL),
height=500,
width=550)

def commit(self):
for pony in self._xml_handle.ponies.values():
pony.level = self._ponies[pony.ID].level
pony.shards = 10 if self._ponies[pony.ID].level_up else 0
pony.next_game = Pony.GameTypes.map[self._ponies[pony.ID].next_game]
11 changes: 8 additions & 3 deletions src/ponygui.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
from tkinter.messagebox import showerror
from src.basegui import BaseGui
from src.currenciesframe import CurrenciesFrame
from src.poniesframe import PoniesFrame
from src.zonesframe import ZonesFrame
from src import SaveManager, SaveError
from src import decompress_data, compress_data
from src import XmlHandler
from src.savemanager import (SaveManager, SaveError,
decompress_data, compress_data)
from src.xmlhandler import XmlHandler

class LoadingDialog(Toplevel):

Expand Down Expand Up @@ -68,8 +69,11 @@ def _create_frames(self):
super(PonyGui, self)._create_frames()
self._currencies_frame = CurrenciesFrame(self, self._xml_handle)
self._zones_frame = ZonesFrame(self, self._xml_handle)
self._ponies_frame = PoniesFrame(self, self._xml_handle)
self._notebook.add(self._currencies_frame,
text="Currencies")
self._notebook.add(self._ponies_frame,
text="Ponies")
self._notebook.add(self._zones_frame,
text="Zones")
self._save_button = Button(self,
Expand Down Expand Up @@ -97,6 +101,7 @@ def _save(self):
else:
loadingbox = LoadingDialog(self)
self._currencies_frame.commit()
self._ponies_frame.commit()
self._zones_frame.commit()
try:
self._save_manager.save(compress_data(repr(self._xml_handle)
Expand Down
14 changes: 9 additions & 5 deletions src/ponyshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
import base64
from cmd import Cmd
from pprint import pprint
from src import SaveManager, SaveError
from src import decompress_data, compress_data
from src import XmlHandler
from src.docopt_utils import docopt_cmd
from src.savemanager import (SaveManager, SaveError,
decompress_data, compress_data)
from src.xmlhandler import XmlHandler
from src.utility import Pony
from src.show import *
from src.set import *
from src.show import (show_currencies, show_currency,
show_ponies, show_pony,
show_zones, show_zone)
from src.set import (set_currency,
set_ponies, set_pony,
set_zones, set_zone)

class PonyShell(Cmd):

Expand Down

0 comments on commit 8197345

Please sign in to comment.