Python urwid.set_encoding() Examples

The following are 18 code examples of urwid.set_encoding(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module urwid , or try the search function .
Example #1
Source File: test_graphics.py    From anyMesh-Python with MIT License 6 votes vote down vote up
def test_linebox_border(self):
        urwid.set_encoding("utf-8")
        t = urwid.Text("")

        l = urwid.LineBox(t).render((3,)).text

        # default
        self.assertEqual(l,
            self.border(B("\xe2\x94\x8c"), B("\xe2\x94\x80"),
                B("\xe2\x94\x90"), B("\xe2\x94\x82"), B("\xe2\x94\x82"),
                B("\xe2\x94\x94"), B("\xe2\x94\x80"), B("\xe2\x94\x98")))

        nums = [B(str(n)) for n in range(8)]
        b = dict(zip(["tlcorner", "tline", "trcorner", "lline", "rline",
            "blcorner", "bline", "brcorner"], nums))
        l = urwid.LineBox(t, **b).render((3,)).text

        self.assertEqual(l, self.border(*nums)) 
Example #2
Source File: test_util.py    From anyMesh-Python with MIT License 5 votes vote down vote up
def test4_utf8(self):
        util.set_encoding("utf-8")
        text = "he\xcc\x80llo \xe6\x9b\xbf world"
        tests = [
            (0,15,0, (0,0)),
            (0,15,1, (1,1)),
            (0,15,2, (4,2)),
            (0,15,4, (6,4)),
            (8,15,0, (8,0)),
            (8,15,1, (8,0)),
            (8,15,2, (11,2)),
            (8,15,5, (14,5)),
            ]
        self.ctptest(text, tests) 
Example #3
Source File: test_text_layout.py    From anyMesh-Python with MIT License 5 votes vote down vote up
def setUp(self):
        urwid.set_encoding('utf-8') 
Example #4
Source File: test_text_layout.py    From anyMesh-Python with MIT License 5 votes vote down vote up
def setUp(self):
        urwid.set_encoding("euc-jp") 
Example #5
Source File: test_text_layout.py    From anyMesh-Python with MIT License 5 votes vote down vote up
def test(self):
        urwid.set_encoding("euc-jp")
        self.assertRaises(text_layout.CanNotDisplayText,
            text_layout.default_layout.calculate_text_segments,
            B('\xA1\xA1'), 1, 'space' )
        urwid.set_encoding("utf-8")
        self.assertRaises(text_layout.CanNotDisplayText,
            text_layout.default_layout.calculate_text_segments,
            B('\xe9\xa2\x96'), 1, 'space' ) 
Example #6
Source File: test_text_layout.py    From anyMesh-Python with MIT License 5 votes vote down vote up
def setUp(self):
        urwid.set_encoding("utf-8") 
Example #7
Source File: test_text_layout.py    From anyMesh-Python with MIT License 5 votes vote down vote up
def setUp(self):
        urwid.set_encoding("euc-jp") 
Example #8
Source File: test_text_layout.py    From anyMesh-Python with MIT License 5 votes vote down vote up
def setUp(self):
        urwid.set_encoding("euc-jp") 
Example #9
Source File: test_widget.py    From anyMesh-Python with MIT License 5 votes vote down vote up
def test_utf8_input(self):
        urwid.set_encoding("utf-8")
        self.t1.set_edit_text('')
        self.t1.keypress((12,), u'û')
        self.assertEqual(self.t1.edit_text, u'û'.encode('utf-8'))
        self.t4.keypress((12,), u'û')
        self.assertEqual(self.t4.edit_text, u'û') 
Example #10
Source File: test_widget.py    From anyMesh-Python with MIT License 5 votes vote down vote up
def test5_encode_error(self):
        urwid.set_encoding("ascii")
        expected = [B("?  ")]
        got = urwid.Text(u'û').render((3,))._text
        assert got == expected, "got: %r expected: %r" % (got, expected) 
Example #11
Source File: app.py    From sclack with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, config):
        self._loading = False
        self.config = config
        self.quick_switcher = None
        self.set_snooze_widget = None
        self.workspaces = list(config['workspaces'].items())
        self.store = Store(self.workspaces, self.config)
        Store.instance = self.store
        urwid.set_encoding('UTF-8')
        sidebar = LoadingSideBar()
        chatbox = LoadingChatBox('Everything is terrible!')
        palette = themes.get(config['theme'], themes['default'])

        custom_loop = SclackEventLoop(loop=loop)
        custom_loop.set_exception_handler(self._exception_handler)

        if len(self.workspaces) <= 1:
            self.workspaces_line = None
        else:
            self.workspaces_line = Workspaces(self.workspaces)

        self.columns = urwid.Columns([
            ('fixed', config['sidebar']['width'], urwid.AttrWrap(sidebar, 'sidebar')),
            urwid.AttrWrap(chatbox, 'chatbox')
        ])
        self._body = urwid.Frame(self.columns, header=self.workspaces_line)

        self.urwid_loop = urwid.MainLoop(
            self._body,
            palette=palette,
            event_loop=custom_loop,
            unhandled_input=self.unhandled_input
        )
        self.configure_screen(self.urwid_loop.screen)
        self.last_keypress = (0, None) 
