当前位置: 首页>>代码示例>>Python>>正文


Python urwid.set_encoding方法代码示例

本文整理汇总了Python中urwid.set_encoding方法的典型用法代码示例。如果您正苦于以下问题:Python urwid.set_encoding方法的具体用法?Python urwid.set_encoding怎么用?Python urwid.set_encoding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在urwid的用法示例。


在下文中一共展示了urwid.set_encoding方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_linebox_border

# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import set_encoding [as 别名]
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)) 
开发者ID:AnyMesh,项目名称:anyMesh-Python,代码行数:20,代码来源:test_graphics.py

示例2: __init__

# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import set_encoding [as 别名]
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) 
开发者ID:haskellcamargo,项目名称:sclack,代码行数:37,代码来源:app.py

示例3: createLoop

# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import set_encoding [as 别名]
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() 
开发者ID:huanglizhuo,项目名称:TWchat,代码行数:10,代码来源:gui.py

示例4: sbgtest

# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import set_encoding [as 别名]
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) 
开发者ID:AnyMesh,项目名称:anyMesh-Python,代码行数:9,代码来源:test_graphics.py

示例5: test1

# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import set_encoding [as 别名]
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) 
开发者ID:AnyMesh,项目名称:anyMesh-Python,代码行数:9,代码来源:test_util.py

示例6: test2

# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import set_encoding [as 别名]
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) 
开发者ID:AnyMesh,项目名称:anyMesh-Python,代码行数:7,代码来源:test_util.py

示例7: ctest

# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import set_encoding [as 别名]
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) 
开发者ID:AnyMesh,项目名称:anyMesh-Python,代码行数:11,代码来源:test_util.py

示例8: test2_wide

# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import set_encoding [as 别名]
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) 
开发者ID:AnyMesh,项目名称:anyMesh-Python,代码行数:13,代码来源:test_util.py

示例9: test3_utf8

# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import set_encoding [as 别名]
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) 
开发者ID:AnyMesh,项目名称:anyMesh-Python,代码行数:15,代码来源:test_util.py

示例10: test4_utf8

# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import set_encoding [as 别名]
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) 
开发者ID:AnyMesh,项目名称:anyMesh-Python,代码行数:16,代码来源:test_util.py

示例11: test5_encode_error

# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import set_encoding [as 别名]
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) 
开发者ID:AnyMesh,项目名称:anyMesh-Python,代码行数:7,代码来源:test_widget.py

示例12: test_utf8_input

# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import set_encoding [as 别名]
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'û') 
开发者ID:AnyMesh,项目名称:anyMesh-Python,代码行数:9,代码来源:test_widget.py

示例13: setUp

# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import set_encoding [as 别名]
def setUp(self):
        urwid.set_encoding("euc-jp") 
开发者ID:AnyMesh,项目名称:anyMesh-Python,代码行数:4,代码来源:test_text_layout.py

示例14: test

# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import set_encoding [as 别名]
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' ) 
开发者ID:AnyMesh,项目名称:anyMesh-Python,代码行数:11,代码来源:test_text_layout.py


注:本文中的urwid.set_encoding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。