Skip to content

Instantly share code, notes, and snippets.

@SavinaRoja
Last active August 29, 2015 14:07
Show Gist options
  • Save SavinaRoja/5e79b96050502594415f to your computer and use it in GitHub Desktop.
Save SavinaRoja/5e79b96050502594415f to your computer and use it in GitHub Desktop.
Design Document - Container System for npyscreen

Purpose

This document exists to help formalize design concepts for the building of a Container System for npyscreen. This should clarify the building of the basic structure, as well as compliance with expected behaviors for the creation of objects deriving from this system. This document may use the terms Container and Layout Manager interchangeably; it may help the reader to know that the term Layout Manager is the more common general term in GUI design.

Authors

The following persons have contributed to this document:

  • Paul Barton (SavinaRoja)

Widget vs. Container: Distinguishing Concepts

From a certain perspective, the lines between a Widget and a Container are intentionally blurry. In fact, though npyscreen has not formally possessed a layout management tool, many of the common widgets are in fact Containers in concept. Hopefully this section will help clarify the handful of meaning distinctions, as well as the meaningful indistinctions. Let's look at one traditional npyscreen widget, TitleText, and discuss how it might be viewed as a Container.

On the surface, the TitleText Widget allows one to put an editable text field onto the screen, along with a static text field as a label or title. During instantiation one has the option of setting two values of the widget: name which determines the text of the label, and value which determines the value (initially at least) of the editable text field. Internally however, the name attribute is actually used as the value for the instantiation of a new Textfield widget to serve as the label, and the value attribute is used for the creation of a textfield Widget. If one looks closely it is seen that whenever TitleText's edit method is called, it essentially passes on the call to the text field widget, and returns once that is done.

At this point I hope it's clear that, as a "hybrid widget", TitleText presents an interface of being a normal widget just like those it contains, while internally being a bit more complex. I will present the concept of the Container as an extension of Widgets; Containers are Widgets and a little bit more.

Containers are special widgets meant to contain other widgets and manage them to varying degrees. Containers should be prepared to contain, and be contained by, other Containers; for almost all intents and purposes a Container should not make a distinction between contained widgets or containers. Containers will present the standard Widget interface, yet represent a recursion layer to propagate the interface calls to their contained items.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment