Back to index

gcompris  8.2.2
Public Member Functions | Public Attributes
login.Gcompris_login Class Reference

List of all members.

Public Member Functions

def __init__
def start
def init_rootitem
def check_unique_id
def end
def ok
def repeat
def config
def key_press
def pause
def set_level
def display_user_by_letter
def display_letters
def display_user_list
def letter_click_event
def name_click_event
def logon
def init_config
def entry_text
def enter_char_callback
def enter_callback
def config_start
def config_stop
def ok_callback

Public Attributes

 gcomprisBoard
 Prop
 config_dict
 users
 rootitem
 letter_rootitem
 entry
 widget
 configuring_profile
 main_vbox

Detailed Description

Login screen for gcompris

Definition at line 42 of file login.py.


Constructor & Destructor Documentation

def login.Gcompris_login.__init__ (   self,
  gcomprisBoard 
)

Definition at line 46 of file login.py.

00046 
00047   def __init__(self, gcomprisBoard):
00048     self.gcomprisBoard = gcomprisBoard
00049 
00050     self.gcomprisBoard.disable_im_context = True
00051 
00052     print("Gcompris_login __init__.")
00053 


Member Function Documentation

def login.Gcompris_login.check_unique_id (   self,
  users 
)

Definition at line 139 of file login.py.

00139 
00140   def check_unique_id(self, users):
00141     passed = {}
00142     for user in users:
00143       passed[user.login] = user
00144 
00145     result = []
00146     keys = passed.keys()
00147     keys.sort()
00148     for login in keys:
00149       result.append(passed[login])
00150 
00151     return result

Definition at line 173 of file login.py.

00173 
00174   def config(self):
00175     print("Gcompris_login config.")
00176 

def login.Gcompris_login.config_start (   self,
  profile 
)

Definition at line 516 of file login.py.

00516 
00517   def config_start(self, profile):
00518     print '__login config__'
00519     # keep profile in mind
00520     self.configuring_profile = profile
00521 
00522     # init with default values
00523     self.config_dict = self.init_config()
00524 
00525     #get the configured values for that profile
00526     self.config_dict.update(gcompris.get_conf(profile, self.gcomprisBoard))
00527 
00528     # Init configuration window:
00529     # all the configuration functions will use it
00530     # all the configuration functions returns values for their key in
00531     # the dict passed to the apply_callback
00532     # the returned value is the main GtkVBox of the window,
00533     #we can add what you want in it.
00534 
00535     self.main_vbox = gcompris.configuration_window ( \
00536       _('<b>%s</b> configuration\n for profile <b>%s</b>') % ('Login', profile.name ),
00537       self.ok_callback
00538       )
00539 
00540     # toggle box
00541     uppercase = gcompris.boolean_box(_('Uppercase only text'),
00542                                         'uppercase_only',
00543                                         eval(self.config_dict['uppercase_only'])
00544                                         )
00545 
00546     #uppercase.set_sensitive(False)
00547 
00548     gcompris.separator()
00549 
00550     # toggle box
00551     entry_text = gcompris.boolean_box(_('Enter login to log in'),
00552                                         'entry_text',
00553                                         eval(self.config_dict['entry_text'])
00554                                         )
00555 

Definition at line 556 of file login.py.

00556 
00557   def config_stop(self):
00558     pass

def login.Gcompris_login.display_letters (   self,
  letters,
  users,
  start_filter 
)

Definition at line 247 of file login.py.

