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 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)
string, or an actual widget object
kwargs – The keyword arguments
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)
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.
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
of widgets’s children
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.
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:
- configure()
- configureLayout()
- createElements()
- setupConnections()
Add an element to the main layout.
Add a list of elements to the main layout.
Add an item to the main layout.
Add a widget to the main layout.
Remove all of the child widgets and items currently for this BaseWidget.
Clear all the items from this BaseWidget.
Clear all the widgets from this BaseWidget.
Configure the view.
Configure the layout for this view.
Create the elements for this view. Return the list of widgets, or items in the order that they should be added to the layout.
Create the main layout.
Return the list of child items for this BaseWidget.
Return the list of child widgets for this BaseWidget.
The layoutType property contains the type of layout to use for this Widget. It should be a value from the LayoutType class.
Override the paintEvent function to allow StylSheets to work for this QWidget.
Set the content margins for this widget’s layout.
Set the spacing between components in the layout.
Set the style sheet for this widget.
Set up any connections this view requires.
Create and set up this view.
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 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.