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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
#Copyright (c) 2009, Walter Bender
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#The above copyright notice and this permission notice shall be included in
#all copies or substantial portions of the Software.
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#THE SOFTWARE.
import pygtk
pygtk.require('2.0')
import gtk
import gobject
import sugar
from sugar.activity import activity
try: # 0.86+ toolbar widgets
from sugar.bundle.activitybundle import ActivityBundle
from sugar.activity.widgets import ActivityToolbarButton
from sugar.activity.widgets import StopButton
from sugar.graphics.toolbarbox import ToolbarBox
from sugar.graphics.toolbarbox import ToolbarButton
from namingalert import NamingAlert
except ImportError:
pass
from sugar.graphics.toolbutton import ToolButton
from sugar.graphics.menuitem import MenuItem
from sugar.graphics.icon import Icon
from sugar.datastore import datastore
from gettext import gettext as _
import locale
import os.path
from sprites import *
import window
SERVICE = 'org.sugarlabs.VisualMatchActivity'
IFACE = SERVICE
PATH = '/org/augarlabs/VisualMatchActivity'
#
# Sugar activity
#
class VisualMatchActivity(activity.Activity):
def __init__(self, handle):
super(VisualMatchActivity,self).__init__(handle)
try:
# Use 0.86 toolbar design
toolbar_box = ToolbarBox()
# Buttons added to the Activity toolbar
activity_button = ActivityToolbarButton(self)
toolbar_box.toolbar.insert(activity_button, 0)
activity_button.show()
# Button 1
self.button1 = ToolButton( "button1off" )
self.button1.set_tooltip(_('New game'))
self.button1.props.sensitive = True
self.button1.connect('clicked', self._button1_cb, self)
toolbar_box.toolbar.insert(self.button1, -1)
self.button1.show()
separator = gtk.SeparatorToolItem()
separator.show()
toolbar_box.toolbar.insert(separator, -1)
# Label for showing status
self.results_label = gtk.Label(_("Look for a set"))
self.results_label.show()
results_toolitem = gtk.ToolItem()
results_toolitem.add(self.results_label)
toolbar_box.toolbar.insert(results_toolitem,-1)
separator = gtk.SeparatorToolItem()
separator.props.draw = False
separator.set_expand(True)
separator.show()
toolbar_box.toolbar.insert(separator, -1)
# Write in the Journal
journal_button = ToolButton( "journal-write" )
journal_button.set_tooltip(_('Write in Journal'))
journal_button.props.accelerator = '<Ctrl>j'
journal_button.connect('clicked', self._journal_cb,
activity.get_bundle_path())
toolbar_box.toolbar.insert(journal_button, -1)
journal_button.show()
# The ever-present Stop Button
stop_button = StopButton(self)
stop_button.props.accelerator = '<Ctrl>q'
toolbar_box.toolbar.insert(stop_button, -1)
stop_button.show()
self.set_toolbar_box(toolbar_box)
toolbar_box.show()
except NameError:
# Use pre-0.86 toolbar design
self.toolbox = activity.ActivityToolbox(self)
self.set_toolbox(self.toolbox)
self.projectToolbar = ProjectToolbar(self)
self.toolbox.add_toolbar( _('Project'), self.projectToolbar )
self.toolbox.show()
# Create a canvas
canvas = gtk.DrawingArea()
canvas.set_size_request(gtk.gdk.screen_width(), \
gtk.gdk.screen_height())
self.set_canvas(canvas)
canvas.show()
self.show_all()
# Initialize the canvas
self.tw = window.new_window(canvas, \
os.path.join(activity.get_bundle_path(), \
'images/card-'), \
self)
#
# Button callbacks
#
def _button1_cb(self, button, activity):
self.show_button1(activity.tw)
return True
def show_button1(self, tw):
self.button1.set_icon("button1on")
self.metadata['status'] = "one"
tw.deck.shuffle()
tw.deck.deal(tw)
# do something here
def _journal_cb(self, button, path):
title_alert = NamingAlert(self, path)
title_alert.set_transient_for(self.get_toplevel())
title_alert.show()
self.reveal()
return True
#
# Project toolbar for pre-0.86 toolbars
#
class ProjectToolbar(gtk.Toolbar):
def __init__(self, pc):
gtk.Toolbar.__init__(self)
self.activity = pc
# Button 1
self.activity.button1 = ToolButton( "button1off" )
self.activity.button1.set_tooltip(_('New game'))
self.activity.button1.props.sensitive = True
self.activity.button1.connect('clicked', self.activity._button1_cb,
self.activity)
self.insert(self.activity.button1, -1)
self.activity.button1.show()
# Label for showing status
self.activity.results_label = gtk.Label(\
_("look for a set"))
self.activity.results_label.show()
self.activity.results_toolitem = gtk.ToolItem()
self.activity.results_toolitem.add(self.activity.results_label)
self.insert(self.activity.results_toolitem, -1)
self.activity.results_toolitem.show()
|