00247 
00248   def display_letters(self, letters, users, start_filter):
00249 
00250     # Create a group for the letters
00251     self.letter_rootitem = self.rootitem.add(
00252       self.rootitem,
00253       x=0.0,
00254       y=0.0
00255       )
00256 
00257     #
00258     # Display the current filter
00259     #
00260 
00261     x = gcompris.BOARD_WIDTH/2
00262     y = 20
00263 
00264     # The shadow
00265     self.letter_rootitem.add(
00266       gnomecanvas.CanvasText,
00267       x= x + 1.5,
00268       y= y + 1.5,
00269       text= _("Login: ") + start_filter + "...",
00270       fill_color="black",
00271       font=gcompris.skin.get_font("gcompris/board/huge"),
00272       )
00273     # The text
00274     self.letter_rootitem.add(
00275       gnomecanvas.CanvasText,
00276       x= x,
00277       y= y,
00278       text= _("Login: ") + start_filter + "...",
00279       fill_color="white",
00280       font=gcompris.skin.get_font("gcompris/board/huge"),
00281       )
00282 
00283 
00284     # Tricky but does the job, try to make the layout as large as
00285     # possible
00286     step_x = 480/math.sqrt(len(letters))
00287 
00288     start_x = 100
00289     x = start_x
00290     y = 100
00291     i = 0
00292     step_y = step_x
00293     current_line = 0
00294     max_letter_by_line = (gcompris.BOARD_WIDTH-start_x*2)/step_x
00295     letter_by_line = max_letter_by_line
00296     button_pixbuf = gcompris.utils.load_pixmap(gcompris.skin.image_to_skin("ok.png"))
00297 
00298     for letter in letters:
00299 
00300       # Display both cases for the letter
00301       if eval(self.config_dict['uppercase_only']):
00302         text = letter
00303       else:
00304         text = letter.upper() + letter.lower()
00305 
00306       item = self.letter_rootitem.add(
00307         gnomecanvas.CanvasPixbuf,
00308         pixbuf = button_pixbuf,
00309         x = x -  button_pixbuf.get_width()/2,
00310         y = y -  button_pixbuf.get_height()/2,
00311         )
00312       # This item is clickeable and it must be seen
00313       item.connect("event", gcompris.utils.item_event_focus)
00314       item.connect("event", self.letter_click_event,
00315                    (users, start_filter + letter))
00316 
00317       # The shadow
00318       item = self.letter_rootitem.add(
00319         gnomecanvas.CanvasText,
00320         x= x + 1.5,
00321         y= y + 1.5,
00322         text= text,
00323         fill_color="black",
00324         font=gcompris.skin.get_font("gcompris/board/huge"),
00325         )
00326       item.connect("event", self.letter_click_event,
00327                    (users, start_filter + letter))
00328 
00329       # The text
00330       item = self.letter_rootitem.add(
00331         gnomecanvas.CanvasText,
00332         x= x,
00333         y= y,
00334         text= text,
00335         fill_color="white",
00336         font=gcompris.skin.get_font("gcompris/board/huge"),
00337         )
00338       item.connect("event", self.letter_click_event,
00339                    (users, start_filter + letter))
00340       x += step_x
00341 
00342       i += 1
00343 
00344       # Perform the column switch
00345       if(i>letter_by_line):
00346         i = 0
00347         if(current_line%2):
00348           x = start_x
00349           letter_by_line = max_letter_by_line
00350         else:
00351           x = start_x + step_x/2
00352           letter_by_line = max_letter_by_line-1
00353 
00354         y += step_y
00355         current_line += 1
00356 

Here is the caller graph for this function:

def login.Gcompris_login.display_user_by_letter (   self,
  users,
  start_filter 
)

Definition at line 212 of file login.py.

00212 
00213   def display_user_by_letter(self, users, start_filter):
00214 
00215     print "display_user_by_letter start_filter=" + start_filter
00216 
00217     first_letters = []
00218     current_letter = None
00219     remaining_users=0
00220 
00221     for user in users:
00222       if eval(self.config_dict['uppercase_only']):
00223         login = user.login.decode('utf8').upper().encode('utf8')
00224       else:
00225         login = user.login
00226       if login.startswith(start_filter):
00227         remaining_users += 1
00228         if(len(start_filter)<len(login)):
00229           if(not current_letter or
00230              current_letter != login[len(start_filter)]):
00231             current_letter = login[len(start_filter)]
00232             first_letters.append(current_letter)
00233 
00234     # Fine we have the list of first letters
00235     if(remaining_users<MAX_USERS_AT_ONCE):
00236       # We now can display the list of users
00237       self.display_user_list(users, start_filter)
00238     else:
00239       # Display only the letters
00240       self.display_letters(first_letters, users, start_filter)

