The ui module contains modules pertaining to creating and manipulating user interfaces. This includes tasks such as: getting input from the user, and displaying a graphical user interface to the user.
The input module contains modules pertaining to retrieving input from the user using various methods.
evdev.py
This is a Python interface to the Linux input system’s event device. Events can be read from an open event file and decoded into spiffy python objects. The Event objects can optionally be fed into a Device object that represents the complete state of the device being monitored.
Copyright (C) 2003-2004 Micah Dowty <micah@navi.cx>
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Represents one linux input system event. It can be encoded and decoded in the ‘struct input_event’ format used by the kernel. Types and codes are automatically encoded and decoded with the #define names used in input.h
Bases: pyamp.processes.threading.thread.Thread
The ConsoleInput class provides the ability to receive input from a user through the console. This class runs as a separate thread which monitors the console for input and notifies a callback method in the event that keyboard input is received.
The callback method must take one argument which is the character that was read as input. This class also provides the ability to register a callback function to be called in the event that an exception occurs during the processing of the thread.
This class implements the pyamp.processes.Thread, and the amp.logging.Loggable interfaces.
callback – The function called when input is received
continue waiting for input
exceptionFn – The functionc called when an exception is encountered
logger – The logger object
Clear the console screen.
Get the number of columns for this console screen.
Get the number of rows for this console screen.
Get the size of the current console screen.
Called during each cycle of the Thread.
This function is called in the event that an exception occurs during the processing of the thread.
Called when the ConsoleInput Thread is shutdown.
Called when the ConsoleInput thread is started.
The UserInput class uses the amp.ui.input.evdev module to receive the user’s keyboard presses given the specific Linux keyboard device.
This class provides to ability to add a series of callbacks for specific keyboard presses. These functions will be called in the event that the key presses occur.
Add codes for given key press events. The key can be a tuple where the first index is a list of keys and the second index is a list of modifiers. Or it can be simply a list of keys, or it can be a single key.
Add codes for given key press events. Each key in the keys dictionary can be a tuple where the first index is a list of keys and the second index is a list of modifiers. Or it can be simply a list of keys, or it can be a single key.
Add a single key to the key press cases. The key can be a tuple where the first argument is the list of keys, or a single key, and the second argument is a list of modifiers. Optionally, is can just be a list of keys, or it can be a single key.
Add a list of keys mapped to a single function. Keys can be a tuple where the first index the a list of keys, or a single key, and the second index is the list of modifiers. Or it can be a list of keys, and finally it can be just a single key.
Add a key to the key press cases. The keys is a dictionary of keys. Each key in the dictionary is a normal tuple form of a key, and the value of the dictionary key is the callback method.
Handle keys that are pressed.
The qt module contains classes pertaining to creating graphical user interfaces using PyQt.
Bases: pyamp.logging.loggable.Loggable, pyamp.patterns.interfaces.requiredProperties.RequiredProperties
The BaseView class provides a base framework for creating Qt objects.
It provides several functions that are called in a specific order, and are to be overridden by subclasses in order to provide a specific implementation for the BaseView. These functions pertain to certain aspects of setting up a view and are called in the following order:
This class implements the pyamp.logging.Loggable interface and provides the ability to specify the logData object as well as the color to use for logging (the default color is to use a white foreground color).
Finish setting up the view.
Note
This function should be overridden by subclasses.
Configure the view.
Note
This function should be overridden by subclasses.
Configure the layout for this view.
Note
This function should be overridden by subclasses.
Create the main layout.
Note
This function should be overridden by subclasses.
Set the controller object for this view.
Set up any connections this view requires.
Note
This function should be overridden by subclasses.
Create and set up this view.
Note
This function should be overridden by subclasses.
Bases: PyQt4.QtGui.QWidget, pyamp.ui.qt.baseView.BaseView
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.
This class provided functions for dealing with PyQt4.QtGui.QKeyEvent objects.
The main function of this class is to provide a method to convert a PyQt4.QtGui.QKeyEvent object into a string representation of the keys that were pressed in the given event.
Parse the given QKeyEvent into the string representation of the keys pressed.
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.
Bases: pyamp.ui.qt.baseWidget.BaseWidget
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.
Add an item to the widget list.
Add a widget to this widget list.
Clear all the widgets from the list.
Set the horizontal resize policy.
Set the margin for this widget list.
Set the vertical resize policy.
Bases: pyamp.ui.qt.baseWidget.BaseWidget
The ScrollableList class creates a BaseWidget that contains a QScrollArea which displays a WidgetList inside of the scroll area. This allows a the user to scroll through the WidgetList to see previously added widgets.
In order to fix the size of the scroll area, subclasses of ScrollableList should set the size class property which is a QSize object.
Add an item to the ScrollabelList widget.
Add a widget to the ScrollableList widget.
Clear all of the widgets from the ScrollableList.
Override the BaseWidget createElements class.
Get the QScrollArea for this widget.
Get the WidgetList for this ScrollabeList.
The horizontalPolicy property contains the ScrollBarPolicy for the horizontal scrollbar.
The margin property contains the margin between all items in the list.
Scroll the vertical scrollbar by the given amount.
is positive scrolling down)
Scroll to the given position.
Scroll to the bottom of the list.
Scroll to the top of the list.
The size property contains the size of the scrollable list.
Override the QWidget sizeHint function to return the size of this ScrollableList.
The verticalPolicy property contains the ScrollBarPolicy for the vertical scrollbar.