-
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 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.
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
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.
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, 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 select_gate
is overloaded and allows various parameters to be passed.
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
gate_id = 13 #save gate id
gui.select_gate(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.select_gate(gate_list) #selects gates in HAL GUI Graph View
gate_id_list = [13, 37] #build a list of gate ids
gui.select_gate(gate_id_list) #selects gates in HAL GUI Graph View
The function select_net
is overloaded and allows various parameters to be passed.
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
net_id = 528 #save net id
gui.select_net(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.select_net(net_list) #selects nets in HAL GUI Graph View
net_id_list = [528, 491] #build a list of net ids
gui.select_net(net_id_list) #selects nets in HAL GUI Graph View
The function select_module
is overloaded and allows various parameters to be passed.
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
module_id = 11 #save module id
gui.select_module(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.select_module(module_list) #selects modules in HAL GUI Graph View
module_id_list = [11, 38] #build a list of module ids
gui.select_module(module_id_list) #selects modules in HAL GUI Graph View