From 966c6eb9e77a6043a06f216947c0797c4d87d1cd Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Tue, 17 Apr 2012 01:01:34 -0400 Subject: [PATCH] Started implementing a gogame class to handle GUI aspects of the board --- pygo.py | 3 +- {res => ui/res}/go_b.png | Bin {res => ui/res}/go_c.png | Bin {res => ui/res}/go_d.png | Bin {res => ui/res}/go_dl.png | Bin {res => ui/res}/go_dr.png | Bin {res => ui/res}/go_h.png | Bin {res => ui/res}/go_l.png | Bin {res => ui/res}/go_m.png | Bin {res => ui/res}/go_r.png | Bin {res => ui/res}/go_t.png | Bin {res => ui/res}/go_u.png | Bin {res => ui/res}/go_ul.png | Bin {res => ui/res}/go_ur.png | Bin {res => ui/res}/go_w.png | Bin widgets/gogame.py | 111 ++++++++++++++++++++++++++++++++++++++ 16 files changed, 113 insertions(+), 1 deletion(-) rename {res => ui/res}/go_b.png (100%) rename {res => ui/res}/go_c.png (100%) rename {res => ui/res}/go_d.png (100%) rename {res => ui/res}/go_dl.png (100%) rename {res => ui/res}/go_dr.png (100%) rename {res => ui/res}/go_h.png (100%) rename {res => ui/res}/go_l.png (100%) rename {res => ui/res}/go_m.png (100%) rename {res => ui/res}/go_r.png (100%) rename {res => ui/res}/go_t.png (100%) rename {res => ui/res}/go_u.png (100%) rename {res => ui/res}/go_ul.png (100%) rename {res => ui/res}/go_ur.png (100%) rename {res => ui/res}/go_w.png (100%) create mode 100644 widgets/gogame.py diff --git a/pygo.py b/pygo.py index b4cb093..e85d481 100755 --- a/pygo.py +++ b/pygo.py @@ -8,7 +8,7 @@ sys.path.append('lib/') import goban import config -import gtk, gtk.glade +import gtk, gtk.glade, gobject class Pygo(): @@ -47,6 +47,7 @@ class Pygo(): # fixme: create the go board widget and add it to our box here + def on_net_direct(self, widget): print 'stub: Pygo.on_menu_net_direct()' diff --git a/res/go_b.png b/ui/res/go_b.png similarity index 100% rename from res/go_b.png rename to ui/res/go_b.png diff --git a/res/go_c.png b/ui/res/go_c.png similarity index 100% rename from res/go_c.png rename to ui/res/go_c.png diff --git a/res/go_d.png b/ui/res/go_d.png similarity index 100% rename from res/go_d.png rename to ui/res/go_d.png diff --git a/res/go_dl.png b/ui/res/go_dl.png similarity index 100% rename from res/go_dl.png rename to ui/res/go_dl.png diff --git a/res/go_dr.png b/ui/res/go_dr.png similarity index 100% rename from res/go_dr.png rename to ui/res/go_dr.png diff --git a/res/go_h.png b/ui/res/go_h.png similarity index 100% rename from res/go_h.png rename to ui/res/go_h.png diff --git a/res/go_l.png b/ui/res/go_l.png similarity index 100% rename from res/go_l.png rename to ui/res/go_l.png diff --git a/res/go_m.png b/ui/res/go_m.png similarity index 100% rename from res/go_m.png rename to ui/res/go_m.png diff --git a/res/go_r.png b/ui/res/go_r.png similarity index 100% rename from res/go_r.png rename to ui/res/go_r.png diff --git a/res/go_t.png b/ui/res/go_t.png similarity index 100% rename from res/go_t.png rename to ui/res/go_t.png diff --git a/res/go_u.png b/ui/res/go_u.png similarity index 100% rename from res/go_u.png rename to ui/res/go_u.png diff --git a/res/go_ul.png b/ui/res/go_ul.png similarity index 100% rename from res/go_ul.png rename to ui/res/go_ul.png diff --git a/res/go_ur.png b/ui/res/go_ur.png similarity index 100% rename from res/go_ur.png rename to ui/res/go_ur.png diff --git a/res/go_w.png b/ui/res/go_w.png similarity index 100% rename from res/go_w.png rename to ui/res/go_w.png diff --git a/widgets/gogame.py b/widgets/gogame.py new file mode 100644 index 0000000..c7ee12d --- /dev/null +++ b/widgets/gogame.py @@ -0,0 +1,111 @@ +# This is a widget that handles a go game +# It needs a goban object, and handles it from beginning to end + +import goban +import gtk +import lib.options + + +class GoGame(gtk.HBox): + """ + This class draws a board and some information about the game (turn, captures, etc). + It also handles moves and other operations on the goban. + """ + + _img_res = None + + def __init__(self, goban): + self.HBox.__init__(self) + + if GoGame._img_res is None: + GoGame._img_res = _build_img_res() + + self.goban = goban + + self._init_widgets() + + + def _init_widgets(self): + self.board_area = gtk.DrawingArea() + + info_box = gtk.VBox() + info_rows = [gtk.VBox()] * 3 + to_move_label = gtk.Label('To Move:') + black_cap_label = gtk.Label('Black Captures:') + white_cap_label = gtk.Label('White Captures:') + + self.to_move_value = gtk.Label() + self.black_cap_value = gtk.Label() + self.white_cap_value = gtk.Label() + + info_rows[0].pack_start(to_move_label) + info_rows[1].pack_start(black_cap_label) + info_rows[2].pack_start(white_cap_label) + info_rows[0].pack_end(self.to_move_value) + info_rows[1].pack_end(self.black_cap_value) + info_rows[2].pack_end(self.white_cap_value) + + for row in info_rows: + info_box.pack_start(row) + + self.pass_button = gtk.Button('Pass') + self.resign_button = gtk.Button('Resign') + + info_box.pack_end(self.pass_button) + info_box.pack_end(self.resign_button) + + self.pack_start(self.board_area) + self.pack_end(info_box) + + + def _draw_board(self): + gc = self.board_area.get_style().fg_gc[gtk.STATE_NORMAL] + + # gtk.gdk.gdk_pixbuf_scale_simple(img, new_width, new_height, GDK_INTERP_BILINEAR) + + + + +# pixmap.draw_pixbuf(None, pixbuf, 0, 0, x, y, -1, -1, gtk.gdk.RGB_DITHER_NONE, 0, 0) + + + +def _magnitude(vector): + x,y = vector + return math.sqrt(x*x + y*y) + + +def _build_img_res(): + ret = {} + + triangle = _load_png('go_t.png') + + ret['w'] = _load_png('go_w.png') + ret['wT'] = _load_png('go_w.png') + # ret['wT'].blit(triangle, (0,0)) + ret['wH'] = _load_png('go_w.png', 128) + + ret['b'] = _load_png('go_b.png') + ret['bT'] = _load_png('go_b.png') + # ret['bT'].blit(triangle, (0,0)) + ret['bH'] = _load_png('go_b.png', 128) + + circle = _load_png('go_c.png') + + for d in ('u', 'd', 'l', 'r', 'm', 'dl', 'dr', 'ul', 'ur', 'h'): + ret[d] = _load_png('go_' + d + '.png') + ret[d + 'C'] = _load_png('go_' + d + '.png') + # ret[d + 'C'].blit(circle, (0,0)) + + return ret + + +def _load_png(name, alpha=None): + """ Load image and return image object""" + fullname = os.path.join('ui/res/', name) + image = gtk.gdk.pixbuf_new_from_file(fullname) + + # if alpha is not None: + # image.set_alpha(alpha) + + return image