Back to index

gcompris  8.2.2
Public Member Functions | Public Attributes
pythontest.Gcompris_pythontest Class Reference

List of all members.

Public Member Functions

def __init__
def start
def end
def ok
def repeat
def config
def key_press
def pause
def set_level
def timer_inc_display
def circle_item_event
def config_stop
 Configuration system.
def config_start
def color_disable
def ok_callback
def init_config

Public Attributes

 gcomprisBoard
 canvasitems
 colors
 config_colors
 config_colors_list
 movingline
 solution
 config_dict
 previous_locale
 rootitem
 timerinc
 timer_inc
 counter_left
 counter_right
 textitem_left
 textitem_right
 left_continue
 right_continue
 pos_x
 pos_y
 configuring_profile
 main_vbox
 color_choice
 distance_box

Detailed Description

Testing gcompris python class

Definition at line 13 of file pythontest.py.


Constructor & Destructor Documentation

def pythontest.Gcompris_pythontest.__init__ (   self,
  gcomprisBoard 
)

Definition at line 17 of file pythontest.py.

00017 
00018   def __init__(self, gcomprisBoard):
00019     self.gcomprisBoard = gcomprisBoard
00020 
00021     self.gcomprisBoard.disable_im_context = True
00022 
00023     self.canvasitems = {}
00024 
00025     self.colors = {}
00026     self.colors['circle_in'] = gcompris.skin.get_color("pythontest/circle in")
00027     self.colors['circle_out'] = gcompris.skin.get_color("pythontest/circle out")
00028     self.colors['line'] = gcompris.skin.get_color("pythontest/line")
00029 
00030     # Just for config demo
00031     self.config_colors = { 'red' : 0xFF0000FFL,
00032                            'green' : 0x00FF00FFL,
00033                            'blue' : 0x0000FFFFL }
00034 
00035     # dict .keys() list of keys has random order
00036     self.config_colors_list = [ 'red', 'green', 'blue']
00037 
00038     self.movingline='none'
00039 
00040     # Find a number game
00041     self.solution = random.randint(0,9)
00042 
00043     print("Gcompris_pythontest __init__.")
00044 
00045     #initialisation to default values. Some of them will be replaced by
00046     #the configured values.


Member Function Documentation

def pythontest.Gcompris_pythontest.circle_item_event (   self,
  widget,
  event = None 
)

Definition at line 349 of file pythontest.py.

00349 
00350   def circle_item_event(self, widget, event=None):
00351     if eval(self.config_dict['disable_line']):
00352       return False
00353 
00354     if event.type == gtk.gdk.BUTTON_PRESS:
00355       if event.button == 1:
00356         bounds = widget.get_bounds()
00357         self.pos_x = (bounds[0]+bounds[2])/2
00358         self.pos_y = (bounds[1]+bounds[3])/2
00359         if 'line 1' in self.canvasitems:
00360           self.canvasitems['line 1'].destroy()
00361         self.canvasitems['line 1'] = self.rootitem.add(
00362           gnomecanvas.CanvasLine,
00363           points=( self.pos_x, self.pos_y, event.x, event.y),
00364           fill_color_rgba=self.colors['line'],
00365           width_units=5.0
00366           )
00367         self.movingline='line 1'
00368         print "Button press"
00369         return True
00370     if event.type == gtk.gdk.MOTION_NOTIFY:
00371       if event.state & gtk.gdk.BUTTON1_MASK:
00372         self.canvasitems[self.movingline].set(
00373           points=( self.pos_x, self.pos_y, event.x, event.y)
00374           )
00375     if event.type == gtk.gdk.BUTTON_RELEASE:
00376       if event.button == 1:
00377         self.movingline='line 1'
00378         print "Button release"
00379         return True
00380     return False

Here is the call graph for this function:

def pythontest.Gcompris_pythontest.color_disable (   self,
  button 
)

Definition at line 480 of file pythontest.py.

00480 
00481   def color_disable(self, button):
00482     self.color_choice.set_sensitive(not button.get_active())

Definition at line 262 of file pythontest.py.

00262 
00263   def config(self):
00264     print("Gcompris_pythontest config.")
00265 

def pythontest.Gcompris_pythontest.config_start (   self,
  profile 
)

Definition at line 390 of file pythontest.py.

