Skip to content

Commit

Permalink
use TTApp from ttlib
Browse files Browse the repository at this point in the history
  • Loading branch information
duelafn committed May 11, 2012
1 parent 739ae17 commit 9804223
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 41 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
package_data={'ttgo': list(ttgo_package_data)},
install_requires=[
"Kivy >= 1.2.0",
"TabletopLib >= 0.1.0",
"TabletopLib >= 0.2.1",
],
)
55 changes: 16 additions & 39 deletions ttgo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@
import os.path

ttgo_parent_dir = (os.path.split(__file__))[0]
def ttgo_dir(path=None):
if path is None:
return os.path.join(ttgo_parent_dir)
else:
return os.path.join(ttgo_parent_dir, path)
def ttgo_dir(*path):
return os.path.join(ttgo_parent_dir, *path)


import glob
Expand All @@ -25,6 +22,7 @@ def ttgo_dir(path=None):
from kivy.core.window import Window
from kivy.logger import Logger

from ttlib.ttapp import TTApp

from ttgo.gogame import GoGame
from ttgo.kvwidgets import NewGame
Expand All @@ -34,29 +32,16 @@ def ttgo_dir(path=None):
import ttgo.playerpad


class TTGoApp(App):
class TTGoApp(TTApp):
title = "TTGo"
icon = ttgo_dir('data/ttgo.png')

def build(self):
kivy.resources.resource_add_path(ttgo_dir("data/glyphicons"))
kivy.resources.resource_add_path(ttgo_dir("data/themes/" + self.config.get('ttgo', 'theme')))
self.goto_screen("new")

def on_start(self):
Window.bind(on_key_down=self.on_key_down)

def on_key_down(self, win, key, scancode, string, modifiers):
if key == 292:
win.toggle_fullscreen()
win.update_viewport()
return True
elif key == 27:
if self.screen == "new":
exit()
else:
self.goto_screen("new")
return True
def data_dir(self, *args):
return os.path.join(ttgo_parent_dir, 'data', *args)

def __init__(self, *arg, **kwargs):
self.app_name = 'ttgo'
super(TTGoApp,self).__init__(*arg, **kwargs)

def start_game(self, size):
try:
Expand All @@ -66,11 +51,12 @@ def start_game(self, size):
self.goto_screen("game", size=size)

def goto_screen(self, screen_name, **opt):
self.root.clear_widgets()
super(TTGoApp,self).goto_screen(screen_name, **opt)

if screen_name == "new":
widget = NewGame( app=self, size=self.root.size )
widget = NewGame( app=self )
elif screen_name == "game":
widget = GoGame(app=self, points=opt['size'], size=self.root.size)
widget = GoGame(app=self, points=opt['size'])
self.root.add_widget( widget )
self.screen = screen_name

Expand All @@ -79,18 +65,9 @@ def build_config(self, config):
'theme': 'default'
})

def on_config_change(self, config, section, key, value):
if config is self.config:
token = (section, key)
if token == ('ttgo', 'theme'):
print( 'changed to theme:', value )

def build_settings(self, settings):
jsondata = """
[ { "type": "title",
"title": "TTGo"
},
[
{ "type": "options",
"title": "Theme",
"desc": "Board and go piece theme",
Expand All @@ -100,4 +77,4 @@ def build_settings(self, settings):
}
]
"""
settings.add_json_panel('TTGo application', self.config, data=jsondata)
settings.add_json_panel('TTGo', self.config, data=jsondata)
2 changes: 2 additions & 0 deletions ttgo/newgame.kv
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#:kivy 1.0

<NewGame>
size_hint: (1, 1)

BoxLayout:
orientation: "vertical"
spacing: 10
Expand Down
2 changes: 1 addition & 1 deletion ttgo/ttgo.kv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#:kivy 1.0

# Root widget - boring
AnchorLayout:
FloatLayout:

0 comments on commit 9804223

Please sign in to comment.