コード例 #1
0
ファイル: box.py プロジェクト: Gopaal/2014-interns
    def add_text(self, buddy, text, status_message=False):
        """Display text on screen, with name and colors.

        buddy -- buddy object or dict {nick: string, color: string}
                 (The dict is for loading the chat log from the journal,
                 when we don't have the buddy object any more.)
        text -- string, what the buddy said
        status_message -- boolean
            False: show what buddy said
            True: show what buddy did

        .------------- rb ---------------.
        | +name_vbox+ +----align-----+ |
        | |         | |                | |
        | | nick:   | | +--message---+ | |
        | |         | | |  text      | | |
        | +---------+ | +------------+ | |
        |             +----------------+ |
        `--------------------------------'
        """
        if not buddy:
            buddy = self.owner

        if type(buddy) is dict:
            # dict required for loading chat log from journal
            nick = buddy['nick']
            color = buddy['color']
        else:
            nick = buddy.props.nick
            color = buddy.props.color
        try:
            color_stroke_html, color_fill_html = color.split(',')
        except ValueError:
            color_stroke_html, color_fill_html = ('#000000', '#888888')

        # Select text color based on fill color:
        color_fill_rgba = style.Color(color_fill_html).get_rgba()
        color_fill_gray = (color_fill_rgba[0] + color_fill_rgba[1] +
                color_fill_rgba[2]) / 3
        color_stroke = style.Color(color_stroke_html)
        color_fill = style.Color(color_fill_html)

        if color_fill_gray < 0.5:
            text_color = style.COLOR_WHITE
        else:
            text_color = style.COLOR_BLACK

        self._add_log(nick, color, text, status_message)

        # Check for Right-To-Left languages:
        if pango.find_base_dir(nick, -1) == pango.DIRECTION_RTL:
            lang_rtl = True
        else:
            lang_rtl = False

        # Check if new message box or add text to previous:
        new_msg = True
        if self._last_msg_sender:
            if not status_message:
                if buddy == self._last_msg_sender:
                    # Add text to previous message
                    new_msg = False

        if not new_msg:
            message = self._last_msg
        else:
            rb = RoundBox()
            screen_width = gtk.gdk.screen_width()
            # keep space to the scrollbar
            rb.set_size_request(screen_width - 50, -1)
            rb.props.border_width = style.DEFAULT_PADDING
            rb.props.spacing = style.DEFAULT_SPACING
            rb.background_color = color_fill
            rb.border_color = color_stroke
            self._last_msg_sender = buddy
            if not status_message:
                name = ColorLabel(text=nick + ':', color=text_color)
                name_vbox = gtk.VBox()
                name_vbox.pack_start(name, False, False)
                rb.pack_start(name_vbox, False, False)

            message = TextBox(text_color, color_fill, lang_rtl)
            vbox = gtk.VBox()
            vbox.pack_start(message, True, True)
            rb.pack_start(vbox, True, True)
            self._last_msg = message
            self._conversation.pack_start(rb, False, False)

        if status_message:
            self._last_msg_sender = None

        message.add_text(text)
        self._conversation.show_all()		"""Here message.add_text(text) adding text in entry box add it to chatbox 
コード例 #2
0
    def add_text(self, buddy, text, status_message=False):
        """Display text on screen, with name and colors.

        buddy -- buddy object or dict {nick: string, color: string}
                 (The dict is for loading the chat log from the journal,
                 when we don't have the buddy object any more.)
        text -- string, what the buddy said
        status_message -- boolean
            False: show what buddy said
            True: show what buddy did

        .------------- rb ---------------.
        | +name_vbox+ +----align-----+ |
        | |         | |                | |
        | | nick:   | | +--message---+ | |
        | |         | | |  text      | | |
        | +---------+ | +------------+ | |
        |             +----------------+ |
        `--------------------------------'
        """
        if not buddy:
            buddy = self.owner

        if type(buddy) is dict:
            # dict required for loading chat log from journal
            nick = buddy['nick']
            color = buddy['color']
        else:
            nick = buddy.props.nick
            color = buddy.props.color
        try:
            color_stroke_html, color_fill_html = color.split(',')
        except ValueError:
            color_stroke_html, color_fill_html = ('#000000', '#888888')

        # Select text color based on fill color:
        color_fill_rgba = style.Color(color_fill_html).get_rgba()
        color_fill_gray = (color_fill_rgba[0] + color_fill_rgba[1] +
                color_fill_rgba[2]) / 3
        color_stroke = style.Color(color_stroke_html)
        color_fill = style.Color(color_fill_html)

        if color_fill_gray < 0.5:
            text_color = style.COLOR_WHITE
        else:
            text_color = style.COLOR_BLACK

        self._add_log(nick, color, text, status_message)

        # Check for Right-To-Left languages:
        if pango.find_base_dir(nick, -1) == pango.DIRECTION_RTL:
            lang_rtl = True
        else:
            lang_rtl = False

        # Check if new message box or add text to previous:
        new_msg = True
        if self._last_msg_sender:
            if not status_message:
                if buddy == self._last_msg_sender:
                    # Add text to previous message
                    new_msg = False

        if not new_msg:
            message = self._last_msg
        else:
            rb = RoundBox()
            screen_width = gtk.gdk.screen_width()
            # keep space to the scrollbar
            rb.set_size_request(screen_width - 50, -1)
            rb.background_color = color_fill
            rb.border_color = color_stroke
            self._last_msg_sender = buddy
            if not status_message:
                name = ColorLabel(text=nick + ':   ', color=text_color)
                name_vbox = gtk.VBox()
                name_vbox.pack_start(name, False, False)
                rb.pack_start(name_vbox, False, False, padding=5)

            message = TextBox(text_color, color_fill, lang_rtl)
            vbox = gtk.VBox()
            vbox.pack_start(message, True, True, padding=5)
            rb.pack_start(vbox, True, True, padding=5)
            self._last_msg = message
            self._conversation.pack_start(rb, False, False, padding=2)

        if status_message:
            self._last_msg_sender = None

        message.add_text(text)
        self._conversation.show_all()
コード例 #3
0
ファイル: box.py プロジェクト: gnowledge/sugar-ChatStudio
    def add_text(self, buddy, text, status_message=False):

        if not buddy:
            buddy = self.owner
        if buddy == "Computer":
            nick = "Computer"
            color = '#000000,#FFF8DC'

        else:
            if type(buddy) is dict:
                # dict required for loading chat log from journal
                nick = buddy['nick']
                color = buddy['color']
            else:
                nick = buddy.props.nick
                color = buddy.props.color
        try:
            color_stroke_html, color_fill_html = color.split(',')
        except ValueError:
            color_stroke_html, color_fill_html = ('#000000', '#888888')

        # Select text color based on fill color:
        color_fill_rgba = style.Color(color_fill_html).get_rgba()
        color_fill_gray = (color_fill_rgba[0] + color_fill_rgba[1] +
                           color_fill_rgba[2]) / 3
        color_stroke = style.Color(color_stroke_html)
        color_fill = style.Color(color_fill_html)

        if color_fill_gray < 0.5:
            text_color = style.COLOR_WHITE
        else:
            text_color = style.COLOR_BLACK

        self._add_log(nick, text, status_message)

        # Check for Right-To-Left languages:
        if pango.find_base_dir(nick, -1) == pango.DIRECTION_RTL:
            lang_rtl = True
        else:
            lang_rtl = False

        # Check if new message box or add text to previous:
        new_msg = True
        if self._last_msg_sender:
            if not status_message:
                if buddy == self._last_msg_sender:
                    # Add text to previous message
                    new_msg = True

        if not new_msg:
            message = self._last_msg
        else:
            rb = RoundBox()
            screen_width = gtk.gdk.screen_width()
            # keep space to the scrollbar
            rb.set_size_request(screen_width - 50, -1)
            rb.props.border_width = style.DEFAULT_PADDING
            rb.props.spacing = style.DEFAULT_SPACING
            rb.background_color = color_fill
            rb.border_color = color_stroke
            self._last_msg_sender = buddy
            if not status_message:
                name = ColorLabel(text=nick + ':', color=text_color)
                name_vbox = gtk.VBox()
                name_vbox.pack_start(name, False, False)
                rb.pack_start(name_vbox, False, False)

            message = TextBox(text_color, color_fill, lang_rtl)
            vbox = gtk.VBox()
            vbox.pack_start(message, True, True)
            rb.pack_start(vbox, True, True)
            self._last_msg = message
            self._conversation.pack_start(rb, False, False)

        if status_message:
            self._last_msg_sender = None

        message.add_text(text)
        self._conversation.show_all()