00390 
00391   def config_start(self, profile):
00392     # keep profile in mind
00393     # profile can be Py_None
00394     self.configuring_profile = profile
00395 
00396     # init with default values
00397     self.config_dict = self.init_config()
00398 
00399     #get the configured values for that profile
00400     self.config_dict.update(gcompris.get_conf(profile, self.gcomprisBoard))
00401 
00402     # Init configuration window:
00403     # all the configuration functions will use it
00404     # all the configuration functions returns values for their key in
00405     # the dict passed to the apply_callback
00406     # the returned value is the main GtkVBox of the window,
00407     #we can add what you want in it.
00408 
00409     self.main_vbox = gcompris.configuration_window ( \
00410       _('<b>%s</b> configuration\n for profile <b>%s</b>') % ('Pythontest', profile.name ),
00411       self.ok_callback
00412       )
00413 
00414     # toggle box
00415     control_line = gcompris.boolean_box(_('Disable line drawing in circle'),
00416                                         'disable_line',
00417                                         eval(self.config_dict['disable_line'])
00418                                         )
00419     # sample of control in python
00420     control_line.connect("toggled", self.color_disable)
00421 
00422     # combo box
00423     self.color_choice = \
00424        gcompris.combo_box(_('Color of the line'),
00425                           self.config_colors_list,
00426                           'color_line',
00427                           self.config_dict['color_line']
00428                           )
00429     self.color_choice.set_sensitive(not eval(self.config_dict['disable_line']))
00430 
00431     gcompris.separator()
00432 
00433     #spin button for int
00434     self.distance_box = \
00435        gcompris.spin_int(_('Distance between circles'),
00436                          'distance_circle',
00437                          20,
00438                          200,
00439                          20,
00440                          eval(self.config_dict['distance_circle'])
00441                          )
00442 
00443     gcompris.separator()
00444 
00445     #radio buttons for circle or rectangle
00446     patterns = { 'circle': _('Use circles'),
00447                  'rectangle': _('Use rectangles')
00448                  }
00449 
00450     gcompris.radio_buttons(_('Choice of pattern'),
00451                            'pattern',
00452                            patterns,
00453                            self.config_dict['pattern']
00454                            )
00455 
00456     print "List of locales shown in gcompris.combo_locale :"
00457     print gcompris.get_locales_list()
00458 
00459     gcompris.separator()
00460 
00461     gcompris.combo_locales( self.config_dict['locale'])
00462 
00463     gcompris.separator()
00464 
00465     print "List of locales shown in gcompris.combo_locales_asset :"
00466     locales_purple = gcompris.get_locales_asset_list( "gcompris colors", None, "audio/x-ogg", "purple.ogg")
00467     print locales_purple
00468 
00469     label = gtk.Label()
00470     label.set_markup('<i>-- unused, but here for test --</i>')
00471     label.show()
00472     self.main_vbox.pack_start (label, False, False, 8)
00473 
00474     gcompris.combo_locales_asset( _("Select sound locale"), self.config_dict['locale_sound'], "gcompris colors", None, "audio/x-ogg", "purple.ogg" )
00475 
00476     print gcompris.utils.get_asset_file ("gcompris colors", None, "audio/x-ogg", "purple.ogg")
00477     print gcompris.utils.get_asset_file_locale ("gcompris colors", None, "audio/x-ogg", "purple.ogg", None)
00478     for lang in locales_purple:
00479       print gcompris.utils.get_asset_file_locale ("gcompris colors", None, "audio/x-ogg", "purple.ogg", lang)

Configuration system.

Definition at line 386 of file pythontest.py.

00386 
00387   def config_stop(self):
00388     pass

Definition at line 243 of file pythontest.py.

00243 
00244   def end(self):
00245 
00246     gcompris.reset_locale()
00247 
00248     # Remove the root item removes all the others inside it
00249     self.rootitem.destroy()
00250 
00251     if self.timer_inc :
00252       gtk.timeout_remove(self.timer_inc)
00253 

Definition at line 500 of file pythontest.py.

00500 
00501   def init_config(self):
00502     default_config = { 'disable_line'    : 'False',
00503                        'color_line'      : 'red',
00504                        'distance_circle' : '100',
00505                        'pattern'         : 'circle',
00506                        'locale'          : 'NULL',
00507                        'locale_sound'    : 'NULL'
00508                        }
00509     return default_config
00510 
00511 
def pythontest.Gcompris_pythontest.key_press (   self,
  keyval,
  commit_str,
  preedit_str 
)

