當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。