From 8197345af25008fb0332559dd005c697377245f2 Mon Sep 17 00:00:00 2001 From: Arzaroth Lekva Date: Sun, 28 Dec 2014 03:19:56 +0900 Subject: [PATCH] ponies tab gui --- CelestiaSunrise.py | 2 +- src/__init__.py | 8 --- src/poniesframe.py | 155 +++++++++++++++++++++++++++++++++++++++++++++ src/ponygui.py | 11 +++- src/ponyshell.py | 14 ++-- 5 files changed, 173 insertions(+), 17 deletions(-) create mode 100644 src/poniesframe.py diff --git a/CelestiaSunrise.py b/CelestiaSunrise.py index 0abe60d..d614796 100755 --- a/CelestiaSunrise.py +++ b/CelestiaSunrise.py @@ -11,7 +11,7 @@ from docopt import docopt PRGM = os.path.basename(__file__) -VERSION = "0.6.1b" +VERSION = "0.6.4a" __doc__ = """ {prgm} {ver} diff --git a/src/__init__.py b/src/__init__.py index 35071b2..24ddfd3 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -6,18 +6,10 @@ # arzaroth@arzaroth.com # -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', ] diff --git a/src/poniesframe.py b/src/poniesframe.py new file mode 100644 index 0000000..2801ca3 --- /dev/null +++ b/src/poniesframe.py @@ -0,0 +1,155 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# File: poniesframe.py +# by Arzaroth Lekva +# arzaroth@arzaroth.com +# + +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('', 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] diff --git a/src/ponygui.py b/src/ponygui.py index 6045b6a..21a5958 100644 --- a/src/ponygui.py +++ b/src/ponygui.py @@ -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): @@ -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, @@ -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) diff --git a/src/ponyshell.py b/src/ponyshell.py index 7130281..3f1bf48 100644 --- a/src/ponyshell.py +++ b/src/ponyshell.py @@ -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):