Back to index

gcompris  8.2.2
Public Member Functions | Public Attributes
watercycle.Gcompris_watercycle 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 update_waterlevel
def set_cleanwater
def move_boat
def move_cloud
def init_vapor
def move_vapor
def move_sun
def pause
def set_level
def sun_item_event
def cloud_item_event
def waterpump_item_event
def watercleaning_item_event
def shower_water_update
def showerbutton_item_event

Public Attributes

 gcomprisBoard
 timerinc
 boat_timerinc
 boat_timer
 sun_timer
 vapor_timer
 cloud_timer
 waterlevel_timer
 rootitem
 riveritem
 riverfull
 badwateritem
 cleanwateritem
 cleanwaterstatus
 sunitem
 sun_direction
 sun_on
 snowitem
 rainitem
 rain_on
 clouditem
 cloud_on
 vaporitem
 waterpumpitem
 waterpump_on
 pumpwateritem
 watercleaningitem
 watercleaning_on
 tuxboatitem
 tuxboatcanvas
 tuxshoweritem
 tuxisinshower
 tuxshowerwateritem
 showerbuttonitem_on
 showerbutton
 showerbuttonitem_off
 waterlevel_max
 waterlevel_min
 waterlevel
 waterlevel_item
 vapor_on

Detailed Description

The Cycle Water activity

Definition at line 29 of file watercycle.py.


Constructor & Destructor Documentation

def watercycle.Gcompris_watercycle.__init__ (   self,
  gcomprisBoard 
)

Definition at line 33 of file watercycle.py.

00033 
00034   def __init__(self, gcomprisBoard):
00035     self.gcomprisBoard = gcomprisBoard
00036 
00037     print("Gcompris_watercycle __init__.")
00038 


Member Function Documentation

def watercycle.Gcompris_watercycle.cloud_item_event (   self,
  widget,
  event = None 
)

Definition at line 475 of file watercycle.py.

00475 
00476   def cloud_item_event(self, widget, event=None):
00477     if event.type == gtk.gdk.BUTTON_PRESS:
00478       if event.button == 1:
00479         self.rain_on = 1
00480         return True
00481     return False

Definition at line 306 of file watercycle.py.

00306 
00307   def config(self):
00308     print("Gcompris_watercycle config.")

Definition at line 279 of file watercycle.py.

00279 
00280   def end(self):
00281     # Remove all the timer first
00282     if self.boat_timer :
00283       gtk.timeout_remove(self.boat_timer)
00284     if self.sun_timer :
00285       gtk.timeout_remove(self.sun_timer)
00286     if self.vapor_timer :
00287       gtk.timeout_remove(self.vapor_timer)
00288     if self.cloud_timer :
00289       gtk.timeout_remove(self.cloud_timer)
00290     if self.waterlevel_timer :
00291       gtk.timeout_remove(self.waterlevel_timer)
00292 
00293     # Remove the root item removes all the others inside it
00294     self.rootitem.destroy()
00295 
00296     print("Gcompris_watercycle end.")
00297 

Definition at line 419 of file watercycle.py.

00419 
00420   def init_vapor(self):
00421     self.vapor_on = 1
00422     self.vaporitem.show()
00423     self.move_vapor()

Here is the caller graph for this function:

def watercycle.Gcompris_watercycle.key_press (   self,
  keyval,
  commit_str,
  preedit_str 
)

Definition at line 309 of file watercycle.py.

00309 
00310   def key_press(self, keyval, commit_str, preedit_str):
00311     print("got key %i" % keyval)
00312     return False

Definition at line 357 of file watercycle.py.

