Widgets#

ButtonBase Class#

class ButtonBase(*args: Any, **kwargs: Any)#

Abstract base class for all buttons.

setProperties(kwds)#

Ensure proper order of setting properties.

Parameters:

kwds – A dict so the order of the properties are set is unpredictable checkable must be set before checked, or checked will not take effect.

property accel#

Keyboard accelerator to execute the command (ie ‘Ctrl-r’).

property autoRepeat#

Returns and sets if button will auto-repeat if the user holds it down.

property checkable#

Returns and sets if button can be toggled/checked (depending on rendering)

property checked#

Returns and sets if button has been toggled/checked. Only works if it is checkable.

property command#

Method called when the button is clicked.

property dialog#

(type[ActionDialog]) Dialog toggled by button.

The dialog is accessed/created through its cls.get() classmethod.

property flat#

Returns and sets if button has a flat borderless appearance.

property icon#

Icon file name.

property text#

Text to display.

ButtonGroup Class#

class ButtonGroup(*args: Any, **kwargs: Any)#

A ButtonGroup is a group of mutually exclusive buttons.

Used with RadioButton, CheckBox to so only one is checked at a time

CheckBox Class#

class CheckBox(*args: Any, **kwargs: Any)#

A CheckBox is a bool control with a text label.

Example of a CheckBox#
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.

Example of a CheckBox#
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#

class Cursor#

The cursor of the application.

classmethod get(cursor)#

Returns the named cursor.

classmethod register(name, icon, pickmask=None, x=0, y=0)#

Registers a cursor so it can be set

classmethod set(cursor=None)#

Sets the named cursor.

If the cursor is None, uses the standard cursor.

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

ExpanderButton Class#

class ExpanderButton(*args: Any, **kwargs: Any)#

Button used to control the visibility of another widget.

It can be constructed with an associated checkbox or radiobutton which will sync with the state of the controlled widget.

property content#

The Widget to control.

property expanded#

The visibility state of the content widget.

IconLabel Class#

class IconLabel(*args: Any, **kwargs: Any)#

A Widget that displays an icon from an IconSet file.

An IconLabel is used to indicate a separate section in a Dialog. When clicked, it can be used to display help.

property tooltip#

The text displayed in a popup, when cursor is over the icon or text.

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)#
Example of a Label#
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).

Example of a Legend#
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.

Example of a ListBox#
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.

PopupMenu Class#

class PopupMenu(*args: Any, **kwargs: Any)#

A PopupMenu Widget.

The PopupMenu is a specialized control that has the abilty of being selected. You can add items and commands to the popup menu.

Example of a PopupMenu#
from hwx import gui

def onItem1():
        gui.tellUser("onItem1 selected")

def onItem2():
        gui.tellUser("onItem2 selected")

def onItem3():
        gui.tellUser("onItem3 selected")

def onClick(event):
        button.text = "Un-display the menu" if button.checked else "Display the menu"
        popup.show() if button.checked else popup.hide()

# Create a button that displays a pop up menu, generate a message dialog box
# when each menu item is selected
button = gui.ToggleButton('Display the menu', command=onClick)

# Create an empty pop-up menu, populate it with some items
popup = gui.PopupMenu()

popup.insertItem("Item 1", command=onItem1)
popup.insertItem("Item 2", command=onItem2)
popup.insertItem("Item 3", command=onItem3)
popup.hide()

frame = gui.HFrame((button, "<->"), 5, popup)
show(frame)
clear()#

Remove all items.

insertItem(text, menu=None, icon=None, command=None, enabled=True, visible=True, accel=None, checked=None, advancedTooltip=None)#

Inserts item and command into menu.

Parameters:
  • text (str) – The item text to be displayed.

  • menu (PopupMenu) – The menu object to insert.

  • icon (str) – The icon file to be inserted on the left side of text.

  • command (callback) – The callback method to be executed when item is clicked.

  • enabled (bool) – Determines whether to enable the inserted item.

  • visible (bool) – Determines whether the inserted item is visible.

  • accel (str) – Keyboard accelerator to execute the command (e.g. ‘Del’)

  • checked (bool) – Determines if the item is checkable. True or False makes it checkable.

  • advancedTooltip (str) – UUID to display advanced tooltips.

Returns:

The index where the item has been inserted.

Return type:

int

insertMenu(text, menu=None)#

Adds and returns a cascading menu.

Parameters:
  • text (str) – Text to be displayed in the menu.

  • menu (PopupMenu) – Cascading menu.

Returns:

Returns a cascading menu.

Return type:

PopupMenu

insertSeparator()#

Inserts a separator in the Pop menu.

insertWidget(widget)#

Inserts a widget into the menu

popup(event=None)#

Shows the Popup menu.

Parameters:

