⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graphics.py

📁 Urwid is a Python library for making text console applications. It has many features including fluid
💻 PY
字号:
#!/usr/bin/python# -*- coding: utf-8 -*-## Urwid graphics widgets#    Copyright (C) 2004-2007  Ian Ward##    This library is free software; you can redistribute it and/or#    modify it under the terms of the GNU Lesser General Public#    License as published by the Free Software Foundation; either#    version 2.1 of the License, or (at your option) any later version.##    This library is distributed in the hope that it will be useful,#    but WITHOUT ANY WARRANTY; without even the implied warranty of#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU#    Lesser General Public License for more details.##    You should have received a copy of the GNU Lesser General Public#    License along with this library; if not, write to the Free Software#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA## Urwid web site: http://excess.org/urwid/from __future__ import nested_scopesfrom util import *from canvas import *from widget import *from escape import utf8decodeclass BigText(FixedWidget):	def __init__(self, markup, font):		"""		markup -- same as Text widget markup		font -- instance of a Font class		"""		self.set_font(font)		self.set_text(markup)		def set_text(self, markup):		self.text, self.attrib = decompose_tagmarkup(markup)		self._invalidate()		def get_text(self):		"""		Returns (text, attributes).		"""		return self.text, self.attrib		def set_font(self, font):		self.font = font		self._invalidate()		def pack(self, size=None, focus=False):		rows = self.font.height		cols = 0		for c in self.text:			cols += self.font.char_width(c)		return cols, rows		def render(self, size, focus=False):		fixed_size(size) # complain if parameter is wrong		a = None		ai = ak = 0		o = []		rows = self.font.height		attrib = self.attrib+[(None,len(self.text))]		for ch in self.text:			if not ak:				a, ak = attrib[ai]				ai += 1			ak -= 1			width = self.font.char_width(ch)			if not width: 				# ignore invalid characters				continue			c = self.font.render(ch)			if a is not None:				c = CompositeCanvas(c)				c.fill_attr(a)			o.append((c, None, False, width))		if o:			canv = CanvasJoin(o)		else:			canv = TextCanvas([""]*rows, maxcol=0, 				check_width=False)			canv = CompositeCanvas(canv)		canv.set_depends([])		return canv		class LineBox(WidgetWrap):	def __init__(self, w):		"""Draw a line around w."""				tlcorner=None; tline=None; lline=None		trcorner=None; blcorner=None; rline=None		bline=None; brcorner=None				def use_attr( a, t ):			if a is not None:				t = urwid.AttrWrap(t, a)			return t					tline = use_attr( tline, Divider(utf8decode("鈹

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -