-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathGoGoActivity.py
93 lines (66 loc) · 2.47 KB
/
GoGoActivity.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
# GoGoActivity/GoGoActivity.py
import os
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import time
import logging
from gettext import gettext as _
from sugar3.activity import activity
from sugar3.graphics.toolbarbox import ToolbarBox
from sugar3.activity.widgets import ActivityToolbarButton
from monitor import BoardMonitor
from power import power
def runningOnXO():
return (os.uname()[2]).find("olpc") != -1
_logger = logging.getLogger('read-activity')
class GoGoActivity(activity.Activity):
"""GoGo Activity"""
APM = None # Automatic Power Management
def __init__(self, handle):
"""Set up the GoGo activity."""
activity.Activity.__init__(self, handle)
self.set_title(_('GoGo'))
logging.info(_('GoGo'))
# Show the toolbox elements
toolbox = ToolbarBox(self)
self.set_toolbar_box(toolbox)
toolbox.show()
self.monitor = BoardMonitor(self)
# Display everything
vb = Gtk.VBox()
self.monitor.notebookMain.reparent(vb)
self.monitor.statusbar.reparent(vb)
self.set_canvas(vb)
self.show_all()
if runningOnXO():
try:
self.APM = power.get_automatic_pm()
power.set_automatic_pm(False)
except:
pass
def can_close(self):
if runningOnXO():
if self.APM != None:
try:
power.set_automatic_pm(self.APM)
except:
pass
return True
def read_file(self, file_path):
"""Load a file from the datastore on activity start."""
_logger.debug('GoGoActivity.read_file: %s', file_path)
try:
FILE = open(file_path,"r")
self.monitor.proceduresTab.LogoProceduresBuffer.set_text(FILE.read())
FILE.close()
except Exception as e:
_logger.error('read_file(): %s, error: %s', file_path, e)
def write_file(self, file_path):
_logger.debug('GoGoActivity.write_file: %s', file_path)
try:
FILE = open(file_path,"w")
FILE.write(self.monitor.proceduresTab.LogoProceduresBuffer.get_text(self.LogoProceduresBuffer.get_start_iter(),self.LogoProceduresBuffer.get_end_iter()))
FILE.close()
except Exception as e:
_logger.error('write_file(): %s, error: %s', file_path, e)