#!/usr/bin/env python # Copyright (C) 2013 Cristhofer Travieso # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA from gi.repository import Gtk from gi.repository import Gdk from gi.repository import GObject import os import random WIDTH = 1200 HEIGHT = 700 class Eventbox(Gtk.EventBox): def __init__(self): Gtk.EventBox.__init__(self) #773525 parse, color = Gdk.Color.parse('#773525') self.modify_bg(Gtk.StateType.NORMAL, color) self.add(Box()) self.show_all() class Box(Gtk.VBox): def __init__(self): Gtk.VBox.__init__(self) self.cards = [] #opponent box self.opponent_box = Gtk.HBox() self.pack_start(self.opponent_box, True, True, 0) #play box self.play_box = Gtk.HBox() self.pack_start(self.play_box, True, True, 0) #my box self.my_box = Gtk.HBox() self.pack_start(self.my_box, True, True, 0) self._deal() def _deal(self): num = 0 while num < 7: l = [1, 2, 3, 4, 5, 6, 7, 10, 11, 12] self.cards.append( str(random.choice(l))+ random.choice(['coarse', 'cup', 'gold', 'sword']) ) num += 1 #card1 btn1 = Gtk.Button() img1 = Gtk.Image() img1.set_from_file('icons/cards/' + self.cards[0] + '.svg') btn1.add(img1) btn1.connect('clicked', self._click) self.my_box.pack_start(btn1, True, False, 0) #card2 btn2 = Gtk.Button() img2 = Gtk.Image() img2.set_from_file('icons/cards/' + self.cards[1] + '.svg') btn2.add(img2) btn2.connect('clicked', self._click) self.my_box.pack_start(btn2, True, False, 0) #card3 btn3 = Gtk.Button() img3 = Gtk.Image() img3.set_from_file('icons/cards/' + self.cards[2] + '.svg') btn3.add(img3) btn3.connect('clicked', self._click) self.my_box.pack_start(btn3, True, False, 0) #deck deck = Gtk.Image() deck.set_from_file('icons/cards/back.svg') self.play_box.pack_start(deck, False, False, 0) #sample sample = Gtk.Image() sample.set_from_file('icons/cards/' + self.cards[6] + '.svg') self.play_box.pack_start(sample, False, False, 0) #card_opponent 1 card1 = Gtk.Image() card1.set_from_file('icons/cards/back.svg') self.opponent_box.pack_start(card1, True, True, 0) #card_opponent 2 card2 = Gtk.Image() card2.set_from_file('icons/cards/back.svg') self.opponent_box.pack_start(card2, True, True, 0) #card_opponent 3 card3 = Gtk.Image() card3.set_from_file('icons/cards/back.svg') self.opponent_box.pack_start(card3, True, True, 0) def _click(self, widget): children = self.play_box.get_children() if len(children) > 2: self.play_box.remove(children[-1]) self.play_box.remove(children[-2]) self.my_box.remove(widget) self.play_box.pack_start(widget, True, False, 0) self.opponent_box.remove(random.choice(self.opponent_box.get_children())) img = Gtk.Image() c = random.choice(self.cards[3: 5]) img.set_from_file('icons/cards/' + c + '.svg') self.play_box.pack_start(img, True, False, 0) img.show()