1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
#!/usr/bin/env python
# Copyright (C) 2013 Cristhofer Travieso <cristhofert97@gmail.com>
# 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
OPPONENT_CARDS = [None, None, None]
MY_CARDS = [None, None, None]
CARDS = []
class Eventbox(Gtk.EventBox):
def __init__(self):
Gtk.EventBox.__init__(self)
parse, color = Gdk.Color.parse('green')
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:
self.cards.append( str(random.randint(1, 12))+ random.choice(['coarse', 'cup', 'gold', 'sword']) )
num += 1
#card1
btn1 = Gtk.Button(self.cards[0])
btn1.connect('clicked', self._click)
self.my_box.pack_start(btn1, True, True, 0)
#card2
btn2 = Gtk.Button(self.cards[1])
btn2.connect('clicked', self._click)
self.my_box.pack_start(btn2, True, True, 0)
#card3
btn3 = Gtk.Button(self.cards[2])
btn3.connect('clicked', self._click)
self.my_box.pack_start(btn3, True, True, 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/' + self.cards[3] + '.svg')
self.opponent_box.pack_start(card1, True, True, 0)
#card_opponent 2
card2 = Gtk.Image()
card2.set_from_file('icons/cards/' + self.cards[4] + '.svg')
self.opponent_box.pack_start(card2, True, True, 0)
#card_opponent 3
card3 = Gtk.Image()
card3.set_from_file('icons/cards/' + self.cards[5] + '.svg')
self.opponent_box.pack_start(card3, True, True, 0)
def _click(self, widget):
self.my_box.remove(widget)
self.play_box.pack_start(widget, True, True, 0)
if __name__ == "__main__":
window = Gtk.Window()
window.connect('destroy', lambda w: Gtk.main_quit())
window.add(Eventbox())
window.maximize()
window.set_title('Truco')
window.show()
Gtk.main()
|