Example #1
0
    def __init__(self, **kwargs):
        # private
        self.last_line_rtl = False
        self.line_rtl = False

        self.rtl_font = kwargs.get("rtl_font", self.rtl_font)
        self.rtl_font_size = kwargs.get("rtl_font_size", self.rtl_font_size)
        self.rtl_halign_ignore = kwargs.get("rtl_halign_ignore", self.rtl_halign_ignore)

        dkw = {}
        value = kwargs.get("text", "")
        self.line_rtl = False
        if value:
            rtl, has_rtl = get_display_hasrtl(value)
            self.line_rtl = (rtl != 0) or (has_rtl)

        super(BidiLabel, self).__init__(**kwargs)
        dkw["rtl_font"] = partial(self._trigger_texture_update, "rtl_font")
        dkw["rtl_font_size"] = partial(self._trigger_texture_update, "rtl_font_size")
        self.bind(**dkw)
        dkw["rtl"] = self.line_rtl
Example #2
0
    def _trigger_texture_update(self, name=None, source=None, value=None):
        # check if the label core class need to be switch to a new one
        if name == "markup":
            self._create_label()
        if source:
            if name == "text":
                rtl, has_rtl = get_display_hasrtl(value)
                self.line_rtl = (rtl != 0) or (has_rtl)

                if self.line_rtl != self.last_line_rtl:
                    self._create_label()

                # if self.line_rtl:
                #     rtext, _ = remove_leading_spaces(rtext)
                #     print 'BEFORE %s' % self._label.text.encode('utf-8')
                #     print 'AFTER %s' % rtext.encode('utf-8')
                #     self._label.text = rtext
                # else:
                self._label.text = value

            elif name == "text_size":
                self._label.usersize = value
            elif name == "font_size":
                self._label.options[name] = value
                if self.rtl_font_size < 0:
                    self.rtl_font_size = value
            elif name == "rtl_font":
                if self.line_rtl:
                    self._label.options["font_name"] = value
                self.rtl_font = value
            elif name == "rtl_font_size":
                if self.line_rtl:
                    self._label.options["font_size"] = value
                self.rtl_font_size = value
            else:
                self._label.options[name] = value

        self._trigger_texture()