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


Python Line.width方法代码示例

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


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

示例1: __init__

# 需要导入模块: from line import Line [as 别名]
# 或者: from line.Line import width [as 别名]
class UI:
  def __init__(self, irc, server, room, screen, theme):
    self.theme = theme
    self.screen = screen
    self.irc = irc
    self.server = server
    self.room = room
    self.height, self.width = self._limits();
    self.topic = Line('topic', '', False)
    self.status = Line('status', '', False)
    self.input_line = Line('input', '', False)

    self.lines = []

    curses.echo()
    curses.start_color()
    self.screen.clear()
    self.screen.timeout(0)
    self.screen.scrollok(True)
    self.screen.setscrreg(1, self.height-3)

    self._draw_chat()

    self.irc.add_global_handler("welcome", self.on_connect)
    self.irc.add_global_handler("motd", self.on_motd)
    self.irc.add_global_handler("pubmsg", self.on_pubmsg)
    self.irc.add_global_handler("currenttopic", self.on_currenttopic)

  def _limits(self):
    return self.screen.getmaxyx()

  def _draw_line(self, linenum, line):
    self.screen.move(linenum,0)
    offset = 0
    if line.timestamp:
      self.screen.attrset(self.theme.color_pair('time'))
      self.screen.addnstr(line.timestamp, self.width)
      offset += len(line.timestamp)

    self.screen.attrset(self.theme.color_pair(line.attr))
    if line.data:
      self.screen.addnstr(line.data, self.width)
      offset += len(line.data)

    pad_count = self.width - offset - 1
    while pad_count > 0:
      self.screen.addch(' ')
      pad_count -= 1

  def _draw_chat(self):
    pair = self.theme.color_pair('chat')
    self.screen.bkgdset(' ', pair)

  def _goto_input(self):
    self.screen.move(self.height-1, self.input_line.width())

  def _draw_topic(self):
    self._draw_line(0, self.topic)

  def _draw_status(self):
    self._draw_line(self.height-2, self.status)

  def _draw_lines(self):
    i = 1
    for line in self.lines[-self.height:]:
      self._draw_line(i, line)
      i = i+1

  def _draw_input(self):
    self._draw_line(self.height-1, self.input_line)

  def draw(self):
    self._draw_topic()
    self._draw_status()
    self._draw_lines()
    self._draw_input()
    self._goto_input()
    self.screen.refresh()

  def add_line(self, line):
    self.lines.append(line)
    self.screen.scroll()
    self._draw_line(self.height-3, line)
    self._draw_input()
    self.screen.refresh()

  def on_currenttopic(self, connection, event):
    topic = event.arguments()[1]
    self.topic = Line('topic', topic.strip(), False)
    self._draw_topic()
    self._goto_input()

  def on_connect(self, connection, event):
    if irclib.is_channel(self.room):
      connection.join(self.room)
      who = event.source()[0:event.source().find("!")]
      self.status = Line('status', "[%s] [%s]" % (who, self.room))
      self._draw_status()
      self._goto_input()

#.........这里部分代码省略.........
开发者ID:hunner,项目名称:irc-256,代码行数:103,代码来源:ui.py


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