示例#1
0
文件: exitpage.py 项目: oriolrg/yorg
 def build(self, back_btn=True):
     menu_props = self.menu_props
     frm = Frame(
         frame_size=(-1.5, 1.5, -.9, .9), frame_col=(.95, .95, .7, .85))
     txt = _(
         'Please, visit our site after exiting!\n\nIt helps us! Thank you!')
     txt = Text(
         txt, pos=(0, .64), scale=.08, wordwrap=32,
         fg=menu_props.text_active_col, font=menu_props.font)
     menu_data = [
         ('visit our site after exiting', _('visit our site after exiting'),
          lambda: self.on_end(True)),
         ("don't visit our site after exiting",
          _("don't visit our site after exiting"),
          lambda: self.on_end(False))]
     btn_args = self.menu_props.btn_args
     btn_args['frame_size'] = (-12, 12, -.8, 1.2)
     btn_visit = Btn(
         text=menu_data[0][1], pos=(0, 0), cmd=menu_data[0][2],
         text_scale=.9, **btn_args)
     btn_dont_visit = Btn(
         text=menu_data[1][1], pos=(0, -.5), cmd=menu_data[1][2],
         text_scale=.7, **btn_args)
     widgets = [frm, txt, btn_visit, btn_dont_visit]
     self.add_widgets(widgets)
     PageGui.build(self, False)
示例#2
0
文件: button.py 项目: oriolrg/yorg
 def __init__(self, parent, owner, menu_props, img_path, msg_btn_x, cb,
              usr_name, tooltip):
     GameObject.__init__(self)
     self.owner = owner
     lab_args = menu_props.label_args
     lab_args['scale'] = .046
     #lab_args['text_fg'] = menu_props.text_normal_col
     self.btn = ImgBtn(parent=parent,
                       scale=(.024, .024),
                       pos=(msg_btn_x, .01),
                       frame_col=(1, 1, 1, 1),
                       frame_texture=img_path,
                       cmd=cb,
                       extra_args=[usr_name],
                       **menu_props.imgbtn_args)
     self.btn.bind(ENTER, self.on_enter)
     self.btn.bind(EXIT, self.on_exit)
     self.tooltip_btn = Btn(parent=parent,
                            scale=(.024, .024),
                            pos=(msg_btn_x, .01),
                            frame_col=(1, 1, 1, 0),
                            frame_size=(-1, 1, -1, 1),
                            cmd=None,
                            **menu_props.imgbtn_args)
     self.tooltip_btn.bind(ENTER, self.on_enter)
     self.tooltip_btn.bind(EXIT, self.on_exit)
     self.on_create()
     self.tooltip = Label(text=tooltip,
                          pos=self.btn.get_pos() + self.tooltip_offset,
                          parent=parent,
                          text_wordwrap=10,
                          text_align=self.tooltip_align,
                          **lab_args)
     self.tooltip.set_bin('gui-popup', 10)
     self.tooltip.hide()
示例#3
0
 def build(self):
     menu_props = self.menu_props
     t_a = menu_props.text_args.copy()
     players_lab = Text(_('How many players?'),
                        pos=(0, .6),
                        align='center',
                        **t_a)
     p2_btn = Btn(text='2',
                  pos=(0, .2),
                  cmd=self.on_btn,
                  extra_args=[2],
                  **self.props.gameprops.menu_props.btn_args)
     p3_btn = Btn(text='3',
                  pos=(0, 0),
                  cmd=self.on_btn,
                  extra_args=[3],
                  **self.props.gameprops.menu_props.btn_args)
     p4_btn = Btn(text='4',
                  pos=(0, -.2),
                  cmd=self.on_btn,
                  extra_args=[4],
                  **self.props.gameprops.menu_props.btn_args)
     t_a['scale'] = .06
     widgets = [p2_btn, p3_btn, p4_btn, players_lab]
     self.add_widgets(widgets)
     ThanksPageGui.build(self)