Here is the call graph for this function:

Here is the caller graph for this function:

def login.Gcompris_login.display_user_list (   self,
  users,
  start_filter 
)

Definition at line 361 of file login.py.

00361 
00362   def display_user_list(self, users, start_filter):
00363 
00364     y_start = 80
00365     y = y_start
00366     x = gcompris.BOARD_WIDTH/4
00367     i = 0
00368     step_y = 90
00369     button_pixbuf = gcompris.utils.load_pixmap(gcompris.skin.image_to_skin("button_large2.png"))
00370 
00371     for user in users:
00372       if eval(self.config_dict['uppercase_only']):
00373         login = user.login.decode('utf8').upper().encode('utf8')
00374       else:
00375         login = user.login
00376 
00377       if not login.startswith(start_filter):
00378         continue
00379 
00380       item = self.rootitem.add(
00381         gnomecanvas.CanvasPixbuf,
00382         pixbuf = button_pixbuf,
00383         x = x -  button_pixbuf.get_width()/2,
00384         y = y -  button_pixbuf.get_height()/2,
00385         )
00386       # This item is clickeable and it must be seen
00387       item.connect("event", gcompris.utils.item_event_focus)
00388       item.connect("event", self.name_click_event, user)
00389 
00390 
00391       # The shadow
00392       item = self.rootitem.add(
00393         gnomecanvas.CanvasText,
00394         x= x + 1.5,
00395         y= y + 1.5,
00396         text= login,
00397         fill_color="black",
00398         font=gcompris.skin.get_font("gcompris/board/huge"),
00399         )
00400       item.connect("event", self.name_click_event, user)
00401 
00402       # The text
00403       item = self.rootitem.add(
00404         gnomecanvas.CanvasText,
00405         x= x,
00406         y= y,
00407         text= login,
00408         fill_color="white",
00409         font=gcompris.skin.get_font("gcompris/board/huge"),
00410         )
00411       item.connect("event", self.name_click_event, user)
00412 
00413       y += step_y
00414       i += 1
00415 
00416       # Perform the column switch
00417       if(i==5):
00418         y = y_start
00419         x = 3*gcompris.BOARD_WIDTH/4
00420 

Here is the call graph for this function:

Here is the caller graph for this function:

def login.Gcompris_login.end (   self)

Definition at line 152 of file login.py.

00152 
00153   def end(self):
00154 
00155     # Remove the root item removes all the others inside it
00156     self.rootitem.destroy()
00157 

def login.Gcompris_login.enter_callback (   self,
  widget 
)

Definition at line 499 of file login.py.

00499 
00500   def enter_callback(self, widget):
00501     text = widget.get_text()
00502 
00503     found = False
00504     for user in self.users:
00505       if eval(self.config_dict['uppercase_only']):
00506         login = user.login.decode('utf8').upper().encode('utf8')
00507       else:
00508         login = user.login
00509       if text == login:
00510         self.widget.destroy()
00511         self.logon(user)
00512         found = True
00513 
00514     if not found:
00515       widget.set_text('')

Here is the call graph for this function:

def login.Gcompris_login.enter_char_callback (   self,
  widget 
)

Definition at line 494 of file login.py.

00494 
00495   def enter_char_callback(self, widget):
00496     if eval(self.config_dict['uppercase_only']):
00497       text = widget.get_text()
00498       widget.set_text(text.decode('utf8').upper().encode('utf8'))

Here is the call graph for this function:

Definition at line 457 of file login.py.