Example #12
Source File: test_util.py    From anyMesh-Python with MIT License 5 votes vote down vote up
def test3_utf8(self):
        util.set_encoding("utf-8")
        text = "hel\xc4\x83 world \xe2\x81\x81 there"
        tests = [
            (0,21,0, (0,0)),
            (0,21,4, (5,4)),
            (2,21,1, (3,1)),
            (2,21,2, (5,2)),
            (2,21,3, (6,3)),
            (6,21,7, (15,7)),
            (6,21,8, (16,8)),
            ]
        self.ctptest(text, tests) 
Example #13
Source File: test_util.py    From anyMesh-Python with MIT License 5 votes vote down vote up
def test2_wide(self):
        util.set_encoding("euc-jp")
        text = "hel\xA1\xA1 world out there"
        tests = [
            (0,21,0, (0,0)),
            (0,21,4, (3,3)),
            (2,21,2, (3,1)),
            (2,21,3, (5,3)),
            (6,21,0, (6,0)),
            ]
        self.ctptest(text, tests) 
Example #14
Source File: test_util.py    From anyMesh-Python with MIT License 5 votes vote down vote up
def ctest(self, desc, s, exp, expcs):
        exp = B(exp)
        util.set_encoding('ascii')
        c = urwid.Text(s).render((5,))
        result = c._text[0]
        assert result==exp, "%s got:%r expected:%r" % (desc, result, exp)
        resultcs = c._cs[0]
        assert resultcs==expcs, "%s got:%r expected:%r" % (desc,
                                                           resultcs, expcs) 
Example #15
Source File: test_util.py    From anyMesh-Python with MIT License 5 votes vote down vote up
def test2(self):
        util.set_encoding("euc-jp")
        self.wtest("narrow", "hello", 5)
        self.wtest("wide", "\xA1\xA1\xA1\xA1", 4)
        self.wtest("invalid", "\xA1", 1) 
Example #16
Source File: test_util.py    From anyMesh-Python with MIT License 5 votes vote down vote up
def test1(self):
        util.set_encoding("utf-8")
        self.wtest("narrow", "hello", 5)
        self.wtest("wide char", '\xe6\x9b\xbf', 2)
        self.wtest("invalid", '\xe6', 1)
        self.wtest("zero width", '\xcc\x80', 0)
        self.wtest("mixed", 'hello\xe6\x9b\xbf\xe6\x9b\xbf', 9) 
Example #17
Source File: test_graphics.py    From anyMesh-Python with MIT License 5 votes vote down vote up
def sbgtest(self, desc, data, top, exp ):
        urwid.set_encoding('utf-8')
        g = urwid.BarGraph( ['black','red','blue'],
                None, {(1,0):'red/black', (2,1):'blue/red'})
        g.set_data( data, top )
        rval = g.calculate_display((5,3))
        assert rval == exp, "%s expected %r, got %r"%(desc,exp,rval) 
Example #18
Source File: gui.py    From TWchat with MIT License 5 votes vote down vote up
def createLoop(self):
        placeholder = urwid.SolidFill()
        urwid.set_encoding("UTF-8")
        self.loop = urwid.MainLoop(placeholder,self.palette,unhandled_input=exit_on_alt_q)
        self.loop.screen.set_terminal_properties(colors=256)
        self.loop.widget = urwid.AttrMap(placeholder, 'bg')
        self.loop.widget.original_widget = urwid.Filler(self.createLayout())
        self.loop.run()