Exemplo n.º 1
0
def safe_unicode(text):
    """
    Returns a safe unicode version of the text
    """
    if urwid.supports_unicode():
        return text
    else:
        return text.encode('ascii', errors='replace')
Exemplo n.º 2
0
    def set_servers(self, servers, current=None):
        new = []
        for s in sorted(servers):
            e = PMenuButton(" %s " % s, lambda button, _s=s: self.connect_to_server(_s))
            e = urwid.AttrMap(e, 'server_current' if s == current else 'server')
            new.append((e, self.g_servers.options('pack')))

        contents = self.g_servers.contents
        del contents[0:len(contents)]
        sep = u'\u2022' if urwid.supports_unicode() else u':'
        contents.append((urwid.AttrMap(urwid.Text(u' mark2 %s' % sep), 'mark2'), self.g_servers.options('pack')))
        contents.extend(new)
        contents.append((urwid.Divider(), self.g_users.options()))
Exemplo n.º 3
0
def _check_encoding():
    """Set the Urwid global byte encoding to utf-8.

    Exit the application if, for some reasons, the change does not have effect.
    """
    urwid.set_encoding('utf-8')
    if not urwid.supports_unicode():
        # Note: the following message must only include ASCII characters.
        msg = (
            'Error: your terminal does not seem to support UTF-8 encoding.\n'
            'Please check your locale settings.\n'
            'On Ubuntu, running the following might fix the problem:\n'
            '  sudo locale-gen en_US.UTF-8\n'
            '  sudo dpkg-reconfigure locales')
        sys.exit(msg.encode('ascii'))
Exemplo n.º 4
0
def _check_encoding():
    """Set the Urwid global byte encoding to utf-8.

    Exit the application if, for some reasons, the change does not have effect.
    """
    urwid.set_encoding('utf-8')
    if not urwid.supports_unicode():
        # Note: the following message must only include ASCII characters.
        msg = (
            'Error: your terminal does not seem to support UTF-8 encoding.\n'
            'Please check your locale settings.\n'
            'On Ubuntu, running the following might fix the problem:\n'
            '  sudo locale-gen en_US.UTF-8\n'
            '  sudo dpkg-reconfigure locales'
        )
        sys.exit(msg.encode('ascii'))
Exemplo n.º 5
0
    def set_servers(self, servers, current=None):
        new = []
        for s in sorted(servers):
            e = PMenuButton(" %s " % s,
                            lambda button, _s=s: self.connect_to_server(_s))
            e = urwid.AttrMap(e,
                              'server_current' if s == current else 'server')
            new.append((e, self.g_servers.options('pack')))

        contents = self.g_servers.contents
        del contents[0:len(contents)]
        sep = u'\u21C9 ' if urwid.supports_unicode() else u':'
        contents.append(
            (urwid.AttrMap(urwid.Text(u' mark2 %s' % sep),
                           'mark2'), self.g_servers.options('pack')))
        contents.extend(new)
        contents.append((urwid.Divider(), self.g_users.options()))
Exemplo n.º 6
0
 def safe_unicode(self, text):
     if urwid.supports_unicode():
         return text
     else:
         return text.encode('ascii', errors='replace')
Exemplo n.º 7
0
 def safe_unicode(self, text):
     if urwid.supports_unicode():
         return text
     else:
         return text.encode("ascii", errors="replace")
Exemplo n.º 8
0
 def safe_unicode(self, text):
     if urwid.supports_unicode():
         return text
     else:
         return text.encode('ascii', errors='replace')