pygo/pygo.py

118 lines
3.0 KiB
Python
Raw Normal View History

#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# A GTK Python GO client
import sys
sys.path.append('lib/')
sys.path.append('widgets/')
import goban
2012-04-16 17:00:56 +00:00
import config
import gtk, gtk.glade, gobject
import gogame
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.go_game = None
2012-04-16 17:00:56 +00:00
self.init_user_interface('./ui/default.glade')
self.init_widgets()
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')
self.games = self.tree.get_widget('games')
2012-04-16 17:00:56 +00:00
def init_widgets(self):
self.window.resize(800,600)
2012-04-16 17:00:56 +00:00
# gobject.timeout_add(1000, self.update)
# fixme - ctrl+shift+tab just does a shift+tab, even with the return True...
def on_key_pressed(self, widget, event):
key = gtk.gdk.keyval_name(event.keyval)
if key == 'Tab' and event.state & gtk.gdk.CONTROL_MASK:
if event.state & gtk.gdk.SHIFT_MASK:
self.do_prev_page()
else:
self.do_next_page()
return True
def on_game_close(self, widget):
if self.games.get_current_page() == -1:
return
self.games.remove_page(self.games.get_current_page())
2012-04-17 02:07:07 +00:00
def on_local_new(self, widget):
game = gogame.GoGame(goban.Goban())
self.games.append_page(game, gtk.Label('Local Game'))
self.games.set_tab_reorderable(game, True)
game.show_all()
game.winner_box.hide()
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 do_prev_page(self):
'''Goes to the previous tab page, but looping if this is the first'''
if self.games.get_current_page() == -1:
return
new_page = self.games.get_current_page() - 1
if new_page < 0:
new_page = self.games.get_n_pages() - 1
self.games.set_current_page(new_page)
def do_next_page(self):
'''Goes to the next tab page, but looping if this is the last'''
if self.games.get_current_page() == -1:
return
new_page = self.games.get_current_page() + 1
if new_page >= self.games.get_n_pages():
new_page = 0
self.games.set_current_page(new_page)
2012-04-16 17:00:56 +00:00
def main():
# Read config file
config.init()
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
if __name__ == '__main__': main()