提供一个模块化接口来设计trac
TracThemeEngine的Python项目详细描述
注释
添加用于打包和配置trac主题的简单api和gui。
配置
trac.ini
所有配置选项都位于[theme]部分。
- theme:可选,默认值:“default”
- 要使用的主题名称。名称不区分大小写。
- enable_css:可选,默认值:false
- 启用或禁用CSS自定义设置。
- color.*:可选
- 用于简单CSS覆盖的存储值请注意,更改此选项将 在您将它们保存到“管理”面板中之前不会生效。
网络接口
主题
使用箭头从已安装的选项中选择主题,然后单击 激活它的按钮。
自定义
在这里你可以通过改变颜色来进一步定制你的主题 用户界面的片段“方案”下拉列表允许您加载预先配置的 配色方案。请注意,并非所有主题都支持这一点,或者支持 同样的选择。
自定义:高级
在这里您可以进一步定制css。如文件所述,如果你 手动编辑此文件,不应使用简单的自定义程序系统或 您将丢失更改。
示例
要启用pydotorg主题:
[theme] theme = pydotorg [components] themeengine.* = enabled pydotorgtheme.* = enabled
创建主题
简单方式
创建新主题的最简单方法是从ThemeBase继承一个 基本示例主题如下:
from trac.core import * from themeengine.api import ThemeBase class ExampleTheme(ThemeBase): """A example theme.""" template = htdocs = css = screenshot = True
将从类名(在本例中为“example”)和 docstring将用作描述。有几个类变量 可以设置为配置主题。默认情况下,所有这些都设置为 False和so被禁用。如果设置为True,则每个选项将使用 通常是理智的违约如果设置为除这些值以外的任何值,则该值将 直接使用
可用选项如下(所有选项都是可选的):
- template:默认值:$name_theme.html
- 替换模板的文件名。
- css:默认值:$name.css
- 要包含的样式表的文件名。
- htdocs:默认值:htdocs
- 包含静态内容的子文件夹。
- screenshot:默认值:htdocs/screenshot.png
- 包到屏幕截图文件的相对路径。文件应为640x400或 使用相同的纵横比。
- colors:
- 简单颜色自定义系统的说明符。这应该是一个 形式为(name, property, selector)的元组的iterablename 将显示在该项的自定义用户界面中。property将 一般是color或background-color。selector应该是 要应用颜色规则的CSS选择器字符串。
- schemes:
- 预先构建的颜色方案这应该是形式的元组的iterable (name, color_dict)。color_dict应该是字典映射 颜色名称到十六进制颜色字符串(格式为#00AAFF)。
高级API
对于更高级的控件,可以从 themeengine.api。接口定义为:
class IThemeProvider(Interface): """An interface to provide style information.""" def get_theme_names(): """Return an iterable of names.""" def get_template_overrides(name): """(Optional) local changes to specific templates Return a sequence of tuples (old_html, new_html, function) where old_html:: The name of the template overriden by this theme. new_html:: The name of the template file replacing the former. function:: Optional callback (or None) to add further data . Signature: req:: Request object template:: The value of `old_html` above data:: Template data, may be modified content_type:: Reported MIME type since 2.2.0 """ def get_theme_info(name): """Return a dict containing 0 or more of the following pairs: description:: A brief description of the theme. template:: The name of the theme template file. css:: The filename of the CSS file. htdocs:: The folder containing the static content. screenshot:: The name of the screenshot file. colors:: A list of (name, css-property, selector) tuples. schemes:: A list of (name, {color-name: value, ...}) tuples. scripts:: A list of (filename, mimetype, charset, ie_if) respectively for script (relative | absolute) URI (mandatory), script MIME type (optional , defaults to 'text/javascript'), script charset encoding (optional, defaults to 'utf-8'), and a bool flag for MSIE-only shims (optional, defaults to False) @since 2.2.2 """
除了^{tt25}之外,大多数都与上面的简单api相同$ 是明确的。
自定义特定视图
由于版本2.2.0,可以通过实现 (可选)get_template_overrides方法例如 下面的示例代码将使用 自定义Genshi模板:
class CustomTheme(...): #------8<------ Code omitted ------8<------ def get_template_overrides(self, name): """Override ticket and wiki templates using custom templates """ yield ('ticket.html', 'custom_ticket.html', None) yield ('wiki.html', 'custom_wiki.html', self._modify_wiki) def _modify_wiki(self, req, template, data, content_type): data['var'] = 'value'
注意,在样本公司de,将添加新数据以呈现wiki页面。