示例#4
0
 def build(self, back_btn=True):
     frm = Frame(frame_size=(-1.5, 1.5, -.9, .9),
                 frame_col=(.95, .95, .7, .85))
     question_txt = _(
         "What do you want to do?\n\nNote: use '%s' for pausing the game.")
     question_txt = question_txt % self.keys.pause
     menu_props = self.menu_props
     txt = Text(question_txt,
                pos=(0, .64),
                scale=.08,
                wordwrap=32,
                fg=menu_props.text_active_col,
                font=menu_props.font)
     on_back = lambda: self.on_end(True)
     on_end = lambda: self.on_end(False)
     menu_data = [('back to the game', _('back to the game'), on_back),
                  ('back to the main menu', _('back to the main menu'),
                   on_end)]
     btn_args = menu_props.btn_args
     btn_visit = Btn(text=menu_data[0][1],
                     pos=(0, 0),
                     cmd=menu_data[0][2],
                     text_scale=.8,
                     **btn_args)
     btn_dont_visit = Btn(text=menu_data[1][1],
                          pos=(0, -.5),
                          cmd=menu_data[1][2],
                          text_scale=.8,
                          **btn_args)
     self.add_widgets([frm, txt, btn_visit, btn_dont_visit])
     PageGui.build(self, False)
     self.eng.show_cursor()
示例#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)
示例#6
0
文件: button.py 项目: cflavio/yorg
 def __init__(self, parent, owner, menu_props, img_path, msg_btn_x, cb,
              usr_name, tooltip):
     GameObject.__init__(self)
     self.owner = owner
     lab_args = menu_props.label_args
     lab_args['scale'] = .046
     #lab_args['text_fg'] = menu_props.text_normal_col
     self.btn = ImgBtn(
         parent=parent, scale=(.024, .024), pos=(msg_btn_x, .01),
         frame_col=(1, 1, 1, 1), frame_texture=img_path, cmd=cb,
         extra_args=[usr_name], **menu_props.imgbtn_args)
     self.btn.bind(ENTER, self.on_enter)
     self.btn.bind(EXIT, self.on_exit)
     self.tooltip_btn = Btn(
         parent=parent, scale=(.024, .024), pos=(msg_btn_x, .01),
         frame_col=(1, 1, 1, 0), frame_size=(-1, 1, -1, 1), cmd=None,
         **menu_props.imgbtn_args)
     self.tooltip_btn.bind(ENTER, self.on_enter)
     self.tooltip_btn.bind(EXIT, self.on_exit)
     self.on_create()
     self.tooltip = Label(
         text=tooltip, pos=self.btn.get_pos() + self.tooltip_offset,
         parent=parent, text_wordwrap=10, text_align=self.tooltip_align,
         **lab_args)
     self.tooltip.set_bin('gui-popup', 10)
     self.tooltip.hide()
示例#7
0
 def __init__(self, menu_props, room):
     MatchFrm.__init__(self, menu_props, room)
     btn_args = self.menu_props.btn_args
     btn_args['scale'] = (.06, .06)
     self.start_btn = Btn(
         text=_('Start'), pos=(1.68, .03), cmd=self.on_start,
         parent=self.match_frm, **btn_args)
示例#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)
示例#9
0
文件: inputpage.py 项目: oriolrg/yorg
 def _add_btn(self, text, pos_z):
     btn = Btn(pos=(.46, pos_z),
               text=text,
               cmd=self.start_rec,
               **self.menu_props.btn_args)
     btn['extraArgs'] = [btn]
     self.ibuttons += [btn]
     return btn
示例#10
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)
示例#11
0
文件: inputpage.py 项目: oriolrg/yorg
 def build(self):
     p_btn = Btn(text='',
                 pos=(0, -.74),
                 cmd=self.on_player3,
                 tra_src='Player 4',
                 tra_tra=_('Player 4'),
                 **self.menu_props.btn_args)
     self.add_widgets([p_btn])
     InputPageGui4Joystick.build(self)
示例#12
0
 def __init__(self,
              uid,
              is_supporter,
              pos,
              parent,
              menu_props,
              msg_btn_x=.58):
     Subject.__init__(self)
     GameObject.__init__(self)
     self.menu_props = menu_props
     self.frm = Btn(frame_size=(-.01, 2.54, .05, -.03),
                    frame_col=(1, 1, 1, 0),
                    pos=pos,
                    parent=parent,
                    cmd=self.on_cmd,
                    extra_args=[uid])
     self.lab = UserLabel(uid, self.frm, menu_props, is_supporter)
     self.frm.bind(ENTER, self.on_enter)
     self.frm.bind(EXIT, self.on_exit)