Definition at line 266 of file pythontest.py.

00266 
00267   def key_press(self, keyval, commit_str, preedit_str):
00268     print("Gcompris_pythontest key press. %i %s" % (keyval, str))
00269 
00270     utf8char = gtk.gdk.keyval_to_unicode(keyval)
00271     strn = u'%c' % utf8char
00272 
00273     win = False
00274 
00275     if (keyval == gtk.keysyms.Shift_L):
00276       self.left_continue  = False
00277 
00278     if (keyval == gtk.keysyms.Shift_R):
00279       self.right_continue = False
00280 
00281     if(not self.left_continue and not self.right_continue):
00282       if(self.counter_left == self.counter_right):
00283         self.canvasitems[6].set(text="WIN",
00284                                 fill_color_rgba=0x2bf9f2FFL)
00285         win=True
00286       else:
00287         self.canvasitems[6].set(text="LOOSE",
00288                                 fill_color_rgba=0xFF0000FFL)
00289 
00290     if ((keyval == gtk.keysyms.BackSpace) or
00291         (keyval == gtk.keysyms.Delete)):
00292       self.timerinc = 1100
00293       keyval = 32
00294 
00295     if (keyval == 32):
00296       self.left_continue  = True
00297       self.right_continue = True
00298       self.counter_left  = 0
00299       self.counter_right = 0
00300       if(win):
00301         if(self.timerinc>500):
00302           self.timerinc -= 100
00303         elif(self.timerinc>200):
00304           self.timerinc -= 50
00305         elif(self.timerinc>10):
00306           self.timerinc -= 10
00307         elif(self.timerinc>1):
00308           self.timerinc -= 1
00309 
00310       if(self.timerinc<1):
00311           self.timerinc = 1
00312 
00313       self.canvasitems[3].set(text="")
00314       self.canvasitems[6].set(text="")
00315 
00316     self.canvasitems[7].set(text="Speed="+str(self.timerinc)+" ms")
00317 
00318     # Find a number game
00319     if str(self.solution) == strn:
00320       print "WIN"
00321     else:
00322       print "LOST"
00323 
00324     # Return  True  if you did process a key
00325     # Return  False if you did not processed a key
00326     #         (gtk need to send it to next widget)
00327     return True

Definition at line 254 of file pythontest.py.

00254 
00255   def ok(self):
00256     print("Gcompris_pythontest ok.")
00257 

def pythontest.Gcompris_pythontest.ok_callback (   self,
  table 
)

Definition at line 485 of file pythontest.py.

00485 
00486   def ok_callback(self, table):
00487     if (table == None):
00488       print 'Configuration returns None'
00489       return
00490 
00491     print "Keys and values returned by PythonTest config window:"
00492 
00493     if (len(table) == 0):
00494         print '%20s' % 'None'
00495 
00496     for key,value in table.iteritems():
00497       print '%20s:%20s    ' % (key, value)
00498       gcompris.set_board_conf(self.configuring_profile, self.gcomprisBoard, key, value)
00499 

def pythontest.Gcompris_pythontest.pause (   self,
  pause 
)

Definition at line 328 of file pythontest.py.

00328 
00329   def pause(self, pause):
00330     print("Gcompris_pythontest pause. %i" % pause)
00331 

Definition at line 258 of file pythontest.py.

00258 
00259   def repeat(self):
00260     print("Gcompris_pythontest repeat.")
00261 

Here is the caller graph for this function:

def pythontest.Gcompris_pythontest.set_level (   self,
  level 
)

Definition at line 332 of file pythontest.py.

00332 
00333   def set_level(self, level):
00334     print("Gcompris_pythontest set level. %i" % level)
00335 
00336 # ---- End of Initialisation

Definition at line 47 of file pythontest.py.

