本文整理汇总了Python中urwid.util.apply_target_encoding函数的典型用法代码示例。如果您正苦于以下问题:Python apply_target_encoding函数的具体用法?Python apply_target_encoding怎么用?Python apply_target_encoding使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了apply_target_encoding函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: attrrange
def attrrange( start_offs, end_offs, destw ):
"""
Add attributes based on attributes between
start_offs and end_offs.
"""
if start_offs == end_offs:
[(at,run)] = arange(start_offs,end_offs)
rle_append_modify( linea, ( at, destw ))
return
if destw == end_offs-start_offs:
for at, run in arange(start_offs,end_offs):
rle_append_modify( linea, ( at, run ))
return
# encoded version has different width
o = start_offs
for at, run in arange(start_offs, end_offs):
if o+run == end_offs:
rle_append_modify( linea, ( at, destw ))
return
tseg = text[o:o+run]
tseg, cs = apply_target_encoding( tseg )
segw = rle_len(cs)
rle_append_modify( linea, ( at, segw ))
o += run
destw -= segw
开发者ID:adiabuk,项目名称:arch-tf701t,代码行数:26,代码来源:canvas.py
示例2: make_canvas
def make_canvas(txt, attr, maxcol, fill_attr=None):
processed_txt = []
processed_attr = []
processed_cs = []
for line, line_attr in zip(txt, attr):
# filter out zero-length attrs
line_attr = [(aname, l) for aname, l in line_attr if l > 0]
diff = maxcol - len(line)
if diff > 0:
line += " "*diff
line_attr.append((fill_attr, diff))
else:
from urwid.util import rle_subseg
line = line[:maxcol]
line_attr = rle_subseg(line_attr, 0, maxcol)
from urwid.util import apply_target_encoding
line, line_cs = apply_target_encoding(line)
processed_txt.append(line)
processed_attr.append(line_attr)
processed_cs.append(line_cs)
return urwid.TextCanvas(
processed_txt,
processed_attr,
processed_cs,
maxcol=maxcol)
开发者ID:AguNnamdi,项目名称:machine-learning,代码行数:30,代码来源:ui_tools.py
示例3: render
def render(self, size, focus=False):
from pudb.debugger import CONFIG
render_line_nr = CONFIG["line_numbers"]
maxcol = size[0]
hscroll = self.dbg_ui.source_hscroll_start
attrs = []
if self.is_current:
crnt = ">"
attrs.append("current")
else:
crnt = " "
if self.has_breakpoint:
bp = "*"
attrs.append("breakpoint")
else:
bp = " "
if focus:
attrs.append("focused")
elif self.highlight:
if not self.has_breakpoint:
attrs.append("highlighted")
if render_line_nr:
line_nr_len = len(self.line_nr)
else:
line_nr_len = 0
text = self.text
if not attrs and self.attr is not None:
attr = self.attr
else:
attr = [(" ".join(attrs+["source"]), hscroll+maxcol-2-line_nr_len)]
from urwid.util import rle_subseg, rle_len
if hscroll:
text = text[hscroll:]
attr = rle_subseg(attr, hscroll, rle_len(attr))
if render_line_nr:
attr = [("line number", len(self.line_nr))] + attr
text = self.line_nr + text
text = crnt+bp+text
attr = [("source", 1), ("bp_star", 1)] + attr
# clipping ------------------------------------------------------------
if len(text) > maxcol:
text = text[:maxcol]
attr = rle_subseg(attr, 0, maxcol)
# shipout -------------------------------------------------------------
from urwid.util import apply_target_encoding
txt, cs = apply_target_encoding(text)
return urwid.TextCanvas([txt], [attr], [cs], maxcol=maxcol)
开发者ID:AguNnamdi,项目名称:machine-learning,代码行数:59,代码来源:source_view.py
示例4: __init__
def __init__(self, fill_char, cols, rows):
Canvas.__init__(self)
end, col = calc_text_pos(fill_char, 0, len(fill_char), 1)
assert col == 1, "Invalid fill_char: %r" % fill_char
self._text, cs = apply_target_encoding(fill_char[:end])
self._cs = cs[0][0]
self.size = cols, rows
self.cursor = None
开发者ID:adiabuk,项目名称:arch-tf701t,代码行数:8,代码来源:canvas.py
示例5: render
def render(self, c):
if c in self.canvas:
return self.canvas[c]
width, l = self.char[c]
tl = []
csl = []
for d in l:
t, cs = apply_target_encoding(d)
tl.append(t)
csl.append(cs)
canv = TextCanvas(tl, None, csl, maxcol=width, check_width=False)
self.canvas[c] = canv
return canv
开发者ID:kevinSC,项目名称:urwid,代码行数:13,代码来源:font.py
示例6: make_canvas
def make_canvas(txt, attr, maxcol, fill_attr=None):
processed_txt = []
processed_attr = []
processed_cs = []
for line, line_attr in zip(txt, attr):
# filter out zero-length attrs
line_attr = [(aname, l) for aname, l in line_attr if l > 0]
diff = maxcol - len(line)
if diff > 0:
line += " "*diff
line_attr.append((fill_attr, diff))
else:
from urwid.util import rle_subseg
line = line[:maxcol]
line_attr = rle_subseg(line_attr, 0, maxcol)
from urwid.util import apply_target_encoding
encoded_line, line_cs = apply_target_encoding(line)
# line_cs contains byte counts as requested by TextCanvas, but
# line_attr still contains column counts at this point: let's fix this.
def get_byte_line_attr(line, line_attr):
i = 0
for label, column_count in line_attr:
byte_count = len(line[i:i+column_count].encode(_target_encoding))
i += column_count
yield label, byte_count
line_attr = list(get_byte_line_attr(line, line_attr))
processed_txt.append(encoded_line)
processed_attr.append(line_attr)
processed_cs.append(line_cs)
return urwid.TextCanvas(
processed_txt,
processed_attr,
processed_cs,
maxcol=maxcol)
开发者ID:adilnurimanov,项目名称:pudb,代码行数:41,代码来源:ui_tools.py
示例7: apply_text_layout
def apply_text_layout(text, attr, ls, maxcol):
t = []
a = []
c = []
class AttrWalk:
pass
aw = AttrWalk
aw.k = 0 # counter for moving through elements of a
aw.off = 0 # current offset into text of attr[ak]
def arange( start_offs, end_offs ):
"""Return an attribute list for the range of text specified."""
if start_offs < aw.off:
aw.k = 0
aw.off = 0
o = []
while aw.off < end_offs:
if len(attr)<=aw.k:
# run out of attributes
o.append((None,end_offs-max(start_offs,aw.off)))
break
at,run = attr[aw.k]
if aw.off+run <= start_offs:
# move forward through attr to find start_offs
aw.k += 1
aw.off += run
continue
if end_offs <= aw.off+run:
o.append((at, end_offs-max(start_offs,aw.off)))
break
o.append((at, aw.off+run-max(start_offs, aw.off)))
aw.k += 1
aw.off += run
return o
for line_layout in ls:
# trim the line to fit within maxcol
line_layout = trim_line( line_layout, text, 0, maxcol )
line = []
linea = []
linec = []
def attrrange( start_offs, end_offs, destw ):
"""
Add attributes based on attributes between
start_offs and end_offs.
"""
if start_offs == end_offs:
[(at,run)] = arange(start_offs,end_offs)
rle_append_modify( linea, ( at, destw ))
return
if destw == end_offs-start_offs:
for at, run in arange(start_offs,end_offs):
rle_append_modify( linea, ( at, run ))
return
# encoded version has different width
o = start_offs
for at, run in arange(start_offs, end_offs):
if o+run == end_offs:
rle_append_modify( linea, ( at, destw ))
return
tseg = text[o:o+run]
tseg, cs = apply_target_encoding( tseg )
segw = rle_len(cs)
rle_append_modify( linea, ( at, segw ))
o += run
destw -= segw
for seg in line_layout:
#if seg is None: assert 0, ls
s = LayoutSegment(seg)
if s.end:
tseg, cs = apply_target_encoding(
text[s.offs:s.end])
line.append(tseg)
attrrange(s.offs, s.end, rle_len(cs))
rle_join_modify( linec, cs )
elif s.text:
tseg, cs = apply_target_encoding( s.text )
line.append(tseg)
attrrange( s.offs, s.offs, len(tseg) )
rle_join_modify( linec, cs )
elif s.offs:
if s.sc:
line.append(bytes().rjust(s.sc))
attrrange( s.offs, s.offs, s.sc )
else:
line.append(bytes().rjust(s.sc))
linea.append((None, s.sc))
linec.append((None, s.sc))
t.append(bytes().join(line))
a.append(linea)
c.append(linec)
#.........这里部分代码省略.........
开发者ID:adiabuk,项目名称:arch-tf701t,代码行数:101,代码来源:canvas.py
示例8: rle_len
rle_len(attr))
if render_line_nr:
text = self.line_nr + text
text = crnt+bp+text
attr = [("source", 1), ("bp_star", 1)] + attr
# clipping ------------------------------------------------------------
if len(text) > maxcol:
text = text[:maxcol]
attr = rle_subseg(attr, 0, maxcol)
# shipout -------------------------------------------------------------
from urwid.util import apply_target_encoding
txt, cs = apply_target_encoding(text)
return urwid.TextCanvas([txt], [attr], [cs], maxcol=maxcol)
def keypress(self, size, key):
return key
def format_source(debugger_ui, lines, breakpoints):
lineno_format = "%%%dd "%(len(str(len(lines))))
try:
import pygments
except ImportError:
开发者ID:cfarrow,项目名称:pudb,代码行数:31,代码来源:source_view.py
示例9: render
def render(self, size, focus=False):
from pudb.debugger import CONFIG
render_line_nr = CONFIG["line_numbers"]
maxcol = size[0]
hscroll = self.dbg_ui.source_hscroll_start
# attrs is a list of words like 'focused' and 'breakpoint'
attrs = []
if self.is_current:
crnt = ">"
attrs.append("current")
else:
crnt = " "
if self.has_breakpoint:
bp = "*"
attrs.append("breakpoint")
else:
bp = " "
if focus:
attrs.append("focused")
elif self.highlight:
if not self.has_breakpoint:
attrs.append("highlighted")
text = self.text
if not attrs and self.attr is not None:
attr = self.attr + [("source", None)]
else:
attr = [(" ".join(attrs+["source"]), None)]
from urwid.util import apply_target_encoding, trim_text_attr_cs
# build line prefix ---------------------------------------------------
line_prefix = ""
line_prefix_attr = []
if render_line_nr and self.line_nr:
line_prefix_attr = [("line number", len(self.line_nr))]
line_prefix = self.line_nr
line_prefix = crnt+bp+line_prefix
line_prefix_attr = [("source", 1), ("breakpoint marker", 1)] \
+ line_prefix_attr
# assume rendered width is same as len
line_prefix_len = len(line_prefix)
encoded_line_prefix, line_prefix_cs = apply_target_encoding(line_prefix)
assert len(encoded_line_prefix) == len(line_prefix)
# otherwise we'd have to adjust line_prefix_attr... :/
# shipout, encoding ---------------------------------------------------
cs = []
encoded_text_segs = []
encoded_attr = []
i = 0
for seg_attr, seg_len in attr:
if seg_len is None:
# means: gobble up remainder of text and rest of line
# and fill with attribute
rowlen = hscroll+maxcol
remaining_text = text[i:]
encoded_seg_text, seg_cs = apply_target_encoding(
remaining_text + rowlen*" ")
encoded_attr.append((seg_attr, len(remaining_text)+rowlen))
else:
unencoded_seg_text = text[i:i+seg_len]
encoded_seg_text, seg_cs = apply_target_encoding(unencoded_seg_text)
adjustment = len(encoded_seg_text) - len(unencoded_seg_text)
encoded_attr.append((seg_attr, seg_len + adjustment))
i += seg_len
encoded_text_segs.append(encoded_seg_text)
cs.extend(seg_cs)
encoded_text = b"".join(encoded_text_segs)
encoded_text, encoded_attr, cs = trim_text_attr_cs(
encoded_text, encoded_attr, cs,
hscroll, hscroll+maxcol-line_prefix_len)
encoded_text = encoded_line_prefix + encoded_text
encoded_attr = line_prefix_attr + encoded_attr
cs = line_prefix_cs + cs
return urwid.TextCanvas([encoded_text], [encoded_attr], [cs], maxcol=maxcol)
开发者ID:lechat,项目名称:pudb,代码行数:95,代码来源:source_view.py
注:本文中的urwid.util.apply_target_encoding函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论