Skip to content

Python GUI API

Tobias Hermanns edited this page Oct 25, 2020 · 18 revisions

The Python GUI API enables access to the HAL GUI through the Python Console and through python scripts executed in the Python Editor. The core functionality of the Python GUI API evolves around 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 them from it. The HAL Python Environment provides the variable gui to interact with the Python GUI API. It can be used in python scripts in the Python Editor and in the Python Console.

Retrieve Items and Item IDs

The functions get_selected_gates, get_selected_nets, get_selected_modules, and get_selected_items are used to retrieve items which are currently selected in the Graph View of the HAL GUI.

selected_gates = gui.get_selected_gates()       #returns a list of all selected gates
selected_nets = gui.get_selected_nets()         #returns a list of all selected nets
selected_modules = gui.get_selected_modules()   #returns a list of all selected modules


selected_items = gui.get_selected_items()       #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 get_selected_gate_ids, get_selected_net_ids, get_selected_module_ids, and get_selected_item_ids are used to retrieve item ids of items which are currently selected in the Graph View of the HAL GUI.

selected_gate_ids = gui.get_selected_gate_ids()       #returns a list of all selected gate ids
selected_net_ids = gui.get_selected_net_ids()         #returns a list of all selected net ids
selected_module_ids = gui.get_selected_module_ids()   #returns a list of all selected module ids


selected_item_ids = gui.get_selected_item_ids()       #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

Select Items

The functions select, select_gate, select_net and select_module are used to select items. For convenience, they allow a variety of parameters to be passed. Examples of how to use these function 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.

Use of Funtion select

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.

Pass single gate, net or module

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

Pass a single list of gates, nets or module objects

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

Pass lists of gates, nets and module objects

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

Pass lists of gate ids, net ids and module ids

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

Use of Function select_gate

The function select_gate 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.

Pass single gate object

gate = netlist.get_gate_by_id(13)   #fetches gate with id 13 from netlist

gui.select_gate(gate)               #selects gate in HAL GUI Graph View

Pass single gate id

gate_id = 13               #save gate id

gui.select_gate(gate_id)   #selects gate in HAL GUI Graph View

Pass list of gate objects

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.select_gate(gate_list)                  #selects gates in HAL GUI Graph View

Pass list of gate ids

gate_id_list = [13, 37]          #build a list of gate ids

gui.select_gate(gate_id_list)    #selects gates in HAL GUI Graph View

Use of Function select_net

The function select_net is overloaded and allows various parameters to be passed.

Pass single net object

net = netlist.get_net_by_id(528)   #fetches net with id 528 from netlist

gui.select_net(net)                #selects net in HAL GUI Graph View

Pass single net id

net_id = 528             #save net id

gui.select_net(net_id)   #selects net in HAL GUI Graph View

Pass list of net objects

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.select_net(net_list)                   #selects nets in HAL GUI Graph View

Pass list of net ids

net_id_list = [528, 491]       #build a list of net ids

gui.select_net(net_id_list)    #selects nets in HAL GUI Graph View

Use of Function select_module

The function select_module is overloaded and allows various parameters to be passed.

Pass single module object

module = netlist.get_module_by_id(11)   #fetches module with id 11 from netlist

gui.select_module(module)               #selects module in HAL GUI Graph View

Pass single module id

module_id = 11                 #save module id

gui.select_module(module_id)   #selects module in HAL GUI Graph View

Pass list of module objects

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.select_module(module_list)                  #selects modules in HAL GUI Graph View

Pass list of module ids

module_id_list = [11, 38]            #build a list of module ids

gui.select_module(module_id_list)    #selects modules in HAL GUI Graph View

Pass list of module ids

Deselect Items

The functions deselect, deselect_gate, deselect_net and deselect_module 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.

Use of Funtion deselect

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.

Pass single gate, net or module

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

Pass a single list of gates, nets or module objects

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

Pass lists of gates, nets and module objects

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

Pass lists of gate ids, net ids and module ids

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

Use of Function deselect_gate

The function deselect_gate 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.

Pass single gate object

gate = netlist.get_gate_by_id(13)   #fetches gate with id 13 from netlist

gui.deselect_gate(gate)             #deselects gate in HAL GUI Graph View

Pass single gate id

gate_id = 13                 #save gate id

gui.deselect_gate(gate_id)   #deselects gate in HAL GUI Graph View

Pass list of gate objects

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.deselect_gate(gate_list)                #deselects gates in HAL GUI Graph View

Pass list of gate ids

gate_id_list = [13, 37]          #build a list of gate ids

gui.deselect_gate(gate_id_list)  #deselects gates in HAL GUI Graph View

Use of Function deselect_net

The function deselect_net is overloaded and allows various parameters to be passed.

Pass single net object

net = netlist.get_net_by_id(528)   #fetches net with id 528 from netlist

gui.deselect_net(net)              #deselects net in HAL GUI Graph View

Pass single net id

net_id = 528               #save net id

gui.deselect_net(net_id)   #deselects net in HAL GUI Graph View

Pass list of net objects

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.deselect_net(net_list)                 #deselects nets in HAL GUI Graph View

Pass list of net ids

net_id_list = [528, 491]        #build a list of net ids

gui.deselect_net(net_id_list)   #deselects nets in HAL GUI Graph View

Use of Function deselect_module

The function deselect_module is overloaded and allows various parameters to be passed.

Pass single module object

module = netlist.get_module_by_id(11)   #fetches module with id 11 from netlist

gui.deselect_module(module)             #deselects module in HAL GUI Graph View

Pass single module id

module_id = 11                   #save module id

gui.deselect_module(module_id)   #deselects module in HAL GUI Graph View

Pass list of module objects

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.deselect_module(module_list)                #deselects modules in HAL GUI Graph View

Pass list of module ids

module_id_list = [11, 38]             #build a list of module ids

gui.deselect_module(module_id_list)   #deselects modules in HAL GUI Graph View
Clone this wiki locally