Widgets#
CheckBox Class#
- class CheckBox(*args: Any, **kwargs: Any)#
A CheckBox is a bool control with a text label.
from hwx import gui def onClick(event): output.text = event.value button = gui.CheckBox('True or False', command=onClick) output = gui.Label(button.value) frame = gui.HFrame(button, 10, output) show(frame)
- property checked#
Returns and sets if checkbox is checked ot not.
- property text#
Returns and sets the text of the check box.
ComboBox Class#
- class ComboBox(*args: Any, **kwargs: Any)#
A ComboBox is used for displaying various options. Only one option can be selected.
from hwx import gui def onSelected(event): output.text = event.value # ComboBox values are a list of tuples. Each entry is a (value, text). # The value is what is used by the value property. # The text is what is displayed. colors = (("red", "Red"), ("green", "Green"), ("blue", "Blue"),) combobox = gui.ComboBox(colors, command=onSelected) output = gui.Label(combobox.value) frame = gui.HFrame(combobox, 10, output) show(frame)
- setValues(values, value=None)#
Update options user can select.
- Parameters:
values (list[list[value, label]]) – List of (value, label) pairs.
- property command#
The method called when the value changes.
Cursor Class#
DoubleEdit Class#
- class DoubleEdit(*args: Any, **kwargs: Any)#
A widget that can display/edit a double.
- get()#
Gets the value converted to base units.
- set(value)#
Sets the value converted to user units with the units label.
- Parameters:
value (str, float) – A float value or a string with the units.
- validate(widget)#
Validates whether the value entered is a double and convert to base units.
- Parameters:
widget (Widget) – Widget where the value is entered.
- Returns:
True if the widget value entered is an int, otherwise False.
- Return type:
bool
IconLabel Class#
IntEdit Class#
- class IntEdit(*args: Any, **kwargs: Any)#
A widget that can display/edit an integer.
- get()#
Overloaded method that returns the value as in integer.
- validate(widget)#
Validates whether the value entered is an integer and in [minValue, maxValue] range.
- Parameters:
widget (Widget) – The widget where the value is entered.
- Returns:
True if the widget value entered is an int, otherwise False.
- Return type:
bool
- property maxValue#
The upper bound of the IntEdit
- property minValue#
The lower bound of the IntEdit
Label Class#
- class Label(*args: Any, **kwargs: Any)#
from hwx import gui text = gui.Label("Display text", font=dict(size=14, bold=True, italic=True)) icon = gui.Label(icon="msobjbrowser.png") label = gui.Label("Display World", icon="msobjbrowser.png", font=dict(size=14, bold=True, italic=True)) frame = gui.GridFrame( children=( ("Text label -> ", text), ("Icon label -> ", icon), ("Text and Icon label -> ", label) ) ) show(frame)
- property alignment#
The alignment of the label. Use the Enum values defined in the Label.Align class.
- class Align(*args: Any, **kwargs: Any)#
- property alignment#
The alignment of the Label, it can be
- property icon#
The name of icon file to display.
- property margin#
The text to display.
- property text#
The text to display.
Legend Class#
- class Legend(*args: Any, **kwargs: Any)#
A color coded legend.
A Legend widget contains color and labels. The items in the legend can be selected and an action performed. Legends are used to easily change between discrete values with associated colors.
For example, when defining the type of joint among three options (Active, Locked, Free).
from hwx import gui # A series of colors, values and labels displayed in the legend State = (("red", "value1", "Red"), ("green", "value2", "Green"), ("blue", "value3", "Blue"),) # This method is called when the a new item from the legend is selected. def onSelected(event): output.text = legend.value legend = gui.Legend(values=State, command=onSelected) output = gui.Label() frame = gui.VFrame(output, legend, height=100) show(frame)
- clear()#
Clears all the legends.
- get()#
Returns the legend value.
- setValues(values)#
List of legend properties to be set.
- Parameters:
values (list) – A list of properties.
- property activeValues#
List of values which are not deactivated (shown as transparent).
Pass True to activate or False to deactivate all.
- property values#
List of (color, value, label) tuples populating the legend.
LineEdit Class#
- class LineEdit(*args: Any, **kwargs: Any)#
A LineEdit Widget that can display/edit a string.
A line edit allows the user to enter and edit a single line of plain text with a useful collection of editing functions, including undo and redo, cut and paste, and drag and drop.
- validate(widget)#
Validates the value of the widget.
- property alignment#
Alignment of text (left, center or, right).
- property readonly#
Returns and sets whether text/value can be edited.
- property text#
Alias for value property.
ListBox Class#
- class ListBox(*args: Any, **kwargs: Any)#
A ListBox widget.
from hwx import gui values = ['Item-1', 'Item-2', 'Right click in the listbox to add/remove item'] #Context menu for Listbox def buildContextMenu(menu, index): if index is None: def addItem(): listBox.append("New-Item") listBox.setChecked(len(listBox.items)-1, False) menu.insertItem('Add', icon='glyphPlusStrip-16.png', command=addItem) else: def removeItem(): listBox.remove(index) menu.insertItem('Remove', icon='glyphDeleteStrip-16.png', command=removeItem) # Creating ListBox object with command, so that whenever user selects the # item in ListBox, it will be printed in output console. def onItemSelected(event): print('clicked text:', event.value) if event.widget.selectedIndex: print('selected index:', event.widget.selectedIndex) else: print('selected indexes:', event.widget.selectedIndexes) listBox = gui.ListBox(values, command=onItemSelected, onContextMenu=buildContextMenu) listBox.checked = True listBox.selectionMode = "MultiSelection" # Creating Dialog dialog = gui.Dialog(caption="ListBox", children=listBox, height=145, width=350) show(dialog)
- append(item)#
Appends an item to the end of the ListBox.
- Parameters:
item (str) – Text value to be inserted.
- clear()#
Removes all items of the List Box.
- get()#
Returns the text of curren row.
- insert(item, index=9999999)#
Inserts an item in the ListBox at position index.
By default it gets appended to the end.
- Parameters:
item (str) – Text value to be inserted.
index (int) – Index at which item is inserted.
- isChecked(index)#
Returns whether the item at the specified index is checked or not.
- Parameters:
index (int) –
- Returns:
bool
- remove(index)#
Remove item at index from List Box.
- Parameters:
index (int) – index of item to be removed.
- select(index)#
Select an index.
Same as setting the selectedIndex except the command callback gets called.
- set(text)#
Sets the text in current row.
- setChecked(index, value=True)#
Checks or unchecks the item at the specified index.
- Parameters:
index (int) –
value (bool) –
- sort(ascending=True)#
Sorts the items in the ListBox, based on their text.
- Parameters:
ascending (bool) – If set to True, sort the items in ascending order.
- property checked#
Determines whether items in the list box are checked or not.
By default, all are unchecked.
- Returns:
list[bool]
- property items#
Gets/Sets items of the ListBox
- property selectedIndex#
(int | None) The currently selected index.
- property selectedIndexes#
(list[int] | None) List of currently selected indexes.
- property selectionMode#
Determines the way the items can be selected.
- Parameters:
value (ListBox.selectionModeType) – The type of selection to allow.
- property viewMode#
Determines the way the items can be viewed.
- Parameters:
value (ListBox.viewMode) – The type of view to allow.
ProgressBar Class#
- class ProgressBar(*args: Any, **kwargs: Any)#
A Widget that shows the running status of a process.
from hwx import gui import time def onClick(): while p1.progress < 100: time.sleep(0.5) p1.progress += 20 p1 = gui.ProgressBar() b1 = gui.PushButton('Run',command=onClick) # Initial value p1.progress = 0 dialog = gui.Dialog(caption="ProgressBar", children=(p1,b1), height=145, width=200) show(dialog)
- reset()#
Reset the ProgressBar.
- property centerIndicator#
Center Indicator.
- property percentageVisible#
Show/Hide percentage progress
- property progress#
Current progress of progress bar.
- property totalSteps#
Total number of steps in progress bar.
Slider Class#
- class Slider(*args: Any, **kwargs: Any)#
A Slider Widget.
The Slider is the classic widget for controlling a bounded value.
A Slider Widget displays a range of values from which a user selects a single value between a minimum and a maximum value.
Slider widgets are usually created to control discrete integer values such as the number of coils of a coil spring .
from hwx import gui def onModified(): output.value = str(slider.value) slider = gui.Slider(maxvalue=200, tracking=False, value=10,command=onModified) output = gui.Label(slider.value) frame = gui.HFrame(output, 5, slider) show(frame)
- get()#
Returns the slider widget value.
- set(value, emit=True)#
“Sets the slider widget value. :param value: Value to set. :type value: int :param emit: If False, no signals emitted on value change otherwise emit
the value change signal.
- property maxvalue#
The maximum/right most value.
- property minvalue#
The minimum/left most value.
- property pageStep#
The larger of two steps a slider provides corresponding to the user pressing PageUp or PageDown.
- property tracking#
Doesn’t seem to do anything SetTickInterval SetLineStep
SpacerItem Class#
- class SpacerItem(*args: Any, **kwargs: Any)#
A Widget that adds a horizontal and vertical spacer.
from hwx import gui spacerItem = gui.SpacerItem(5, 5) text = gui.TextEdit(parent=None,name='TextEdit') button1 = gui.PushButton(parent=None,name='uiPushButton',text='OK') button2 = gui.PushButton(parent=None,name='uiPushButton_2',text='Cancel') gridLayout = gui.GridLayout( spacing=6, children=( (text, '-', '-',), (spacerItem, button1, button2,), ) ) gridLayout.SetColStretch(0, 100) dialog = gui.Dialog(caption="SpacerItem", children=(gridLayout,), height=145, width=700) show(dialog)
- isEmpty()#
Checks if the spacer item is empty.
- resize(width, height, spacing='horizontal')#
Resize the spacer item is empty.
- Parameters:
width (float) – Resize width of the spacer item.
height (float) – Resize height of the spacer item.
spacing (str) – It can be either ‘horizontal’ or ‘vertical’.
SpinBox Class#
- class SpinBox(*args: Any, **kwargs: Any)#
A SpinBox Widget.
SpinBox allows to choose a value by clicking the up/down buttons or pressing up/down on the keyboard to increase/decrease the displayed value.
The upper and lower bounds are defined by the min and max properties. The user can also type the value manually. The SpinBox supports integer values and invokes the callback command every time the value is changed.
from hwx import gui def onChanged(): output.text = spin.value # Create a SpinBox with displayed text = prefix + value + suffix spin = gui.SpinBox(prefix='Use ', value=5, suffix=' samples', min=0, max=10, command=onChanged) # Create a label to show the spin box value output = gui.Label(spin.value) frame = gui.HFrame(spin, 10, output) show(frame)
- setValue(value)#
Sets the specified value after converting it into an integer.
- Parameters:
value (int) – The numeric value to be set for the SpinBox.
- property max#
The maximum integer value.
- property min#
The minimum integer value.
- property prefix#
The text that appears before the int.
- property step#
The value by which SpinBox is increased/decreased when you click the arrows.
- property suffix#
The text that appears after the int.
Splitter Class#
- class Splitter(*args: Any, **kwargs: Any)#
A Splitter Widget.
A Splitter controls the relative size of the children widgets by modifying the boundary between them. Splitter widget allows to create and control a dynamic layout of resizeable and collapsible panes. This can be useful when the areas that the splitter divides have variable dimensions.
For example, the Demo dialog box shows a splitter between the text edit area and the run edit. When the mouse pointer is located in proximity of the splitter, it will change appearance.
from hwx import gui first = gui.TextEdit(text="""<p>pane 1</p>""", readonly=True) second = gui.TextEdit(text="""<p>pane 2</p>""", readonly=True) splitter = gui.Splitter(children=(first, second)) splitter.orientation = "horizontal" show(splitter)
- property collapsible#
Returns and sets if the children can be resized down to size 0.
- property opaqueResize#
Updates the widgets when the side is being dragged.
- property orientation#
Specifies the orientation of the widget.
- property sizes#
A list of widths (horizontal) or heights(vertical) in pixels.
HSplitter Class#
- class HSplitter(*args: Any, **kwargs: Any)#
A Splitter with horizontal orientation.
from hwx import gui first = gui.TextEdit(text="""<p>pane 1</p>""", readonly=True) second = gui.TextEdit(text="""<p>pane 2</p>""", readonly=True) splitter = gui.HSplitter(children=(first, second)) show(splitter)
VSplitter Class#
- class VSplitter(*args: Any, **kwargs: Any)#
A Splitter with vertical orientation.
from hwx import gui first = gui.TextEdit(text="""<p>pane 1</p>""", readonly=True) second = gui.TextEdit(text="""<p>pane 2</p>""", readonly=True) splitter = gui.VSplitter(children=(first, second)) show(splitter)
TableView Class#
- class TableView(*args: Any, **kwargs: Any)#
A widget that presents data in a spreadsheet-like table view and provides means of visual observation and interaction with them.
The data stored in TableView.values are a list of list. The outer list contains the rows and each nested list contains the values for the columns. When defyining a TableView, one MUST define the columns of the TableView. A column must contain information of the same data type. Consequently, each nested list of TableView.values must provide data of the correct type, and be of size equal to the TableView.columns.
Examples of columns types are: views.Bool, views.Int, views.String, views.Float and views.Enum.
To use it, it’s suggested to inherit from it and define the type of columns.
- class ControlBar(*args: Any, **kwargs: Any)#
Horizontal Bar with layout and methods to add widgets.
- class ResizeMode(value)#
An enumeration.
- class selectionBehaviorType(value)#
An enumeration.
- class selectionModeType(value)#
An enumeration.
- addRow(row)#
Appends a row.
- clearSelection(emit=False)#
Unselects all cells.
- Parameters:
emit (bool) – Determines whether slots connected to onSelectionChange will be called or not.
- get()#
(list[list]) The data the TableView holds.
The outer list contains the rows and each nested list contains the values for the columns.
- getSelectedCells()#
A list of tuples specifying which cells are selected and in which order.
- Returns:
list(tuple)
- getSelectedRows()#
A list of indices specifying which rows are selected and in which order.
- Returns:
list
- removeRow(index)#
Deletes a row based on index.
- selectCell(row, col, clear=True, emit=False)#
Selects a cells.
- Parameters:
row (int) – The index of the row to be selected.
col (int) – The index of the column to be selected.
clear (bool) – Determines whether the previously selected will be cleared.
emit (bool) – Determines whether slots connected to onSelectionChange will be called or not.
- selectColumn(col, clear=True, emit=False)#
Selects all cells of a column.
- Parameters:
col (int) – The index of the column to be selected.
clear (bool) – Determines whether the previously selected will be cleared.
emit (bool) – Determines whether slots connected to onSelectionChange will be called or not.
- selectRow(row, clear=True, emit=False)#
Selects all cells of a row.
- Parameters:
row (int) – The index of the row to be selected.
clear (bool) – Determines whether the previously selected will be cleared.
emit (bool) – Determines whether slots connected to onSelectionChange will be called or not.
- setHResizeMode(mode, col='all')#
Controls resize behavior of the cells in the horizontal axis.
- Parameters:
mode (TableView.ResizeMode) –
col (int | 'all') –
- setVResizeMode(mode, row='all')#
Controls resize behavior of the cells in the vertical axis.
- Parameters:
mode (TableView.ResizeMode) –
row (int | 'all') –
- property controlBar#
Horizontal Bar with layout and methods to add widgets.
- property hResizeMode#
(TableView.ResizeMode) The resize mode that applies to the horizontal header.
- property numCols#
(int) The number of columns.
- property numRows#
(int) The number of rows.
- property selectionBehavior#
(TableView.selectionBehaviorType) Determines whether selection, selects single items, rows or columns.
- property selectionMode#
(TableView.selectionModeType) Determines whether selection, selects none, one or many items.
In many-item selections, whether the selection must be a continuous range of items, extended or multi-selection.
- property vResizeMode#
(TableView.ResizeMode) The resize mode that applies to the vertical header.
- property values#
(list[list]) The data the TableView holds.
The outer list contains the rows and each nested list contains the values for the columns.
TextEdit Class#
- class TextEdit(*args: Any, **kwargs: Any)#
A TextEdit Widget.
It is used to display and modify formatted and HTML text. It can be editable or not. Ctrl+Wheel zooms in/out.
from hwx import gui # Create an HTML TextEdit area textEdit = gui.TextEdit(text=""" <h1>Heading1</h1> <h2>Heading2</h2> <p>This is a paragraph.</p>""", readonly=True, ) textEdit.setStyleToSection(0,0,0,9,color="red", bold=True, italic=True) show(textEdit)
- onKeyPress(event)#
Callback method when a key is pressed on the TextEdit widget.
<Ret> adds a new line, lets add <Shift+Ret> for onCommand.
- Parameters:
event (KeyEvent) – Event to get key pressed.
- onWheelHandler(event)#
Callback method when the mouse wheel is rotated inside the TextEdit widget.
Ctrl+Wheel Zooms in/out.
- Parameters:
event (KeyEvent, MouseEvent) – The key event to capture the ctrl pressed and mouse wheel event to determine if is used zoom in or out.
- setStyleToSection(paraFrom, indexFrom, paraTo, indexTo, color=None, size=None, bold=False, italic=False)#
Function to set style (color/bold/italic/size) to a particular section in text.
- Parameters:
paraFrom (int) – Starting paragraph number.
indexFrom (int) – Index in starting paragraph.
paraTo (int) – Ending paragraph number.
indexTo (int) – Index in ending paragraph.
color (string | tuple(int)) – Text color. It can be RGB values in form of tuple or color name.
size (int) – Text size.
bold (bool) – If True, text will be bold.
italic (bool) – If True, text will be italic.
- property html#
The HTML formatted text.
- property readonly#
Returns and sets whether text/value can be edited.
- property text#
The text to display.
Tree Class#
- class Tree(*args: Any, **kwargs: Any)#
Hierarchical list of items.
- add(parent=None, text=None, icon=None, **kwds)#
Adds a TreeItem to the Tree.
- addColumn(label, width=-1)#
Adds one or more columns to the tree, width pixes wide.
All columns apart from the first one are inserted to the right of the existing ones. If width is negative, the new column’s width is set to maximum.
- Parameters:
label (str|list[str]) – Name of the column.
width (int|list[int]) – How wide each column is in pixels.
- Returns:
The indices of the new columns.
- Return type:
list[int]
- addWidget(widget, col, item)#
Add any widget to a tree item.
- Parameters:
widget (gui.Widget) – Widget needs to be inserted.
col (int) – Column index of TreeItem in which widget needs to be inserted.
item (TreeItem) – TreeItem in which widget needs to be inserted.
- clear()#
Removes all items from the tree.
- collapseAll()#
Collapses all items.
- enableEdit(col=None, edit=True)#
Makes all tree items or specific tree column to be editable.
- Parameters:
col (int) – Column index needs to be make editable.
edit (bool) – If True, column is editable else not.
- ensureItemVisible(item)#
Scrolls view so this item is visible.
- Parameters:
item (TreeItem) – TreeItem to make visible.
- expandAll(expanded=True)#
Expands (or collapses) all items.
- Parameters:
expanded (bool) – Determines whether to expand or not.
- fitColumns()#
Fit the columns in the tree.
- get()#
Returns the current selected item.
- getChildren(parent=None)#
Overloaded Widget method for ‘children’ property.
- getSelected()#
Returns a list of the selected items.
- remove(item)#
Removes the specified item from the tree.
- Parameters:
item (TreeItem) – Item to be removed.
- removeColumn(indices)#
Removes columns based on their initial indices.
- Parameters:
indices (int|list[int]) –
- setColumnWidth(column, width)#
Set the width of a particular column in a tree.
- Parameters:
column (int) – Column index of tree.
width (int) – Width of the column.
- setSelected(items, selected=True, clear=True)#
Selects the specified items.
- Parameters:
items (list[TreeItem]) – list of TreeItems to be selected.
selected (bool) – Determines if items will be selected or not.
clear (bool) – Determines if al previously selected items will be cleared or not.
- property children#
Returns all the children of a tree
- property header#
Column labels of the tree.
- property numCols#
The number of columns in the tree.
- property selectionMode#
The selection mode. Valid choices are:
“single”
“extended”
“multi”
“contiguous”
“none”
from hwx import gui
def buildContextMenu(menu, col):
if exTree.getSelected():
def delete():
for item in exTree.getSelected():
exTree.remove(item)
menu.insertItem('Remove', icon='glyphDeleteStrip-16.png', command=delete)
else:
def add():
exTree.add(text=['New-Item_1', "New-item_2"])
menu.insertItem('Add', icon='glyphPlusStrip-16.png', command=add)
exTree = gui.Tree(headers=["Name", "Value"], onContextMenu=buildContextMenu)
exTree.add(text=['Name', 'Base'])
item1 = exTree.add(text=["Material"])
choices = [("a", "A"), ("b", "B"), ("c", "C")]
combobox = gui.ComboBox(values=choices)
exTree.addWidget(combobox, 1, item1)
item2 = exTree.add(text=["Design Space"])
checkBox = gui.CheckBox()
exTree.addWidget(checkBox, 1, item2)
dialog = gui.Dialog(caption="Tree", children=exTree)
show(dialog)
TreeItem Class#
- class TreeItem(*args: Any, **kwargs: Any)#
An item in a Tree.
- add(text, icon=None, **kwds)#
Adds a TreeItem to the Tree.
- Parameters:
text (str) – Text that gets displayed.
icon (str) – Absolute path of the icon.
- Returns:
The added TreeItem.
- Return type:
- clear()#
Removes all the children from the tree.
- collapse()#
Collapse the tree item.
- enableEdit(col, edit=True)#
Makes a column of a tree item editable.
- Parameters:
col (int) – Column index needs to be make editable.
edit (bool) – If True, column is editable else not.
- ensureVisible()#
Ensures this TreeItem is visible.
- expand()#
Expand the tree item.
- getChildren()#
Overloaded Widget method for ‘children’ property.
- remove()#
Removes the item from the Tree.
- selectAndShow(clear=True)#
Selects and makes this TreeItem visible.
- property icon#
A list of icons to be displayed.
- property selectable#
(bool) Determines whether the item can be selected or not.
- property selected#
(bool) Determines whether the item is selected or not.
- property text#
A list of text to be displayed.
- property tooltip#
The tooltip to be displayed.
- property visible#
(bool) Determines whether the item is visible or not.