Exemplo n.º 1
0
class DriverPageSinglePlayerGui(DriverPageGui):

    def build(self):
        menu_props = self.menu_props
        self.ent = Entry(
            scale=.08, pos=(0, .6), entry_font=menu_props.font, width=12,
            frame_col=menu_props.btn_col,
            initial_text=self.props.gameprops.player_name or _('your name'),
            text_fg=menu_props.text_active_col)
        self.add_widgets([self.ent])
        self.update_tsk = taskMgr.add(self.update_text, 'update text')
        DriverPageGui.build(self, exit_behav=False)
        self.enable_buttons(False)

    def update_text(self, task):
        has_name = self.ent.text != _('your name')
        if has_name and self.ent.text.startswith(_('your name')):
            self.ent.enter_text(self.ent.text[len(_('your name')):])
            self.enable_buttons(True)
        elif self.ent.text in [_('your name')[:-1], '']:
            self.ent.enter_text('')
            self.enable_buttons(False)
        elif self.ent.text not in [_('your name'), '']:
            self.enable_buttons(True)
        return task.cont  # don't do a task, attach to modifications events

    def this_name(self): return self.ent.text

    def destroy(self):
        taskMgr.remove(self.update_tsk)
        DriverPageGui.destroy(self)
Exemplo n.º 2
0
 def build(self):
     menu_props = self.menu_props
     t_a = menu_props.text_args.copy()
     # del t_a['scale']
     email_lab = Text(_('Your email:'), pos=(-.05, .4),
                            align='right', **t_a)
     jid_lab = Text(_('Your user id:'), pos=(-.05, .2),
                            align='right', **t_a)
     init_txt = self.props.opt_file['settings']['login']['usr'] if \
         self.props.opt_file['settings']['login']['usr'] else \
         _('your user id')
     self.email_ent = Entry(
         scale=.08, pos=(.05, .4), entry_font=menu_props.font, width=12,
         frame_col=menu_props.btn_col, initial_text=_('your email'),
         text_fg=menu_props.text_active_col, on_tab=self.on_tab_email,
         on_click=self.on_click_email)
     self.jid_ent = Entry(
         scale=.08, pos=(.05, .2), entry_font=menu_props.font, width=12,
         frame_col=menu_props.btn_col, initial_text=init_txt,
         text_fg=menu_props.text_active_col, on_tab=self.on_tab_id,
         on_click=self.on_click_id)
     start_btn = Btn(
         text=_('Reset'), pos=(0, -.2), cmd=self.reset,
         **self.props.gameprops.menu_props.btn_args)
     t_a['scale'] = .06
     widgets = [self.jid_ent, start_btn, jid_lab, email_lab, self.email_ent]
     self.add_widgets(widgets)
     self.eng.attach_obs(self.on_frame)
     ThanksPageGui.build(self)