00047 
00048   def start(self):
00049     logged = gcompris.admin.get_current_user()
00050 
00051     wordlist = gcompris.get_wordlist('wordslevel_max_pt_BR')
00052     print wordlist
00053 #    print wordlist.filename
00054 #    print wordlist.level
00055 #    print wordlist.locale
00056 #    print wordlist.description
00057 #    print wordlist.words
00058 
00059 
00060     print gcompris.get_current_user_dirname()
00061     print gcompris.get_current_board_dirname()
00062 
00063     if logged:
00064       print "User Logged in:"
00065       print "   ", logged.login, logged.firstname, logged.lastname
00066 
00067     self.gcomprisBoard.level=1
00068     self.gcomprisBoard.maxlevel=1
00069     self.gcomprisBoard.sublevel=1
00070     self.gcomprisBoard.number_of_sublevel=1
00071 
00072     # init config to default values
00073     self.config_dict = self.init_config()
00074 
00075     print "init self.config_dict :", self.config_dict
00076 
00077     # change configured values
00078     print "gcompris.get_board_conf() : ", gcompris.get_board_conf()
00079     self.config_dict.update(gcompris.get_board_conf())
00080 
00081     print "self.config_dict final :", self.config_dict
00082 
00083     self.previous_locale = gcompris.get_locale()
00084 
00085     if self.config_dict.has_key('locale'):
00086       gcompris.change_locale(self.config_dict['locale'])
00087 
00088     # self.colors['line'] s set in init.
00089     # I put here the configuration use
00090 
00091     color_name = self.config_dict['color_line']
00092     self.colors['line'] = self.config_colors[color_name]
00093 
00094     gcompris.bar_set(gcompris.BAR_CONFIG)
00095     gcompris.set_background(self.gcomprisBoard.canvas.root(),
00096                             gcompris.skin.image_to_skin("gcompris-bg.jpg"))
00097     gcompris.bar_set_level(self.gcomprisBoard)
00098 
00099     # Create our rootitem. We put each canvas item in it so at the end we
00100     # only have to kill it. The canvas deletes all the items it contains automaticaly.
00101     self.rootitem = self.gcomprisBoard.canvas.root().add(
00102       gnomecanvas.CanvasGroup,
00103       x=0.0,
00104       y=0.0
00105       )
00106 
00107     # distance is used to demo of gcompris.spin_int
00108     distance = eval(self.config_dict['distance_circle'])
00109 
00110     # pattern is for gcompris.radio_buttons
00111     pattern = self.config_dict['pattern']
00112 
00113     patterns = { 'circle': gnomecanvas.CanvasEllipse,
00114                  'rectangle': gnomecanvas.CanvasRect
00115                  }
00116 
00117     #error check
00118     if not patterns.has_key(pattern):
00119       pattern = 'circle'
00120 
00121     self.canvasitems[1] = self.rootitem.add(
00122       patterns[pattern],
00123       x1=400.0 - distance ,
00124       y1=200.0,
00125       x2=380.0 - distance,
00126       y2=220.0,
00127       fill_color_rgba= self.colors['circle_in'],
00128       outline_color_rgba= self.colors['circle_out'],
00129       width_units=1.0
00130       )
00131     self.canvasitems[1].connect("event", self.circle_item_event)
00132 
00133     self.canvasitems[2] = self.rootitem.add(
00134       patterns[pattern],
00135       x1=400.0 + distance,
00136       y1=200.0,
00137       x2=420.0 + distance,
00138       y2=220.0,
00139       fill_color_rgba= self.colors['circle_in'],
00140       outline_color_rgba= self.colors['circle_out'],
00141       width_units=1.0
00142       )
00143     self.canvasitems[2].connect("event", self.circle_item_event)
00144 
00145     self.canvasitems[3] = self.rootitem.add(
00146       gnomecanvas.CanvasText,
00147       x=400.0,
00148       y=100.0,
00149       text=_("This is the first plugin in gcompris coded in the Python\nProgramming language."),
00150       fill_color="white",
00151       justification=gtk.JUSTIFY_CENTER
00152       )
00153 
00154     self.canvasitems[4] = self.rootitem.add(
00155       gnomecanvas.CanvasText,
00156       x=400.0,
00157       y=140.0,
00158       text=_("It is now possible to develop gcompris activities in C or in Python.\nThanks to Olivier Samys who makes this possible."),
00159       fill_color="white",
00160       justification=gtk.JUSTIFY_CENTER
00161       )
00162 
00163     self.canvasitems[5] = self.rootitem.add(
00164       gnomecanvas.CanvasText,
00165       x=400.0,
00166       y=250.0,
00167       text=_("This activity is not playable, just a test"),
00168       fill_color="white",
00169       justification=gtk.JUSTIFY_CENTER
00170       )
00171 
00172     #----------------------------------------
00173     # A simple game.
00174     # Try to hit left shift and right shift together. The peed increases
00175     self.rootitem.add(
00176           gnomecanvas.CanvasRect,
00177           x1=20,
00178           y1=gcompris.BOARD_HEIGHT-180,
00179           x2=gcompris.BOARD_WIDTH-20,
00180           y2=gcompris.BOARD_HEIGHT-10,
00181           fill_color_rgba=0x101077FFL,
00182           outline_color_rgba=0x07A3E080L,
00183           width_units=2.0)
00184 
00185     # For the game status WIN/LOOSE
00186     self.canvasitems[6] = self.rootitem.add(
00187       gnomecanvas.CanvasText,
00188       x=gcompris.BOARD_WIDTH / 2,
00189       y=gcompris.BOARD_HEIGHT - 40,
00190       font=gcompris.skin.get_font("gcompris/content"),
00191       fill_color_rgba=0x123456FFL,
00192       justification=gtk.JUSTIFY_CENTER
00193       )
00194 
00195     self.rootitem.add(
00196       gnomecanvas.CanvasText,
00197       x=400.0,
00198       y=400.0,
00199       text=("Test your reflex with the counter. Hit the 2 shifts key together.\nHit space to reset the counter and increase the speed.\nBackspace to reset the speed"),
00200       fill_color="white",
00201       justification=gtk.JUSTIFY_CENTER
00202       )
00203 
00204     # The basic tick for object moves
00205     self.timerinc = 1000
00206 
00207     self.timer_inc  = gtk.timeout_add(self.timerinc, self.timer_inc_display)
00208 
00209     self.counter_left  = 0
00210     self.counter_right = 0
00211 
00212     self.canvasitems[7] = self.rootitem.add(
00213       gnomecanvas.CanvasText,
00214       x=gcompris.BOARD_WIDTH / 2,
00215       y=gcompris.BOARD_HEIGHT - 80,
00216       font=gcompris.skin.get_font("gcompris/content"),
00217       text="Speed="+str(self.timerinc)+" ms",
00218       fill_color="white",
00219       justification=gtk.JUSTIFY_CENTER
00220       )
00221 
00222     self.textitem_left = self.rootitem.add(
00223       gnomecanvas.CanvasText,
00224       font=gcompris.skin.get_font("gcompris/content"),
00225       x=gcompris.BOARD_WIDTH / 3,
00226       y=gcompris.BOARD_HEIGHT - 40,
00227       fill_color_rgba=0xFFFFFFFFL
00228       )
00229 
00230     self.textitem_right = self.rootitem.add(
00231       gnomecanvas.CanvasText,
00232       font=gcompris.skin.get_font("gcompris/content"),
00233       x=gcompris.BOARD_WIDTH / 1.5,
00234       y=gcompris.BOARD_HEIGHT - 40,
00235       fill_color_rgba=0xFFFFFFFFL
00236       )
00237 
00238     self.left_continue  = True
00239     self.right_continue = True
00240 
00241     print("Gcompris_pythontest start.")
00242 

