-
Notifications
You must be signed in to change notification settings - Fork 76
Python GUI API
The Python GUI API enables access to the HAL GUI through the Python Console and through python scripts executed in the Python Editor. The Python GUI API allows interacting with the current selection of the Graph View. The python code can retrieve gates, nets and modules of the current selection as well as select and deselect items. To access the Python GUI API, the HAL Python Environment provides the variable gui
.
The functions getSelectedGates
, getSelectedNets
, getSelectedModules
, and getSelectedItems
are used to retrieve items which are currently selected in the Graph View of the HAL GUI.
selected_gates = gui.getSelectedGates() #returns a list of all selected gates
selected_nets = gui.getSelectedNets() #returns a list of all selected nets
selected_modules = gui.getSelectedModules() #returns a list of all selected modules
selected_items = gui.getSelectedItems() #returns a tuple containing the lists of all selected gates, nets and modules
selected_gates = selected_items[0] #tuple index 0 holds the list of all selected gates
selected_nets = selected_items[1] #tuple index 1 holds the list of all selected nets
selected_modules = selected_items[2] #tuple index 2 holds the list of all selected modules
The functions getSelectedGateIds
, getSelectedNetIds
, getSelectedModuleIds
, and getSelectedItemIds
are used to retrieve item ids of items which are currently selected in the Graph View of the HAL GUI.
selected_gate_ids = gui.getSelectedGateIds() #returns a list of all selected gate ids
selected_net_ids = gui.getSelectedNetIds() #returns a list of all selected net ids
selected_module_ids = gui.getSelectedModuleIds() #returns a list of all selected module ids
selected_item_ids = gui.getSelectedItemIds() #returns a tuple containing the lists of all selected gate ids, net ids and module ids
selected_gate_ids = selected_item_ids[0] #tuple index 0 holds the list of all selected gate ids
selected_net_ids = selected_item_ids[1] #tuple index 1 holds the list of all selected net ids
selected_module_ids = selected_item_ids[2] #tuple index 2 holds the list of all selected module ids
The functions select
↓, selectGate
↓, selectNet
↓ and selectModule
↓ are used to select items. For convenience, they allow a variety of parameters to be passed. Examples of how to use these functions in python are shown below. Note that the used ids of the gates, nets and modules in the examples are not necessarily valid for every netlist. Please make sure to use valid ids.
The function select
is overloaded and allows various parameters to be passed. It's possible to pass a single gate, net or module, a singe list of gates, nets or modules, lists of gates, nets and modules or lists of gate ids, net ids and module ids.
gate = netlist.get_gate_by_id(13) #fetches gate with id 13 from netlist
net = netlist.get_net_by_id(37) #fetches net with id 37 from netlist
module = netlist.get_module_by_id(11) #fetches module with id 0 from netlist
gui.select(gate) #selects gate in HAL GUI Graph View
gui.select(net) #selects net in HAL GUI Graph View
gui.select(module) #selects module in HAL GUI Graph View
some_gate = netlist.get_gate_by_id(13) #fetches gate with id 13 from netlist
another_gate = netlist.get_gate_by_id(37) #fetches gate with id 37 from netlist
some_net = netlist.get_net_by_id(528) #fetches net with id 528 from netlist
another_net = netlist.get_net_by_id(491) #fetches net with id 491 from netlist
some_module = netlist.get_module_by_id(11) #fetches module with id 11 from netlist
another_module = netlist.get_module_by_id(38) #fetches module with id 38 from netlist
gate_list = [some_gate, another_gate] #build a list of gates
net_list = [some_net, another_net] #build a list of nets
module_list = [some_module, another_module] #build a list of modules
gui.select(gate_list) #selects gates in HAL GUI Graph View
gui.select(net_list) #selects nets in HAL GUI Graph View
gui.select(module_list) #selects modules in HAL GUI Graph View
some_gate = netlist.get_gate_by_id(13) #fetches gate with id 13 from netlist
another_gate = netlist.get_gate_by_id(37) #fetches gate with id 37 from netlist
some_net = netlist.get_net_by_id(528) #fetches net with id 528 from netlist
another_net = netlist.get_net_by_id(491) #fetches net with id 491 from netlist
some_module = netlist.get_module_by_id(11) #fetches module with id 11 from netlist
another_module = netlist.get_module_by_id(38) #fetches module with id 38 from netlist
gate_list = [some_gate, another_gate] #build a list of gates
net_list = [some_net, another_net] #build a list of nets
module_list = [some_module, another_module] #build a list of modules
gui.select(gate_list, net_list, module_list) #selects gates in HAL GUI Graph View
gate_id = [13, 37] #build a list of gate ids
net_ids = [528, 491] #build a list of net ids
module_ids = [11, 38] #build a list of module ids
gui.select(gate_ids, net_ids, module_ids) #selects gates in HAL GUI Graph View
The function selectGate
is overloaded and allows various parameters to be passed. It's possible to pass a single gate, a single gate id, a list of gates or a list of gate ids.
gate = netlist.get_gate_by_id(13) #fetches gate with id 13 from netlist
gui.selectGate(gate) #selects gate in HAL GUI Graph View
gate_id = 13 #save gate id
gui.selectGate(gate_id) #selects gate in HAL GUI Graph View
some_gate = netlist.get_gate_by_id(13) #fetches gate with id 13 from netlist
another_gate = netlist.get_gate_by_id(37) #fetches gate with id 37 from netlist
gate_list = [some_gate , another_gate] #build a list of gates
gui.selectGate(gate_list) #selects gates in HAL GUI Graph View
gate_id_list = [13, 37] #build a list of gate ids
gui.selectGate(gate_id_list) #selects gates in HAL GUI Graph View
The function selectNet
is overloaded and allows various parameters to be passed. It's possible to pass a single net, a single net id, a list of nets or a list of net ids.
net = netlist.get_net_by_id(528) #fetches net with id 528 from netlist
gui.selectNet(net) #selects net in HAL GUI Graph View
net_id = 528 #save net id
gui.selectNet(net_id) #selects net in HAL GUI Graph View
some_net = netlist.get_net_by_id(528) #fetches net with id 528 from netlist
another_net = netlist.get_net_by_id(491) #fetches net with id 491 from netlist
net_list = [some_net , another_net] #build a list of nets
gui.selectNet(net_list) #selects nets in HAL GUI Graph View
net_id_list = [528, 491] #build a list of net ids
gui.selectNet(net_id_list) #selects nets in HAL GUI Graph View
The function selectModule
is overloaded and allows various parameters to be passed. It's possible to pass a single module, a single module id, a list of modules or a list of module ids.
module = netlist.get_module_by_id(11) #fetches module with id 11 from netlist
gui.selectModule(module) #selects module in HAL GUI Graph View
module_id = 11 #save module id
gui.selectModule(module_id) #selects module in HAL GUI Graph View
some_module = netlist.get_module_by_id(11) #fetches module with id 11 from netlist
another_module = netlist.get_module_by_id(38) #fetches module with id 38 from netlist
module_list = [some_module , another_module] #build a list of modules
gui.selectModule(module_list) #selects modules in HAL GUI Graph View
module_id_list = [11, 38] #build a list of module ids
gui.selectModule(module_id_list) #selects modules in HAL GUI Graph View
Note that each type of select-funtion has two optional parameters to change its behavior.
By default, before selecting items, the current selection gets cleared. If items should be added to the already existing selection pass the parameter clear_current_selection = False
to the function.
some_gate_id_list = [42, 69] #build a list of some gate ids
another_gate_id_list = [19, 48] #build a list of more gate ids
gui.select(some_gate_id_list) #selects gates in HAL GUI Graph View, previous selection is overwritten
gui.select(another_gate_id_list, clear_current_selection=False) #adds the gates to HAL GUI Graph View selection
By default, when selecting items, the Graph View zooms and moves to show the newly selected items. To disable this behavior pass navigate_to_selection=False
to the function.
The functions deselectAllItems
↓, deselect
↓, deselectGate
↓, deselectNet
↓ and deselectModule
↓ are used to deselect items. For convenience, they allow a variety of parameters to be passed. Examples of how to use these functions in python are shown below. Note that the used ids of the gates, nets and modules in the examples are not necessarily valid for every netlist. Please make sure to use valid ids.
gui.deselectAllItems() #deselects all items in HAL GUI Graph View
The function deselect
is overloaded and allows various parameters to be passed. It's possible to pass a single gate, net or module, a singe list of gates, nets or modules, lists of gates, nets and modules or lists of gate ids, net ids and module ids.
gate = netlist.get_gate_by_id(13) #fetches gate with id 13 from netlist
net = netlist.get_net_by_id(37) #fetches net with id 37 from netlist
module = netlist.get_module_by_id(11) #fetches module with id 0 from netlist
gui.deselect(gate) #deselects gate in HAL GUI Graph View
gui.deselect(net) #deselects net in HAL GUI Graph View
gui.deselect(module) #deselects module in HAL GUI Graph View
some_gate = netlist.get_gate_by_id(13) #fetches gate with id 13 from netlist
another_gate = netlist.get_gate_by_id(37) #fetches gate with id 37 from netlist
some_net = netlist.get_net_by_id(528) #fetches net with id 528 from netlist
another_net = netlist.get_net_by_id(491) #fetches net with id 491 from netlist
some_module = netlist.get_module_by_id(11) #fetches module with id 11 from netlist
another_module = netlist.get_module_by_id(38) #fetches module with id 38 from netlist
gate_list = [some_gate, another_gate] #build a list of gates
net_list = [some_net, another_net] #build a list of nets
module_list = [some_module, another_module] #build a list of modules
gui.deselect(gate_list) #deselects gates in HAL GUI Graph View
gui.deselect(net_list) #deselects nets in HAL GUI Graph View
gui.deselect(module_list) #deselects modules in HAL GUI Graph View
some_gate = netlist.get_gate_by_id(13) #fetches gate with id 13 from netlist
another_gate = netlist.get_gate_by_id(37) #fetches gate with id 37 from netlist
some_net = netlist.get_net_by_id(528) #fetches net with id 528 from netlist
another_net = netlist.get_net_by_id(491) #fetches net with id 491 from netlist
some_module = netlist.get_module_by_id(11) #fetches module with id 11 from netlist
another_module = netlist.get_module_by_id(38) #fetches module with id 38 from netlist
gate_list = [some_gate, another_gate] #build a list of gates
net_list = [some_net, another_net] #build a list of nets
module_list = [some_module, another_module] #build a list of modules
gui.deselect(gate_list, net_list, module_list) #deselects gates in HAL GUI Graph View
gate_id = [13, 37] #build a list of gate ids
net_ids = [528, 491] #build a list of net ids
module_ids = [11, 38] #build a list of module ids
gui.deselect(gate_ids, net_ids, module_ids) #deselects gates in HAL GUI Graph View
The function deselectGate
is overloaded and allows various parameters to be passed. It's possible to pass a single gate, a single gate id, a list of gates or a list of gate ids.
gate = netlist.get_gate_by_id(13) #fetches gate with id 13 from netlist
gui.deselectGate(gate) #deselects gate in HAL GUI Graph View
gate_id = 13 #save gate id
gui.deselectGate(gate_id) #deselects gate in HAL GUI Graph View
some_gate = netlist.get_gate_by_id(13) #fetches gate with id 13 from netlist
another_gate = netlist.get_gate_by_id(37) #fetches gate with id 37 from netlist
gate_list = [some_gate , another_gate] #build a list of gates
gui.deselectGate(gate_list) #deselects gates in HAL GUI Graph View
gate_id_list = [13, 37] #build a list of gate ids
gui.deselectGate(gate_id_list) #deselects gates in HAL GUI Graph View
The function deselectNet
is overloaded and allows various parameters to be passed. It's possible to pass a single net, a single net id, a list of nets or a list of net ids.
net = netlist.get_net_by_id(528) #fetches net with id 528 from netlist
gui.deselectNet(net) #deselects net in HAL GUI Graph View
net_id = 528 #save net id
gui.deselectNet(net_id) #deselects net in HAL GUI Graph View
some_net = netlist.get_net_by_id(528) #fetches net with id 528 from netlist
another_net = netlist.get_net_by_id(491) #fetches net with id 491 from netlist
net_list = [some_net , another_net] #build a list of nets
gui.deselectNet(net_list) #deselects nets in HAL GUI Graph View
net_id_list = [528, 491] #build a list of net ids
gui.deselectNet(net_id_list) #deselects nets in HAL GUI Graph View
The function deselectModule
is overloaded and allows various parameters to be passed. It's possible to pass a single module, a single module id, a list of modules or a list of module ids.
module = netlist.get_module_by_id(11) #fetches module with id 11 from netlist
gui.deselectModule(module) #deselects module in HAL GUI Graph View
module_id = 11 #save module id
gui.deselectModule(module_id) #deselects module in HAL GUI Graph View
some_module = netlist.get_module_by_id(11) #fetches module with id 11 from netlist
another_module = netlist.get_module_by_id(38) #fetches module with id 38 from netlist
module_list = [some_module , another_module] #build a list of modules
gui.deselectModule(module_list) #deselects modules in HAL GUI Graph View
module_id_list = [11, 38] #build a list of module ids
gui.deselectModule(module_id_list) #deselects modules in HAL GUI Graph View