示例#13
0
文件: forms.py 项目: cflavio/yorg
 def __init__(self, uid, is_supporter, pos, parent, menu_props,
              msg_btn_x=.58):
     Subject.__init__(self)
     GameObject.__init__(self)
     self.menu_props = menu_props
     self.frm = Btn(
         frame_size=(-.01, 2.54, .05, -.03), frame_col=(1, 1, 1, 0),
         pos=pos, parent=parent, cmd=self.on_cmd, extra_args=[uid])
     self.lab = UserLabel(uid, self.frm, menu_props, is_supporter)
     self.frm.bind(ENTER, self.on_enter)
     self.frm.bind(EXIT, self.on_exit)
示例#14
0
文件: inputpage.py 项目: oriolrg/yorg
 def build(self):
     p2_btn = Btn(text='',
                  pos=(0, -.74),
                  cmd=self.on_player2,
                  tra_src='Player 2',
                  tra_tra=_('Player 2'),
                  **self.menu_props.btn_args)
     self.add_widgets([p2_btn])
     self.add_widgets([self._add_lab(_('Pause'), -.56)])
     self.add_widgets(
         [self._add_btn(self.eng.event.key2desc(self.keys['pause']), -.56)])
     InputPageGui4Keyboard.build(self)
示例#15
0
 def build(self):
     ccb = lambda: self.notify('on_push_page', 'client', [self.props])
     menu_data = [('Host', self.on_server), ('Join', ccb)]
     widgets = [
         Btn(text=menu[0],
             pos=(0, .3 - i * .28),
             cmd=menu[1],
             **self.props.gameprops.menu_props.btn_args)
         for i, menu in enumerate(menu_data)
     ]
     self.add_widgets(widgets)
     ThanksPageGui.build(self)
示例#16
0
文件: forms.py 项目: cflavio/yorg
class UserFrmMe(GameObject, Subject):

    def __init__(self, uid, is_supporter, pos, parent, menu_props,
                 msg_btn_x=.58):
        Subject.__init__(self)
        GameObject.__init__(self)
        self.menu_props = menu_props
        self.frm = Btn(
            frame_size=(-.01, 2.54, .05, -.03), frame_col=(1, 1, 1, 0),
            pos=pos, parent=parent, cmd=self.on_cmd, extra_args=[uid])
        self.lab = UserLabel(uid, self.frm, menu_props, is_supporter)
        self.frm.bind(ENTER, self.on_enter)
        self.frm.bind(EXIT, self.on_exit)

    @property
    def widgets(self): return [self.frm] + self.lab.widgets

    def on_enter(self, pos):
        self.lab.on_enter(pos)

    def on_exit(self, pos):
        self.lab.on_exit(pos)

    def on_cmd(self, uid): self.notify('on_clicked', uid)

    def destroy(self):
        self.lab.destroy()
        self.frm.destroy()
        Subject.destroy(self)
        GameObject.destroy(self)
示例#17
0
 def set_news(self):
     menu_props = self.props.gameprops.menu_props
     feed = urlopen(self.props.feed_url).read()
     items = etree.fromstring(feed).findall('channel/item')
     setlocale(LC_ALL, 'en_US.UTF-8')
     try:
         entries = [(datetime.strptime(entry.findtext('pubDate'),
                                       '%a, %d %b %Y %H:%M:%S %z'),
                     entry.findtext('title') or '') for entry in items]
     except TypeError:
         entries = []
     entries = list(reversed(sorted(entries,
                                    key=lambda entry: entry[0])))[:5]
     entries = [(datetime.strftime(entry[0],
                                   '%b %d'), self.__ellipsis_str(entry[1]))
                for entry in entries]
     frm = Frame(frame_size=(0, 1.0, 0, .75),
                 frame_col=(.2, .2, .2, .5),
                 pos=(.05, .1),
                 parent=base.a2dBottomLeft)
     texts = [
         Text(_('Last news:'),
              pos=(.55, .75),
              scale=.055,
              wordwrap=32,
              parent='bottomleft',
              fg=menu_props.text_normal_col,
              font=menu_props.font,
              tra_src='Last news:',
              tra_tra=_('Last news:'))
     ]
     texts += [
         Text(': '.join(entries[i]),
              pos=(.1, .65 - i * .1),
              scale=.055,
              wordwrap=32,
              parent='bottomleft',
              align='left',
              fg=menu_props.text_normal_col,
              font=menu_props.font) for i in range(min(5, len(entries)))
     ]
     btn_args = self.props.gameprops.menu_props.btn_args.copy()
     btn_args['scale'] = (.055, .055)
     show_btn = Btn(text=_('show'),
                    pos=(.55, .15),
                    cmd=self.eng.open_browser,
                    extra_args=[self.props.site_url],
                    parent=base.a2dBottomLeft,
                    tra_src='show',
                    tra_tra=_('show'),
                    **btn_args)
     self.add_widgets([frm] + texts + [show_btn])