Exemplo n.º 3
0
 def build(self):
     menu_props = self.menu_props
     t_a = menu_props.text_args.copy()
     # del t_a['scale']
     jid_lab = Text(_('Your user id:'), pos=(-.05, .4),
                            align='right', **t_a)
     pwd_lab = Text(_('Your password:'******'right', **t_a)
     init_txt = self.props.opt_file['settings']['login']['usr'] if \
         self.props.opt_file['settings']['login']['usr'] else \
         _('your user id')
     self.jid_ent = Entry(
         scale=.08, pos=(.05, .4), entry_font=menu_props.font, width=12,
         frame_col=menu_props.btn_col, initial_text=init_txt,
         text_fg=menu_props.text_active_col, on_tab=self.on_tab,
         on_click=self.on_click)
     self.pwd_ent = Entry(
         scale=.08, pos=(.05, .2), entry_font=menu_props.font, width=12,
         frame_col=menu_props.btn_col, obscured=True,
         text_fg=menu_props.text_active_col, cmd=self.start)
     start_btn = Btn(
         text=_('Log-in'), pos=(0, 0), cmd=self.start,
         **self.props.gameprops.menu_props.btn_args)
     widgets = [self.jid_ent, self.pwd_ent, start_btn, jid_lab,
                pwd_lab]
     self.add_widgets(widgets)
     self.eng.attach_obs(self.on_frame)
     ThanksPageGui.build(self)
Exemplo n.º 4
0
 def build(self):
     menu_props = self.menu_props
     t_a = menu_props.text_args.copy()
     # del t_a['scale']
     email_lab = Text(_('Your email:'),
                      pos=(-.65, .4),
                      align='right',
                      **t_a)
     jid_lab = Text(_('Your user id:'),
                    pos=(-.65, .2),
                    align='right',
                    **t_a)
     pwd_lab = Text(_('Your password:'******'right',
                    **t_a)
     init_txt = self.props.opt_file['settings']['login']['usr'] if \
         self.props.opt_file['settings']['login']['usr'] else \
         _('your user id')
     self.email_ent = Entry(scale=.08,
                            pos=(-.55, .4),
                            entry_font=menu_props.font,
                            width=20,
                            frame_col=menu_props.btn_col,
                            initial_text=_('your email'),
                            text_fg=menu_props.text_active_col,
                            on_tab=self.on_tab_email,
                            on_click=self.on_click_email)
     self.jid_ent = Entry(scale=.08,
                          pos=(-.55, .2),
                          entry_font=menu_props.font,
                          width=20,
                          frame_col=menu_props.btn_col,
                          initial_text=init_txt,
                          text_fg=menu_props.text_active_col,
                          on_tab=self.on_tab_id,
                          on_click=self.on_click_id)
     self.pwd_ent = Entry(scale=.08,
                          pos=(-.55, 0),
                          entry_font=menu_props.font,
                          width=20,
                          frame_col=menu_props.btn_col,
                          obscured=True,
                          text_fg=menu_props.text_active_col,
                          cmd=self.register)
     start_btn = Btn(text=_('Register'),
                     pos=(0, -.2),
                     cmd=self.register,
                     **self.props.gameprops.menu_props.btn_args)
     t_a['scale'] = .06
     widgets = [
         self.jid_ent, self.pwd_ent, start_btn, jid_lab, pwd_lab, email_lab,
         self.email_ent
     ]
     self.add_widgets(widgets)
     self.eng.attach_obs(self.on_frame)
     ThanksPageGui.build(self)
Exemplo n.º 5
0
 def build(self):
     menu_props = self.menu_props
     t_a = menu_props.text_args.copy()
     # del t_a['scale']
     jid_lab = Text(_('Your user id:'), pos=(-.05, .4),
                            align='right', **t_a)
     pwd_lab = Text(_('Your password:'******'right', **t_a)
     init_txt = self.props.opt_file['settings']['login']['usr'] if \
         self.props.opt_file['settings']['login']['usr'] else \
         _('your user id')
     self.jid_ent = Entry(
         scale=.08, pos=(.05, .4), entry_font=menu_props.font, width=12,
         frame_col=menu_props.btn_col, initial_text=init_txt,
         text_fg=menu_props.text_active_col, on_tab=self.on_tab,
         on_click=self.on_click)
     self.pwd_ent = Entry(
         scale=.08, pos=(.05, .2), entry_font=menu_props.font, width=12,
         frame_col=menu_props.btn_col, obscured=True,
         text_fg=menu_props.text_active_col, cmd=self.start)
     start_btn = Btn(
         text=_('Log-in'), pos=(0, 0), cmd=self.start,
         **self.props.gameprops.menu_props.btn_args)
     widgets = [self.jid_ent, self.pwd_ent, start_btn, jid_lab,
                pwd_lab]
     self.add_widgets(widgets)
     self.eng.attach_obs(self.on_frame)
     ThanksPageGui.build(self)
Exemplo n.º 6
0
 def build(self):
     menu_props = self.menu_props
     all_names = self.props.gameprops.player_names + self.props.gameprops.stored_player_names[
         len(self.props.gameprops.player_names):]
     self.ent = Entry(
         scale=.08,
         pos=(0, .6),
         entry_font=menu_props.font,
         width=12,
         frame_col=menu_props.btn_col,
         initial_text=all_names[0] if all_names else _('your name'),
         text_fg=menu_props.text_active_col)
     self.add_widgets([self.ent])
     self.update_tsk = taskMgr.add(self.update_text, 'update text')
     DriverPageGui.build(self, exit_behav=False)
     self.enable_buttons(False)
Exemplo n.º 7
0
 def __init__(self,
              attr_name,
              init_val,
              pos,
              val_range,
              callback,
              args=None):
     # unused val_range
     GameObject.__init__(self)
     self.__callback = callback
     self.__args = args or []
     self.__lab = OnscreenText(text=attr_name,
                               pos=pos,
                               align=TextNode.ARight,
                               fg=(1, 1, 1, 1),
                               parent=base.a2dTopLeft,
                               scale=.046)
     slider_pos = LVector3f(pos[0], 1, pos[1]) + (.05, 0, .01)
     self.__slider = Entry(pos=slider_pos,
                           initial_text=str(init_val),
                           cmd=self.__set_attr,
                           parent=base.a2dTopLeft,
                           scale=.05,
                           frame_col=(0, 0, 0, .2),
                           text_fg=(1, 1, 1, 1))
     # txt_pos = LVector3f(pos[0], pos[1], 1) + (.6, 0, 0)
     self.widgets = [self.__slider, self.__lab]
     self.toggle()
Exemplo n.º 8
0
 def __init__(self, menu_props):
     GameObject.__init__(self)
     self.eng.log('created match message form')
     self.chat = None
     self.msg_frm = Frame(
         frame_size=(-.02, 3.49, 0, 1.22),
         frame_col=(.2, .2, .2, .5),
         pos=(.04, -1.69), parent=base.a2dTopLeft)
     t_a = menu_props.text_args
     t_a['scale'] = .05
     t_a['fg'] = menu_props.text_normal_col
     self.dst_txt = Text(
         txt='', pos=(0, 1.16), parent=self.msg_frm, align='left',
         **t_a)
     self.ent = Entry(
         scale=.04, pos=(0, .03), entry_font=menu_props.font, width=86,
         frame_col=menu_props.btn_col, parent=self.msg_frm,
         initial_text=_('write here your message'),
         cmd=self.on_typed_msg, focus_in_cmd=self.on_focus,
         focus_in_args=['in'], focus_out_cmd=self.on_focus,
         focus_out_args=['out'], text_fg=menu_props.text_active_col)
     self.ent['state'] = DISABLED
     self.txt_frm = ScrolledFrame(
         frame_sz=(-.02, 2.46, -.02, 1.02),
         canvas_sz=(-.02, 2.42, -.02, 1.02),
         scrollbar_width=.036,
         frame_col=(1, 1, 1, .0),
         pos=(.02, .11), parent=self.msg_frm)
     t_a['scale'] = .046
     self.msg_txt = Text(
         txt='', pos=(0, .24), parent=self.txt_frm.canvas,
         align='left', wordwrap=52, **t_a)
     lab_args = menu_props.label_args
     lab_args['scale'] = .046
     lab_args['text_fg'] = menu_props.text_normal_col
     self.lab_frm = Btn(
         frame_size=(-.02, 2.5, -.01, .05),
         frame_col=(1, 1, 1, 0),
         pos=(0, 1.15), parent=self.msg_frm)
     self.lab_frm.bind(ENTER, self.on_enter)
     self.lab_frm.bind(EXIT, self.on_exit)
     self.tooltip = Label(
         text='', pos=(2.4, -.06), parent=self.lab_frm, text_wordwrap=50,
         text_align=TextNode.A_right, **lab_args)
     self.tooltip.set_bin('gui-popup', 10)
     self.tooltip.hide()
     self.eng.client.attach(self.on_groupchat_msg)
Exemplo n.º 9
0
class DriverPageSinglePlayerGui(DriverPageGui):
    def __init__(self, mediator, driverpage_props, nplayers=1):
        DriverPageGui.__init__(self, mediator, driverpage_props, nplayers)
        if self.ent.text != _('your name'):
            btn = [
                wdg for wdg in self.widgets
                if wdg.__class__.__name__ == 'ImgBtnWidget'
            ][0]
            for player in self.players:
                self.focus(btn, player)

    def build(self):
        menu_props = self.menu_props
        all_names = self.props.gameprops.player_names + self.props.gameprops.stored_player_names[
            len(self.props.gameprops.player_names):]
        self.ent = Entry(
            scale=.08,
            pos=(0, .6),
            entry_font=menu_props.font,
            width=12,
            frame_col=menu_props.btn_col,
            initial_text=all_names[0] if all_names else _('your name'),
            text_fg=menu_props.text_active_col)
        self.add_widgets([self.ent])
        self.update_tsk = taskMgr.add(self.update_text, 'update text')
        DriverPageGui.build(self, exit_behav=False)
        self.enable_buttons(False)

    def update_text(self, task):
        has_name = self.ent.text != _('your name')
        if has_name and self.ent.text.startswith(_('your name')):
            self.ent.enter_text(self.ent.text[len(_('your name')):])
            self.enable_buttons(True)
        elif self.ent.text in [_('your name')[:-1], '']:
            self.ent.enter_text('')
            self.enable_buttons(False)
        elif self.ent.text not in [_('your name'), '']:
            self.enable_buttons(True)
        return task.cont  # don't do a task, attach to modifications events

    def this_name(self):
        return self.ent.text

    def destroy(self):
        taskMgr.remove(self.update_tsk)
        DriverPageGui.destroy(self)
Exemplo n.º 10
0
 def build(self):
     menu_props = self.menu_props
     self.ent = Entry(
         scale=.08, pos=(0, .6), entry_font=menu_props.font, width=12,
         frame_col=menu_props.btn_col,
         initial_text=self.props.gameprops.player_name or _('your name'),
         text_fg=menu_props.text_active_col)
     self.add_widgets([self.ent])
     self.update_tsk = taskMgr.add(self.update_text, 'update text')
     DriverPageGui.build(self, exit_behav=False)
     self.enable_buttons(False)
Exemplo n.º 11
0
 def __init__(self, menu_props):
     GameObject.__init__(self)
     self.eng.log('created match message form')
     self.chat = None
     self.msg_frm = Frame(
         frame_size=(-.02, 3.49, 0, 1.22),
         frame_col=(.2, .2, .2, .5),
         pos=(.04, -1.69), parent=base.a2dTopLeft)
     t_a = menu_props.text_args
     t_a['scale'] = .05
     t_a['fg'] = menu_props.text_normal_col
     self.dst_txt = Text(
         txt='', pos=(0, 1.16), parent=self.msg_frm, align='left',
         **t_a)
     self.ent = Entry(
         scale=.04, pos=(0, .03), entry_font=menu_props.font, width=86,
         frame_col=menu_props.btn_col, parent=self.msg_frm,
         initial_text=_('write here your message'),
         cmd=self.on_typed_msg, focus_in_cmd=self.on_focus,
         focus_in_args=['in'], focus_out_cmd=self.on_focus,
         focus_out_args=['out'], text_fg=menu_props.text_active_col)
     self.ent['state'] = DISABLED
     self.txt_frm = ScrolledFrame(
         frame_sz=(-.02, 2.46, -.02, 1.02),
         canvas_sz=(-.02, 2.42, -.02, 1.02),
         scrollbar_width=.036,
         frame_col=(1, 1, 1, .0),
         pos=(.02, .11), parent=self.msg_frm)
     t_a['scale'] = .046
     self.msg_txt = Text(
         txt='', pos=(0, .24), parent=self.txt_frm.canvas,
         align='left', wordwrap=52, **t_a)
     lab_args = menu_props.label_args
     lab_args['scale'] = .046
     lab_args['text_fg'] = menu_props.text_normal_col
     self.lab_frm = Btn(
         frame_size=(-.02, 2.5, -.01, .05),
         frame_col=(1, 1, 1, 0),
         pos=(0, 1.15), parent=self.msg_frm)
     self.lab_frm.bind(ENTER, self.on_enter)
     self.lab_frm.bind(EXIT, self.on_exit)
     self.tooltip = Label(
         text='', pos=(2.4, -.06), parent=self.lab_frm, text_wordwrap=50,
         text_align=TextNode.A_right, **lab_args)
     self.tooltip.set_bin('gui-popup', 10)
     self.tooltip.hide()
Exemplo n.º 12
0
class RegisterPageGui(ThanksPageGui):

    def __init__(self, mediator, mp_props):
        self.props = mp_props
        ThanksPageGui.__init__(self, mediator, mp_props.gameprops.menu_props)

    def build(self):
        menu_props = self.menu_props
        t_a = menu_props.text_args.copy()
        # del t_a['scale']
        email_lab = Text(_('Your email:'), pos=(-.65, .4),
                               align='right', **t_a)
        jid_lab = Text(_('Your user id:'), pos=(-.65, .2),
                               align='right', **t_a)
        pwd_lab = Text(_('Your password:'******'right', **t_a)
        init_txt = self.props.opt_file['settings']['login']['usr'] if \
            self.props.opt_file['settings']['login']['usr'] else \
            _('your user id')
        self.email_ent = Entry(
            scale=.08, pos=(-.55, .4), entry_font=menu_props.font, width=20,
            frame_col=menu_props.btn_col, initial_text=_('your email'),
            text_fg=menu_props.text_active_col, on_tab=self.on_tab_email,
            on_click=self.on_click_email)
        self.jid_ent = Entry(
            scale=.08, pos=(-.55, .2), entry_font=menu_props.font, width=20,
            frame_col=menu_props.btn_col, initial_text=init_txt,
            text_fg=menu_props.text_active_col, on_tab=self.on_tab_id,
            on_click=self.on_click_id)
        self.pwd_ent = Entry(
            scale=.08, pos=(-.55, 0), entry_font=menu_props.font, width=20,
            frame_col=menu_props.btn_col, obscured=True,
            text_fg=menu_props.text_active_col, cmd=self.register)
        start_btn = Btn(
            text=_('Register'), pos=(0, -.2), cmd=self.register,
            **self.props.gameprops.menu_props.btn_args)
        t_a['scale'] = .06
        widgets = [self.jid_ent, self.pwd_ent, start_btn, jid_lab, pwd_lab,
                   email_lab, self.email_ent]
        self.add_widgets(widgets)
        self.eng.attach_obs(self.on_frame)
        ThanksPageGui.build(self)

    def register(self, pwd_name=None):
        def process_msg(data_lst, sender):
            print(sender, data_lst)
        if len(self.pwd_ent.text) >= 6:
            self.eng.client.start(process_msg)
            self.eng.client.register_rpc('register')
            self.eng.client.register_rpc('get_salt')
            salt = self.eng.client.get_salt(self.jid_ent.text)
            ret_val = self.eng.client.register(
                self.jid_ent.text,
                sha512(self.pwd_ent.text + salt).hexdigest(), salt,
                self.email_ent.text.replace('_AT_', '@'))
        else: ret_val = 'short'
        self.ret_val = ret_val
        ok_txt = _(
            'Your account has been registered. Now, in order to '
            "activate it, you should click the link that we've sent to your "
            "email (please check your spam folder if you can't find it). "
            'After that, you can log in.')
        inv_nick_txt = _(
            "Your nickname's format is invalid: please use only letters and "
            'numbers.')
        inv_email_txt = _("Your email's format is invalid.")
        already_nick_txt = _('Your nickname already exists.')
        already_email_txt = _('Your email has already been used.')
        short_txt = _('Please use more than 6 characters for your password.')
        err_txt = _('Connection error.')
        if ret_val == 'ok': txt = ok_txt
        elif ret_val == 'invalid_nick': txt = inv_nick_txt
        elif ret_val == 'invalid_email': txt = inv_email_txt
        elif ret_val == 'already_used_nick': txt = already_nick_txt
        elif ret_val == 'already_used_email': txt = already_email_txt
        elif ret_val == 'short': txt = short_txt
        else: txt = err_txt
        self.register_dlg = RegisterDialog(self.menu_props, txt)
        self.register_dlg.attach(self.on_register_dlg)

    def on_register_dlg(self):
        self.register_dlg.destroy()
        if self.ret_val == 'ok':
            self._on_back()

    def on_frame(self):
        init_txt = _('your user id')
        curr_txt = self.jid_ent.text
        if curr_txt == init_txt[:-1]:
            self.jid_ent.set('')
        elif curr_txt.startswith(init_txt) and len(curr_txt) == len(init_txt) + 1:
            self.jid_ent.set(curr_txt[-1:])
        init_txt = _('your email')
        curr_txt = self.email_ent.text
        if curr_txt == init_txt[:-1]:
            self.email_ent.set('')
        elif curr_txt.startswith(init_txt) and len(curr_txt) == len(init_txt) + 1:
            self.email_ent.set(curr_txt[-1:])

    def on_click_email(self, pos):
        init_txt = _('your email')
        curr_txt = self.email_ent.text
        if curr_txt == init_txt: self.email_ent.set('')

    def on_click_id(self, pos):
        init_txt = _('your user id')
        curr_txt = self.jid_ent.text
        if curr_txt == init_txt: self.jid_ent.set('')

    def on_tab_email(self):
        self.email_ent['focus'] = 0
        self.jid_ent['focus'] = 1
        self.pwd_ent['focus'] = 0

    def on_tab_id(self):
        self.email_ent['focus'] = 0
        self.jid_ent['focus'] = 0
        self.pwd_ent['focus'] = 1

    def on_ok(self):
        self.props.opt_file['settings']['login']['usr'] = self.jid_ent.text
        if self.store_cb['indicatorValue']:
            self.props.opt_file['settings']['login']['pwd'] = self.pwd_ent.text
        self.props.opt_file.store()
        self._on_back()
        self.notify('on_login')

    def on_ko(self, err):  # unused err
        txt = Text(_('Error'), pos=(-.2, -.05), fg=(1, 0, 0, 1),
                           scale=.16, font=self.menu_props.font)
        self.eng.do_later(5, txt.destroy)

    def destroy(self):
        self.eng.detach_obs(self.on_frame)
        ThanksPageGui.destroy(self)
Exemplo n.º 13
0
    def build(self):
        self.drv_info = self.props.gameprops.drivers_info
        menu_props = self.menu_props
        widgets = [
            Text(_('Select the drivers'), pos=(0, .91), **menu_props.text_args)
        ]
        t_a = self.menu_props.text_args.copy()
        del t_a['scale']
        self.name = Text(_('Write your names:'),
                         pos=(-.1, .7),
                         scale=.06,
                         align='right',
                         wordwrap=128,
                         **t_a)
        self.drivers = []
        for row, col in product(range(2), range(4)):
            idx = col + row * 4
            drv_btn = ImgBtn(scale=(.24, .24),
                             pos=(-.75 + col * .5, .1 - row * .64),
                             frame_col=(0, 0, 0, 0),
                             img=self.props.gameprops.drivers_img.path % idx,
                             cmd=self.on_click,
                             extra_args=[idx],
                             **self.menu_props.imgbtn_args)
            name = Text('',
                        pos=(-.75 + col * .5, -.19 - row * .64),
                        scale=.046,
                        **t_a)
            drv_btn._name_txt = name
            widgets += [drv_btn, name]
            self.drivers += [widgets[-2]]
            sign = lambda pos_x: '\1green\1+\2' if pos_x > 0 else ''
            psign = lambda pos_x, sgn=sign: '+' if pos_x == 0 else sgn(pos_x)

            def ppcol(x):
                return '\1green\1%s\2' % x if x > 0 else '\1red\1%s\2' % x

            pcol = lambda x: x if x == 0 else ppcol(x)
            lab_lst = [(_('adherence'), -.11), (_('speed'), .01),
                       (_('stability'), -.05)]
            widgets += list(
                map(lambda lab_def: self._add_lab(*(lab_def + (row, col))),
                    lab_lst))
            txt_lst = [(self.drv_info[idx - 1].adherence, -.11),
                       (self.drv_info[idx - 1].speed, .01),
                       (self.drv_info[idx - 1].stability, -.05)]
            widgets += list(
                map(
                    lambda txt_def: self._add_txt(*txt_def +
                                                  (psign, pcol, col, row)),
                    txt_lst))
        self.sel_drv_img = []
        self.tss = []
        instr_txt = _(
            'If you use the keyboard, press FIRE to edit the field, then '
            "ENTER when you're done. Other players can't move while someone "
            'is writing (since, with keyboards, some letters may be bound to '
            'movements).')
        instr = Text(instr_txt, pos=(1.28, .8), scale=.042, wordwrap=24, **t_a)
        widgets += [self.name, instr]
        for i, car in enumerate(self.mediator.cars):
            self.sel_drv_img += [
                Img(self.props.gameprops.cars_img % car,
                    parent=base.a2dBottomLeft,
                    pos=(.3, 1.74 - i * .46),
                    scale=.22)
            ]
            widgets += [self.sel_drv_img[-1]]
            ffilterpath = self.eng.curr_path + 'yyagl/assets/shaders/filter.vert'
            with open(ffilterpath) as ffilter:
                vert = ffilter.read()
            shader = load_shader(vert, frag)
            if shader:
                self.sel_drv_img[-1].set_shader(shader)
            self.sel_drv_img[-1].set_transparent()
            self.tss += [TextureStage('ts')]
            self.tss[-1].set_mode(TextureStage.MDecal)
            empty_img = PNMImage(1, 1)
            empty_img.add_alpha()
            empty_img.alpha_fill(0)
            tex = Texture()
            tex.load(empty_img)
            self.sel_drv_img[-1].set_texture(self.tss[-1], tex)
        all_names = self.props.gameprops.player_names + self.props.gameprops.stored_player_names[
            len(self.props.gameprops.player_names):]
        self.ents = [
            Entry(scale=.06,
                  pos=(0, .8 - .12 * i),
                  entry_font=menu_props.font,
                  width=12,
                  frame_col=menu_props.btn_col,
                  initial_text=all_names[i]
                  if i < len(all_names) else _('your name'),
                  text_fg=menu_props.text_active_col)
            for i in range(len(self.mediator.cars))
        ]
        self.add_widgets(self.ents)
        self.add_widgets(widgets)
        ThanksPageGui.build(self, exit_behav=False)
        self.update_tsk = taskMgr.add(self.update_text, 'update text')
        self.enable_buttons(False)
Exemplo n.º 14
0
class LogInPageGui(ThanksPageGui):

    def __init__(self, mediator, mp_props):
        self.props = mp_props
        ThanksPageGui.__init__(self, mediator, mp_props.gameprops.menu_props)

    def build(self):
        menu_props = self.menu_props
        t_a = menu_props.text_args.copy()
        # del t_a['scale']
        jid_lab = Text(_('Your user id:'), pos=(-.05, .4),
                               align='right', **t_a)
        pwd_lab = Text(_('Your password:'******'right', **t_a)
        init_txt = self.props.opt_file['settings']['login']['usr'] if \
            self.props.opt_file['settings']['login']['usr'] else \
            _('your user id')
        self.jid_ent = Entry(
            scale=.08, pos=(.05, .4), entry_font=menu_props.font, width=12,
            frame_col=menu_props.btn_col, initial_text=init_txt,
            text_fg=menu_props.text_active_col, on_tab=self.on_tab,
            on_click=self.on_click)
        self.pwd_ent = Entry(
            scale=.08, pos=(.05, .2), entry_font=menu_props.font, width=12,
            frame_col=menu_props.btn_col, obscured=True,
            text_fg=menu_props.text_active_col, cmd=self.start)
        start_btn = Btn(
            text=_('Log-in'), pos=(0, 0), cmd=self.start,
            **self.props.gameprops.menu_props.btn_args)
        widgets = [self.jid_ent, self.pwd_ent, start_btn, jid_lab,
                   pwd_lab]
        self.add_widgets(widgets)
        self.eng.attach_obs(self.on_frame)
        ThanksPageGui.build(self)

    def start(self, pwd_name=None):
        def process_msg(data_lst, sender):
            print(sender, data_lst)
        #self.eng.client.start(process_msg, self.eng.cfg.dev_cfg.server)
        self.eng.client.register_rpc('login')
        self.eng.client.register_rpc('get_salt')
        #self.eng.client.restart()
        salt = self.eng.client.get_salt(self.jid_ent.text)
        self.pwd = sha512(self.pwd_ent.text.encode() + salt.encode()).hexdigest()
        ret_val = self.eng.client.login(self.jid_ent.text, self.pwd)
        if ret_val in ['invalid_nick', 'unregistered_nick', 'wrong_pwd']:
            return self.on_ko(ret_val)
        self.on_ok()

    def on_frame(self):
        init_txt = _('your user id')
        curr_txt = self.jid_ent.text
        if curr_txt == init_txt[:-1]:
            self.jid_ent.set('')
        elif curr_txt.startswith(init_txt) and len(curr_txt) == len(init_txt) + 1:
            self.jid_ent.set(curr_txt[-1:])

    def on_click(self, pos):
        init_txt = _('your user id')
        curr_txt = self.jid_ent.text
        if curr_txt == init_txt: self.jid_ent.set('')

    def on_tab(self):
        self.jid_ent['focus'] = 0
        self.pwd_ent['focus'] = 1

    def on_ok(self):
        self.eng.client.authenticated = True
        self.props.opt_file['settings']['login']['usr'] = self.jid_ent.text
        self.props.opt_file['settings']['login']['pwd'] = self.pwd
        self.props.opt_file.store()
        self.eng.client.init(self.props.opt_file['settings']['login']['usr'])
        self._on_back()
        self.notify('on_login')

    def on_ko(self, err):  # unused err
        txt = Text(_('Error') + ': ' + err, pos=(-.2, -.05), fg=(1, 0, 0, 1),
                           scale=.16, font=self.menu_props.font)
        self.eng.do_later(5, txt.destroy)

    def destroy(self):
        self.eng.detach_obs(self.on_frame)
        ThanksPageGui.destroy(self)
Exemplo n.º 15
0
class MatchMsgFrm(GameObject):

    def __init__(self, menu_props):
        GameObject.__init__(self)
        self.eng.log('created match message form')
        self.chat = None
        self.msg_frm = Frame(
            frame_size=(-.02, 3.49, 0, 1.22),
            frame_col=(.2, .2, .2, .5),
            pos=(.04, -1.69), parent=base.a2dTopLeft)
        t_a = menu_props.text_args
        t_a['scale'] = .05
        t_a['fg'] = menu_props.text_normal_col
        self.dst_txt = Text(
            txt='', pos=(0, 1.16), parent=self.msg_frm, align='left',
            **t_a)
        self.ent = Entry(
            scale=.04, pos=(0, .03), entry_font=menu_props.font, width=86,
            frame_col=menu_props.btn_col, parent=self.msg_frm,
            initial_text=_('write here your message'),
            cmd=self.on_typed_msg, focus_in_cmd=self.on_focus,
            focus_in_args=['in'], focus_out_cmd=self.on_focus,
            focus_out_args=['out'], text_fg=menu_props.text_active_col)
        self.ent['state'] = DISABLED
        self.txt_frm = ScrolledFrame(
            frame_sz=(-.02, 2.46, -.02, 1.02),
            canvas_sz=(-.02, 2.42, -.02, 1.02),
            scrollbar_width=.036,
            frame_col=(1, 1, 1, .0),
            pos=(.02, .11), parent=self.msg_frm)
        t_a['scale'] = .046
        self.msg_txt = Text(
            txt='', pos=(0, .24), parent=self.txt_frm.canvas,
            align='left', wordwrap=52, **t_a)
        lab_args = menu_props.label_args
        lab_args['scale'] = .046
        lab_args['text_fg'] = menu_props.text_normal_col
        self.lab_frm = Btn(
            frame_size=(-.02, 2.5, -.01, .05),
            frame_col=(1, 1, 1, 0),
            pos=(0, 1.15), parent=self.msg_frm)
        self.lab_frm.bind(ENTER, self.on_enter)
        self.lab_frm.bind(EXIT, self.on_exit)
        self.tooltip = Label(
            text='', pos=(2.4, -.06), parent=self.lab_frm, text_wordwrap=50,
            text_align=TextNode.A_right, **lab_args)
        self.tooltip.set_bin('gui-popup', 10)
        self.tooltip.hide()
        self.eng.client.attach(self.on_groupchat_msg)

    @property
    def widgets(self):
        return [self.msg_frm, self.dst_txt, self.ent, self.txt_frm,
                self.msg_txt, self.lab_frm, self.tooltip]

    def on_enter(self, pos):
        self.tooltip.show()

    def on_exit(self, pos):
        self.tooltip.hide()

    def add_msg_txt(self, msg):
        self.msg_txt['text'] += ('\n' if self.msg_txt['text'] else '') + msg
        txt_height = self.msg_txt.get_np().textNode.getUpperLeft3d()[2] - \
            self.msg_txt.get_np().textNode.getLowerRight3d()[2]
        self.txt_frm['canvasSize'] = (-.02, .72, .28 - txt_height, .28)

    def set_title(self, title):
        ttitle = self.trunc(title, 160)
        fix_name = lambda name: name if '@' not in name else name.split('@')[0] + '\1smaller\1@' + name.split('@')[1] + '\2'
        if title:
            if ',' in ttitle:
                is_muc = True
                ttitle = ttitle
                names = ttitle.split(',')
                names = [name.strip() for name in names]
                names = [fix_name(name) for name in names]
                ttitle = ', '.join(names)
            else:
                ttitle = fix_name(ttitle)
        self.dst_txt['text'] = ttitle
        self.tooltip['text'] = title

    @staticmethod
    def trunc(name, lgt):
        if len(name) > lgt: return name[:lgt] + '...'
        return name

    def on_typed_msg(self, val):
        self.add_msg_txt('\1italic\1' + _('you') + '\2: ' + val)
        self.ent.set('')
        self.eng.client.send([
            'msg_room', self.eng.client.myid, self.chat.dst, val])
        #self.eng.xmpp.client.send_message(
        #    mfrom=self.eng.xmpp.client.boundjid.full,
        #    mto=self.chat.dst,
        #    mtype='groupchat',
        #    mbody=val)
        self.ent['focus'] = 1

    def on_groupchat_msg(self, from_, to, txt):
        #src = str(JID(msg['mucnick']))
        #src = src.split('@')[0] + '\1smaller\1@' + src.split('@')[1] + '\2'
        src = from_
        #self.eng.log('received groupchat message from %s in the chat %s' %(msg['mucnick'], JID(msg['from']).bare))
        self.eng.log('received groupchat message from %s in the chat %s' % (from_, to))
        #str_msg = '\1italic\1' + src + '\2: ' + str(msg['body'])
        str_msg = '\1italic\1' + src + '\2: ' + txt
        if not self.chat:
            #self.chat = MUC(str(JID(msg['from']).bare), self.yorg_client)
            self.chat = MUC(to)
        self.chat.messages += [str_msg]
        if self.dst_txt['text'] == '':
            self.set_chat(self.chat)
        #elif self.chat.dst == str(JID(msg['from']).bare):
        elif self.chat.dst == to:
            self.add_msg_txt(str_msg)

    def on_presence_available_room(self, uid, room):
        #room = str(JID(msg['muc']['room']).bare)
        #nick = str(msg['muc']['nick'])
        self.eng.log('user %s has logged in the chat %s' % (uid, room))
        self.chat.users += [uid]
        self.set_title(self.chat.title)

    def on_presence_unavailable_room(self, uid, room_name):
        room = room_name
        nick = uid
        self.eng.log('user %s has left the chat %s' %(nick, room))
        if nick in self.chat.users: # it is being removed multiple times when
                                    # you remove a user who has accepted
            self.chat.users.remove(nick)
        self.set_title(self.chat.title)

    def on_rm_usr_from_match(self, uid):
        if uid in self.chat.users:  # it is being removed multiple times when
                                    # you remove a user who has accepted
            self.chat.users.remove(uid)
        self.update_title()

    def add_groupchat(self, room):#, usr):
        #self.set_title(usr)
        if not self.chat:
            self.chat = MUC(room)
        self.set_chat(self.chat)

    def set_chat(self, chat):
        self.set_title(chat.title)
        self.msg_txt['text'] = '\n'.join(chat.messages)
        txt_height = self.msg_txt.get_np().textNode.getUpperLeft3d()[2] - \
            self.msg_txt.get_np().textNode.getLowerRight3d()[2]
        self.txt_frm['canvasSize'] = (-.02, .72, .28 - txt_height, .28)
        self.ent['state'] = NORMAL

    def update_title(self):
        self.set_title(self.chat.title)

    def on_focus(self, val):
        if self.observers is None: return
        # it may be called from entries which aren't destroyed yet (i.e. they
        #   are in transition_exit)
        if val == 'in' and self.ent.text == _('write here your message'):
            self.ent.set('')
        self.notify('on_match_msg_focus', val)

    def destroy(self):
        self.eng.client.detach(self.on_groupchat_msg)
        self.eng.log('message form destroyed')
        #self.msg_frm.destroy()
        GameObject.destroy(self)
Exemplo n.º 16
0
 def __init__(self, menu_props):
     GameObject.__init__(self)
     self.eng.log('created message form')
     self.chats = []
     self.curr_chat = None
     self.curr_match_room = None
     self.msg_frm = DirectFrame(
         frameSize=(-.02, .8, 0, .45),
         frameColor=(.2, .2, .2, .5),
         pos=(-.82, 1, .02), parent=base.a2dBottomRight)
     self.presences_sent = []
     self.menu_props = menu_props
     t_a = menu_props.text_args
     t_a['scale'] = .05
     t_a['fg'] = menu_props.text_normal_col
     self.dst_txt = OnscreenText(
         text='', pos=(0, .4), parent=self.msg_frm, align=TextNode.A_left,
         **t_a)
     self.arrow_btn = ImgBtn(
         parent=self.msg_frm, scale=(.024, .024), pos=(.7, 1, .42),
         frame_col=(1, 1, 1, 1),
         frame_texture='assets/images/gui/arrow.txo',
         cmd=self.on_arrow,
         **menu_props.imgbtn_args)
     self.arrow_btn.disable()
     self.close_btn = ImgBtn(
         parent=self.msg_frm, scale=(.024, .024), pos=(.76, 1, .42),
         frame_col=(1, 1, 1, 1),
         frame_texture='assets/images/gui/close.txo',
         cmd=self.on_close,
         **menu_props.imgbtn_args)
     self.close_btn.disable()
     self.ent = Entry(
         scale=.04, pos=(0, .03), entry_font=menu_props.font, width=19.5,
         frame_col=menu_props.btn_col, parent=self.msg_frm,
         initial_text=_('write here your message'),
         cmd=self.on_typed_msg, focus_in_cmd=self.on_focus,
         focus_in_args=['in'], focus_out_cmd=self.on_focus,
         focus_out_args=['out'], text_fg=menu_props.text_active_col)
     self.ent['state'] = DISABLED
     self.txt_frm = DirectScrolledFrame(
         frameSize=(-.02, .76, -.02, .28),
         canvasSize=(-.02, .72, -.02, .28),
         scrollBarWidth=.036,
         verticalScroll_relief=FLAT,
         verticalScroll_frameColor=(.2, .2, .2, .4),
         verticalScroll_thumb_relief=FLAT,
         verticalScroll_thumb_frameColor=(.8, .8, .8, .6),
         verticalScroll_incButton_relief=FLAT,
         verticalScroll_incButton_frameColor=(.8, .8, .8, .6),
         verticalScroll_decButton_relief=FLAT,
         verticalScroll_decButton_frameColor=(.8, .8, .8, .6),
         horizontalScroll_relief=FLAT,
         frameColor=(1, 1, 1, 0),
         pos=(.02, 1, .11), parent=self.msg_frm)
     t_a['scale'] = .046
     self.msg_txt = OnscreenText(
         text='', pos=(0, .24), parent=self.txt_frm.getCanvas(),
         align=TextNode.A_left, wordwrap=14, **t_a)
     lab_args = menu_props.label_args
     lab_args['scale'] = .046
     lab_args['text_fg'] = menu_props.text_normal_col
     self.lab_frm = Btn(
         frame_size=(-.02, .64, -.01, .05),
         frame_col=(1, 1, 1, 0),
         pos=(0, 1, .4), parent=self.msg_frm)
     self.lab_frm.bind(ENTER, self.on_enter)
     self.lab_frm.bind(EXIT, self.on_exit)
     self.tooltip = Label(
         text='', pos=(.78, 1, -.06),
         parent=self.lab_frm, text_wordwrap=16,# text_bg=(.2, .2, .2, .8),
         text_align=TextNode.A_right, **lab_args)
     self.tooltip.set_bin('gui-popup', 10)
     self.tooltip.hide()
Exemplo n.º 17
0
class MessageFrm(GameObject):

    def __init__(self, menu_props):
        GameObject.__init__(self)
        self.eng.log('created message form')
        self.chats = []
        self.curr_chat = None
        self.curr_match_room = None
        self.msg_frm = DirectFrame(
            frameSize=(-.02, .8, 0, .45),
            frameColor=(.2, .2, .2, .5),
            pos=(-.82, 1, .02), parent=base.a2dBottomRight)
        self.presences_sent = []
        self.menu_props = menu_props
        t_a = menu_props.text_args
        t_a['scale'] = .05
        t_a['fg'] = menu_props.text_normal_col
        self.dst_txt = OnscreenText(
            text='', pos=(0, .4), parent=self.msg_frm, align=TextNode.A_left,
            **t_a)
        self.arrow_btn = ImgBtn(
            parent=self.msg_frm, scale=(.024, .024), pos=(.7, 1, .42),
            frame_col=(1, 1, 1, 1),
            frame_texture='assets/images/gui/arrow.txo',
            cmd=self.on_arrow,
            **menu_props.imgbtn_args)
        self.arrow_btn.disable()
        self.close_btn = ImgBtn(
            parent=self.msg_frm, scale=(.024, .024), pos=(.76, 1, .42),
            frame_col=(1, 1, 1, 1),
            frame_texture='assets/images/gui/close.txo',
            cmd=self.on_close,
            **menu_props.imgbtn_args)
        self.close_btn.disable()
        self.ent = Entry(
            scale=.04, pos=(0, .03), entry_font=menu_props.font, width=19.5,
            frame_col=menu_props.btn_col, parent=self.msg_frm,
            initial_text=_('write here your message'),
            cmd=self.on_typed_msg, focus_in_cmd=self.on_focus,
            focus_in_args=['in'], focus_out_cmd=self.on_focus,
            focus_out_args=['out'], text_fg=menu_props.text_active_col)
        self.ent['state'] = DISABLED
        self.txt_frm = DirectScrolledFrame(
            frameSize=(-.02, .76, -.02, .28),
            canvasSize=(-.02, .72, -.02, .28),
            scrollBarWidth=.036,
            verticalScroll_relief=FLAT,
            verticalScroll_frameColor=(.2, .2, .2, .4),
            verticalScroll_thumb_relief=FLAT,
            verticalScroll_thumb_frameColor=(.8, .8, .8, .6),
            verticalScroll_incButton_relief=FLAT,
            verticalScroll_incButton_frameColor=(.8, .8, .8, .6),
            verticalScroll_decButton_relief=FLAT,
            verticalScroll_decButton_frameColor=(.8, .8, .8, .6),
            horizontalScroll_relief=FLAT,
            frameColor=(1, 1, 1, 0),
            pos=(.02, 1, .11), parent=self.msg_frm)
        t_a['scale'] = .046
        self.msg_txt = OnscreenText(
            text='', pos=(0, .24), parent=self.txt_frm.getCanvas(),
            align=TextNode.A_left, wordwrap=14, **t_a)
        lab_args = menu_props.label_args
        lab_args['scale'] = .046
        lab_args['text_fg'] = menu_props.text_normal_col
        self.lab_frm = Btn(
            frame_size=(-.02, .64, -.01, .05),
            frame_col=(1, 1, 1, 0),
            pos=(0, 1, .4), parent=self.msg_frm)
        self.lab_frm.bind(ENTER, self.on_enter)
        self.lab_frm.bind(EXIT, self.on_exit)
        self.tooltip = Label(
            text='', pos=(.78, 1, -.06),
            parent=self.lab_frm, text_wordwrap=16,# text_bg=(.2, .2, .2, .8),
            text_align=TextNode.A_right, **lab_args)
        self.tooltip.set_bin('gui-popup', 10)
        self.tooltip.hide()

    def on_enter(self, pos):
        self.tooltip.show()

    def on_exit(self, pos):
        self.tooltip.hide()

    def show(self):
        self.msg_frm.show()

    def hide(self):
        self.msg_frm.hide()

    def add_msg_txt(self, msg):
        self.msg_txt['text'] += ('\n' if self.msg_txt['text'] else '') + msg
        txt_height = self.msg_txt.textNode.getUpperLeft3d()[2] - \
            self.msg_txt.textNode.getLowerRight3d()[2]
        self.txt_frm['canvasSize'] = (-.02, .72, .28 - txt_height, .28)

    def set_title(self, title):
        ttitle = self.trunc(title, 32)
        fix_name = lambda name: name if '@' not in name else name.split('@')[0] + '\1smaller\1@' + name.split('@')[1] + '\2'
        if title:
            if ',' in ttitle:
                is_muc = True
                ttitle = ttitle
                names = ttitle.split(',')
                names = [name.strip() for name in names]
                names = [fix_name(name) for name in names]
                ttitle = ', '.join(names)
            else:
                ttitle = fix_name(ttitle)
        self.dst_txt['text'] = ttitle
        self.tooltip['text'] = title

    @staticmethod
    def trunc(name, lgt):
        if len(name) > lgt: return name[:lgt] + '...'
        return name

    def set_chat(self, chat):
        self.curr_chat = chat
        self.set_title(chat.title)
        self.msg_txt['text'] = '\n'.join(chat.messages)
        txt_height = self.msg_txt.textNode.getUpperLeft3d()[2] - \
            self.msg_txt.textNode.getLowerRight3d()[2]
        self.txt_frm['canvasSize'] = (-.02, .72, .28 - txt_height, .28)
        if not self.chats:
            self.close_btn.disable()
            self.ent['state'] = DISABLED
        elif len(self.chats) == 1:
            self.close_btn.enable()
            self.ent['state'] = NORMAL
            self.arrow_btn.disable()
        else:
            self.close_btn.enable()
            self.ent['state'] = NORMAL
            self.arrow_btn.enable()
        if all(_chat.read for _chat in self.chats):
            self.arrow_btn['frameTexture'] = 'assets/images/gui/arrow.txo'
        else:
            self.arrow_btn['frameTexture'] = 'assets/images/gui/message.txo'

    def on_arrow(self):
        chat_idx = self.chats.index(self.curr_chat)
        next_idx = (chat_idx + 1) % len(self.chats)
        chat = self.chats[next_idx]
        self.set_title(chat.title)
        chat.read = True
        self.set_chat(chat)

    @property
    def open_chats(self):
        return [chat for chat in self.chats if not chat.closed]

    def on_close(self):
        if self.curr_chat not in self.open_chats: return
        curr_idx = self.open_chats.index(self.curr_chat)
        #self.chats.remove(self.curr_chat)
        self.curr_chat.closed = True
        if self.open_chats:
            self.set_chat(self.open_chats[curr_idx - 1])
        else:
            self.set_chat(Chat(''))
            self.notify('on_close_all_chats')

    def on_typed_msg(self, val):
        self.add_msg_txt('\1italic\1' + _('you') + '\2: ' + val)
        self.ent.set('')
        #if self.curr_chat.dst not in self.presences_sent and \
        #        not str(self.curr_chat.dst).startswith('yorg'):
        #    self.eng.xmpp.client.send_presence(
        #        pfrom=self.eng.xmpp.client.boundjid.full,
        #        pto=self.curr_chat.dst)
        #    self.presences_sent += [self.curr_chat.dst]
        #if str(self.curr_chat.dst).startswith('yorg'):
        #    self.eng.xmpp.client.send_message(
        #        mfrom=self.eng.xmpp.client.boundjid.full,
        #        mto=self.curr_chat.dst,
        #        mtype='groupchat',
        #        mbody=val)
        #else:
        #    self.eng.xmpp.client.send_message(
        #        mfrom=self.eng.xmpp.client.boundjid.full,
        #        mto=self.curr_chat.dst,
        #        msubject='chat',
        #        mbody=val)
        if len(self.curr_chat.dst) > 12 and all(char.isdigit() for char in self.curr_chat.dst[-12:]):
            self.eng.client.send([
                'msg_room', self.eng.client.myid, self.curr_chat.dst, val])
        else:
            self.eng.client.send(['msg', self.eng.client.myid, self.curr_chat.dst, val])
        msg = '\1italic\1' + _('you') + '\2: ' + val
        self.curr_chat.messages += [msg]
        self.ent['focus'] = 1

    def on_msg(self, from_, to, txt):
        #src = str(JID(msg['from']).bare)
        #src = src.split('@')[0] + '\1smaller\1@' + src.split('@')[1] + '\2'
        str_msg = '\1italic\1' + from_ + '\2: ' + txt
        chat = self.__find_chat(from_)
        if not chat:
            chat = Chat(from_)
            self.chats += [chat]
        chat.messages += [str_msg]
        if self.dst_txt['text'] == '':
            self.set_chat(chat)
        elif self.curr_chat.dst == from_:
            self.add_msg_txt(str_msg)
        else:
            chat.read = False
            chat.closed = False
            self.arrow_btn['frameTexture'] = 'assets/images/gui/message.txo'

    def on_groupchat_msg(self, from_, to, txt):
        #if str(JID(msg['from']).bare) == self.curr_match_room:
        if to == self.curr_match_room:
            if self.match_msg_frm:  # we're still in the room page
                self.match_msg_frm.on_groupchat_msg(from_, to, txt)
        #src = str(JID(msg['mucnick']))
        #src = src.split('@')[0] + '\1smaller\1@' + src.split('@')[1] + '\2'
        src = from_
        #self.eng.log('received groupchat message from %s in the chat %s' %(msg['mucnick'], JID(msg['from']).bare))
        self.eng.log('received groupchat message from %s in the chat %s' % (from_, to))
        #str_msg = '\1italic\1' + src + '\2: ' + str(msg['body'])
        str_msg = '\1italic\1' + src + '\2: ' + txt
        chat = self.curr_chat
        if not chat:
            #chat = MUC(str(JID(msg['from']).bare))
            chat = MUC(to)
            self.chats += [chat]
        chat.messages += [str_msg]
        if self.dst_txt['text'] == '':
            self.set_chat(chat)
        #elif self.curr_chat.dst == str(JID(msg['from']).bare):
        elif self.curr_chat.dst == to:
            self.add_msg_txt(str_msg)
        else:
            chat.read = False
            chat.closed = False
            self.arrow_btn['frameTexture'] = 'assets/images/gui/message.txo'

    def on_presence_available_room(self, uid, room):
        if room == self.curr_match_room:
            self.match_msg_frm.on_presence_available_room(uid, room)
        #room = str(JID(msg['muc']['room']).bare)
        #nick = str(msg['muc']['nick'])
        self.eng.log('user %s has logged in the chat %s' %(uid, room))
        chat = self.__find_chat(room)
        chat.users += [uid]
        if room != self.curr_match_room:
            if self.curr_chat.dst == room:
                self.set_title(chat.title)

    def on_presence_unavailable_room(self, uid, room_name):
        if self.match_msg_frm and room_name == self.curr_match_room:
            self.match_msg_frm.on_presence_unavailable_room(uid, room_name)
            return
        room = room_name
        nick = uid
        self.eng.log('user %s has left the chat %s' %(nick, room))
        chat = self.__find_chat(room)
        if nick == self.eng.client.myid:
            self.on_close()
        else:
            chat.users.remove(nick)
            if self.curr_chat.dst == room:
                self.set_title(chat.title)

    def __find_chat(self, dst):
        chats = [chat for chat in self.chats if chat.dst == dst]
        if chats: return chats[0]

    def add_chat(self, usr):
        #self.set_title(JID(usr).bare)
        chat = self.__find_chat(usr)
        if not chat:
            chat = Chat(usr)
            self.chats += [chat]
        self.set_chat(chat)
        self.ent['focus'] = 1

    def add_groupchat(self, room, usr):
        self.set_title(usr)
        chat = self.__find_chat(room)
        if not chat:
            chat = MUC(room)
            self.chats += [chat]
        chat.users += [usr]
        self.set_chat(chat)
        self.add_match_chat(room, usr)

    def remove_groupchat(self):
        self.match_msg_frm.detach(self.on_match_msg_focus)
        self.match_msg_frm = self.match_msg_frm.destroy()

    def on_focus(self, val):
        if val and self.ent.get() == _('write here your message'):
            self.ent.set('')
        self.notify('on_msg_focus', val)

    def on_match_msg_focus(self, val):
        self.notify('on_msg_focus', val)

    def on_room_back(self):
        self.curr_match_room = None
        self.match_msg_frm.destroy()

    def add_match_chat(self, room, usr):
        if self.curr_match_room: return
        self.curr_match_room = room
        self.match_msg_frm = MatchMsgFrm(self.menu_props)
        self.match_msg_frm.attach(self.on_match_msg_focus)
        self.match_msg_frm.add_groupchat(room, usr)
Exemplo n.º 18
0
class ResetPageGui(ThanksPageGui):
    def __init__(self, mediator, mp_props):
        self.props = mp_props
        ThanksPageGui.__init__(self, mediator, mp_props.gameprops.menu_props)

    def build(self):
        menu_props = self.menu_props
        t_a = menu_props.text_args.copy()
        # del t_a['scale']
        email_lab = Text(_('Your email:'),
                         pos=(-.05, .4),
                         align='right',
                         **t_a)
        jid_lab = Text(_('Your user id:'),
                       pos=(-.05, .2),
                       align='right',
                       **t_a)
        init_txt = self.props.opt_file['settings']['login']['usr'] if \
            self.props.opt_file['settings']['login']['usr'] else \
            _('your user id')
        self.email_ent = Entry(scale=.08,
                               pos=(.05, .4),
                               entry_font=menu_props.font,
                               width=12,
                               frame_col=menu_props.btn_col,
                               initial_text=_('your email'),
                               text_fg=menu_props.text_active_col,
                               on_tab=self.on_tab_email,
                               on_click=self.on_click_email)
        self.jid_ent = Entry(scale=.08,
                             pos=(.05, .2),
                             entry_font=menu_props.font,
                             width=12,
                             frame_col=menu_props.btn_col,
                             initial_text=init_txt,
                             text_fg=menu_props.text_active_col,
                             on_tab=self.on_tab_id,
                             on_click=self.on_click_id)
        start_btn = Btn(text=_('Reset'),
                        pos=(0, -.2),
                        cmd=self.reset,
                        **self.props.gameprops.menu_props.btn_args)
        t_a['scale'] = .06
        widgets = [self.jid_ent, start_btn, jid_lab, email_lab, self.email_ent]
        self.add_widgets(widgets)
        self.eng.attach_obs(self.on_frame)
        ThanksPageGui.build(self)

    def reset(self, pwd_name=None):
        def process_msg(data_lst, sender):
            print(sender, data_lst)

        self.eng.client.start(process_msg)
        self.eng.client.register_rpc('reset')
        self.ret_val = ret_val = self.eng.client.reset(self.jid_ent.text,
                                                       self.email_ent.text)
        ok_txt = _(
            "We've sent an email to you (please check your spam folder if you "
            "can't find it) with the instructions for completing the reset.")
        nomail_txt = _("This email isn't in our archive.")
        nonick_txt = _("This nickname isn't in our archive.")
        dontmatch_txt = _("This nickname-email pair isn't in our archive.")
        err_txt = _('Connection error.')
        if ret_val == 'ok': txt = ok_txt
        elif ret_val == 'nomail': txt = nomail_txt
        elif ret_val == 'nonick': txt = nonick_txt
        elif ret_val == 'dontmatch': txt = dontmatch_txt
        else: txt = err_txt
        self.reset_dlg = ResetDialog(self.menu_props, txt)
        self.reset_dlg.attach(self.on_reset_dlg)

    def on_reset_dlg(self):
        self.reset_dlg.destroy()
        if self.ret_val == 'ok':
            self._on_back()

    def on_frame(self):
        init_txt = _('your user id')
        curr_txt = self.jid_ent.text
        if curr_txt == init_txt[:-1]:
            self.jid_ent.set('')
        elif curr_txt.startswith(init_txt) and len(
                curr_txt) == len(init_txt) + 1:
            self.jid_ent.set(curr_txt[-1:])
        init_txt = _('your email')
        curr_txt = self.email_ent.text
        if curr_txt == init_txt[:-1]:
            self.email_ent.set('')
        elif curr_txt.startswith(init_txt) and len(
                curr_txt) == len(init_txt) + 1:
            self.email_ent.set(curr_txt[-1:])

    def on_click_email(self, pos):
        init_txt = _('your email')
        curr_txt = self.email_ent.text
        if curr_txt == init_txt: self.email_ent.set('')

    def on_click_id(self, pos):
        init_txt = _('your user id')
        curr_txt = self.jid_ent.text
        if curr_txt == init_txt: self.jid_ent.set('')

    def on_tab_email(self):
        self.email_ent['focus'] = 0
        self.jid_ent['focus'] = 1

    def on_tab_id(self):
        self.email_ent['focus'] = 0
        self.jid_ent['focus'] = 0

    def on_ok(self):
        self.props.opt_file['settings']['login']['usr'] = self.jid_ent.text
        if self.store_cb['indicatorValue']:
            self.props.opt_file['settings']['login']['pwd'] = self.pwd_ent.text
        self.props.opt_file.store()
        self._on_back()
        self.notify('on_login')

    def on_ko(self, err):  # unused err
        txt = Text(_('Error'),
                   pos=(-.2, -.05),
                   fg=(1, 0, 0, 1),
                   scale=.16,
                   font=self.menu_props.font)
        self.eng.do_later(5, txt.destroy)

    def destroy(self):
        self.eng.detach_obs(self.on_frame)
        ThanksPageGui.destroy(self)
Exemplo n.º 19
0
class MessageFrm(GameObject):

    def __init__(self, menu_props):
        GameObject.__init__(self)
        self.eng.log('created message form')
        self.chats = []
        self.curr_chat = None
        self.curr_match_room = None
        self.msg_frm = DirectFrame(
            frameSize=(-.02, .8, 0, .45),
            frameColor=(.2, .2, .2, .5),
            pos=(-.82, 1, .02), parent=base.a2dBottomRight)
        self.presences_sent = []
        self.menu_props = menu_props
        t_a = menu_props.text_args
        t_a['scale'] = .05
        t_a['fg'] = menu_props.text_normal_col
        self.dst_txt = OnscreenText(
            text='', pos=(0, .4), parent=self.msg_frm, align=TextNode.A_left,
            **t_a)
        self.arrow_btn = ImgBtn(
            parent=self.msg_frm, scale=(.024, .024), pos=(.7, 1, .42),
            frame_col=(1, 1, 1, 1),
            frame_texture='assets/images/gui/arrow.txo',
            cmd=self.on_arrow,
            **menu_props.imgbtn_args)
        self.arrow_btn.disable()
        self.close_btn = ImgBtn(
            parent=self.msg_frm, scale=(.024, .024), pos=(.76, 1, .42),
            frame_col=(1, 1, 1, 1),
            frame_texture='assets/images/gui/close.txo',
            cmd=self.on_close,
            **menu_props.imgbtn_args)
        self.close_btn.disable()
        self.ent = Entry(
            scale=.04, pos=(0, .03), entry_font=menu_props.font, width=19.5,
            frame_col=menu_props.btn_col, parent=self.msg_frm,
            initial_text=_('write here your message'),
            cmd=self.on_typed_msg, focus_in_cmd=self.on_focus,
            focus_in_args=['in'], focus_out_cmd=self.on_focus,
            focus_out_args=['out'], text_fg=menu_props.text_active_col)
        self.ent['state'] = DISABLED
        self.txt_frm = DirectScrolledFrame(
            frameSize=(-.02, .76, -.02, .28),
            canvasSize=(-.02, .72, -.02, .28),
            scrollBarWidth=.036,
            verticalScroll_relief=FLAT,
            verticalScroll_frameColor=(.2, .2, .2, .4),
            verticalScroll_thumb_relief=FLAT,
            verticalScroll_thumb_frameColor=(.8, .8, .8, .6),
            verticalScroll_incButton_relief=FLAT,
            verticalScroll_incButton_frameColor=(.8, .8, .8, .6),
            verticalScroll_decButton_relief=FLAT,
            verticalScroll_decButton_frameColor=(.8, .8, .8, .6),
            horizontalScroll_relief=FLAT,
            frameColor=(1, 1, 1, 0),
            pos=(.02, 1, .11), parent=self.msg_frm)
        t_a['scale'] = .046
        self.msg_txt = OnscreenText(
            text='', pos=(0, .24), parent=self.txt_frm.getCanvas(),
            align=TextNode.A_left, wordwrap=14, **t_a)
        lab_args = menu_props.label_args
        lab_args['scale'] = .046
        lab_args['text_fg'] = menu_props.text_normal_col
        self.lab_frm = Btn(
            frame_size=(-.02, .64, -.01, .05),
            frame_col=(1, 1, 1, 0),
            pos=(0, 1, .4), parent=self.msg_frm)
        self.lab_frm.bind(ENTER, self.on_enter)
        self.lab_frm.bind(EXIT, self.on_exit)
        self.tooltip = Label(
            text='', pos=(.78, 1, -.06),
            parent=self.lab_frm, text_wordwrap=16,# text_bg=(.2, .2, .2, .8),
            text_align=TextNode.A_right, **lab_args)
        self.tooltip.set_bin('gui-popup', 10)
        self.tooltip.hide()

    def on_enter(self, pos):
        self.tooltip.show()

    def on_exit(self, pos):
        self.tooltip.hide()

    def show(self):
        self.msg_frm.show()

    def hide(self):
        self.msg_frm.hide()

    def add_msg_txt(self, msg):
        self.msg_txt['text'] += ('\n' if self.msg_txt['text'] else '') + msg
        txt_height = self.msg_txt.textNode.getUpperLeft3d()[2] - \
            self.msg_txt.textNode.getLowerRight3d()[2]
        self.txt_frm['canvasSize'] = (-.02, .72, .28 - txt_height, .28)

    def set_title(self, title):
        ttitle = self.trunc(title, 32)
        fix_name = lambda name: name if '@' not in name else name.split('@')[0] + '\1smaller\1@' + name.split('@')[1] + '\2'
        if title:
            if ',' in ttitle:
                is_muc = True
                ttitle = ttitle
                names = ttitle.split(',')
                names = [name.strip() for name in names]
                names = [fix_name(name) for name in names]
                ttitle = ', '.join(names)
            else:
                ttitle = fix_name(ttitle)
        self.dst_txt['text'] = ttitle
        self.tooltip['text'] = title

    @staticmethod
    def trunc(name, lgt):
        if len(name) > lgt: return name[:lgt] + '...'
        return name

    def set_chat(self, chat):
        self.curr_chat = chat
        self.set_title(chat.title)
        self.msg_txt['text'] = '\n'.join(chat.messages)
        txt_height = self.msg_txt.textNode.getUpperLeft3d()[2] - \
            self.msg_txt.textNode.getLowerRight3d()[2]
        self.txt_frm['canvasSize'] = (-.02, .72, .28 - txt_height, .28)
        if not self.chats:
            self.close_btn.disable()
            self.ent['state'] = DISABLED
        elif len(self.chats) == 1:
            self.close_btn.enable()
            self.ent['state'] = NORMAL
            self.arrow_btn.disable()
        else:
            self.close_btn.enable()
            self.ent['state'] = NORMAL
            self.arrow_btn.enable()
        if all(_chat.read for _chat in self.chats):
            self.arrow_btn['frameTexture'] = 'assets/images/gui/arrow.txo'
        else:
            self.arrow_btn['frameTexture'] = 'assets/images/gui/message.txo'

    def on_arrow(self):
        chat_idx = self.chats.index(self.curr_chat)
        next_idx = (chat_idx + 1) % len(self.chats)
        chat = self.chats[next_idx]
        self.set_title(chat.title)
        chat.read = True
        self.set_chat(chat)

    @property
    def open_chats(self):
        return [chat for chat in self.chats if not chat.closed]

    def on_close(self):
        if self.curr_chat not in self.open_chats: return
        curr_idx = self.open_chats.index(self.curr_chat)
        #self.chats.remove(self.curr_chat)
        self.curr_chat.closed = True
        if self.open_chats:
            self.set_chat(self.open_chats[curr_idx - 1])
        else:
            self.set_chat(Chat(''))
            self.notify('on_close_all_chats')

    def on_typed_msg(self, val):
        self.add_msg_txt('\1italic\1' + _('you') + '\2: ' + val)
        self.ent.set('')
        #if self.curr_chat.dst not in self.presences_sent and \
        #        not str(self.curr_chat.dst).startswith('yorg'):
        #    self.eng.xmpp.client.send_presence(
        #        pfrom=self.eng.xmpp.client.boundjid.full,
        #        pto=self.curr_chat.dst)
        #    self.presences_sent += [self.curr_chat.dst]
        #if str(self.curr_chat.dst).startswith('yorg'):
        #    self.eng.xmpp.client.send_message(
        #        mfrom=self.eng.xmpp.client.boundjid.full,
        #        mto=self.curr_chat.dst,
        #        mtype='groupchat',
        #        mbody=val)
        #else:
        #    self.eng.xmpp.client.send_message(
        #        mfrom=self.eng.xmpp.client.boundjid.full,
        #        mto=self.curr_chat.dst,
        #        msubject='chat',
        #        mbody=val)
        if len(self.curr_chat.dst) > 12 and all(char.isdigit() for char in self.curr_chat.dst[-12:]):
            self.eng.client.send([
                'msg_room', self.eng.client.myid, self.curr_chat.dst, val])
        else:
            self.eng.client.send(['msg', self.eng.client.myid, self.curr_chat.dst, val])
        msg = '\1italic\1' + _('you') + '\2: ' + val
        self.curr_chat.messages += [msg]
        self.ent['focus'] = 1

    def on_msg(self, from_, to, txt):
        #src = str(JID(msg['from']).bare)
        #src = src.split('@')[0] + '\1smaller\1@' + src.split('@')[1] + '\2'
        str_msg = '\1italic\1' + from_ + '\2: ' + txt
        chat = self.__find_chat(from_)
        if not chat:
            chat = Chat(from_)
            self.chats += [chat]
        chat.messages += [str_msg]
        if self.dst_txt['text'] == '':
            self.set_chat(chat)
        elif self.curr_chat.dst == from_:
            self.add_msg_txt(str_msg)
        else:
            chat.read = False
            chat.closed = False
            self.arrow_btn['frameTexture'] = 'assets/images/gui/message.txo'

    def on_groupchat_msg(self, from_, to, txt):
        #if str(JID(msg['from']).bare) == self.curr_match_room:
        if to == self.curr_match_room:
            if self.match_msg_frm:  # we're still in the room page
                self.match_msg_frm.on_groupchat_msg(from_, to, txt)
        #src = str(JID(msg['mucnick']))
        #src = src.split('@')[0] + '\1smaller\1@' + src.split('@')[1] + '\2'
        src = from_
        #self.eng.log('received groupchat message from %s in the chat %s' %(msg['mucnick'], JID(msg['from']).bare))
        self.eng.log('received groupchat message from %s in the chat %s' % (from_, to))
        #str_msg = '\1italic\1' + src + '\2: ' + str(msg['body'])
        str_msg = '\1italic\1' + src + '\2: ' + txt
        chat = self.curr_chat
        if not chat:
            #chat = MUC(str(JID(msg['from']).bare))
            chat = MUC(to)
            self.chats += [chat]
        chat.messages += [str_msg]
        if self.dst_txt['text'] == '':
            self.set_chat(chat)
        #elif self.curr_chat.dst == str(JID(msg['from']).bare):
        elif self.curr_chat.dst == to:
            self.add_msg_txt(str_msg)
        else:
            chat.read = False
            chat.closed = False
            self.arrow_btn['frameTexture'] = 'assets/images/gui/message.txo'

    def on_presence_available_room(self, uid, room):
        if room == self.curr_match_room:
            self.match_msg_frm.on_presence_available_room(uid, room)
        #room = str(JID(msg['muc']['room']).bare)
        #nick = str(msg['muc']['nick'])
        self.eng.log('user %s has logged in the chat %s' %(uid, room))
        chat = self.__find_chat(room)
        chat.users += [uid]
        if room != self.curr_match_room:
            if self.curr_chat.dst == room:
                self.set_title(chat.title)

    def on_presence_unavailable_room(self, uid, room_name):
        if self.match_msg_frm and room_name == self.curr_match_room:
            self.match_msg_frm.on_presence_unavailable_room(uid, room_name)
            return
        room = room_name
        nick = uid
        self.eng.log('user %s has left the chat %s' %(nick, room))
        chat = self.__find_chat(room)
        if nick == self.eng.client.myid:
            self.on_close()
        else:
            chat.users.remove(nick)
            if self.curr_chat.dst == room:
                self.set_title(chat.title)

    def __find_chat(self, dst):
        chats = [chat for chat in self.chats if chat.dst == dst]
        if chats: return chats[0]

    def add_chat(self, usr):
        #self.set_title(JID(usr).bare)
        chat = self.__find_chat(usr)
        if not chat:
            chat = Chat(usr)
            self.chats += [chat]
        self.set_chat(chat)
        self.ent['focus'] = 1

    def add_groupchat(self, room, usr):
        self.set_title(usr)
        chat = self.__find_chat(room)
        if not chat:
            chat = MUC(room)
            self.chats += [chat]
        chat.users += [usr]
        self.set_chat(chat)
        self.add_match_chat(room, usr)

    def remove_groupchat(self):
        self.match_msg_frm.detach(self.on_match_msg_focus)
        self.match_msg_frm = self.match_msg_frm.destroy()

    def on_focus(self, val):
        if val and self.ent.get() == _('write here your message'):
            self.ent.set('')
        self.notify('on_msg_focus', val)

    def on_match_msg_focus(self, val):
        self.notify('on_msg_focus', val)

    def on_room_back(self):
        self.curr_match_room = None
        self.match_msg_frm.destroy()

    def add_match_chat(self, room, usr):
        if self.curr_match_room: return
        self.curr_match_room = room
        self.match_msg_frm = MatchMsgFrm(self.menu_props)
        self.match_msg_frm.attach(self.on_match_msg_focus)
        self.match_msg_frm.add_groupchat(room, usr)
Exemplo n.º 20
0
class ResetPageGui(ThanksPageGui):

    def __init__(self, mediator, mp_props):
        self.props = mp_props
        ThanksPageGui.__init__(self, mediator, mp_props.gameprops.menu_props)

    def build(self):
        menu_props = self.menu_props
        t_a = menu_props.text_args.copy()
        # del t_a['scale']
        email_lab = Text(_('Your email:'), pos=(-.05, .4),
                               align='right', **t_a)
        jid_lab = Text(_('Your user id:'), pos=(-.05, .2),
                               align='right', **t_a)
        init_txt = self.props.opt_file['settings']['login']['usr'] if \
            self.props.opt_file['settings']['login']['usr'] else \
            _('your user id')
        self.email_ent = Entry(
            scale=.08, pos=(.05, .4), entry_font=menu_props.font, width=12,
            frame_col=menu_props.btn_col, initial_text=_('your email'),
            text_fg=menu_props.text_active_col, on_tab=self.on_tab_email,
            on_click=self.on_click_email)
        self.jid_ent = Entry(
            scale=.08, pos=(.05, .2), entry_font=menu_props.font, width=12,
            frame_col=menu_props.btn_col, initial_text=init_txt,
            text_fg=menu_props.text_active_col, on_tab=self.on_tab_id,
            on_click=self.on_click_id)
        start_btn = Btn(
            text=_('Reset'), pos=(0, -.2), cmd=self.reset,
            **self.props.gameprops.menu_props.btn_args)
        t_a['scale'] = .06
        widgets = [self.jid_ent, start_btn, jid_lab, email_lab, self.email_ent]
        self.add_widgets(widgets)
        self.eng.attach_obs(self.on_frame)
        ThanksPageGui.build(self)

    def reset(self, pwd_name=None):
        def process_msg(data_lst, sender):
            print(sender, data_lst)
        self.eng.client.start(process_msg)
        self.eng.client.register_rpc('reset')
        self.ret_val = ret_val = self.eng.client.reset(self.jid_ent.text, self.email_ent.text)
        ok_txt = _(
            "We've sent an email to you (please check your spam folder if you "
            "can't find it) with the instructions for completing the reset.")
        nomail_txt = _("This email isn't in our archive.")
        nonick_txt = _("This nickname isn't in our archive.")
        dontmatch_txt = _("This nickname-email pair isn't in our archive.")
        err_txt = _('Connection error.')
        if ret_val == 'ok': txt = ok_txt
        elif ret_val == 'nomail': txt = nomail_txt
        elif ret_val == 'nonick': txt = nonick_txt
        elif ret_val == 'dontmatch': txt = dontmatch_txt
        else: txt = err_txt
        self.reset_dlg = ResetDialog(self.menu_props, txt)
        self.reset_dlg.attach(self.on_reset_dlg)

    def on_reset_dlg(self):
        self.reset_dlg.destroy()
        if self.ret_val == 'ok':
            self._on_back()

    def on_frame(self):
        init_txt = _('your user id')
        curr_txt = self.jid_ent.text
        if curr_txt == init_txt[:-1]:
            self.jid_ent.set('')
        elif curr_txt.startswith(init_txt) and len(curr_txt) == len(init_txt) + 1:
            self.jid_ent.set(curr_txt[-1:])
        init_txt = _('your email')
        curr_txt = self.email_ent.text
        if curr_txt == init_txt[:-1]:
            self.email_ent.set('')
        elif curr_txt.startswith(init_txt) and len(curr_txt) == len(init_txt) + 1:
            self.email_ent.set(curr_txt[-1:])

    def on_click_email(self, pos):
        init_txt = _('your email')
        curr_txt = self.email_ent.text
        if curr_txt == init_txt: self.email_ent.set('')

    def on_click_id(self, pos):
        init_txt = _('your user id')
        curr_txt = self.jid_ent.text
        if curr_txt == init_txt: self.jid_ent.set('')

    def on_tab_email(self):
        self.email_ent['focus'] = 0
        self.jid_ent['focus'] = 1

    def on_tab_id(self):
        self.email_ent['focus'] = 0
        self.jid_ent['focus'] = 0

    def on_ok(self):
        self.props.opt_file['settings']['login']['usr'] = self.jid_ent.text
        if self.store_cb['indicatorValue']:
            self.props.opt_file['settings']['login']['pwd'] = self.pwd_ent.text
        self.props.opt_file.store()
        self._on_back()
        self.notify('on_login')

    def on_ko(self, err):  # unused err
        txt = Text(_('Error'), pos=(-.2, -.05), fg=(1, 0, 0, 1),
                           scale=.16, font=self.menu_props.font)
        self.eng.do_later(5, txt.destroy)

    def destroy(self):
        self.eng.detach_obs(self.on_frame)
        ThanksPageGui.destroy(self)
Exemplo n.º 21
0
class LogInPageGui(ThanksPageGui):

    def __init__(self, mediator, mp_props):
        self.props = mp_props
        ThanksPageGui.__init__(self, mediator, mp_props.gameprops.menu_props)

    def build(self):
        menu_props = self.menu_props
        t_a = menu_props.text_args.copy()
        # del t_a['scale']
        jid_lab = Text(_('Your user id:'), pos=(-.05, .4),
                               align='right', **t_a)
        pwd_lab = Text(_('Your password:'******'right', **t_a)
        init_txt = self.props.opt_file['settings']['login']['usr'] if \
            self.props.opt_file['settings']['login']['usr'] else \
            _('your user id')
        self.jid_ent = Entry(
            scale=.08, pos=(.05, .4), entry_font=menu_props.font, width=12,
            frame_col=menu_props.btn_col, initial_text=init_txt,
            text_fg=menu_props.text_active_col, on_tab=self.on_tab,
            on_click=self.on_click)
        self.pwd_ent = Entry(
            scale=.08, pos=(.05, .2), entry_font=menu_props.font, width=12,
            frame_col=menu_props.btn_col, obscured=True,
            text_fg=menu_props.text_active_col, cmd=self.start)
        start_btn = Btn(
            text=_('Log-in'), pos=(0, 0), cmd=self.start,
            **self.props.gameprops.menu_props.btn_args)
        widgets = [self.jid_ent, self.pwd_ent, start_btn, jid_lab,
                   pwd_lab]
        self.add_widgets(widgets)
        self.eng.attach_obs(self.on_frame)
        ThanksPageGui.build(self)

    def start(self, pwd_name=None):
        def process_msg(data_lst, sender):
            print(sender, data_lst)
        #self.eng.client.start(process_msg, self.eng.cfg.dev_cfg.server)
        self.eng.client.register_rpc('login')
        self.eng.client.register_rpc('get_salt')
        #self.eng.client.restart()
        salt = self.eng.client.get_salt(self.jid_ent.text)
        self.pwd = sha512(self.pwd_ent.text.encode() + salt.encode()).hexdigest()
        ret_val = self.eng.client.login(self.jid_ent.text, self.pwd)
        if ret_val in ['invalid_nick', 'unregistered_nick', 'wrong_pwd', 'unactivated']:
            return self.on_ko(ret_val)
        self.on_ok()

    def on_frame(self):
        init_txt = _('your user id')
        curr_txt = self.jid_ent.text
        if curr_txt == init_txt[:-1]:
            self.jid_ent.set('')
        elif curr_txt.startswith(init_txt) and len(curr_txt) == len(init_txt) + 1:
            self.jid_ent.set(curr_txt[-1:])

    def on_click(self, pos):
        init_txt = _('your user id')
        curr_txt = self.jid_ent.text
        if curr_txt == init_txt: self.jid_ent.set('')

    def on_tab(self):
        self.jid_ent['focus'] = 0
        self.pwd_ent['focus'] = 1

    def on_ok(self):
        self.eng.client.authenticated = True
        self.props.opt_file['settings']['login']['usr'] = self.jid_ent.text
        self.props.opt_file['settings']['login']['pwd'] = self.pwd
        self.props.opt_file.store()
        self.eng.client.init(self.props.opt_file['settings']['login']['usr'])
        self._on_back()
        self.notify('on_login_page')

    def on_ko(self, err):
        txt = Text(_('Error') + ': ' + err, pos=(-.2, -.05), fg=(1, 0, 0, 1),
                           scale=.16, font=self.menu_props.font)
        self.eng.do_later(5, txt.destroy)

    def destroy(self):
        self.eng.detach_obs(self.on_frame)
        ThanksPageGui.destroy(self)
Exemplo n.º 22
0
 def __init__(self, menu_props):
     GameObject.__init__(self)
     self.eng.log('created message form')
     self.chats = []
     self.curr_chat = None
     self.curr_match_room = None
     self.msg_frm = DirectFrame(
         frameSize=(-.02, .8, 0, .45),
         frameColor=(.2, .2, .2, .5),
         pos=(-.82, 1, .02), parent=base.a2dBottomRight)
     self.presences_sent = []
     self.menu_props = menu_props
     t_a = menu_props.text_args
     t_a['scale'] = .05
     t_a['fg'] = menu_props.text_normal_col
     self.dst_txt = OnscreenText(
         text='', pos=(0, .4), parent=self.msg_frm, align=TextNode.A_left,
         **t_a)
     self.arrow_btn = ImgBtn(
         parent=self.msg_frm, scale=(.024, .024), pos=(.7, 1, .42),
         frame_col=(1, 1, 1, 1),
         frame_texture='assets/images/gui/arrow.txo',
         cmd=self.on_arrow,
         **menu_props.imgbtn_args)
     self.arrow_btn.disable()
     self.close_btn = ImgBtn(
         parent=self.msg_frm, scale=(.024, .024), pos=(.76, 1, .42),
         frame_col=(1, 1, 1, 1),
         frame_texture='assets/images/gui/close.txo',
         cmd=self.on_close,
         **menu_props.imgbtn_args)
     self.close_btn.disable()
     self.ent = Entry(
         scale=.04, pos=(0, .03), entry_font=menu_props.font, width=19.5,
         frame_col=menu_props.btn_col, parent=self.msg_frm,
         initial_text=_('write here your message'),
         cmd=self.on_typed_msg, focus_in_cmd=self.on_focus,
         focus_in_args=['in'], focus_out_cmd=self.on_focus,
         focus_out_args=['out'], text_fg=menu_props.text_active_col)
     self.ent['state'] = DISABLED
     self.txt_frm = DirectScrolledFrame(
         frameSize=(-.02, .76, -.02, .28),
         canvasSize=(-.02, .72, -.02, .28),
         scrollBarWidth=.036,
         verticalScroll_relief=FLAT,
         verticalScroll_frameColor=(.2, .2, .2, .4),
         verticalScroll_thumb_relief=FLAT,
         verticalScroll_thumb_frameColor=(.8, .8, .8, .6),
         verticalScroll_incButton_relief=FLAT,
         verticalScroll_incButton_frameColor=(.8, .8, .8, .6),
         verticalScroll_decButton_relief=FLAT,
         verticalScroll_decButton_frameColor=(.8, .8, .8, .6),
         horizontalScroll_relief=FLAT,
         frameColor=(1, 1, 1, 0),
         pos=(.02, 1, .11), parent=self.msg_frm)
     t_a['scale'] = .046
     self.msg_txt = OnscreenText(
         text='', pos=(0, .24), parent=self.txt_frm.getCanvas(),
         align=TextNode.A_left, wordwrap=14, **t_a)
     lab_args = menu_props.label_args
     lab_args['scale'] = .046
     lab_args['text_fg'] = menu_props.text_normal_col
     self.lab_frm = Btn(
         frame_size=(-.02, .64, -.01, .05),
         frame_col=(1, 1, 1, 0),
         pos=(0, 1, .4), parent=self.msg_frm)
     self.lab_frm.bind(ENTER, self.on_enter)
     self.lab_frm.bind(EXIT, self.on_exit)
     self.tooltip = Label(
         text='', pos=(.78, 1, -.06),
         parent=self.lab_frm, text_wordwrap=16,# text_bg=(.2, .2, .2, .8),
         text_align=TextNode.A_right, **lab_args)
     self.tooltip.set_bin('gui-popup', 10)
     self.tooltip.hide()
Exemplo n.º 23
0
class RegisterPageGui(ThanksPageGui):
    def __init__(self, mediator, mp_props):
        self.props = mp_props
        ThanksPageGui.__init__(self, mediator, mp_props.gameprops.menu_props)

    def build(self):
        menu_props = self.menu_props
        t_a = menu_props.text_args.copy()
        # del t_a['scale']
        email_lab = Text(_('Your email:'),
                         pos=(-.65, .4),
                         align='right',
                         **t_a)
        jid_lab = Text(_('Your user id:'),
                       pos=(-.65, .2),
                       align='right',
                       **t_a)
        pwd_lab = Text(_('Your password:'******'right',
                       **t_a)
        init_txt = self.props.opt_file['settings']['login']['usr'] if \
            self.props.opt_file['settings']['login']['usr'] else \
            _('your user id')
        self.email_ent = Entry(scale=.08,
                               pos=(-.55, .4),
                               entry_font=menu_props.font,
                               width=20,
                               frame_col=menu_props.btn_col,
                               initial_text=_('your email'),
                               text_fg=menu_props.text_active_col,
                               on_tab=self.on_tab_email,
                               on_click=self.on_click_email)
        self.jid_ent = Entry(scale=.08,
                             pos=(-.55, .2),
                             entry_font=menu_props.font,
                             width=20,
                             frame_col=menu_props.btn_col,
                             initial_text=init_txt,
                             text_fg=menu_props.text_active_col,
                             on_tab=self.on_tab_id,
                             on_click=self.on_click_id)
        self.pwd_ent = Entry(scale=.08,
                             pos=(-.55, 0),
                             entry_font=menu_props.font,
                             width=20,
                             frame_col=menu_props.btn_col,
                             obscured=True,
                             text_fg=menu_props.text_active_col,
                             cmd=self.register)
        start_btn = Btn(text=_('Register'),
                        pos=(0, -.2),
                        cmd=self.register,
                        **self.props.gameprops.menu_props.btn_args)
        t_a['scale'] = .06
        widgets = [
            self.jid_ent, self.pwd_ent, start_btn, jid_lab, pwd_lab, email_lab,
            self.email_ent
        ]
        self.add_widgets(widgets)
        self.eng.attach_obs(self.on_frame)
        ThanksPageGui.build(self)

    def register(self, pwd_name=None):
        def process_msg(data_lst, sender):
            print(sender, data_lst)

        if len(self.pwd_ent.text) >= 6:
            self.eng.client.start(process_msg)
            self.eng.client.register_rpc('register')
            self.eng.client.register_rpc('get_salt')
            salt = self.eng.client.get_salt(self.jid_ent.text)
            ret_val = self.eng.client.register(
                self.jid_ent.text,
                sha512((self.pwd_ent.text + salt).encode('utf-8')).hexdigest(),
                salt, self.email_ent.text.replace('_AT_', '@'))
        else:
            ret_val = 'short'
        self.ret_val = ret_val
        ok_txt = _(
            'Your account has been registered. Now, in order to '
            "activate it, you should click the link that we've sent to your "
            "email (please check your spam folder if you can't find it). "
            'After that, you can log in.')
        inv_nick_txt = _(
            "Your nickname's format is invalid: please use only letters and "
            'numbers.')
        inv_email_txt = _("Your email's format is invalid.")
        already_nick_txt = _('Your nickname already exists.')
        already_email_txt = _('Your email has already been used.')
        short_txt = _('Please use more than 6 characters for your password.')
        err_txt = _('Connection error.')
        if ret_val == 'ok': txt = ok_txt
        elif ret_val == 'invalid_nick': txt = inv_nick_txt
        elif ret_val == 'invalid_email': txt = inv_email_txt
        elif ret_val == 'already_used_nick': txt = already_nick_txt
        elif ret_val == 'already_used_email': txt = already_email_txt
        elif ret_val == 'short': txt = short_txt
        else: txt = err_txt
        self.register_dlg = RegisterDialog(self.menu_props, txt)
        self.register_dlg.attach(self.on_register_dlg)

    def on_register_dlg(self):
        self.register_dlg.destroy()
        if self.ret_val == 'ok':
            self._on_back()

    def on_frame(self):
        init_txt = _('your user id')
        curr_txt = self.jid_ent.text
        if curr_txt == init_txt[:-1]:
            self.jid_ent.set('')
        elif curr_txt.startswith(init_txt) and len(
                curr_txt) == len(init_txt) + 1:
            self.jid_ent.set(curr_txt[-1:])
        init_txt = _('your email')
        curr_txt = self.email_ent.text
        if curr_txt == init_txt[:-1]:
            self.email_ent.set('')
        elif curr_txt.startswith(init_txt) and len(
                curr_txt) == len(init_txt) + 1:
            self.email_ent.set(curr_txt[-1:])

    def on_click_email(self, pos):
        init_txt = _('your email')
        curr_txt = self.email_ent.text
        if curr_txt == init_txt: self.email_ent.set('')

    def on_click_id(self, pos):
        init_txt = _('your user id')
        curr_txt = self.jid_ent.text
        if curr_txt == init_txt: self.jid_ent.set('')

    def on_tab_email(self):
        self.email_ent['focus'] = 0
        self.jid_ent['focus'] = 1
        self.pwd_ent['focus'] = 0

    def on_tab_id(self):
        self.email_ent['focus'] = 0
        self.jid_ent['focus'] = 0
        self.pwd_ent['focus'] = 1

    def on_ok(self):
        self.props.opt_file['settings']['login']['usr'] = self.jid_ent.text
        if self.store_cb['indicatorValue']:
            self.props.opt_file['settings']['login']['pwd'] = self.pwd_ent.text
        self.props.opt_file.store()
        self._on_back()
        self.notify('on_login')

    def on_ko(self, err):  # unused err
        txt = Text(_('Error'),
                   pos=(-.2, -.05),
                   fg=(1, 0, 0, 1),
                   scale=.16,
                   font=self.menu_props.font)
        self.eng.do_later(5, txt.destroy)

    def destroy(self):
        self.eng.detach_obs(self.on_frame)
        ThanksPageGui.destroy(self)
Exemplo n.º 24
0
class MatchMsgFrm(GameObject):

    def __init__(self, menu_props):
        GameObject.__init__(self)
        self.eng.log('created match message form')
        self.chat = None
        self.msg_frm = Frame(
            frame_size=(-.02, 3.49, 0, 1.22),
            frame_col=(.2, .2, .2, .5),
            pos=(.04, -1.69), parent=base.a2dTopLeft)
        t_a = menu_props.text_args
        t_a['scale'] = .05
        t_a['fg'] = menu_props.text_normal_col
        self.dst_txt = Text(
            txt='', pos=(0, 1.16), parent=self.msg_frm, align='left',
            **t_a)
        self.ent = Entry(
            scale=.04, pos=(0, .03), entry_font=menu_props.font, width=86,
            frame_col=menu_props.btn_col, parent=self.msg_frm,
            initial_text=_('write here your message'),
            cmd=self.on_typed_msg, focus_in_cmd=self.on_focus,
            focus_in_args=['in'], focus_out_cmd=self.on_focus,
            focus_out_args=['out'], text_fg=menu_props.text_active_col)
        self.ent['state'] = DISABLED
        self.txt_frm = ScrolledFrame(
            frame_sz=(-.02, 2.46, -.02, 1.02),
            canvas_sz=(-.02, 2.42, -.02, 1.02),
            scrollbar_width=.036,
            frame_col=(1, 1, 1, .0),
            pos=(.02, .11), parent=self.msg_frm)
        t_a['scale'] = .046
        self.msg_txt = Text(
            txt='', pos=(0, .24), parent=self.txt_frm.canvas,
            align='left', wordwrap=52, **t_a)
        lab_args = menu_props.label_args
        lab_args['scale'] = .046
        lab_args['text_fg'] = menu_props.text_normal_col
        self.lab_frm = Btn(
            frame_size=(-.02, 2.5, -.01, .05),
            frame_col=(1, 1, 1, 0),
            pos=(0, 1.15), parent=self.msg_frm)
        self.lab_frm.bind(ENTER, self.on_enter)
        self.lab_frm.bind(EXIT, self.on_exit)
        self.tooltip = Label(
            text='', pos=(2.4, -.06), parent=self.lab_frm, text_wordwrap=50,
            text_align=TextNode.A_right, **lab_args)
        self.tooltip.set_bin('gui-popup', 10)
        self.tooltip.hide()

    @property
    def widgets(self):
        return [self.msg_frm, self.dst_txt, self.ent, self.txt_frm,
                self.msg_txt, self.lab_frm, self.tooltip]

    def on_enter(self, pos):
        self.tooltip.show()

    def on_exit(self, pos):
        self.tooltip.hide()

    def add_msg_txt(self, msg):
        self.msg_txt['text'] += ('\n' if self.msg_txt['text'] else '') + msg
        txt_height = self.msg_txt.textNode.getUpperLeft3d()[2] - \
            self.msg_txt.textNode.getLowerRight3d()[2]
        self.txt_frm['canvasSize'] = (-.02, .72, .28 - txt_height, .28)

    def set_title(self, title):
        ttitle = self.trunc(title, 160)
        fix_name = lambda name: name if '@' not in name else name.split('@')[0] + '\1smaller\1@' + name.split('@')[1] + '\2'
        if title:
            if ',' in ttitle:
                is_muc = True
                ttitle = ttitle
                names = ttitle.split(',')
                names = [name.strip() for name in names]
                names = [fix_name(name) for name in names]
                ttitle = ', '.join(names)
            else:
                ttitle = fix_name(ttitle)
        self.dst_txt['text'] = ttitle
        self.tooltip['text'] = title

    @staticmethod
    def trunc(name, lgt):
        if len(name) > lgt: return name[:lgt] + '...'
        return name

    def on_typed_msg(self, val):
        #self.add_msg_txt('\1italic\1' + _('you') + '\2: ' + val)
        self.ent.set('')
        self.eng.client.send([
            'msg_room', self.eng.client.myid, self.chat.dst, val])
        #self.eng.xmpp.client.send_message(
        #    mfrom=self.eng.xmpp.client.boundjid.full,
        #    mto=self.chat.dst,
        #    mtype='groupchat',
        #    mbody=val)
        self.ent['focus'] = 1

    def on_groupchat_msg(self, from_, to, txt):
        #src = str(JID(msg['mucnick']))
        #src = src.split('@')[0] + '\1smaller\1@' + src.split('@')[1] + '\2'
        src = from_
        #self.eng.log('received groupchat message from %s in the chat %s' %(msg['mucnick'], JID(msg['from']).bare))
        self.eng.log('received groupchat message from %s in the chat %s' % (from_, to))
        #str_msg = '\1italic\1' + src + '\2: ' + str(msg['body'])
        str_msg = '\1italic\1' + src + '\2: ' + txt
        if not self.chat:
            #self.chat = MUC(str(JID(msg['from']).bare), self.yorg_client)
            self.chat = MUC(to)
        self.chat.messages += [str_msg]
        if self.dst_txt['text'] == '':
            self.set_chat(self.chat)
        #elif self.chat.dst == str(JID(msg['from']).bare):
        elif self.chat.dst == to:
            self.add_msg_txt(str_msg)

    def on_presence_available_room(self, uid, room):
        #room = str(JID(msg['muc']['room']).bare)
        #nick = str(msg['muc']['nick'])
        self.eng.log('user %s has logged in the chat %s' % (uid, room))
        self.chat.users += [uid]
        self.set_title(self.chat.title)

    def on_presence_unavailable_room(self, uid, room_name):
        room = room_name
        nick = uid
        self.eng.log('user %s has left the chat %s' %(nick, room))
        if nick in self.chat.users: # it is being removed multiple times when
                                    # you remove a user who has accepted
            self.chat.users.remove(nick)
        self.set_title(self.chat.title)

    def on_rm_usr_from_match(self, uid):
        if uid in self.chat.users:  # it is being removed multiple times when
                                    # you remove a user who has accepted
            self.chat.users.remove(uid)
        self.update_title()

    def add_groupchat(self, room, usr):
        self.set_title(usr)
        if not self.chat:
            self.chat = MUC(room)
        self.set_chat(self.chat)

    def set_chat(self, chat):
        self.set_title(chat.title)
        self.msg_txt['text'] = '\n'.join(chat.messages)
        txt_height = self.msg_txt.textNode.getUpperLeft3d()[2] - \
            self.msg_txt.textNode.getLowerRight3d()[2]
        self.txt_frm['canvasSize'] = (-.02, .72, .28 - txt_height, .28)
        self.ent['state'] = NORMAL

    def update_title(self):
        self.set_title(self.chat.title)

    def on_focus(self, val):
        if val == 'in' and self.ent.get() == _('write here your message'):
            self.ent.set('')
        self.notify('on_match_msg_focus', val)

    def destroy(self):
        self.eng.log('message form destroyed')
        #self.msg_frm.destroy()
        GameObject.destroy(self)