forked from sugarlabs/jam-clock-activity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JAMClock.py
128 lines (104 loc) · 3.89 KB
/
JAMClock.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# JAMClock.py por:
# Flavio Danesse <fdanesse@gmail.com>
# CeibalJAM! - Uruguay
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
from Main import Main
from sugar3.activity.widgets import ActivityToolbarButton
from sugar3.activity.widgets import StopButton
from sugar3.graphics.toolbarbox import ToolbarBox
from sugar3.activity import activity
from pygame.locals import *
from sugargame import event
from sugargame import canvas
import sugargame
from sugar3.graphics.style import GRID_CELL_SIZE
import pygame
import socket
import sys
from gi.repository import Gtk, GObject, Gdk
import os
import gi
gi.require_version('Gtk', '3.0')
class JAMClock(activity.Activity):
def __init__(self, handle):
activity.Activity.__init__(self, handle, False)
self.set_title('JAMClock')
# self.set_toolbox(activity.ActivityToolbox(self))
w = Gdk.Screen.width()
h = Gdk.Screen.height() - 1 * GRID_CELL_SIZE
# Start the Game activity
self.game = Main((w, h))
# Build the Pygame canvas and start the game running
# (self.game.run is called when the activity constructor
# returns).
self._pygamecanvas = canvas.PygameCanvas(
self, main=self.game.run, modules=[pygame.display])
# Note that set_canvas implicitly calls read_file when
# resuming from the Journal.
self._pygamecanvas.set_size_request(w, h)
self.set_canvas(self._pygamecanvas)
self._pygamecanvas.grab_focus()
# Build the activity toolbar.
self.build_toolbar()
def build_toolbar(self):
self.toolbar_box = ToolbarBox()
self.activity_button = ActivityToolbarButton(self)
self.toolbar_box.toolbar.insert(self.activity_button, 0)
self.activity_button.show()
self._separator = Gtk.SeparatorToolItem()
self._separator.props.draw = False
self._separator.set_expand(True)
self.toolbar_box.toolbar.insert(self._separator, -1)
self._separator.show()
self.stop = StopButton(self)
self.toolbar_box.toolbar.insert(self.stop, -1)
self.stop.show()
self.set_toolbar_box(self.toolbar_box)
self.toolbar_box.show_all()
return self.toolbar_box
def get_run_game(self):
raise NotImplementedError
pass
def salir(self, widget):
lambda w: Gtk.main_quit()
sys.exit()
# -----------------------------------------------
# ******** El Juego en Gtk ********
# -----------------------------------------------
class VentanaGTK(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, Gtk.WINDOW_TOPLEVEL)
self.set_title("JAMClock")
# self.fullscreen()
self.set_size_request(800, 600)
self.socket = Gtk.Socket()
self.add(self.socket)
self.ventana = None
self.add_events(Gdk.ALL_EVENTS_MASK)
self.connect("destroy", self.salir)
self.connect("set-focus-child", self.refresh)
self.show_all()
def refresh(self, widget, datos):
try:
pygame.display.update()
except:
pass
self.queue_draw()
return True
def salir(self, widget):
pygame.quit()
sys.exit()