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
|
# sugar_and_spock.py - proof verification activity based upon ghilbert
# -*- coding: UTF-8 -*-
#
# ... and everything knock ;-)
from sugar.activity import activity
from sugar.graphics.toolbutton import ToolButton
import spock
import gtk
import ghilbert
import sys, os, array
from gettext import gettext as _
class EditToolbar(gtk.Toolbar):
def __init__(self, shpock):
gtk.Toolbar.__init__(self)
self.shpock = shpock
# system-search
self.find = ToolButton('system-search')
self.find.set_tooltip(_('Find'))
self.insert(self.find, -1)
self.find.props.accelerator = _('<Ctrl>F')
self.find.connect('clicked', self._find_cb)
self.find.show()
# go-next
self.find_next = ToolButton('go-next')
self.find_next.set_tooltip(_('Find next occurrence'))
self.insert(self.find_next, -1)
self.find_next.props.accelerator = _('<Alt>N')
self.find_next.connect('clicked', self._find_next_cb)
self.find_next.show()
# go-previous
self.find_prev = ToolButton('go-previous')
self.find_prev.set_tooltip(_('Find previous occurrence'))
self.insert(self.find_prev, -1)
self.find_prev.props.accelerator = _('<Alt>P')
self.find_prev.connect('clicked', self._find_prev_cb)
self.find_prev.show()
def _find_next_cb(self, widget):
spock = self.shpock.spockObj
spock.search_op(True)
def _find_prev_cb(self, widget):
spock = self.shpock.spockObj
spock.search_op(False)
def _find_cb(self, widget):
spock = self.shpock.spockObj
spock.find()
class Shpock(activity.Activity):
def __init__(self, handle):
activity.Activity.__init__(self, handle)
# handle is a sugar.activity.activityhandle.ActivityHandle object
self._name = handle
# TRANS: The default title for the activity instance.
self.set_title(_('Spock!'))
# Creates the Toolbox. It contains the Activity Toolbar, which is the
# bar that appears on every Sugar window and contains essential
# functionalities, such as the 'Collaborate' and 'Close' buttons.
toolbox = activity.ActivityToolbox(self)
self._edit_toolbar = EditToolbar(self)
toolbox.add_toolbar(_('Edit'), self._edit_toolbar)
self._edit_toolbar.show()
self.set_toolbox(toolbox)
toolbox.show()
self.vbox = gtk.VBox()
self.spockObj = spock.Spock(self.vbox)
self.set_canvas(self.vbox)
self.show_all()
def write_file(self, file_path):
"""Write Spock journal entries"""
spock.logger.info(_('Writing to journal (%s)'), file_path)
# delegate write_file to spock...
self.spockObj.write_file(file_path)
def read_file(self, file_path):
"""Read a journal record."""
spock.logger.info(_('Reading from journal (%s)'), file_path)
# delegate read_file to spock...
spockObj = self.spockObj
spockObj.read_file(file_path)
|