00457 
00458   def entry_text(self):
00459     print "__entry__"
00460     self.entry = gtk.Entry()
00461 
00462     self.entry.modify_font(pango.FontDescription("sans bold 36"))
00463     text_color = gtk.gdk.color_parse("brown")
00464     text_color_selected = gtk.gdk.color_parse("brown")
00465     bg_color = gtk.gdk.color_parse("blue")
00466 
00467     self.entry.modify_text(gtk.STATE_NORMAL, text_color)
00468     self.entry.modify_text(gtk.STATE_SELECTED, text_color_selected)
00469     self.entry.modify_base(gtk.STATE_NORMAL, bg_color)
00470 
00471     self.entry.set_max_length(50)
00472     self.entry.connect("activate", self.enter_callback)
00473     self.entry.connect("changed", self.enter_char_callback)
00474 
00475     self.entry.show()
00476 
00477     self.widget = self.rootitem.add(
00478       gnomecanvas.CanvasWidget,
00479       widget=self.entry,
00480       x=400,
00481       y=400,
00482       width=400,
00483       height=72,
00484       anchor=gtk.ANCHOR_CENTER,
00485       size_pixels=False
00486       )
00487 
00488     self.widget.raise_to_top()
00489 
00490     # does not work. Why ?
00491     #self.gcomprisBoard.canvas.grab_focus()
00492     self.widget.grab_focus()
00493     self.entry.grab_focus()

Here is the caller graph for this function:

Definition at line 450 of file login.py.

00450 
00451   def init_config(self):
00452     default_config = { 'uppercase_only'    : 'False',
00453                        'entry_text'      : 'False'
00454                        }
00455     return default_config
00456 

def login.Gcompris_login.init_rootitem (   self,
  Prop 
)

Definition at line 100 of file login.py.

00100 
00101   def init_rootitem(self, Prop):
00102     print "__rootitem__"
00103     # Create our rootitem.
00104     # We put each canvas item in it so at the end we only have to kill it.
00105     # The canvas deletes all the items it contains automaticaly.
00106     self.rootitem = self.gcomprisBoard.canvas.root().add(
00107       gnomecanvas.CanvasGroup,
00108       x=0.0,
00109       y=0.0
00110       )
00111 
00112     # Display the profile name
00113     x = gcompris.BOARD_WIDTH-100
00114     y = 20.0
00115     text = _("Profile: ") + Prop.profile.name
00116 
00117     # Shadow
00118     self.rootitem.add(
00119       gnomecanvas.CanvasText,
00120       x= x + 1,
00121       y= y + 1,
00122       text= text,
00123       fill_color="black",
00124       font=gcompris.skin.get_font("gcompris/board/small"),
00125       justification=gtk.JUSTIFY_RIGHT
00126       )
00127 
00128     # Profile name
00129     self.rootitem.add(
00130       gnomecanvas.CanvasText,
00131       x= x,
00132       y= y,
00133       text= text,
00134       fill_color="white",
00135       font=gcompris.skin.get_font("gcompris/board/small"),
00136       justification=gtk.JUSTIFY_RIGHT
00137       )
00138 

Here is the caller graph for this function:

def login.Gcompris_login.key_press (   self,
  keyval,
  commit_str,
  preedit_str 
)

Definition at line 177 of file login.py.

00177 
00178   def key_press(self, keyval, commit_str, preedit_str):
00179     print("Gcompris_login key press. %i" % keyval)
00180 
00181     # Return  True  if you did process a key
00182     # Return  False if you did not processed a key
00183     #         (gtk need to send it to next widget)
00184     return False

def login.Gcompris_login.letter_click_event (   self,
  widget,
  event,
  data 
)

Definition at line 425 of file login.py.

00425 
00426   def letter_click_event(self, widget, event, data):
00427     if event.type == gtk.gdk.BUTTON_PRESS:
00428       self.letter_rootitem.destroy()
00429       self.display_user_by_letter(data[0], data[1])
00430       return True
00431 
00432     return False

Here is the call graph for this function:

def login.Gcompris_login.logon (   self,
  user 
)

Definition at line 445 of file login.py.

00445 
00446   def logon(self, user):
00447     gcompris.admin.set_current_user(user)
00448     gcompris.admin.board_run_next(self.Prop.menu_board)
00449 

Here is the caller graph for this function:

def login.Gcompris_login.name_click_event (   self,
  widget,
  event,
  user 
)

Definition at line 436 of file login.py.

