-
Notifications
You must be signed in to change notification settings - Fork 4
/
activity.py
131 lines (99 loc) · 3.65 KB
/
activity.py
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
121
122
123
124
125
126
127
128
129
130
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import GObject
import pygame
from sugar3.activity import activity
from sugar3.graphics.toolbarbox import ToolbarBox
from sugar3.activity.widgets import ActivityToolbarButton
from sugar3.activity.widgets import StopButton
from sugar3.activity.widgets import ToolButton
from gettext import gettext as _
import sugargame.canvas
import jump
class JumpActivity(activity.Activity):
def __init__(self, handle):
activity.Activity.__init__(self, handle)
self.sound_enable = True
self.game = jump.SolitaireMain()
self.build_toolbar()
self.game.canvas = self._pygamecanvas = \
sugargame.canvas.PygameCanvas(self,
main=self.game.SuperLooper,
modules=[pygame.display, pygame.font, pygame.mixer])
self.set_canvas(self._pygamecanvas)
self._pygamecanvas.grab_focus()
def build_toolbar(self):
toolbar_box = ToolbarBox()
self.set_toolbar_box(toolbar_box)
toolbar_box.show()
activity_button = ActivityToolbarButton(self)
toolbar_box.toolbar.insert(activity_button, -1)
activity_button.show()
separator1 = Gtk.SeparatorToolItem()
separator1.props.draw = True
separator1.set_expand(False)
toolbar_box.toolbar.insert(separator1, -1)
separator1.show()
item1 = Gtk.ToolItem()
label1 = Gtk.Label()
label1.set_text(_('Levels') + ' ')
item1.add(label1)
toolbar_box.toolbar.insert(item1, -1)
item2 = Gtk.ToolItem()
levels = (_('Cross'),
_('Cross 2'),
#TRANS:'chimney' - the place where you make fire
_('Hearth'),
_('Arrow'),
_('Pyramid'),
_('Diamond'),
_('Solitaire'))
combo = Combo(levels)
item2.add(combo)
combo.connect('changed', self.change_combo)
toolbar_box.toolbar.insert(item2, -1)
separator2 = Gtk.SeparatorToolItem()
separator2.props.draw = True
separator2.set_expand(False)
toolbar_box.toolbar.insert(separator2, -1)
separator2.show()
sound_button = ToolButton('speaker-muted-100')
sound_button.set_tooltip(_('Sound'))
sound_button.connect('clicked', self.sound_control)
toolbar_box.toolbar.insert(sound_button, -1)
separator3 = Gtk.SeparatorToolItem()
separator3.props.draw = False
separator3.set_expand(True)
toolbar_box.toolbar.insert(separator3, -1)
separator3.show()
stop_button = StopButton(self)
toolbar_box.toolbar.insert(stop_button, -1)
stop_button.show()
self.show_all()
def change_combo(self, combo):
level = combo.get_active()
self.game.change_level(level)
def sound_control(self, button):
self.sound_enable = not self.sound_enable
self.game.change_sound(self.sound_enable)
if not self.sound_enable:
button.set_icon_name('speaker-muted-000')
button.set_tooltip(_('No sound'))
else:
button.set_icon_name('speaker-muted-100')
button.set_tooltip(_('Sound'))
class Combo(Gtk.ComboBox):
def __init__(self, options):
self.liststore = Gtk.ListStore(str)
for o in options:
self.liststore.append([o])
Gtk.ComboBox.__init__(self)
self.set_model(self.liststore)
cell = Gtk.CellRendererText()
self.pack_start(cell, True)
self.add_attribute(cell, 'text', 0)
self.set_active(0)