示例#18
0
 def build(self):
     lmp_cb = lambda: self.notify('on_push_page', 'localmp', [self.props])
     omp_cb = lambda: self.notify('on_push_page', 'online', [self.props])
     menu_data = [('Local', _('Local'), lmp_cb),
                  ('Online', _('Online'), omp_cb)]
     widgets = [
         Btn(text=menu[0],
             pos=(0, .3 - i * .28),
             cmd=menu[2],
             **self.props.gameprops.menu_props.btn_args)
         for i, menu in enumerate(menu_data)
     ]
     self.add_widgets(widgets)
     ThanksPageGui.build(self)
示例#19
0
 def build(self):
     menu_data = [
         (_('Single race'), self.on_single_race),
         (_('New season'), self.on_start),
         (_('Continue season'), lambda: self.notify('on_continue'))]
     widgets = [
         Btn(
             text=menu[0], pos=(0, .4-i*.28), cmd=menu[1],
             **self.props.gameprops.menu_props.btn_args)
         for i, menu in enumerate(menu_data)]
     self.add_widgets(widgets)
     #self._set_widgets()
     ThanksPageGui.build(self)
     if not self.props.has_save:
         widgets[-1].disable()
示例#20
0
 def build(self, back_btn=True):  # parameters differ from overridden
     self.eng.init_gfx()
     self.font = self.menu_props.font
     self.text_fg = self.menu_props.text_active_col
     self.text_bg = self.menu_props.text_normal_col
     self.text_err_col = self.menu_props.text_err_col
     # items = self.ranking.carname2points.items()
     items = [(player.car, player.points) for player in self.__players]
     sorted_ranking = reversed(sorted(items, key=lambda el: el[1]))
     txt = Text(_('Ranking'),
                scale=.1,
                pos=(0, .76),
                font=self.font,
                fg=self.text_bg)
     self.add_widgets([txt])
     for i, car in enumerate(sorted_ranking):
         txt, img = RankingGui.set_drv_txt_img(self, i, car[0], 0, .52,
                                               str(car[1]) + ' %s',
                                               self.__players)
         self.add_widgets([txt, img])
     track = self.rprops.track_name
     ntracks = len(self.sprops.gameprops.season_tracks)
     if self.sprops.gameprops.season_tracks.index(track) == ntracks - 1:
         cont_btn_cmd = self.notify
         cont_btn_ea = ['on_ranking_next_race']
         img = Img('assets/images/gui/trophy.txo',
                   parent=base.a2dRightCenter,
                   pos=(-.58, 0),
                   scale=.55)
         img.set_transparent()
         txt = Text(_('Congratulations!'),
                    fg=(.8, .6, .2, 1),
                    scale=.16,
                    pos=(0, -.3),
                    font=loader.loadFont(self.sprops.font),
                    parent='leftcenter')
         txt.set_r(-79)
         self.add_widgets([txt, img])
     else:
         cont_btn_cmd = self.notify
         cont_btn_ea = ['on_ranking_end', self.__players]
     cont_btn = Btn(text=_('Continue'),
                    pos=(0, -.8),
                    cmd=cont_btn_cmd,
                    extra_args=cont_btn_ea,
                    **self.menu_props.btn_args)
     self.add_widgets([cont_btn])
     PageGui.build(self, False)