00357 
00358   def move_boat(self):
00359     if( self.tuxboatcanvas.get_bounds()[2] < 770 ) :
00360 
00361       # Make the boat slow down when arriving
00362       if(self.tuxboatcanvas.get_bounds()[2]==700 or self.tuxboatcanvas.get_bounds()[2]==701):
00363         self.boat_timerinc+=50
00364 
00365       self.tuxboatcanvas.move(2, 0)
00366       self.boat_timer = gtk.timeout_add(self.boat_timerinc, self.move_boat)
00367     else:
00368       if self.tuxboatcanvas.get_bounds()[2] < 800 :
00369         # Park the boat
00370         self.tuxboatcanvas.move(0.7, -0.7)
00371         self.tuxboatitem.setState(1)
00372         self.boat_timer = gtk.timeout_add(self.timerinc, self.move_boat)
00373       else :
00374         # We are parked, change the boat to remove tux
00375         #self.tuxboatcanvas.set(
00376         #  pixbuf = gcompris.utils.load_pixmap("gcompris/misc/fishingboat.png"),
00377         #  width = 100.0,
00378         #  height = 48.0,
00379         #  width_set = 1,
00380         #  height_set = 1,
00381         #  )
00382         self.tuxboatitem.setState(2)
00383 
00384         # Now display tux in the shower
00385         self.tuxshoweritem.show()
00386         self.tuxisinshower = 1
00387 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 388 of file watercycle.py.

00388 
00389   def move_cloud(self):
00390     if(self.cloud_on):
00391       self.clouditem.show()
00392     else:
00393       self.clouditem.hide()
00394 
00395     if(self.rain_on):
00396       self.rainitem.show()
00397       # The snow appear if we are close to the left mountain
00398       if( self.clouditem.get_bounds()[0] < 250):
00399           self.snowitem.show()
00400       # The river
00401       if(not self.riverfull):
00402         self.riveritem.set(pixbuf = gcompris.utils.load_pixmap("watercycle/riverfull.png"));
00403         self.riverfull = 1
00404 
00405     else:
00406       self.rainitem.hide()
00407 
00408     self.clouditem.move(1, 0);
00409     self.rainitem.move(1, 0);
00410     if( self.clouditem.get_bounds()[0] > 800 ) :
00411       self.clouditem.move(-800, 0);
00412       self.rainitem.move(-800, 0);
00413       self.cloud_on = 0
00414       self.rain_on = 0
00415       self.clouditem.hide()
00416       self.rainitem.hide()
00417     else:
00418       self.cloud_timer = gtk.timeout_add(self.timerinc, self.move_cloud)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 431 of file watercycle.py.

00431 
00432   def move_sun(self):
00433     self.sunitem.move(0, self.sun_direction);
00434     if( (self.sunitem.get_bounds()[1] > 0 and
00435          self.sunitem.get_bounds()[1] < 70 ) ) :
00436       self.sun_timer = gtk.timeout_add(self.timerinc, self.move_sun)
00437     else :
00438       # The sun is at is top
00439       if(self.sun_direction < 0) :
00440         # Stop the sun
00441         self.sun_timer = gtk.timeout_add(15000, self.move_sun)
00442         # Start the vapor
00443         self.vapor_timer = gtk.timeout_add(5000 , self.init_vapor)
00444         self.vapor_on = 1
00445         # Start the cloud
00446         if(not self.cloud_on):
00447           self.cloud_timer = gtk.timeout_add(10000, self.move_cloud)
00448           self.cloud_on = 1
00449         # Remove the snow
00450         self.snowitem.hide()
00451 
00452       else :
00453         # Stop the vapor
00454         self.vapor_on = 0
00455         self.vaporitem.hide()
00456         # Stop the sun
00457         self.sun_on = 0
00458 
00459       self.sun_direction = self.sun_direction * -1

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 424 of file watercycle.py.

00424 
00425   def move_vapor(self):
00426     self.vaporitem.move(0, -1);
00427     if( self.vaporitem.get_bounds()[1] < 20 ) :
00428       self.vaporitem.move(0, +100);
00429 
00430     self.vapor_timer = gtk.timeout_add(self.timerinc, self.move_vapor)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 298 of file watercycle.py.

00298 
00299   def ok(self):
00300     print("Gcompris_watercycle ok.")
00301 

def watercycle.Gcompris_watercycle.pause (   self,
  pause 
)

Definition at line 460 of file watercycle.py.

00460 
00461   def pause(self, pause):
00462     print("Gcompris_watercycle pause. %i" % pause)

Definition at line 302 of file watercycle.py.

00302 
00303   def repeat(self):
00304     print("Gcompris_watercycle repeat.")
00305 

def watercycle.Gcompris_watercycle.set_cleanwater (   self,
  status 
)

Definition at line 346 of file watercycle.py.

00346 
00347   def set_cleanwater(self, status):
00348     if(status == self.cleanwaterstatus):
00349       return
00350 
00351     if status:
00352       self.cleanwateritem.set(pixbuf = gcompris.utils.load_pixmap("watercycle/cleanwater.png"));
00353     else:
00354       self.cleanwateritem.set(pixbuf = gcompris.utils.load_pixmap("watercycle/cleanwater_off.png"));
00355     self.cleanwaterstatus = status
00356 

Here is the caller graph for this function:

def watercycle.Gcompris_watercycle.set_level (   self,
  level 
)

Definition at line 463 of file watercycle.py.

00463 
00464   def set_level(self, level):
00465     print("Gcompris_watercycle set level. %i" % level)

Definition at line 502 of file watercycle.py.

00502 
00503   def shower_water_update(self):
00504 
00505     if not self.tuxisinshower:
00506       return
00507 
00508     if self.cleanwaterstatus and self.showerbutton:
00509       self.tuxshoweritem.hide()
00510       self.tuxshowerwateritem.show()
00511     else:
00512       self.tuxshoweritem.show()
00513       self.tuxshowerwateritem.hide()
00514 

Here is the caller graph for this function:

def watercycle.Gcompris_watercycle.showerbutton_item_event (   self,
  widget,
  event = None 
)

Definition at line 515 of file watercycle.py.

00515 
00516   def showerbutton_item_event(self, widget, event=None):
00517 
00518     # Not active until tux is in the shower and the watercleaning station is running
00519     if not self.tuxisinshower:
00520       return
00521 
00522     if not self.watercleaning_on:
00523       return
00524 
00525     if event.type == gtk.gdk.BUTTON_PRESS:
00526       if event.button == 1:
00527         if self.showerbutton:
00528           self.showerbuttonitem_on.hide()
00529           self.showerbuttonitem_off.show()
00530         else:
00531           self.showerbuttonitem_on.show()
00532           self.showerbuttonitem_off.hide()
00533 
00534         self.showerbutton = not self.showerbutton
00535 
00536         self.shower_water_update()

Here is the call graph for this function:

Definition at line 39 of file watercycle.py.

