The widgetList module

Contains the WidgetList and ScrollableList classes which provide the ability to create a list of widgets, and contain that list within a QScrollArea.

The StyleSheet class

Inheritance diagram of pyamp.ui.qt.widgetList.StyleSheet

class pyamp.ui.qt.widgetList.StyleSheet(widget=None, **kwargs)

The StyleSheet class provides a wrapper for PyQt4.QtGui.QWidget style sheet strings. StyleSheets can be easily created an exported into a string that is properly formatted for setting the style sheet of a PyQt4.QtGui.QWidget.

Example:

from PyQt4.QtGui import QApplication, QWidget
from pyamp.ui.qt import StyleSheet

# Create the widget, and set its name
app = QApplication([])
widget = QWidget()
widget.setObjectName("ObjectName")

# Create a simple style sheet
style = StyleSheet(border="2px solid black")
normal = "border: 2px solid black"

# These calls are identical
widget.setStyleSheet(str(style))
widget.setStyleSheet(normal)

# Create another style sheet, notice that underscores in the
# StylSheet parameter names are converted to dashes in the
# style sheet string
style = StyleSheet(background_color="red", color="blue",
                   font_weight="bold")
normal = "background-color: red; color: blue; font-weight: bold"

# These calls are identical
widget.setStyleSheet(str(style))
widget.setStyleSheet(normal)

# You can also specify a specific CSS selector string, which can be
# either a specific string, or a widget. If given a widget, the
# selector will be created using the object's class name (e.g.,
# QWidget) and will append an ID selector with the object's name (if
# and only if the widget is named).
style1 = StyleSheet(widget="QWidget#ObjectName",
                    border="1px solid red", margin_top="10")
style2 = StyleSheet(widget, border="1px solid red", margin_top="10")
normal = "QWidget#ObjectName { border: 1px solid red; margin-top: 10;"

# These calls are identical
widget.setStyleSheet(str(style1))
widget.setStyleSheet(str(style2))
widget.setStyleSheet(normal)
  • widget – The widget selector for this style sheet. Can be either a

    string, or an actual widget object

  • kwargs – The keyword arguments

The ResizePolicy class

Inheritance diagram of pyamp.ui.qt.widgetList.ResizePolicy

class pyamp.ui.qt.widgetList.ResizePolicy

The ResizePolicy encapsulates a specific policy for resizing widgets.

The possible resize policies are:

  • Fixed – The size never changes
  • Expanding – The size expands

For a specific policy, the ResizePolicy class can return the correct size for a widget, given the widget’s current size as well as the size of all of the widget’s child widgets.

For the Fixed resize policy: the size will always remain the same.

For the Expanding resize policy: the size will always expand to fit all of the widget’s children.

Example:

from PyQt4 import QtCore
from pyamp.ui.qt import ResizePolicy

# Create the size of the widget, and the list of sizes for all of
# the widget's children
size = QtCore.QSize(100, 200)
childSizes = [QtCore.QSize(200, 500), QtCore.QSize(300, 400)]

# Get the list of widths and heights for the child widgets
childWidths = map(QtCore.QSize.width, childSizes)
childHeights = map(QtCore.QSize.width, childSizes)

# Both of these return: 100
# Which is the given value of width
ResizePolicy.getSize(ResizePolicy.Fixed, size.width(), childWidths)
ResizePolicy.getWidth(ResizePolicy.Fixed, size, childSizes)

# Both of these return: 900
# Which is the sum of the childHeights list
ResizePolicy.getSize(ResizePolicy.Expanding, size.height(),
                     childHeights)
ResizePolicy.getHeight(ResizePolicy.Fixed, size, childSizes)
classmethod getHeight(policy, size, sizeList)

For the given resize policy, get the correct height for the size of the widget as well as the size of all of the widget’s children.

  • resizePolicy – The resize policy
  • size – The main PyQt4.QtCore.QSize of the widget
  • sizeList – The list of PyQt4.QtCore.QSize for sub widgets
classmethod getSize(policy, size, sizeList)

Get the correct size based on the given resize policy.

  • resizePolicy – The resize policy

  • size – The main single size (width or height) of the widget

  • sizeList – The list of the single dimension size (widths or heights)

    of widgets’s children

