pygo/pygo.py

82 lines
1.9 KiB
Python
Executable File

#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# A GTK Python GO client
import sys
sys.path.append('lib/')
sys.path.append('widgets/')
import goban
import config
import gtk, gtk.glade, gobject
import gogame
class Pygo():
"""This class handles the main interface, defines basic callbacks"""
def __init__(self):
self.resize = True
self.go_game = None
self.init_user_interface('./ui/default.glade')
self.init_widgets()
def init_user_interface(self, path_to_skin):
self.tree=gtk.glade.XML(path_to_skin, "window")
self.tree.signal_autoconnect(self)
self.window = self.tree.get_widget('window')
self.contents = self.tree.get_widget('main_box')
def init_widgets(self):
self.window.resize(1000,800)
self.gogame = None
# gobject.timeout_add(1000, self.update)
def on_game_close(self, widget):
if self.gogame:
self.contents.remove(self.gogame)
self.gogame = None
def on_local_new(self, widget):
# Remove any existing game
# fixme - we'll remove this later and add a new concurrent game instead
self.on_game_close(None)
self.gogame = gogame.GoGame(goban.Goban())
self.contents.pack_start(self.gogame)
self.gogame.show_all()
def on_net_direct(self, widget):
print 'stub: Pygo.on_menu_net_direct()'
def on_quit(self, widget):
sys.exit(0)
def main():
# Read config file
config.init()
# base_icon = gtk.gdk.pixbuf_new_from_file('ui/icon.svg')
# icon = base_icon.scale_simple(128, 128, gtk.gdk.INTERP_BILINEAR)
# gtk.window_set_default_icon(icon)
go_obj = Pygo()
# Let's see if we can avoid using threads in this implementation
# gtk.gdk.threads_init()
# gtk.gdk.threads_enter()
gtk.main()
# gtk.gdk.threads_leave()
if __name__ == '__main__': main()