示例#21
0
 def build(self):
     lmp_cb = lambda: self.notify('on_push_page', 'input1keyboard',
                                  [self.keys])
     omp_cb = lambda: self.notify('on_push_page', 'input1joystick',
                                  [self.joystick])
     menu_data = [('Keyboard', _('Keyboard'), lmp_cb),
                  ('Joystick', _('Joystick'), omp_cb)]
     widgets = [
         Btn(text=menu[0],
             pos=(0, .3 - i * .28),
             cmd=menu[2],
             **self.props.gameprops.menu_props.btn_args)
         for i, menu in enumerate(menu_data)
     ]
     self.add_widgets(widgets)
     ThanksPageGui.build(self)
示例#22
0
 def build(self):
     menu_props = self.menu_props
     dev_str = [
         _('Code') + ': Flavio Calva',
         _('Art') + ': Luca Quartero',
         _('Audio') + ': Jay Bachelor',
         _('Translations') + ': Wuzzy, GunChleoc, Leandro Vergara, xin'
     ]
     dev_str = '\n\n'.join(dev_str)
     txt = Text(dev_str, pos=(0, .72), wordwrap=20, **menu_props.text_args)
     btn = Btn(text=_('Supporters'),
               pos=(0, -.4),
               cmd=lambda: self.notify('on_push_page', 'supporters'),
               **menu_props.btn_args)
     self.add_widgets([txt, btn])
     ThanksPageGui.build(self)
示例#23
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()
示例#24
0
 def build(self):
     sp_cb = lambda: self.notify('on_push_page', 'singleplayer',
                                 [self.props])
     mp_cb = lambda: self.notify('on_push_page', 'multiplayer',
                                 [self.props])
     supp_cb = lambda: self.eng.open_browser(self.props.support_url)
     cred_cb = lambda: self.notify('on_push_page', 'credits')
     menu_data = [('Single Player', _('Single Player'), sp_cb),
                  ('Multiplayer', _('Multiplayer'), mp_cb),
                  ('Options', _('Options'), self.on_options),
                  ('Support us', _('Support us'), supp_cb),
                  ('Credits', _('Credits'), cred_cb),
                  ('Quit', _('Quit'), lambda: self.notify('on_exit'))]
     widgets = [
         Btn(text='',
             pos=(0, .64 - i * .23),
             cmd=menu[2],
             tra_src=menu_data[i][0],
             tra_tra=menu_data[i][1],
             **self.props.gameprops.menu_props.btn_args)
         for i, menu in enumerate(menu_data)
     ]
     logo_img = Img(self.props.title_img,
                    scale=(.64, 1, .64 * (380.0 / 772)),
                    parent=base.a2dTopLeft,
                    pos=(.65, -.32))
     widgets += [logo_img]
     lab_args = self.props.gameprops.menu_props.label_args
     lab_args['scale'] = .12
     lab_args['text_fg'] = self.props.gameprops.menu_props.text_err_col
     wip_lab = Label(text='',
                     pos=(-.05, -1.58),
                     parent=base.a2dTopRight,
                     text_wordwrap=10,
                     text_align=TextNode.A_right,
                     tra_src='Note: the game is work-in-progress',
                     tra_tra=_('Note: the game is work-in-progress'),
                     **lab_args)
     self.widgets += [wip_lab]
     self.add_widgets(widgets)
     self.set_news()
     MainPageGui.build(self)
     if not self.ver_check.is_uptodate():
         self.widgets[2]['state'] = DISABLED
示例#25
0
 def build(self):
     lmp_cb = lambda: self.notify('on_push_page', 'localmp', [self.props])
     menu_data = []
     top = .3
     if self.eng.client.is_active and self.eng.client.authenticated:
         menu_data = [('Play', _('Play'), self.on_play)]
         top = .5
     menu_data += [('Server problem', self.get_label(), self.on_loginout),
                   ('Register', _('Register'), self.on_register),
                   ('Reset password', _('Reset password'), self.on_reset)]
     widgets = [
         Btn(text=menu[0],
             pos=(0, top - i * .28),
             cmd=menu[2],
             tra_src=menu[0],
             tra_tra=menu[1],
             **self.props.gameprops.menu_props.btn_args)
         for i, menu in enumerate(menu_data)
     ]
     self.__loginout_btn = widgets[-3]
     self.add_widgets(widgets)
     ThanksPageGui.build(self)