00436 
00437   def name_click_event(self, widget, event, user):
00438     if event.type == gtk.gdk.BUTTON_PRESS:
00439       print "selected user = " + user.login
00440 
00441       self.logon(user)
00442       return True
00443 
00444     return False

Here is the call graph for this function:

Here is the caller graph for this function:

def login.Gcompris_login.ok (   self)

Definition at line 158 of file login.py.

00158 
00159   def ok(self):
00160     print("Gcompris_login ok.")
00161 

def login.Gcompris_login.ok_callback (   self,
  table 
)

Definition at line 559 of file login.py.

00559 
00560   def ok_callback(self, table):
00561     if(not table):
00562       return
00563     for key,value in table.iteritems():
00564       gcompris.set_board_conf(self.configuring_profile, self.gcomprisBoard, key, value)
00565 
def login.Gcompris_login.pause (   self,
  pause 
)

Definition at line 185 of file login.py.

00185 
00186   def pause(self, pause):
00187     print("Gcompris_login pause. %i" % pause)
00188     # There is a problem with GTK widgets, they are not covered by the help
00189     # We hide/show them here
00190     if(pause):
00191       self.entry.hide()
00192     else:
00193       self.entryt.show()
00194 

Definition at line 162 of file login.py.

00162 
00163   def repeat(self):
00164     print("Gcompris_login repeat.")
00165     self.rootitem.destroy()
00166 
00167     self.init_rootitem(self.Prop)
00168 
00169     if eval(self.config_dict['entry_text']):
00170       self.entry_text()
00171     else:
00172       self.display_user_by_letter(self.users, "")

Here is the call graph for this function:

Here is the caller graph for this function:

def login.Gcompris_login.set_level (   self,
  level 
)

Definition at line 195 of file login.py.

00195 
00196   def set_level(self, level):
00197     print("Gcompris_login set level. %i" % level)

Definition at line 54 of file login.py.

00054 
00055   def start(self):
00056     self.gcomprisBoard.level=1
00057     self.gcomprisBoard.maxlevel=1
00058     self.gcomprisBoard.sublevel=1
00059     self.gcomprisBoard.number_of_sublevel=1
00060     pixmap = gcompris.utils.load_pixmap(gcompris.skin.image_to_skin("button_reload.png"))
00061     if(pixmap):
00062       gcompris.bar_set_repeat_icon(pixmap)
00063       gcompris.bar_set(gcompris.BAR_REPEAT_ICON)
00064     else:
00065       gcompris.bar_set(gcompris.BAR_REPEAT)
00066 
00067     gcompris.bar_set_level(self.gcomprisBoard)
00068 
00069     gcompris.set_background(self.gcomprisBoard.canvas.root(),
00070                             backgrounds[self.gcomprisBoard.level-1])
00071 
00072     # Get the default profile
00073     self.Prop = gcompris.get_properties()
00074 
00075     # init config to default values
00076     self.config_dict = self.init_config()
00077 
00078     print gcompris.get_board_conf(), self.gcomprisBoard.board_id, self.gcomprisBoard.name
00079 
00080     # change configured values
00081     self.config_dict.update(gcompris.get_board_conf())
00082 
00083     # Create and Initialize the rootitem.
00084     self.init_rootitem(self.Prop)
00085 
00086     # Get the user list
00087     users = []
00088     for group_id in self.Prop.profile.group_ids:
00089       users.extend( gcompris.admin.get_users_from_group(group_id))
00090 
00091     self.users = self.check_unique_id(users)
00092 
00093     if eval(self.config_dict['entry_text']):
00094       self.entry_text()
00095     else:
00096       self.display_user_by_letter(self.users, "")
00097 
00098     print("Gcompris_login start.")
00099 


Member Data Documentation

Definition at line 75 of file login.py.

Definition at line 519 of file login.py.

Definition at line 459 of file login.py.

Definition at line 47 of file login.py.

Definition at line 250 of file login.py.

Definition at line 534 of file login.py.

Definition at line 72 of file login.py.

Definition at line 105 of file login.py.

Definition at line 90 of file login.py.

Definition at line 476 of file login.py.


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