00039 
00040   def start(self):
00041     self.gcomprisBoard.level=1
00042     self.gcomprisBoard.maxlevel=1
00043     self.gcomprisBoard.sublevel=1
00044     self.gcomprisBoard.number_of_sublevel=1
00045 
00046     # The basic tick for object moves
00047     self.timerinc = 50
00048 
00049     # The tick for the boat is variable
00050     self.boat_timerinc = self.timerinc
00051 
00052     # Need to manage the timers to quit properly
00053     self.boat_timer = 0
00054     self.sun_timer = 0
00055     self.vapor_timer = 0
00056     self.cloud_timer = 0
00057     self.waterlevel_timer = 0
00058 
00059     gcompris.bar_set(0)
00060     gcompris.set_background(self.gcomprisBoard.canvas.root(),
00061                             "watercycle/background.png")
00062     gcompris.bar_set_level(self.gcomprisBoard)
00063 
00064     # Create our rootitem. We put each canvas item in it so at the end we
00065     # only have to kill it. The canvas deletes all the items it contains automaticaly.
00066     self.rootitem = self.gcomprisBoard.canvas.root().add(
00067       gnomecanvas.CanvasGroup,
00068       x=0.0,
00069       y=0.0
00070       )
00071 
00072     # Take care, the items are stacked on each other in the order you add them.
00073     # If you need, you can reorder them later with raise and lower functions.
00074 
00075     # The River
00076     self.riveritem = self.rootitem.add(
00077       gnomecanvas.CanvasPixbuf,
00078       pixbuf = gcompris.utils.load_pixmap("watercycle/riverempty.png"),
00079       x=150.0,
00080       y=50.0
00081       )
00082     self.riverfull = 0
00083 
00084     # The bad water
00085     self.badwateritem = self.rootitem.add(
00086       gnomecanvas.CanvasPixbuf,
00087       pixbuf = gcompris.utils.load_pixmap("watercycle/badwater_off.png"),
00088       x=360.0,
00089       y=292.0
00090       )
00091 
00092     # The clean water
00093     self.cleanwateritem = self.rootitem.add(
00094       gnomecanvas.CanvasPixbuf,
00095       pixbuf = gcompris.utils.load_pixmap("watercycle/cleanwater_off.png"),
00096       x=470.0,
00097       y=130.0
00098       )
00099     self.cleanwaterstatus = 0
00100 
00101     # The Sun
00102     self.sunitem = self.rootitem.add(
00103       gnomecanvas.CanvasPixbuf,
00104       pixbuf = gcompris.utils.load_pixmap("watercycle/sun.png"),
00105       x=10.0,
00106       y=70.0
00107       )
00108     self.sunitem.connect("event", self.sun_item_event)
00109     # This item is clickeable and it must be seen
00110     self.sunitem.connect("event", gcompris.utils.item_event_focus)
00111     self.sun_direction = -1
00112     self.sun_on = 0
00113 
00114     # The sun mask object to simulate the see
00115     self.rootitem.add(
00116       gnomecanvas.CanvasRect,
00117       x1=10.0,
00118       y1=89.0,
00119       x2=90.0,
00120       y2=155.0,
00121       fill_color_rgba=0x0099FFFFL,
00122       width_units=0.0
00123       )
00124 
00125     # The Snow
00126     self.snowitem = self.rootitem.add(
00127       gnomecanvas.CanvasPixbuf,
00128       pixbuf = gcompris.utils.load_pixmap("watercycle/snow.png"),
00129       x=180.0,
00130       y=3.0
00131       )
00132     self.snowitem.hide()
00133 
00134     # The rain
00135     self.rainitem = self.rootitem.add(
00136       gnomecanvas.CanvasPixbuf,
00137       pixbuf = gcompris.utils.load_pixmap("watercycle/rain.png"),
00138       x=40.0,
00139       y=70.0
00140       )
00141     self.rainitem.hide()
00142     self.rain_on = 0
00143 
00144     # The cloud
00145     self.clouditem = self.rootitem.add(
00146       gnomecanvas.CanvasPixbuf,
00147       pixbuf = gcompris.utils.load_pixmap("gcompris/misc/cloud.png"),
00148       x=10.0,
00149       y=10.0
00150       )
00151     self.clouditem.hide()
00152     self.clouditem.connect("event", self.cloud_item_event)
00153     # This item is clickeable and it must be seen
00154     self.clouditem.connect("event", gcompris.utils.item_event_focus)
00155     self.cloud_on = 0
00156 
00157     # The vapor
00158     self.vaporitem = self.rootitem.add(
00159       gnomecanvas.CanvasPixbuf,
00160       pixbuf = gcompris.utils.load_pixmap("watercycle/vapor.png"),
00161       x=35.0,
00162       y=150.0
00163       )
00164     self.vaporitem.hide()
00165 
00166     # The Waterpump
00167     self.waterpumpitem = self.rootitem.add(
00168       gnomecanvas.CanvasPixbuf,
00169       pixbuf = gcompris.utils.load_pixmap("watercycle/waterpump.png"),
00170       x=165.0,
00171       y=120.0
00172       )
00173     self.waterpumpitem.connect("event", self.waterpump_item_event)
00174     # This item is clickeable and it must be seen
00175     self.waterpumpitem.connect("event", gcompris.utils.item_event_focus)
00176     self.waterpump_on = 0
00177 
00178     # The pump water
00179     self.pumpwateritem = self.rootitem.add(
00180       gnomecanvas.CanvasPixbuf,
00181       pixbuf = gcompris.utils.load_pixmap("watercycle/pumpwater_off.png"),
00182       x=270.0,
00183       y=133.0
00184       )
00185 
00186     # The WaterCleaning
00187     self.watercleaningitem = self.rootitem.add(
00188       gnomecanvas.CanvasPixbuf,
00189       pixbuf = gcompris.utils.load_pixmap("watercycle/watercleaning.png"),
00190       x=520.0,
00191       y=380.0
00192       )
00193     self.watercleaningitem.connect("event", self.watercleaning_item_event)
00194     # This item is clickeable and it must be seen
00195     self.watercleaningitem.connect("event", gcompris.utils.item_event_focus)
00196     self.watercleaning_on = 0
00197 
00198     # The tuxboat
00199     self.tuxboatitem = gcompris.anim.CanvasItem( gcompris.anim.Animation("watercycle/tuxboat.txt"),
00200                                                  self.rootitem );
00201     numstates = self.tuxboatitem.num_states
00202 
00203     self.tuxboatcanvas = self.tuxboatitem.gnomecanvas
00204     self.tuxboatcanvas.set( x=-100.0, y=430.0 )
00205 
00206     # Tux in the shower (without water)
00207     self.tuxshoweritem = self.rootitem.add(
00208       gnomecanvas.CanvasPixbuf,
00209       pixbuf = gcompris.utils.load_pixmap("gcompris/misc/minitux.png"),
00210       x=569.0,
00211       y=239.0
00212       )
00213     self.tuxshoweritem.hide()
00214     self.tuxisinshower = 0
00215 
00216     # Tux in the shower with the water
00217     self.tuxshowerwateritem = self.rootitem.add(
00218       gnomecanvas.CanvasPixbuf,
00219       pixbuf = gcompris.utils.load_pixmap("watercycle/showerwater.png"),
00220       x=561.0,
00221       y=231.0
00222       )
00223     self.tuxshowerwateritem.hide()
00224 
00225     # The shower itself
00226     self.rootitem.add(
00227       gnomecanvas.CanvasPixbuf,
00228       pixbuf = gcompris.utils.load_pixmap("watercycle/shower.png"),
00229       x=560.0,
00230       y=283.0
00231       )
00232 
00233     # The shower on/off button (I need to get the 2 buttons to manage the focus)
00234     self.showerbuttonitem_on = self.rootitem.add(
00235       gnomecanvas.CanvasPixbuf,
00236       pixbuf = gcompris.utils.load_pixmap("watercycle/shower_on.png"),
00237       x=622.0,
00238       y=260.0
00239       )
00240     self.showerbuttonitem_on.connect("event", self.showerbutton_item_event)
00241     # This item is clickeable and it must be seen
00242     self.showerbuttonitem_on.connect("event", gcompris.utils.item_event_focus)
00243     self.showerbuttonitem_on.hide()
00244     self.showerbutton = 0
00245 
00246     self.showerbuttonitem_off = self.rootitem.add(
00247       gnomecanvas.CanvasPixbuf,
00248       pixbuf = gcompris.utils.load_pixmap("watercycle/shower_off.png"),
00249       x=622.0,
00250       y=260.0
00251       )
00252     self.showerbuttonitem_off.connect("event", self.showerbutton_item_event)
00253     # This item is clickeable and it must be seen
00254     self.showerbuttonitem_off.connect("event", gcompris.utils.item_event_focus)
00255 
00256     # The level of water in the castle
00257     self.waterlevel_max = 65
00258     self.waterlevel_min = 85
00259     self.waterlevel     = self.waterlevel_min
00260     self.waterlevel_timer = gtk.timeout_add(1000, self.update_waterlevel)
00261 
00262     self.waterlevel_item = self.rootitem.add(
00263           gnomecanvas.CanvasLine,
00264           points = (655 , self.waterlevel,
00265                     655 , self.waterlevel_min),
00266           fill_color_rgba = 0x0033FFFFL,
00267           width_units = 20.0
00268           )
00269 
00270     # Some item ordering
00271     self.rainitem.raise_to_top()
00272     self.clouditem.raise_to_top()
00273 
00274     # Ready GO
00275     self.move_boat()
00276 
00277     print("Gcompris_watercycle start.")
00278 