示例#26
0
class UserFrmMe(GameObject, Subject):
    def __init__(self,
                 uid,
                 is_supporter,
                 pos,
                 parent,
                 menu_props,
                 msg_btn_x=.58):
        Subject.__init__(self)
        GameObject.__init__(self)
        self.menu_props = menu_props
        self.frm = Btn(frame_size=(-.01, 2.54, .05, -.03),
                       frame_col=(1, 1, 1, 0),
                       pos=pos,
                       parent=parent,
                       cmd=self.on_cmd,
                       extra_args=[uid])
        self.lab = UserLabel(uid, self.frm, menu_props, is_supporter)
        self.frm.bind(ENTER, self.on_enter)
        self.frm.bind(EXIT, self.on_exit)

    @property
    def widgets(self):
        return [self.frm] + self.lab.widgets

    def on_enter(self, pos):
        self.lab.on_enter(pos)

    def on_exit(self, pos):
        self.lab.on_exit(pos)

    def on_cmd(self, uid):
        self.notify('on_clicked', uid)

    def destroy(self):
        self.lab.destroy()
        self.frm.destroy()
        Subject.destroy(self)
        GameObject.destroy(self)
示例#27
0
 def build(self):
     menu_props = self.menu_props
     widgets = [self.__add_lab('Language', _('Language'), .85)]
     langs = [lan[0] for lan in self.eng.languages]
     self.lang_opt = OptionMenu(text='',
                                items=langs,
                                pos=(.49, .85),
                                initialitem=self.props.lang,
                                cmd=self.__change_lang,
                                **menu_props.option_args)
     widgets += [self.__add_lab('Volume', _('Volume'), .65)]
     self.vol_slider = Slider(
         pos=(.52, .68),
         scale=.49,
         val=self.props.volume,
         frame_col=menu_props.btn_col,
         thumb_frame_col=menu_props.text_active_col,
         cmd=lambda: self.eng.set_volume(self.vol_slider['value']))
     widgets += [self.__add_lab('Fullscreen', _('Fullscreen'), .45)]
     self.fullscreen_cb = CheckBtn(
         pos=(.12, .47),
         text='',
         indicator_val=self.props.fullscreen,
         indicator_frame_col=menu_props.text_active_col,
         cmd=lambda val: self.eng.toggle_fullscreen(),
         **menu_props.checkbtn_args)
     widgets += [self.__add_lab('Resolution', _('Resolution'), .25)]
     res2vec = lambda res: LVector2i(*[int(val) for val in res.split('x')])
     self.res_opt = OptionMenu(
         text='',
         items=[
             'x'.join([str(el_res) for el_res in res])
             for res in self.eng.resolutions
         ],
         pos=(.49, .25),
         initialitem='x'.join(
             str(res) for res in self.eng.closest_resolution),
         cmd=lambda res: self.eng.set_resolution(res2vec(res)),
         **menu_props.option_args)
     widgets += [self.__add_lab('Antialiasing', _('Antialiasing'), .05)]
     self.aa_cb = CheckBtn(pos=(.12, .08),
                           text='',
                           indicator_val=self.props.antialiasing,
                           indicator_frame_col=menu_props.text_active_col,
                           cmd=self.eng.gfx.gfx_mgr.toggle_aa,
                           **menu_props.checkbtn_args)
     widgets += [self.__add_lab('Shaders', _('Shaders'), -.15)]
     self.shaders_cb = CheckBtn(
         pos=(.12, -.12),
         text='',
         indicator_val=self.props.shaders,
         indicator_frame_col=menu_props.text_active_col,
         **menu_props.checkbtn_args)
     widgets += [self.__add_lab('Cars number', _('Cars number'), -.35)]
     widgets += [self.__add_lab('Camera', _('Camera'), -.55)]
     self.cars_opt = OptionMenu(text='',
                                items=[str(i) for i in range(1, 9)],
                                pos=(.49, -.35),
                                initialitem=self.props.cars_num - 1,
                                **menu_props.option_args)
     self.cameras = [_('Top'), _('Rear')]
     self.camera_codes = ['top', 'rear']
     self.cam_opt = OptionMenu(
         text='',
         items=self.cameras,
         pos=(.49, -.55),
         initialitem=self.cameras[self.camera_codes.index(
             self.props.camera)],
         **menu_props.option_args)
     input_btn = Btn(text='',
                     pos=(0, -.75),
                     cmd=self.on_input_btn,
                     tra_src='Configure input',
                     tra_tra=_('Configure input'),
                     **menu_props.btn_args)
     widgets += [
         self.lang_opt, self.vol_slider, self.fullscreen_cb, self.res_opt,
         self.aa_cb, input_btn, self.shaders_cb, self.cars_opt, self.cam_opt
     ]
     self.add_widgets(widgets)
     idx = self.eng.lang_mgr.lang_codes.index(self.props.lang)
     self.__change_lang(self.eng.languages[idx][0])
     ThanksPageGui.build(self)
