User interface
This page lists some examples on how the user interface can be used. More information on the user interface can be found on the user interface's documentation page.
Basic user interface example
Below is a basic example implementing the user interface. In this example, the user interface has been set up for a mock key programming procedure. It demonstrates several use cases for the different UI control types.
from openobd import *
# Start an openOBD session on a ticket
openobd = OpenOBD()
openobd_session = openobd.start_session_on_ticket(TICKET_ID) # The ticket ID needs to be filled in (as a string)
# Start the SessionTokenHandler to ensure the openOBD session remains authenticated
SessionTokenHandler(openobd_session)
# Create a UiHandler object and use it to show a welcome message
ui_handler = UiHandler(openobd_session)
ui_handler.show_ui(Label(label="Welcome to the start of the procedure!", minimal_display_time=4))
# Ensure the ignition is on before proceeding
if not ui_handler.show_ui(YesNo(label="Is the ignition on?")):
ui_handler.show_ui(Continue(label="Please turn the ignition on and press continue."))
# Ensure that the correct PIN of the vehicle is entered
while True:
pin = ui_handler.show_ui(FreeText(label="Please enter the PIN of the vehicle."))
if ui_handler.show_ui(YesNo(label=f"You entered: {pin}. Is this correct?")):
break
# Ask what type of keys should be programmed
key_types = ["Keyless", "Transponder"]
key_type_index = ui_handler.show_ui(Options(label="Do you want to program keyless or transponder keys?", options=key_types))
# Ask how many keys should be programmed, and display the key currently being programmed
key_amount = ui_handler.show_ui(Numbers(label=f"How many keys do you want to program?", minimum=1, maximum=5))
for i in range(key_amount):
ui_handler.show_ui(Label(label=f"{key_types[key_type_index]} key {i + 1} is currently being programmed...", minimal_display_time=3))
ui_handler.show_ui(Label(label=f"Successfully programmed key {i + 1}!", minimal_display_time=2))
# Show a final message and close the UI
ui_handler.show_ui(Label(label="Procedure finished!", minimal_display_time=3))
ui_handler.stop_stream()
# Close the session with a successful result
result = ServiceResult(result=[Result.RESULT_SUCCESS])
openobd_session.finish(result)
Displaying the operator interface
Besides being able to show the user interface to the customer, it is also possible to show a UI to the operator. Both of these UIs can be shown at the same time and can be updated independently. Below is an example demonstrating this.
from openobd import *
# Start an openOBD session on a ticket
openobd = OpenOBD()
openobd_session = openobd.start_session_on_ticket(TICKET_ID) # The ticket ID needs to be filled in (as a string)
# Start the SessionTokenHandler to ensure the openOBD session remains authenticated
SessionTokenHandler(openobd_session)
# Create a UiHandler object for the customer/user (which is the default)
customer_ui = UiHandler(openobd_session)
# Create a second UiHandler object, explicitly stating that it should be shown to the operator
operator_ui = UiHandler(openobd_session, target=InterfaceType.INTERFACE_OPERATOR)
# Inform the operator that the customer is entering a PIN
operator_ui.show_ui(Label(label="The customer is currently entering a PIN."))
while True:
# Wait for the customer to enter a PIN
pin = customer_ui.show_ui(FreeText(label="Please enter the PIN of the vehicle."))
# Tell the customer to wait while asking the operator to check the PIN
customer_ui.show_ui(Label(label="Please wait while the operator checks if the PIN is correct."))
if operator_ui.show_ui(YesNo(label=f"The customer entered the PIN 'f{pin}'. Is this correct?")):
# Inform both the customer and operator that the procedure is finished
operator_ui.show_ui(Label(label="The procedure is finished."))
customer_ui.show_ui(Label(label="Your PIN is correct. The procedure is finished.", minimal_display_time=3))
break
else:
# Inform both the operator and customer that the customer needs to enter a PIN again
operator_ui.show_ui(Label(label="The customer is entering a PIN again."))
customer_ui.show_ui(Label(label="The operator has indicated that the entered PIN is incorrect. Please try again.", minimal_display_time=5))
# Close both UIs
customer_ui.stop_stream()
operator_ui.stop_stream()
# Close the session with a successful result
result = ServiceResult(result=[Result.RESULT_SUCCESS])
openobd_session.finish(result)