def watercycle.Gcompris_watercycle.sun_item_event (   self,
  widget,
  event = None 
)

Definition at line 466 of file watercycle.py.

00466 
00467   def sun_item_event(self, widget, event=None):
00468     if event.type == gtk.gdk.BUTTON_PRESS:
00469       if event.button == 1:
00470         if not self.sun_on :
00471           self.sun_timer = gtk.timeout_add(self.timerinc, self.move_sun)
00472           self.sun_on = 1
00473         return True
00474     return False

Here is the call graph for this function:

Definition at line 314 of file watercycle.py.

00314 
00315   def update_waterlevel(self):
00316     old_waterlevel = self.waterlevel
00317 
00318     if self.waterpump_on and self.waterlevel > self.waterlevel_max :
00319       self.waterlevel -= 1
00320 
00321     # It tux is in the shower and it works, then remove some water
00322     if (self.tuxisinshower and self.cleanwaterstatus and self.showerbutton
00323         and self.waterlevel < self.waterlevel_min) :
00324       self.waterlevel += 2
00325 
00326     # Redisplay the level of water if needed
00327     if old_waterlevel != self.waterlevel :
00328       self.waterlevel_item.set(
00329         points = (655, self.waterlevel,
00330                   655, self.waterlevel_min),
00331         )
00332 
00333     # Update the clean water tubes
00334     if self.waterlevel < self.waterlevel_min - 5 :
00335       self.set_cleanwater(1)
00336     else:
00337       self.set_cleanwater(0)
00338       # In this case, de activate the shower to avoid blinking tubes
00339       self.showerbuttonitem_on.hide()
00340       self.showerbuttonitem_off.show()
00341       self.showerbutton = 0
00342       self.shower_water_update()
00343 
00344     self.waterlevel_timer = gtk.timeout_add(1000, self.update_waterlevel)
00345 