示例#28
0
    def show(self, race_ranking, lap_times, players):
        track = self.rprops.track_path
        self.players = players
        self.result_frm = DirectFrame(frameColor=(.8, .8, .8, .64),
                                      frameSize=(-2, 2, -1, 1))
        laps = len(lap_times)
        text_bg = self.rprops.season_props.gameprops.menu_props.text_normal_col
        pars = {
            'scale': .1,
            'fg': text_bg,
            'font': self.rprops.season_props.gameprops.menu_props.font
        }
        self.__res_txts = [
            OnscreenText(str(round(lap_times[i], 2)),
                         pos=(0, .52 - .2 * (i + 1)),
                         **pars) for i in range(laps)
        ]
        self.__res_txts += [OnscreenText(_('LAP'), pos=(-.6, .68), **pars)]
        self.__res_txts += [OnscreenText(_('TIME'), pos=(0, .68), **pars)]
        self.__res_txts += [
            OnscreenText(_('RANKING'),
                         pos=(.5, .68),
                         align=TextNode.A_left,
                         **pars)
        ]
        self.__res_txts += [
            OnscreenText(str(i), pos=(-.6, .52 - .2 * i), **pars)
            for i in range(1, 4)
        ]
        race_ranking_sorted = sorted(race_ranking.items(), key=lambda x: x[1])
        race_ranking_sorted = reversed([el[0] for el in race_ranking_sorted])

        for i, car in enumerate(race_ranking_sorted):
            dpars = i, car, .76, .54, str(i + 1) + '. %s'
            txt, img = RankingGui.set_drv_txt_img(self, *dpars, self.players)
            self.__res_txts += [txt, img]
        self.__res_txts += [
            OnscreenText(_('share:'),
                         pos=(-.1, -.82),
                         align=TextNode.A_right,
                         **pars)
        ]
        self._buttons = []

        min_time = min(lap_times or [0])
        facebook_url = self.rprops.share_urls[0]
        twitter_url = self.rprops.share_urls[1]
        twitter_url = twitter_url.format(time=round(min_time, 2), track=track)
        # plus_url = self.rprops.share_urls[2]
        # tumblr_url = self.rprops.share_urls[3]
        sites = [('facebook', facebook_url), ('twitter', twitter_url)]
        # ('google_plus', plus_url), ('tumblr', tumblr_url)
        menu_props = self.rprops.season_props.gameprops.menu_props
        self._buttons += [
            ImgBtn(scale=(.078, .078),
                   pos=(.02 + i * .18, -.79),
                   frame_col=(0, 0, 0, 0),
                   img=menu_props.social_imgs_dirpath % site[0],
                   cmd=self.eng.open_browser,
                   extra_args=[site[1]],
                   over_snd=menu_props.over_sfx,
                   click_snd=menu_props.click_sfx)
            for i, site in enumerate(sites)
        ]

        def step():
            if self.eng.server.is_active:
                self.eng.server.send([NetMsgs.end_race])
            self.notify('on_race_step', race_ranking)
            self.destroy()
            GameObject.destroy(self)

        cont_btn = Btn(
            text=_('Continue'),
            pos=(0, -.6),
            cmd=step,
            **self.rprops.season_props.gameprops.menu_props.btn_args)
        self._buttons += [cont_btn]
        for i in range(self.eng.joystick_mgr.joystick_lib.num_joysticks):
            self.accept('joypad%s-face_a-up' % i, step)
示例#29
0
文件: button.py 项目: oriolrg/yorg
class MPBtn(GameObject):

    tooltip_align = TextNode.A_right
    tooltip_offset = (.01, 0, -.08)

    def __init__(self, parent, owner, menu_props, img_path, msg_btn_x, cb,
                 usr_name, tooltip):
        GameObject.__init__(self)
        self.owner = owner
        lab_args = menu_props.label_args
        lab_args['scale'] = .046
        #lab_args['text_fg'] = menu_props.text_normal_col
        self.btn = ImgBtn(parent=parent,
                          scale=(.024, .024),
                          pos=(msg_btn_x, .01),
                          frame_col=(1, 1, 1, 1),
                          frame_texture=img_path,
                          cmd=cb,
                          extra_args=[usr_name],
                          **menu_props.imgbtn_args)
        self.btn.bind(ENTER, self.on_enter)
        self.btn.bind(EXIT, self.on_exit)
        self.tooltip_btn = Btn(parent=parent,
                               scale=(.024, .024),
                               pos=(msg_btn_x, .01),
                               frame_col=(1, 1, 1, 0),
                               frame_size=(-1, 1, -1, 1),
                               cmd=None,
                               **menu_props.imgbtn_args)
        self.tooltip_btn.bind(ENTER, self.on_enter)
        self.tooltip_btn.bind(EXIT, self.on_exit)
        self.on_create()
        self.tooltip = Label(text=tooltip,
                             pos=self.btn.get_pos() + self.tooltip_offset,
                             parent=parent,
                             text_wordwrap=10,
                             text_align=self.tooltip_align,
                             **lab_args)
        self.tooltip.set_bin('gui-popup', 10)
        self.tooltip.hide()

    def on_create(self):
        self.btn.hide()
        self.tooltip_btn.hide()

    def is_hidden(self):
        return self.btn.hidden

    def show(self):
        if self.btn['state'] == DISABLED:
            self.tooltip_btn.show()
        else:
            self.tooltip_btn.hide()
        return self.btn.show()

    def hide(self):
        self.tooltip_btn.hide()
        return self.btn.hide()

    def enable(self):
        self.tooltip_btn.hide()
        return self.btn.enable()

    def disable(self):
        self.tooltip_btn.show()
        return self.btn.disable()

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

    def on_exit(self, pos):
        self.owner.on_exit(pos)
        self.tooltip.hide()
示例#30
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)
示例#31
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()
示例#32
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)
示例#33
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)
示例#34
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()
示例#35
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)
示例#36
0
文件: button.py 项目: cflavio/yorg
class MPBtn(GameObject):

    tooltip_align = TextNode.A_right
    tooltip_offset = (.01, 0, -.08)

    def __init__(self, parent, owner, menu_props, img_path, msg_btn_x, cb,
                 usr_name, tooltip):
        GameObject.__init__(self)
        self.owner = owner
        lab_args = menu_props.label_args
        lab_args['scale'] = .046
        #lab_args['text_fg'] = menu_props.text_normal_col
        self.btn = ImgBtn(
            parent=parent, scale=(.024, .024), pos=(msg_btn_x, .01),
            frame_col=(1, 1, 1, 1), frame_texture=img_path, cmd=cb,
            extra_args=[usr_name], **menu_props.imgbtn_args)
        self.btn.bind(ENTER, self.on_enter)
        self.btn.bind(EXIT, self.on_exit)
        self.tooltip_btn = Btn(
            parent=parent, scale=(.024, .024), pos=(msg_btn_x, .01),
            frame_col=(1, 1, 1, 0), frame_size=(-1, 1, -1, 1), cmd=None,
            **menu_props.imgbtn_args)
        self.tooltip_btn.bind(ENTER, self.on_enter)
        self.tooltip_btn.bind(EXIT, self.on_exit)
        self.on_create()
        self.tooltip = Label(
            text=tooltip, pos=self.btn.get_pos() + self.tooltip_offset,
            parent=parent, text_wordwrap=10, text_align=self.tooltip_align,
            **lab_args)
        self.tooltip.set_bin('gui-popup', 10)
        self.tooltip.hide()

    def on_create(self):
        self.btn.hide()
        self.tooltip_btn.hide()

    def is_hidden(self): return self.btn.hidden

    def show(self):
        if self.btn['state'] == DISABLED:
            self.tooltip_btn.show()
        else:
            self.tooltip_btn.hide()
        return self.btn.show()

    def hide(self):
        self.tooltip_btn.hide()
        return self.btn.hide()

    def enable(self):
        self.tooltip_btn.hide()
        return self.btn.enable()

    def disable(self):
        self.tooltip_btn.show()
        return self.btn.disable()

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

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