Widgets#
Canvas Class#
- class Canvas(*args: Any, **kwargs: Any)#
Canvas widget to manage drawing items.
- Parameters:
parent – parent widget.
name (str) – widget name.
**kwargs – properties to set on initialization.
Example of a Canvas#from hwx import gui # This is a CanvasView created with a Canvas. cv = gui.CanvasView() # Creating canvas with parent as CanvasView. c = gui.Canvas(parent=cv, background="#ff0000") # Setting clipping for the canvas. cv.canvas = c # add rectangular for i in range(1, 400, 40): for j in range(1, 400, 40): c.addRect(i, j, 40, 40, color="#00ff00") # add line c.addLine(0, 0, 40, 40, color="#00ff00") show(cv)
- addLine(*coords, **kwargs)#
Add a line to the canvas.
- Parameters:
*coords – coordinates (up to 4) defining the line.
**kwargs – additional properties including optional ‘tag’ for the line.
- Returns:
the created line item.
- Return type:
CanvasLine
- Raises:
ValueError – if number of coordinates is not between 1 and 4.
- addRect(*coords, **kwargs)#
Add a rectangle to the canvas.
- Parameters:
*coords – coordinates (up to 4) defining the rectangle.
**kwargs – additional properties including optional ‘tag’ for the rectangle.
- Returns:
the created rectangle item.
- Return type:
CanvasRect
- Raises:
ValueError – if number of coordinates is not between 1 and 4.
- property background#
Get or set the background color of the canvas.
- Returns:
background color.
- Return type:
- property pixmap#
Get or set the background pixmap.
- Returns:
Pixmap object.
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.
ChooseDirEntry Class#
- class ChooseDirEntry(*args: Any, **kwargs: Any)#
Widget helps to Choose the directory.
Example of a ChooseDirEntry#from hwx import gui def onSelected(event): output.text = event.value # Creating a label to display the selected file. output = gui.Label(text="") # This is an ChooseDirEntry created with a placeholder text. modelFile = gui.ChooseDirEntry(placeHolderText="Select Folder", command=onSelected) frame = gui.VFrame(modelFile, output) show(frame)
- postFileDialog()#
Invokes the choose dir dialog.
ColorPicker Class#
- class ColorPicker(**kwds)#
A ColorPicker widget allows users to select a color from a color palette.
Example of a ColorPicker#from hwx import gui def onColorSelected(event): output.text = event.widget.color # This is a ColorPicker created with a color. colorPicker = gui.ColorPicker(command=onColorSelected) # Setting the color for ColorPicker. colorPicker.color = "#ff0000" output = gui.Label() frame = gui.HFrame(colorPicker, 10, output) show(frame)
- changeTheme(theme)#
Change the theme of the ColorPicker. :param theme: The theme to set. Can be ‘Default’ or ‘Rainbow’ or ‘Median’. :type theme: str
- show(x=None, y=None)#
Show the ColorPicker widget at the specified position. :param x: The x-coordinate to show the widget at. :type x: int :param y: The y-coordinate to show the widget at. :type y: int
- property color#
The currently selected color.
- property style#
Get the current style of the ColorPicker.
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 ComboBox#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) # Uncomment this to enable default value # combobox.enableDefaultValue = True frame = gui.HFrame(combobox, 10, output) show(frame)
- setValues(values, labels=None, 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.
- property enableDefaultValue#
If True, the first item in the ComboBox will be selected by default.
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
FloatSlider Class#
- class FloatSlider(*args: Any, **kwargs: Any)#
A widget used for controlling a value within a bounded range of floating values
Example of a FloatSlider#from hwx import gui # This method is invoked when the float slider value is modified. def onModified(): output.value = str(slider.value) # Create a float slider and a label to show its value slider = gui.FloatSlider(minvalue=1.5, maxvalue=10.5, tracking=False, pageStep=0.5, command=onModified) output = gui.Label(slider.value) frame = gui.HFrame(output, 5, slider) show(frame)
- get()#
Gets the value set on the widget
- set(value, emit=True)#
Sets the value to the widget
- property maxvalue#
Maximum value the slider value can achieve
- property minvalue#
Minimum value the slider value can achieve
- property pageStep#
Step interval for the slider
Hyperlink Class#
- class Hyperlink(*args: Any, **kwargs: Any)#
Widget that displays a textual label and/or image, and evaluates a command when pressed.
Example of a Hyperlink#from hwx import gui # This method is called when the hyperlink is clicked. def onClick(event): gui.tellUser("Hello World") # This Hyperlink, when clicked, pops up an information message hyperlink = gui.Hyperlink('Say Hello', command=onClick) # Set the properties outside the constructor # hyperlink.text = "Say Hello World" show(hyperlink)
- onCommand(event=None)#
Slot for link activation. Used to execute the command property.
- property enabled#
Boolean value that, if false, grays out the widget and makes it so it does not respond to user interaction.
- property text#
The string that is currently shown in the hyperlink. Changing this property automatically updates the widget.
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)#
- Example of a Label#
from hwx import gui gui.addResourcePath('C:/Temp') text = gui.Label("Display text", font=dict(size=14, bold=True, italic=True)) icon = gui.Label(icon="test_icon.png") label = gui.Label("Display World", icon="test_icon.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 echoMode#
Hide text when entering a password.
- Parameters:
mode (str) –
Normal
Password
NoEcho
- property placeHolderText#
Set the line edit placeholder text that is displayed as grayed-out as long as the text() is empty and the widget doesn’t have focus.
- 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.
OpenFileEntry Class#
- class OpenFileEntry(*args: Any, **kwargs: Any)#
Widget shows up the file open dialog and shows up the selected files on entry.
Example of an OpenFileEntry#from hwx import gui def onSelected(event): output.text = event.value # Creating a label to display the selected file. output = gui.Label(text="") # This is an OpenFileEntry created with a placeholder text. modelFile = gui.OpenFileEntry(placeHolderText="Select File", command=onSelected) frame = gui.VFrame(modelFile, output) show(frame)
- postFileDialog()#
Invokes the file dialog.
- property multiple#
Multiple selection of file
OpenFilesEntry Class#
- class OpenFilesEntry(*args: Any, **kwargs: Any)#
Widget allows to select multiple file in file open dialog.
Example of an OpenFileEntry#from hwx import gui def onSelected(event): output.text = event.value # Creating a label to display the selected file. output = gui.Label(text="") # This is an OpenFileEntry created with a placeholder text. modelFile = gui.OpenFileEntry(placeHolderText="Select File", command=onSelected) frame = gui.VFrame(modelFile, output) show(frame)
- get()#
Get the list of the file’s entry.
- postFileDialog()#
Invokes the file dialog.
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.
SaveFileEntry Class#
- class SaveFileEntry(*args: Any, **kwargs: Any)#
Widget used to save the file.
Example of a SaveFileEntry#from hwx import gui def onSelected(event): output.text = event.value # Creating a label to display the selected file. output = gui.Label(text="") # This is an SaveFileEntry created with a placeholder text. modelFile = gui.SaveFileEntry(placeHolderText="Save File", command=onSelected) frame = gui.VFrame(modelFile, output) show(frame)
- onButtonCommand(event=None)#
Command invoked on file image is invoked
- postFileDialog()#
Invokes the Save file dialog.
SearchBar Class#
- class SearchBar(*args: Any, **kwargs: Any)#
Widget that displays a search button and a entry that gives a filter capablity on value change in entry
Example of a SearchBar#from hwx import gui def onSelected(event): output.text = event.value # This is an SearchBar created with a list of values. searchbar = gui.SearchBar(command=onSelected) searchbar.addItem("abcdef", "Alphabets") searchbar.addItem("0123456789", "Numbers") output = gui.Label() frame = gui.HFrame(searchbar, 10, output) show(frame)
- addItem(label, category, **kwds)#
Allows to add item to the tree view of search entries.
- Parameters:
label (str) – The label of the item to be added.
category (str) – The category under which the item should be grouped.
kwds (dict) – Additional keyword arguments such as ‘key’, ‘tooltip’, and ‘command’ to customize the item.
- hideSearchButton()#
Hides the search button.
- showSearchButton()#
Shows the search button.
- property wildcard#
Boolean value that, if true, enables wildcards in the search bar. Changing this property automatically sets the wildcards state.
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.
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.
Example of a TableView#import csv import random import string from hwx.gui import views from hwx import gui class BoundedValue(views.Float): """An example of how a Float that must be bounded can be implemented""" def castForSet(self, value): value = super().castForSet(value) if not (self.minVal <= value <= self.maxVal): # This will ensure that the cell will keep the previous value raise ValueError("Value must be between limits") return value class ExampleTableView(views.TableView): """An example of how a TableView with different types of columns can be implemented""" def getMaterials(self, *args): return ["Steel (AISI 304)", "Steel (AISI 316)", "Steel (AISI 1015)"] columns = dict( name=views.String(label="Name"), id=views.Int(label="Id"), transparency=BoundedValue(label="Transparency", minVal=0, maxVal=100), visible=views.Bool(label="Visible"), x=views.Float(label="CoG X", units="length"), mass=BoundedValue(label="Mass", units="mass", minVal=0, maxVal=float("inf")), material=views.Enum(values=getMaterials, label="Material"), ) def saveCommand(self): fname = gui.getSaveFileName(caption="Export", filter="CVS (*.csv)") if fname: with open(fname, "w", newline="") as csvFile: writer = csv.writer(csvFile) labels = [col.label for name, col in table.columns.items()] rows = [labels] + self.values writer.writerows(rows) def addCommand(self): def generateRow(): return [ random.choice(string.ascii_letters).upper(), # Name random.randint(1, 10), # Id random.uniform(0, 100), # Transparency random.choice([True, False]), # Visible random.uniform(0, 1), # CoG X random.uniform(0, 100), # Mass random.choice(list(self.getMaterials())), # Material ] self.addRow(generateRow()) def deleteCommand(self): selected = self.getSelectedRows() for idx, rowIdx in enumerate(selected): self.removeRow(rowIdx - idx) def keyCommand(self, event): import hwui if gui.isCtrlDown() and event.Key() == hwui.ui.Key_S: self.saveCommand() elif event.Key() == hwui.ui.Key_Delete: self.deleteCommand() def createButttons(self): self.controlBar.button( icon="glyphFileSaveStrip-16.png", command=self.saveCommand ) self.controlBar.button( icon="toolbarEditAddStrip-16.png", command=self.addCommand ) self.controlBar.button( icon="toolbarDeleteStrip-16.png", command=self.deleteCommand ) self.controlBar.addSpacer() def buildContextMenu(self, menu, selectedCells): menu.insertItem( gui.tr("Add"), icon="toolbarEditAddStrip-16.png", command=lambda *args: self.addCommand(), ) menu.insertItem( gui.tr("Delete"), icon="glyphDeleteStrip-16.png", accel="Del", command=lambda *args: self.deleteCommand(), ) values = [["A", 1, 50, True, 0.1, "1kg", "Steel (AISI 304)"]] table = ExampleTableView(values=values) table.createButttons() table.onContextMenu.connect(table.buildContextMenu) table.onKeyPress.connect(table.keyCommand) dialog = gui.Dialog(caption="Table", children=table, minimumHeight=200, minimumWidth=800) dialog.show()
- class ControlBar(*args: Any, **kwargs: Any)#
Horizontal Bar with layout and methods to add widgets.
- addSpacer(self)#
- addSpacing(self, val)#
- button(self, icon, command, **kwargs)#
- class ResizeMode(value)#
An enumeration.
Name
Type
Fixed
ResizeMode
Interactive
ResizeMode
ResizeToContents
ResizeMode
Stretch
ResizeMode
- class selectionBehaviorType(value)#
An enumeration.
Name
Type
SelectColumns
selectionBehaviorType
SelectItems
selectionBehaviorType
SelectRows
selectionBehaviorType
- class selectionModeType(value)#
An enumeration.
Name
Type
ContiguousSelection
selectionModeType
ExtendedSelection
selectionModeType
MultiSelection
selectionModeType
NoSelection
selectionModeType
SingleSelection
selectionModeType
- class ControlBar(*args: Any, **kwargs: Any)#
Horizontal Bar with layout and methods to add widgets.
- enum ResizeMode(value)#
- enum selectionBehaviorType(value)#
- enum selectionModeType(value)#
- 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
- hideColumn(col)#
Hides a column by index.
- Parameters:
col (str) – The name of the column to be hidden.
- 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')
- showColumn(col)#
Shows a column by index. :param col: The name of the column to be shown. :type col: str
- sortByColumn(col, ascending=True)#
Sorts the table by a specific column.
- Parameters:
col (int) – The index of the column to sort by.
ascending (bool) – If True, sorts in ascending order; if False, sorts in descending order.
- property controlBar#
Horizontal Bar with layout and methods to add widgets.
- property enableFilterButtons#
Determines whether the filter buttons are enabled.
- property enableSorting#
Determines whether sorting is enabled.
- 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.
ToolBar Class#
- class ToolBar(*args: Any, **kwargs: Any)#
A ToolBar is a container for widgets that can be docked to the main window. It can contain buttons, separators, and other widgets. The ToolBar can be moved, resized, and customized by the user. It can also be programmatically controlled to show or hide, and to change its properties such as visibility, icon size, and orientation.
Example of a ToolBar#from hwx import gui # This is ToolBar created with a ToolButton. toolbutton = gui.PushButton() toolbutton.icon = "msobjbrowser.png" toolbar = gui.ToolBar() toolbar.addWidget(toolbutton) # Set the properties outside the constructor # toolbar.visible = False show(toolbar)
- class AllowedAreasEnum(*args: Any, **kwargs: Any)#
Enum for ToolBar allowed areas.
- class LocationEnum(*args: Any, **kwargs: Any)#
Enum for ToolBar location.
- class OrientationEnum(*args: Any, **kwargs: Any)#
Enum for ToolBar orientation.
- addSeparator()#
Automatically add a separator between every widget already added to the ToolBar and every widget added after the separator is added.
- addWidget(*args)#
Add widgets to the layout as children. This is called implicitly from the initializer when children are specified. This allows for widgets to be added to the layout after the layout has been created.
- clear()#
Remove all children from the ToolBar.
- isFloating()#
Returns True if the ToolBar is currently floating (Not docked), otherwise False
- move(value)#
Programmatically set the location of the ToolBar to a specified docking area.
- setProperties(**kwds)#
Internal method called from constructors
- property allowedAreas#
Which areas is the ToolBar allowed to be positioned. May be $V, but could also be a combination of each.
- property allowedareas#
Which areas is the ToolBar allowed to be positioned. May be $V, but could also be a combination of each.
- property floatable#
Boolean value that, if true, allows the ToolBar to be separated from the docking area and placed elsewhere on the screen.
- property iconsize#
Dimension property that specifies the size of the ToolBar’s icon.
- property movable#
Boolean value that, if true, allows the ToolBar to be moved manually by the user. Otherwise, it must be controlled programatically.
- property orientation#
Defines the orientation of the ToolBar, that is the area that can be grabbed to drag the widget. Can be either $V. If ‘VERTICAL’, the getable area is located on the top of the widget. Otherwise, (If it is ‘HORIZONTAL’) it is placed on the left side of the widget.
- property visible#
Boolean value that, if true, the ToolBar is currently visible. Changing this property automatically sets the visiblity.
Tree Class#
- class Tree(*args: Any, **kwargs: Any)#
Hierarchical list of items.
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)
- 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.
- items()#
Returns all the items in the tree.
- 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 | any]) – TreeItem.data
selected (bool)
clear (bool) – Replace selected items
- 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”
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 enabled#
(bool) Disabled items are greyed out and don’t respond to input events.
- 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.
WebPage Class#
- class WebPage(*args: Any, **kwargs: Any)#
Custom WebPage that handles navigation requests.
Example of a WebPage#from hwx import gui # This is a WebView created with a webpage. webv = gui.WebView() # Creating web page with parent as webview. webp = gui.WebPage(parent=webv) # Setting url for the webpage. webp.url = 'https://help.altair.com/hwdesktop/hwd/index.htm' # Setting page for the webview. webv.page = webp # Calling load method of webpage to load a URL. webp.load("https://help.altair.com/hwdesktop/hwd/index.htm") show(webv)
Intercepts navigation requests.
- Parameters:
url (str) – The target URL.
type (int) – Navigation type.
isMainFrame (bool) – Whether the request is for the main frame.
- Returns:
Whether to accept the navigation.
- Return type:
bool
- load(url)#
Loads the current page. :param url: URL to load. :type url: str
- property url#
Returns the current URL.
WebView Class#
- class WebView(*args: Any, **kwargs: Any)#
A custom WebView that supports setting URLs and HTML content.
Example of a WebView#from hwx import gui # This is a WebView created with a webpage. webview = gui.WebView() # Creating web page with parent as webview. webpage = gui.WebPage(parent=webview) # Set the properties outside the constructor webview.page = webpage # Calling load method of webpage to load a URL. webpage.load('https://www.altair.com') show(webview)
- findText(text)#
Finds and highlights the given text.
- Parameters:
text (str) – Text to search for.
- setHtml(html, baseUrl='')#
Sets the HTML content of the web view.
- Parameters:
html (str) – HTML content.
baseUrl (str) – Base URL for relative links.
- property page#
Gets the current web page.
- property url#
Gets the current URL.