Back to index

gcompris  8.2.2
Public Member Functions | Public Attributes
mosaic.Gcompris_mosaic Class Reference

List of all members.

Public Member Functions

def __init__
def start
def end
def ok
def repeat
def key_press
def pause
def set_level
def increment_level
def cleanup_game
def display_game
def display_mosaic
def display_palette
def set_focus_item_event
def set_color_item_event

Public Attributes

 gcomprisBoard
 indicator
 indicator_s
 current_index
 min
 max
 board_paused
 gamewon
 orig_x
 orig_y
 target_x
 target_y
 palette_x
 palette_y
 palette_item_width
 palette_item_height
 palette_number_of_item_x
 palette_number_of_item_y
 palette_grey_item_x
 palette_grey_item_y
 target_list
 user_list
 rootitem
 number_item_x
 number_item_y
 number_max_of_color_x
 number_max_of_color_y
 current_index_x
 current_index_y
 checked_color_item

Detailed Description

Tux hide a number, you must guess it

Definition at line 33 of file mosaic.py.


Constructor & Destructor Documentation

def mosaic.Gcompris_mosaic.__init__ (   self,
  gcomprisBoard 
)

Definition at line 37 of file mosaic.py.

00037 
00038   def __init__(self, gcomprisBoard):
00039 
00040     self.gcomprisBoard = gcomprisBoard
00041 
00042     self.gcomprisBoard.disable_im_context = True
00043 
00044     # A text canvas item use to indicate it's over or lower
00045     self.indicator = None
00046     self.indicator_s = None
00047 
00048     # The current selected color
00049     self.current_index = None
00050 
00051     # The min and max value that must be found
00052     self.min = -1
00053     self.max = -1
00054 
00055     # These are used to let us restart only after the bonus is displayed.
00056     # When the bonus is displayed, it call us first with pause(1) and then with pause(0)
00057     self.board_paused  = 0
00058     self.gamewon       = 0
00059 
00060     self.orig_x = 35
00061     self.orig_y = 50
00062     self.target_x = gcompris.BOARD_WIDTH/2 + 17
00063     self.target_y = 50
00064 
00065     self.palette_x = 40
00066     self.palette_y = 330
00067 
00068     # In the palette png, the size of each image
00069     self.palette_item_width  = 50
00070     self.palette_item_height = 50
00071 
00072     # In the palette png, the number of image in x and y
00073     self.palette_number_of_item_x = 8
00074     self.palette_number_of_item_y = 3
00075 
00076     # Index of the grey item in the palette
00077     self.palette_grey_item_x = 0
00078     self.palette_grey_item_y = 3
00079 
00080     # What the user have to find
00081     self.target_list = []
00082 
00083     # The user answer
00084     self.user_list   = []


Member Function Documentation

Definition at line 171 of file mosaic.py.

00171 
00172   def cleanup_game(self):
00173 
00174       self.current_index = None
00175       # Remove the root item removes all the others inside it
00176       self.rootitem.destroy()

Here is the caller graph for this function:

Definition at line 178 of file mosaic.py.

00178 
00179   def display_game(self):
00180 
00181       # What the user have to find
00182       self.target_list = []
00183       # The user answer
00184       self.user_list   = []
00185 
00186       # Create our rootitem. We put each canvas item in it so at the end we
00187       # only have to kill it. The canvas deletes all the items it contains automaticaly.
00188       self.rootitem = self.gcomprisBoard.canvas.root().add(
00189           gnomecanvas.CanvasGroup,
00190           x=0.0,
00191           y=0.0
00192           )
00193 
00194       text = _("Rebuild the same mosaic on the right area")
00195       self.rootitem.add(
00196           gnomecanvas.CanvasText,
00197           x=gcompris.BOARD_WIDTH/2 + 1.0,
00198           y=gcompris.BOARD_HEIGHT - 30 + 1.0,
00199           font=gcompris.skin.get_font("gcompris/title"),
00200           text=(text),
00201           fill_color="black",
00202           justification=gtk.JUSTIFY_CENTER
00203           )
00204       self.rootitem.add(
00205           gnomecanvas.CanvasText,
00206           x=gcompris.BOARD_WIDTH/2,
00207           y=gcompris.BOARD_HEIGHT - 30,
00208           font=gcompris.skin.get_font("gcompris/title"),
00209           text=(text),
00210           fill_color="white",
00211           justification=gtk.JUSTIFY_CENTER
00212           )
00213 
00214 
00215 
00216       self.number_item_x = 4
00217       self.number_item_y = 2
00218       self.number_max_of_color_x = 8
00219       self.number_max_of_color_y = 1
00220       if(self.gcomprisBoard.level == 2):
00221         self.number_item_x = 6
00222         self.number_item_y = 2
00223         self.number_max_of_color_y = 1
00224       elif(self.gcomprisBoard.level == 3):
00225         self.number_item_x = 6
00226         self.number_item_y = 3
00227         self.number_max_of_color_y = 2
00228       elif(self.gcomprisBoard.level == 4):
00229         self.number_item_x = 6
00230         self.number_item_y = 3
00231         self.number_max_of_color_y = 3
00232       elif(self.gcomprisBoard.level == 5):
00233         self.number_item_x = 6
00234         self.number_item_y = 4
00235         self.number_max_of_color_y = 3
00236       elif(self.gcomprisBoard.level == 6):
00237         self.number_item_x = 6
00238         self.number_item_y = 4
00239         self.number_max_of_color_y = 3
00240 
00241 
00242       self.current_index_x = -1
00243       self.current_index_y = -1
00244 
00245       palette = gcompris.utils.load_pixmap("images/mosaic_palette.png")
00246 
00247       self.display_mosaic(self.orig_x, self.orig_y, True, palette)
00248 
00249       self.display_mosaic(self.target_x, self.target_y, False, palette)
00250 
00251       self.display_palette(self.palette_x, self.palette_y, palette)
00252 
00253       # Create the check button to show the selected color
00254       self.checked_color_item = self.rootitem.add(
00255         gnomecanvas.CanvasPixbuf,
00256         pixbuf = gcompris.utils.load_pixmap(gcompris.skin.image_to_skin("button_checked.png")),
00257         x = 0,
00258         y = 0)
00259 
00260       self.checked_color_item.hide()

Here is the caller graph for this function:

def mosaic.Gcompris_mosaic.display_mosaic (   self,
  orig_x,
  orig_y,
  colored,
  palette 
)

Definition at line 264 of file mosaic.py.

00264 
00265   def display_mosaic(self, orig_x, orig_y, colored, palette):
00266 
00267       gap_x = 10
00268       gap_y = 10
00269 
00270       i = 0
00271       for y in range(0, self.number_item_y):
00272         for x in range(0, self.number_item_x):
00273 
00274               # Select an image in the palette
00275               color_index_x = random.randint(0, (self.number_max_of_color_x-1))
00276               color_index_y = random.randint(0, (self.number_max_of_color_y-1))
00277 
00278               if colored:
00279                 image  = palette.subpixbuf(color_index_x * self.palette_item_width,
00280                                            color_index_y * self.palette_item_height,
00281                                            self.palette_item_width, self.palette_item_height)
00282               else:
00283                 image  = palette.subpixbuf(self.palette_grey_item_x * self.palette_item_width,
00284                                            self.palette_grey_item_y * self.palette_item_height,
00285                                            self.palette_item_width, self.palette_item_height)
00286 
00287               item = self.rootitem.add(
00288                 gnomecanvas.CanvasPixbuf,
00289                 pixbuf = image,
00290                 x = orig_x + x * (self.palette_item_width  + gap_x),
00291                 y = orig_y + y * (self.palette_item_height + gap_y))
00292 
00293               if not colored:
00294                 item.connect("event", self.set_focus_item_event, (i,
00295                                                                   item, palette))
00296                 self.user_list.append((-1, -1))
00297               else:
00298                 self.target_list.append((color_index_x, color_index_y))
00299 
00300               i += 1
00301 
00302 

Here is the call graph for this function:

def mosaic.Gcompris_mosaic.display_palette (   self,
  orig_x,
  orig_y,
  palette 
)

Definition at line 306 of file mosaic.py.

00306 
00307   def display_palette(self, orig_x, orig_y, palette):
00308 
00309       gap_x = 10
00310       gap_y = 10
00311 
00312       number_item_x = 12
00313       number_item_y = 2
00314 
00315       for i in range(0, self.number_max_of_color_x * self.number_max_of_color_y):
00316 
00317             x         = i % number_item_x
00318             y         = i / number_item_x
00319 
00320             palette_x = i % self.palette_number_of_item_x
00321             palette_y = i / self.palette_number_of_item_x
00322 
00323             image  = palette.subpixbuf(palette_x * self.palette_item_width,
00324                                        palette_y * self.palette_item_height,
00325                                        self.palette_item_width, self.palette_item_height)
00326 
00327             coord_x = orig_x + x * (self.palette_item_width  + gap_x)
00328             coord_y = orig_y + y * (self.palette_item_height + gap_y)
00329             item = self.rootitem.add(
00330               gnomecanvas.CanvasPixbuf,
00331               pixbuf = image,
00332               x = coord_x,
00333               y = coord_y)
00334 
00335             item.connect("event", gcompris.utils.item_event_focus)
00336             item.connect("event", self.set_color_item_event, (item, palette_x, palette_y,
00337                                                               coord_x, coord_y))
00338 

Here is the call graph for this function:

Definition at line 102 of file mosaic.py.

00102 
00103   def end(self):
00104 
00105     gcompris.reset_locale()
00106 
00107     # Remove the root item removes all the others inside it
00108     self.cleanup_game()

Here is the call graph for this function:

Definition at line 154 of file mosaic.py.

00154 
00155   def increment_level(self):
00156     self.gcomprisBoard.sublevel += 1
00157 
00158     if(self.gcomprisBoard.sublevel>self.gcomprisBoard.number_of_sublevel):
00159       # Try the next level
00160       self.gcomprisBoard.sublevel=1
00161       self.gcomprisBoard.level += 1
00162       gcompris.bar_set_level(self.gcomprisBoard)
00163 
00164       if(self.gcomprisBoard.level>self.gcomprisBoard.maxlevel):
00165         # the current board is finished : bail out
00166         gcompris.bonus.board_finished(gcompris.bonus.FINISHED_RANDOM)
00167         return 0
00168 
00169     return 1

Here is the caller graph for this function:

def mosaic.Gcompris_mosaic.key_press (   self,
  keyval,
  commit_str,
  preedit_str 
)

Definition at line 116 of file mosaic.py.

00116 
00117   def key_press(self, keyval, commit_str, preedit_str):
00118     # Return  True  if you did process a key
00119     # Return  False if you did not processed a key
00120     #         (gtk need to send it to next widget)
00121     return False

def mosaic.Gcompris_mosaic.ok (   self)

Definition at line 109 of file mosaic.py.

00109 
00110   def ok(self):
00111     pass

def mosaic.Gcompris_mosaic.pause (   self,
  pause 
)

Definition at line 122 of file mosaic.py.

00122 
00123   def pause(self, pause):
00124     self.board_paused = pause
00125 
00126     # When the bonus is displayed, it call us first with pause(1) and then with pause(0)
00127     # the game is won
00128     if(pause == 0 and self.gamewon):
00129       self.increment_level()
00130       self.gamewon = 0
00131       self.cleanup_game()
00132       self.display_game()
00133 
00134     return
00135 

Here is the call graph for this function:

Definition at line 112 of file mosaic.py.

00112 
00113   def repeat(self):
00114     print("Gcompris_mosaic repeat.")
00115 

Here is the caller graph for this function:

def mosaic.Gcompris_mosaic.set_color_item_event (   self,
  item,
  event,
  data 
)

Definition at line 363 of file mosaic.py.

00363 
00364   def set_color_item_event(self, item, event, data):
00365 
00366     if event.type == gtk.gdk.BUTTON_PRESS:
00367       (box_item, color_index_x, color_index_y, coord_x, coord_y) = data
00368 
00369       self.current_index_x = color_index_x
00370       self.current_index_y = color_index_y
00371 
00372       index = color_index_y * self.palette_number_of_item_x + color_index_x
00373 
00374       self.checked_color_item.set( x = coord_x,
00375                                    y = coord_y + self.palette_item_height/3)
00376       self.checked_color_item.show()

Here is the caller graph for this function:

def mosaic.Gcompris_mosaic.set_focus_item_event (   self,
  item,
  event,
  data 
)

Definition at line 340 of file mosaic.py.

00340 
00341   def set_focus_item_event(self, item, event, data):
00342     (index, box_item, palette)  = data
00343 
00344     if event.type == gtk.gdk.BUTTON_PRESS:
00345       # A color is selected
00346       if(self.current_index_x >= 0):
00347 
00348         image = palette.subpixbuf(self.current_index_x * self.palette_item_width,
00349                                   self.current_index_y * self.palette_item_height,
00350                                   self.palette_item_width, self.palette_item_height)
00351 
00352         box_item.set(pixbuf = image)
00353 
00354         self.user_list[index] = (self.current_index_x,
00355                                  self.current_index_y)
00356 
00357         if(self.target_list == self.user_list):
00358           self.gamewon = True
00359           gcompris.bonus.display(gcompris.bonus.WIN, gcompris.bonus.GNU)
00360 
00361 

Here is the caller graph for this function:

def mosaic.Gcompris_mosaic.set_level (   self,
  level 
)

Definition at line 136 of file mosaic.py.

00136 
00137   def set_level(self, level):
00138     self.gcomprisBoard.level=level;
00139     self.gcomprisBoard.sublevel=1;
00140 
00141     # Set the level in the control bar
00142     gcompris.bar_set_level(self.gcomprisBoard);
00143 
00144     self.cleanup_game()
00145     self.display_game()

Here is the call graph for this function:

Definition at line 85 of file mosaic.py.

00085 
00086   def start(self):
00087 
00088     self.gcomprisBoard.level=1
00089     self.gcomprisBoard.maxlevel=6
00090     self.gcomprisBoard.sublevel=1
00091     self.gcomprisBoard.number_of_sublevel=1
00092 
00093     gcompris.bar_set(gcompris.BAR_LEVEL)
00094 
00095     gcompris.bar_set_level(self.gcomprisBoard)
00096 
00097     gcompris.set_background(self.gcomprisBoard.canvas.root(),
00098                             "images/mosaic_bg.png")
00099 
00100     self.display_game()
00101 

Here is the call graph for this function:


Member Data Documentation

Definition at line 56 of file mosaic.py.

Definition at line 253 of file mosaic.py.

Definition at line 48 of file mosaic.py.

Definition at line 241 of file mosaic.py.

Definition at line 242 of file mosaic.py.

Definition at line 57 of file mosaic.py.

Definition at line 39 of file mosaic.py.

Definition at line 44 of file mosaic.py.

Definition at line 45 of file mosaic.py.

Definition at line 52 of file mosaic.py.

Definition at line 51 of file mosaic.py.

Definition at line 215 of file mosaic.py.

Definition at line 216 of file mosaic.py.

Definition at line 217 of file mosaic.py.

Definition at line 218 of file mosaic.py.

Definition at line 59 of file mosaic.py.

Definition at line 60 of file mosaic.py.

Definition at line 76 of file mosaic.py.

Definition at line 77 of file mosaic.py.

Definition at line 69 of file mosaic.py.

Definition at line 68 of file mosaic.py.

Definition at line 72 of file mosaic.py.

Definition at line 73 of file mosaic.py.

Definition at line 64 of file mosaic.py.

Definition at line 65 of file mosaic.py.

Definition at line 187 of file mosaic.py.

Definition at line 80 of file mosaic.py.

Definition at line 61 of file mosaic.py.

Definition at line 62 of file mosaic.py.

Definition at line 83 of file mosaic.py.


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