2012-04-08 05:06:10 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# A GTK Python GO client
|
|
|
|
|
2012-04-13 20:53:57 +00:00
|
|
|
import sys
|
|
|
|
sys.path.append('lib/')
|
2012-04-17 05:21:39 +00:00
|
|
|
sys.path.append('widgets/')
|
2012-04-13 20:53:57 +00:00
|
|
|
|
|
|
|
import goban
|
2012-04-16 17:00:56 +00:00
|
|
|
import config
|
2012-04-17 05:01:34 +00:00
|
|
|
import gtk, gtk.glade, gobject
|
2012-04-17 05:21:39 +00:00
|
|
|
import gogame
|
2012-04-14 21:10:12 +00:00
|
|
|
|
2012-04-08 05:06:10 +00:00
|
|
|
|
2012-04-16 17:00:56 +00:00
|
|
|
class Pygo():
|
|
|
|
"""This class handles the main interface, defines basic callbacks"""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.resize = True
|
|
|
|
self.goban = None
|
2012-04-15 05:00:36 +00:00
|
|
|
|
2012-04-16 17:00:56 +00:00
|
|
|
self.network_mode = False
|
|
|
|
self.our_color = None
|
2012-04-15 03:42:56 +00:00
|
|
|
|
2012-04-16 17:00:56 +00:00
|
|
|
self.init_user_interface('./ui/default.glade')
|
2012-04-17 05:21:39 +00:00
|
|
|
self._init_widgets()
|
|
|
|
|
2012-04-10 00:55:09 +00:00
|
|
|
|
2012-04-16 17:00:56 +00:00
|
|
|
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')
|
2012-04-17 02:07:07 +00:00
|
|
|
self.contents = self.tree.get_widget('main_box')
|
2012-04-16 17:00:56 +00:00
|
|
|
|
|
|
|
|
2012-04-17 05:21:39 +00:00
|
|
|
def _init_widgets(self):
|
2012-04-16 17:00:56 +00:00
|
|
|
self.window.resize(1000,800)
|
2012-04-17 05:21:39 +00:00
|
|
|
self.gogame = None
|
2012-04-16 17:00:56 +00:00
|
|
|
# gobject.timeout_add(1000, self.update)
|
|
|
|
|
|
|
|
|
|
|
|
def on_local_new(self, widget):
|
2012-04-17 05:21:39 +00:00
|
|
|
if self.gogame:
|
|
|
|
self.contents.remove(self.gogame)
|
|
|
|
del self.gogame
|
2012-04-16 17:00:56 +00:00
|
|
|
if self.goban:
|
|
|
|
del self.goban
|
2012-04-17 05:21:39 +00:00
|
|
|
|
2012-04-16 17:00:56 +00:00
|
|
|
self.goban = goban.Goban()
|
|
|
|
self.network_mode = False
|
|
|
|
self.our_color = None
|
2012-04-17 02:07:07 +00:00
|
|
|
|
2012-04-17 05:21:39 +00:00
|
|
|
self.gogame = gogame.GoGame(self.goban)
|
|
|
|
self.contents.pack_start(self.gogame)
|
|
|
|
self.gogame.show_all()
|
|
|
|
|
2012-04-16 17:00:56 +00:00
|
|
|
|
|
|
|
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()
|
2012-04-08 05:06:10 +00:00
|
|
|
|
2012-04-16 17:00:56 +00:00
|
|
|
# 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()
|
2012-04-15 05:00:36 +00:00
|
|
|
|
2012-04-16 17:00:56 +00:00
|
|
|
# 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()
|
2012-04-15 05:00:36 +00:00
|
|
|
|
|
|
|
|
2012-04-08 05:06:10 +00:00
|
|
|
if __name__ == '__main__': main()
|