14
14
cgitb .handler = sys .excepthook
15
15
16
16
import logging
17
- import gtk
18
- import pango
17
+ import gi
18
+ gi .require_version ('Gtk' ,'3.0' )
19
+ from gi .repository import Gtk
20
+ from gi .repository import Pango
19
21
import random
20
22
import gobject
21
23
import math
28
30
import dobject .groupthink .sugar_tools as sugar_tools
29
31
30
32
from gettext import gettext as _
31
- from sugar .activity import activity
32
- from sugar import profile
33
-
34
- try :
35
- # 0.86+ toolbar widgets
36
- from sugar .activity .widgets import ActivityToolbarButton , StopButton
37
- from sugar .graphics .toolbarbox import ToolbarBox , ToolbarButton
38
- _USE_OLD_TOOLBARS = False
39
- except ImportError :
40
- # Pre-0.86 toolbar widgets
41
- from sugar .activity .activity import ActivityToolbox
42
- _USE_OLD_TOOLBARS = True
33
+ from sugar3 .activity import activity
34
+ from sugar3 import profile
35
+
36
+ from sugar3 .activity .widgets import ActivityToolbarButton , StopButton
37
+ from sugar3 .graphics .toolbarbox import ToolbarBox , ToolbarButton
38
+
43
39
44
40
def score_codec (score_or_opaque , pack_or_unpack ):
45
41
v = score_or_opaque
@@ -93,37 +89,33 @@ def __init__(self, handle):
93
89
self ._configure_toolbars ()
94
90
95
91
def _configure_toolbars (self ):
96
- if _USE_OLD_TOOLBARS :
97
- toolbox = ActivityToolbox (self )
98
- toolbar = gtk .Toolbar ()
99
- else :
100
- toolbar_box = ToolbarBox ()
101
- toolbar = toolbar_box .toolbar
102
92
103
- activity_button = ActivityToolbarButton (self )
104
- toolbar_box .toolbar .insert (activity_button , 0 )
105
- activity_button .show ()
106
93
107
- self ._add_expander (toolbar_box .toolbar )
94
+ toolbar_box = ToolbarBox ()
95
+ toolbar = toolbar_box .toolbar
108
96
109
- toolbar .add (gtk .SeparatorToolItem ())
97
+ activity_button = ActivityToolbarButton (self )
98
+ toolbar_box .toolbar .insert (activity_button , 0 )
99
+ activity_button .show ()
110
100
111
- if _USE_OLD_TOOLBARS :
112
- self .set_toolbox (toolbox )
113
- toolbox .show ()
114
- else :
115
- stop_button = StopButton (self )
116
- stop_button .props .accelerator = '<Ctrl><Shift>Q'
117
- toolbar_box .toolbar .insert (stop_button , - 1 )
118
- stop_button .show ()
101
+ self ._add_expander (toolbar_box .toolbar )
102
+
103
+ toolbar .add (Gtk .SeparatorToolItem ())
104
+
105
+
106
+
107
+ stop_button = StopButton (self )
108
+ stop_button .props .accelerator = '<Ctrl><Shift>Q'
109
+ toolbar_box .toolbar .insert (stop_button , - 1 )
110
+ stop_button .show ()
119
111
120
- self .set_toolbar_box (toolbar_box )
121
- toolbar_box .show ()
112
+ self .set_toolbar_box (toolbar_box )
113
+ toolbar_box .show ()
122
114
123
115
def _add_expander (self , toolbar ):
124
116
"""Insert a toolbar item which will expand to fill the available
125
117
space."""
126
- separator = gtk .SeparatorToolItem ()
118
+ separator = Gtk .SeparatorToolItem ()
127
119
separator .props .draw = False
128
120
separator .set_expand (True )
129
121
toolbar .insert (separator , - 1 )
@@ -157,23 +149,23 @@ def initialize_display(self):
157
149
self ._active_mode_hashes = set ()
158
150
159
151
# Main layout
160
- vbox = gtk .VBox ()
152
+ vbox = Gtk .VBox ()
161
153
162
154
# Set a startpoint for a shared seed
163
155
self .cloud .startpoint = groupthink .HighScore (self .timer .time (), 0 )
164
156
165
157
# Scoreboard
166
- scorebox = gtk .VBox ()
167
- self .model = gtk .TreeStore (gobject .TYPE_STRING , # name
158
+ scorebox = Gtk .VBox ()
159
+ self .model = Gtk .TreeStore (gobject .TYPE_STRING , # name
168
160
gobject .TYPE_INT , # last round score
169
161
gobject .TYPE_INT , # total score
170
162
gobject .TYPE_FLOAT ) # time for last question
171
- self .treeview = treeview = gtk .TreeView (self .model )
172
- cellrenderer = gtk .CellRendererText ()
173
- col1 = gtk .TreeViewColumn (_ ("Name" ), cellrenderer , text = 0 )
174
- col2 = gtk .TreeViewColumn (_ ("Round score" ), cellrenderer , text = 1 )
175
- col3 = gtk .TreeViewColumn (_ ("Total score" ), cellrenderer , text = 2 )
176
- col4 = gtk .TreeViewColumn (_ ("Time for answering last question" ), cellrenderer , text = 3 )
163
+ self .treeview = treeview = Gtk .TreeView (self .model )
164
+ cellrenderer = Gtk .CellRendererText ()
165
+ col1 = Gtk .TreeViewColumn (_ ("Name" ), cellrenderer , text = 0 )
166
+ col2 = Gtk .TreeViewColumn (_ ("Round score" ), cellrenderer , text = 1 )
167
+ col3 = Gtk .TreeViewColumn (_ ("Total score" ), cellrenderer , text = 2 )
168
+ col4 = Gtk .TreeViewColumn (_ ("Time for answering last question" ), cellrenderer , text = 3 )
177
169
treeview .append_column (col1 )
178
170
treeview .append_column (col2 )
179
171
treeview .append_column (col3 )
@@ -190,30 +182,30 @@ def initialize_display(self):
190
182
scorebox .pack_start (treeview )
191
183
192
184
# Horizontal fields
193
- difficultybox = gtk .HBox ()
194
- periodbox = gtk .HBox ()
195
- toprowbox = gtk .HBox ()
196
- modebox = gtk .HBox ()
197
- self .inner_modebox = gtk .HBox ()
198
- questionbox = gtk .HBox ()
199
- answerbox = gtk .HBox ()
200
- decisionbox = gtk .HBox ()
201
- lastroundbox = gtk .HBox ()
202
- bottomrowbox = gtk .HBox ()
203
- countdownbox = gtk .HBox ()
185
+ difficultybox = Gtk .HBox ()
186
+ periodbox = Gtk .HBox ()
187
+ toprowbox = Gtk .HBox ()
188
+ modebox = Gtk .HBox ()
189
+ self .inner_modebox = Gtk .HBox ()
190
+ questionbox = Gtk .HBox ()
191
+ answerbox = Gtk .HBox ()
192
+ decisionbox = Gtk .HBox ()
193
+ lastroundbox = Gtk .HBox ()
194
+ bottomrowbox = Gtk .HBox ()
195
+ countdownbox = Gtk .HBox ()
204
196
205
197
# Labels
206
- difficultylabel = gtk .Label (_ ("Difficulty: " ))
207
- periodlabel = gtk .Label (_ ("Period: " ))
208
- periodunitslabel = gtk .Label (" sec " )
209
- modelabel = gtk .Label (_ ("Puzzles: " ))
210
- questionlabel = gtk .Label (_ ("Question: " ))
211
- answerlabel = gtk .Label (_ ("Answer: " ))
212
- decisionlabel = gtk .Label (_ ("You were: " ))
213
- lastroundlabel = gtk .Label (_ ("Last round: " ))
214
- self .lastanswerlabel = gtk .Label ("" )
215
- staticcountdownlabel = gtk .Label (_ ("Time until next question: " ))
216
- self .countdownlabel = gtk .Label ("" )
198
+ difficultylabel = Gtk .Label (_ ("Difficulty: " ))
199
+ periodlabel = Gtk .Label (_ ("Period: " ))
200
+ periodunitslabel = Gtk .Label (" sec " )
201
+ modelabel = Gtk .Label (_ ("Puzzles: " ))
202
+ questionlabel = Gtk .Label (_ ("Question: " ))
203
+ answerlabel = Gtk .Label (_ ("Answer: " ))
204
+ decisionlabel = Gtk .Label (_ ("You were: " ))
205
+ lastroundlabel = Gtk .Label (_ ("Last round: " ))
206
+ self .lastanswerlabel = Gtk .Label ("" )
207
+ staticcountdownlabel = Gtk .Label (_ ("Time until next question: " ))
208
+ self .countdownlabel = Gtk .Label ("" )
217
209
218
210
# ToggleButtons for difficulty
219
211
self .cloud .easytoggle = groupthink .gtk_tools .SharedToggleButton ("< 10" )
@@ -229,7 +221,7 @@ def initialize_display(self):
229
221
230
222
# Entry for puzzle period
231
223
self .cloud .periodentry = groupthink .gtk_tools .RecentEntry (max = 2 )
232
- self .cloud .periodentry .modify_font (pango .FontDescription ("Mono 14" ))
224
+ self .cloud .periodentry .modify_font (Pango .FontDescription ("Mono 14" ))
233
225
self .cloud .periodentry .set_text (str (self .period ))
234
226
self .cloud .periodentry .set_width_chars (2 )
235
227
self .cloud .periodentry .connect ("changed" , self ._period_cb )
@@ -239,18 +231,18 @@ def initialize_display(self):
239
231
self .cloud .puzzles .register_listener (self .new_puzzles_cb )
240
232
241
233
# Text entry box for question
242
- self .questionentry = gtk .TextView ()
243
- self .questionentry .modify_font (pango .FontDescription ("Mono 14" ))
234
+ self .questionentry = Gtk .TextView ()
235
+ self .questionentry .modify_font (Pango .FontDescription ("Mono 14" ))
244
236
self .questionentry .set_property ("editable" , False )
245
237
246
238
# Text entry box for answer
247
- self .answerentry = gtk .Entry (max = 50 )
248
- self .answerentry .modify_font (pango .FontDescription ("Sans 14" ))
239
+ self .answerentry = Gtk .Entry (max = 50 )
240
+ self .answerentry .modify_font (Pango .FontDescription ("Sans 14" ))
249
241
self .answerentry .connect ("activate" , self .answer_cb )
250
242
251
243
# Whether the user was correct
252
- self .decisionentry = gtk .Entry (max = 50 )
253
- self .decisionentry .modify_font (pango .FontDescription ("Sans 14" ))
244
+ self .decisionentry = Gtk .Entry (max = 50 )
245
+ self .decisionentry .modify_font (Pango .FontDescription ("Sans 14" ))
254
246
self .decisionentry .set_property ("editable" , False )
255
247
256
248
# Packing
@@ -423,7 +415,7 @@ def onesecond_cb(self):
423
415
self .start_question ()
424
416
self .answerentry .set_text ("" )
425
417
426
- self .model = gtk .TreeStore (gobject .TYPE_STRING , # name
418
+ self .model = Gtk .TreeStore (gobject .TYPE_STRING , # name
427
419
gobject .TYPE_INT , # last round score
428
420
gobject .TYPE_INT , # total score
429
421
gobject .TYPE_FLOAT ) # time for last question
0 commit comments