Here is the call graph for this function:

Here is the caller graph for this function:

def watercycle.Gcompris_watercycle.watercleaning_item_event (   self,
  widget,
  event = None 
)

Definition at line 491 of file watercycle.py.

00491 
00492   def watercleaning_item_event(self, widget, event=None):
00493     if event.type == gtk.gdk.BUTTON_PRESS:
00494       if event.button == 1:
00495         if self.waterpump_on:
00496           self.watercleaning_on = 1
00497           self.badwateritem.set(pixbuf = gcompris.utils.load_pixmap("watercycle/badwater.png"));
00498         return True
00499     return False
00500 

def watercycle.Gcompris_watercycle.waterpump_item_event (   self,
  widget,
  event = None 
)

Definition at line 482 of file watercycle.py.

00482 
00483   def waterpump_item_event(self, widget, event=None):
00484     if event.type == gtk.gdk.BUTTON_PRESS:
00485       if event.button == 1:
00486         if self.riverfull:
00487           self.waterpump_on = 1
00488           self.pumpwateritem.set(pixbuf = gcompris.utils.load_pixmap("watercycle/pumpwater.png"));
00489         return True
00490     return False


Member Data Documentation

Definition at line 84 of file watercycle.py.

Definition at line 52 of file watercycle.py.

Definition at line 49 of file watercycle.py.

Definition at line 92 of file watercycle.py.

Definition at line 98 of file watercycle.py.

Definition at line 154 of file watercycle.py.

Definition at line 55 of file watercycle.py.

Definition at line 144 of file watercycle.py.

Definition at line 34 of file watercycle.py.

Definition at line 178 of file watercycle.py.

Definition at line 141 of file watercycle.py.

Definition at line 134 of file watercycle.py.

Definition at line 81 of file watercycle.py.

Definition at line 75 of file watercycle.py.

Definition at line 65 of file watercycle.py.

Definition at line 243 of file watercycle.py.

Definition at line 245 of file watercycle.py.

Definition at line 233 of file watercycle.py.

Definition at line 125 of file watercycle.py.

Definition at line 110 of file watercycle.py.

Definition at line 111 of file watercycle.py.

Definition at line 53 of file watercycle.py.

Definition at line 101 of file watercycle.py.

Definition at line 46 of file watercycle.py.

Definition at line 202 of file watercycle.py.

Definition at line 198 of file watercycle.py.

Definition at line 213 of file watercycle.py.

Definition at line 206 of file watercycle.py.

Definition at line 216 of file watercycle.py.

Definition at line 420 of file watercycle.py.

Definition at line 54 of file watercycle.py.

Definition at line 157 of file watercycle.py.

Definition at line 195 of file watercycle.py.

Definition at line 186 of file watercycle.py.

Definition at line 258 of file watercycle.py.

Definition at line 261 of file watercycle.py.

Definition at line 256 of file watercycle.py.

Definition at line 257 of file watercycle.py.

Definition at line 56 of file watercycle.py.

Definition at line 175 of file watercycle.py.

Definition at line 166 of file watercycle.py.


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