Definition at line 337 of file pythontest.py.

00337 
00338   def timer_inc_display(self):
00339 
00340     if(self.left_continue):
00341       self.textitem_left.set(text=str(self.counter_left))
00342       self.counter_left += self.timer_inc
00343 
00344     if(self.right_continue):
00345       self.textitem_right.set(text=str(self.counter_right))
00346       self.counter_right += self.timer_inc
00347 
00348     self.timer_inc  = gtk.timeout_add(self.timerinc, self.timer_inc_display)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 22 of file pythontest.py.

Definition at line 422 of file pythontest.py.

Definition at line 24 of file pythontest.py.

Definition at line 30 of file pythontest.py.

Definition at line 35 of file pythontest.py.

Definition at line 72 of file pythontest.py.

Definition at line 393 of file pythontest.py.

Definition at line 208 of file pythontest.py.

Definition at line 209 of file pythontest.py.

Definition at line 433 of file pythontest.py.

Definition at line 18 of file pythontest.py.

Definition at line 237 of file pythontest.py.

Definition at line 408 of file pythontest.py.

Definition at line 37 of file pythontest.py.

Definition at line 356 of file pythontest.py.

Definition at line 357 of file pythontest.py.

Definition at line 82 of file pythontest.py.

Definition at line 238 of file pythontest.py.

Definition at line 100 of file pythontest.py.

Definition at line 40 of file pythontest.py.

Definition at line 221 of file pythontest.py.

Definition at line 229 of file pythontest.py.

Definition at line 206 of file pythontest.py.

Definition at line 204 of file pythontest.py.


The documentation for this class was generated from the following file: