|
PwytterThemeDocumentation
Pwytter theme documentation
Phase-Implementation This document outlines how themes for Pwytter should be written and packaged. This document is still a draft and shall be subject to change. This document is only relevant to the backend-split branch in SVN, once this branch is released this document should become stable. Note that this document serves as documentation and is not a tutorial for writing Pwytter themes. IntroductionPwytter can be customized using Qt stylesheets and the TweetView can be customized using HTML, CSS, etc. Each theme resides in it's own directory, this is called the theme directory. Any sub-directory in the "theme" of the pwytter is a theme directory. The name of the theme directory is the name of the theme, this name may only consist of alphanumeric characters. Note that the name of the theme must be unique, and will not be presented to the user for other purposes that error messages. Meta informationIn each theme directory there must be a file called info.yaml and preview.png. The preview.png is a preview of the theme in PNG format, this image will be presented when the user selects a theme. The file info.yaml contains meta-data about the theme in YAML 1.1 format, please refer to yaml.org for a specification of this format. The file contains following keys:
Note: info.yaml must be UTF-8 encoded. VersioningThe meta information contains two different version numbers, the theme version (Version) and the API version (Requires). These version numbers must consist of three numbers: major.minor.maintenance. The theme version is currently not used for anything, and mainly mean to assist users. The API version denotes the version of this documentation that the theme is written for. This version number is currently 0.1.0. The major version is incremented whenever backwards compatibility is broken. The minor version is incremented when a new feature is exposed, which themes need to expose to the user. The maintenance version is incremented whenever a small insignificant feature is added, for instance a convenient variable, that exposes otherwise information which could be obtained otherwise using the old API. TemplatesThe widget in Pwytter is called TweetView, this is the widget that displays tweets and users. This widget is based on WebKit and it's content is generated using templates. A theme must contain such templates. These templates can be written using any technology that runs in WebKit such as HTML, CSS, Javascript, images, Javascript etc. These templates must always be UTF-8 encoded. Pwytter uses Tinpy, a minimalistic python template engine, to render the templates. Tinpy supports only a very limited set of features and complex expressions are not possible, should you require such then consider implementing them using Javascript. To insert a variable write [% var VARIABLE %] where VARIABLE is the variable you wish to insert, this can also be used to access dictionary variable such as [% var Message['Text'] %]. To start a loop over a list of variables write [% for Message in Message %] and end the loop using [% done %]. A template can also contain conditional statements if [%if Message['CanReply']%] and ended with [% endif %], not if statements can being contained within eachother, but they cannot be negated or combined to one expression. All http:// links will be opened in an external web browser, it is possible fetch resources, such as images, from the Internet in a template, however, such behavior is strongly discouraged.URIs that starts with pwytter:// can point to different views and resources in the theme directory, most important views shown below:
Where <account> is the string representation of an account, and <page> is page number starting from 0. Themes does not need to know about these, and shouldn't use them for anything, as they may change in the future. However, an interesting view that themes might want to link to in some cases is the detailed user view:
This view displays the detailed user template with the user specified by <service> string and <username> on the given service. When displaying a list of users or a list messages themes may prefer not to display all details of a user and instead choose to link to this detailed view. A URI for the image of user can be seen below, where <image-id> is unique image identifer, you need not know about this URI as a variable contains the entire URI and not just the image identifier. Nevertheless, the URI is documented here for completeness, but themes should not rely on this URI.
If a theme wish to use external stylesheets or images these can, as previously mentioned, be loaded from the Internet, nevertheless, such behavior is strong discouraged as it breaks the theme when working offline. To solve this issue resources can also be loaded from inside the theme directory, using the following URI:
Where <path-relative-theme-dir> is a path relative to the theme directory. Include an image called pic.png from the /images/ sub-directory of the theme directory use pwytter://theme/images/pic.png. There are currently no restrictions on how resources can be stored in the theme directory, however, it is strongly recommended that images are stored in an /images/ sub-directory. It is also recommended that Javascript, CSS and other resources are stored in a /resources/ sub-directory of the theme directory. Messages templateWhen TweetView needs to display a list of messages the template in Message.tpl is used, this template must be present in the theme directory of a theme. The following variables are available to this template.
The template can use the following Javascript functions to make Pwytter perform an action:
Where <Id> is a message identifier, these identifiers are only assigned to message dictionaries in the Messages variable, and not to user dictionaries or message dictionaries on message dictionaries contained in the Message variable. Message dictionaryA message dictionary Message has the following fields:
User dictionaryA user dictionary User has the following fields:
Translated text dictionaryA dictionary with text string that are translated to the users language is also available to template write. This dictionary always has the identifier Text and it have the following fields:
Users templateWhen TweetView needs to display a list of users the template in Users.tpl is used, this template must be present in the theme directory of a theme. The following variables are available to this template.
The template can use the following Javascript functions to make Pwytter perform an action:
Where <Id> is a user identifier, these identifiers are only assigned to user dictionaries in the Users variable. Detailed user templateWhen TweetView needs to display detailed information on one user the template in "Users.tpl" is used, this template must be present in the theme directory of a theme. The following variables are available to this template.
The template can use the following Javascript functions to make Pwytter perform an action:
Where <Id> is a user identifier, this identifier is only assigned to user dictionary in the User variable. Qt stylesheetsPwytter can also be customized using Qt stylesheets, please note that this might break some native style engines such as GtkStyle for Qt. Note that these stylesheets should not rely on the object names of the Qt widgets. The Qt style is application wide and store in application.qss in the theme directory, this file is optional. Read more about Qt stylesheets in the Qt documentation. Theme packagingNo packaging scheme or distribution channel implemented yet. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||