event (MouseEvent) – The event to get the mouse position.

setItemEnabled(index, enabled=True)#

Enables or Disables the menu item at the specified index.

property numOfItems#

Returns the number of items in the popup menu.

ProgressBar Class#

class ProgressBar(*args: Any, **kwargs: Any)#

A Widget that shows the running status of a process.

Example of a ProgressBar#
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.

PushButton Class#

class PushButton(*args: Any, **kwargs: Any)#

A PushButton.

Push the button to command the computer to preform some action.

The push button, or command button, is perhaps the most commonly used widget in any graphical user interface. Typical buttons are OK, Apply, Cancel, Close, Yes, No and Help.

Example of a PushButton#
from hwx import gui

def onClick(event):
        gui.tellUser("Hello World")

# This PushButton, when clicked, pops up an information message
button = gui.PushButton('Say Hello',command=onClick)

# Set the properties outside the constructor
button.flat    = True
# button.enabled = False
button.accel   = "Ctrl+H"

show(button)

RadioButton Class#

class RadioButton(*args: Any, **kwargs: Any)#

A RadioButton

A RadioButton is a widget that can be switched on/off.

Example of a RadioButton#
from hwx import gui

def onClick(event):
        enabled = "On" if event.value else "Off"
        output.text = enabled

button = gui.RadioButton('On or Off?', command=onClick)
output = gui.Label("Off")

frame = gui.HFrame(button, 10, output)

show(frame)
property centerAlign#

Aligns the radio button at the center of the layout.

RadioButtons Class#

class RadioButtons(*args: Any, **kwargs: Any)#

Group of mutually exclusive RadioButtons.

RadioButtons are mutually exclusive with other RadioButtons in the same container.

Only one radio botton can be switched on within the same container.

RadioButtons are usually used to create composite controls like VRadioButtons or HRadioButtons.

clear()#

Destroys the button.

get()#

Returns the checked item.

set(v)#

Set the item checked.

Parameters:

v (int) – Index of the item to checked.

setValues(values, value=None)#

Specify the options. A button is created for each option.

Parameters:
  • values (list[str, str]) – list of (value, displayName) tuples.

  • value (list[str] | list[int]) – Set new values.

HRadioButtons Class#

class HRadioButtons(*args: Any, **kwargs: Any)#

Group of mutually exclusive RadioButtons layed out horizontally.

Example of HRadioButtons#
from hwx import gui

def onSelected(event):
        output.text = event.value

# These 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 to the user.
colors = (("red", "Red"), ("green", "Green"), ("blue", "Blue"),)

buttons = gui.HRadioButtons(colors,command=onSelected)
output = gui.Label(buttons.value)
frame = gui.HFrame(buttons, 10, (output, "<->"), spacing=5)

show(frame)

VRadioButtons Class#

class VRadioButtons(*args: Any, **kwargs: Any)#

Group of mutually exclusive RadioButtons layed out verically.

Example of VRadioButtons#
from hwx import gui

def onSelected(event):
        output.text = event.value

# These 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 to the user.
colors = (("red", "Red"), ("green", "Green"), ("blue", "Blue"),)

buttons = gui.VRadioButtons(colors,command=onSelected)
output = gui.Label(buttons.value)
frame = gui.HFrame(buttons, 10, (output, "<->"), spacing=5)

show(frame)

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 .

Example of a Slider#
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.

Example of a SpacerItem#
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.

Example of a SpinBox#
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.

Example of a Splitter#
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.

Example of a HSplitter#
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.

Example of a VSplitter#
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:
setVResizeMode(mode, row='all')#

Controls resize behavior of the cells in the vertical axis.

Parameters:
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.

Example of a TextEdit#
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.

ToggleButton Class#

class ToggleButton(*args: Any, **kwargs: Any)#

A ToggleButton

Toggle on off the Button to command the computer to preform some action. ToggleButton is usually used in a ToolBar without text.

The ToggleButton is a specialized control that has the abilty of being selected. ToggleButtons, when clicked, display their state (selected or unselected).

Example of a ToggleButton#
from hwx import gui

def onClick(event):
        button.text = "Un-toggle Me" if button.checked else "Toggle Me"

button = gui.ToggleButton('Toggle me', command=onClick)

show(button)

ToolButton Class#

class ToolButton(*args: Any, **kwargs: Any)#

A ToolButton.

Click the Tool Button to do something. Tool Button is usually used in a ToolBar without text.

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.

Parameters:
  • parent (TreeItem) – A TreeItem to define hierarchy.

  • text (str|list[str]) – Text or List of text that gets displayed in column.

  • icon (str|list[str]) – Absolute path of the icon or a list of icons.

Returns:

the added TreeItem.

Return type:

TreeItem

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”

Example of a Tree#
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:

TreeItem

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.