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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import gtk
import pygame
from sugar.activity import activity
from sugar.graphics.toolbarbox import ToolbarBox
from sugar.activity.widgets import ActivityToolbarButton
from sugar.graphics.toolbutton import ToolButton
from sugar.activity.widgets import StopButton
from sugar.graphics.objectchooser import ObjectChooser
from gettext import gettext as _
import sugargame.canvas
import conozco
from points_list import Data
class Activity(activity.Activity):
def __init__(self, handle):
activity.Activity.__init__(self, handle)
self.init_vars()
self.build_toolbar()
self.actividad = conozco.Conozco(self)
self.build_canvas()
self.run_canvas()
self.show_all()
def init_vars(self):
self._image = None
self._places = {}
def build_toolbar(self):
self.max_participants = 1
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()
# new pic button
new_game = ToolButton('new-pic')
new_game.connect('clicked', self._new_picture)
new_game.set_tooltip(_('New picture'))
toolbar_box.toolbar.insert(new_game, -1)
# add / remove point buttons
add_point = ToolButton("row-insert")
add_point.connect("clicked", self._add_point)
add_point.set_tooltip(_("Add a point"))
toolbar_box.toolbar.insert(add_point, -1)
# separator and stop button
separator = gtk.SeparatorToolItem()
separator.props.draw = False
separator.set_expand(True)
toolbar_box.toolbar.insert(separator, -1)
separator.show()
stop_button = StopButton(self)
toolbar_box.toolbar.insert(stop_button, -1)
stop_button.show()
def build_canvas(self):
self.table = gtk.Table(1, 2, False)
self.box1 = gtk.HBox()
self.box1.set_size_request(350, 350)
self.box1.show()
self.box2 = gtk.HBox()
self.box2.set_size_request(50, 200)
self.box2.show()
self.table.attach(self.box1, 0, 1, 0, 1)
self.table.attach(self.box2, 1, 2, 0, 1)
# buttons to add
#table = gtk.Table(5, 3, False)
self.labels_and_values = Data(self)
self.box2.add(self.labels_and_values)
#self.box2.add(table)
self.set_canvas(self.table)
def run_canvas(self):
self._pygamecanvas = sugargame.canvas.PygameCanvas(self)
self.box1.add(self._pygamecanvas)
self._pygamecanvas.grab_focus()
self._pygamecanvas.run_pygame(self.actividad.principal)
def _new_picture(self, widget):
try:
chooser = ObjectChooser(parent=self)
except:
chooser = None
f = None
if chooser is not None:
result = chooser.run()
if result == gtk.RESPONSE_ACCEPT:
dsobject = chooser.get_selected_object()
f = dsobject.file_path
if f is not None:
self._image = pygame.image.load(f)
self.actividad.set_background(self._image)
#self.actividad.fondo = self._image
#self.actividad.pantalla.blit(self._image, (0, 0))
def _add_point(self, widget, label="", value="City"):
#data = (label, float(value))
#if not data in self.chart_data:
pos = self.labels_and_values.add_value(label, value)
print 'new pos', pos
self._places[pos] = [value, (0,0)]
#self.chart_data.insert(pos, data)
#self._update_chart_data()
def _add_coor(self, pos):
path = self.labels_and_values.update_selected_value(pos)
self._places[path][1] = pos
self._update_points()
def _update_points(self):
self.actividad.update_points(self._places)
def read_file(self, file_path):
pass
def write_file(self, file_path):
pass
|