classmethod getWidth(policy, size, sizeList)

For the given resize policy, get the correct width for the size of the widget as well as the size of all of the widget’s children.

  • resizePolicy – The resize policy
  • size – The main PyQt4.QtCore.QSize of the widget
  • sizeList – The list of PyQt4.QtCore.QSize for sub widgets

The BaseWidget class

Inheritance diagram of pyamp.ui.qt.widgetList.BaseWidget

class pyamp.ui.qt.widgetList.BaseWidget(name=None, controller=None, mainWindow=None, logData=None, logColor=0)

The BaseWidget class provides an implementation of the amp.ui.qt.BaseView class designed to set up and create a PyQt4.QtGui.QWidget object.

This class provides serveral functions which can be overridden by subclasses to easily add features to the BaseWidget. These functions are called in the following order during the set up process:

  1. configure()
  2. configureLayout()
  3. createElements()
  4. setupConnections()
  • name – The name of the BaseWidget
  • controller – The controller for the BaseWidget
  • mainWindow – The main window
  • logData – The pyamp.logging.LogData object
  • logColor – The color to use for logging
addElement(element)

Add an element to the main layout.

  • element – The element to add
addElements(elements)

Add a list of elements to the main layout.

  • elements – The list of elements
addItem(item)

Add an item to the main layout.

  • item – The item to add
addWidget(widget)

Add a widget to the main layout.

  • widget – The widget to add
clear()

Remove all of the child widgets and items currently for this BaseWidget.

clearItems()

Clear all the items from this BaseWidget.

clearWidgets()

Clear all the widgets from this BaseWidget.

configure()

Configure the view.

configureLayout()

Configure the layout for this view.

createElements()

Create the elements for this view. Return the list of widgets, or items in the order that they should be added to the layout.

createLayout()

Create the main layout.

getItems()

Return the list of child items for this BaseWidget.

getWidgets()

Return the list of child widgets for this BaseWidget.

layoutType

The layoutType property contains the type of layout to use for this Widget. It should be a value from the LayoutType class.

paintEvent(_event)

Override the paintEvent function to allow StylSheets to work for this QWidget.

Note this function was taken from the documentation of style sheets
for custom QWidget classes.
  • _event – The QPaintEvent
setMargins(left=None, top=None, right=None, bottom=None)

Set the content margins for this widget’s layout.

  • left – The left margin
  • top – The top margin
  • right – The right margin
  • bottom – The bottom margin
setSpacing(spacing)

Set the spacing between components in the layout.

  • spacing – The spacing
setStyleSheet(styleSheet)

Set the style sheet for this widget.

  • styleSheet – The StyleSheet
setupConnections()

Set up any connections this view requires.

setupView()

Create and set up this view.

tabOrder

The tabOrder property allows concrete widgets to set their tab order. Each element in the list will be tab connected to the next element in the list. The list will cycle around to the front so the final element is tab connected to the first element.

The WidgetList class

Inheritance diagram of pyamp.ui.qt.widgetList.WidgetList

class pyamp.ui.qt.widgetList.WidgetList(name=None, controller=None, mainWindow=None, logData=None, logColor=0)[source]

The WidgetList class defines a BaseWidget object that has the ability to display a list of widgets vertically one after the other. This class handles resizing the widget appropriately based on the widgets that are in the list.

  • name – The name of the BaseWidget
  • controller – The controller for the BaseWidget
  • mainWindow – The main window
  • logData – The pyamp.logging.LogData object
  • logColor – The color to use for logging
addItem(item)[source]

Add an item to the widget list.

  • item – The item to add
addWidget(widget)[source]

Add a widget to this widget list.

  • widget – The widget to add
clear()[source]

Clear all the widgets from the list.

setHorizontalRezizePolicy(policy)[source]

Set the horizontal resize policy.

  • policy – The new resize policy
setMargin(margin)[source]

Set the margin for this widget list.

  • margin – The margin to use
setVerticalResizePolicy(policy)[source]

Set the vertical resize policy.

  • policy – The new resize policy

Table Of Contents

Previous topic

The qt module

Next topic

The baseWidget module

This Page