Skip to content

Built-in Keyboard for AuboCaps Guide

I. Types of Plugin Keyboard:

  1. Standard keyboard
void registerStandardKeyboard(
        QWidget *wd, std::function<std::string(void)> init_cb = nullptr,
        const std::shared_ptr<InputValidator> &validator = nullptr,
        std::function<void(std::string)> result_cb = nullptr);

keyboard-1

  1. String type keyboard
void registerStringKeyboard(
        QWidget *wd, std::function<std::string(void)> init_cb = nullptr,
        const std::shared_ptr<InputValidator> &validator = nullptr,
        std::function<void(std::string)> result_cb = nullptr);

keyboard-2

  1. Expression keyboard
void registerExpressionKeyboard(
        QWidget *wd, std::function<ExpressionPtr(void)> init_cb = nullptr,
        std::function<void(ExpressionPtr result_value)> result_cb = nullptr);

keyboard-3

  1. Password keyboard
void registerPasswordKeyboard(
        QWidget *wd, std::function<std::string(void)> init_cb = nullptr,
        const std::shared_ptr<InputValidator> &validator = nullptr,
        std::function<void(std::string)> result_cb = nullptr);

keyboard-4

  1. Ip address input dedicated keyboard
void registerIPAddressKeyboard(
        QWidget *wd, std::function<std::string(void)> init_cb = nullptr,
        std::function<void(std::string)> result_cb = nullptr);

keyboard-5

  1. Floating point number keyboard
void registerDoubleKeyboard(
        QWidget *wd, std::function<std::string(void)> init_cb = nullptr,
        const std::shared_ptr<InputValidator> &validator = nullptr,
        std::function<void(std::string)> result_cb = nullptr);

keyboard-6

  1. Positive floating point number keyboard
void registerPositiveDoubleKeyboard(
        QWidget *wd, std::function<std::string(void)> init_cb = nullptr,
        const std::shared_ptr<InputValidator> &validator = nullptr,
        std::function<void(std::string)> result_cb = nullptr);

keyboard-7

  1. Integer keyboard
void registerIntegerKeyboard(
        QWidget *wd, std::function<std::string(void)> init_cb = nullptr,
        const std::shared_ptr<InputValidator> &validator = nullptr,
        std::function<void(std::string)> result_cb = nullptr);

keyboard-8

  1. Positive integer keyboard
void registerPositiveIntegerKeyboard(
        QWidget *wd, std::function<std::string(void)> init_cb = nullptr,
        const std::shared_ptr<InputValidator> &validator = nullptr,
        std::function<void(std::string)> result_cb = nullptr);

keyboard-9

  1. Code editing keyboard
void registerCodeEditerKeyboard(
        QWidget *wd, std::function<std::string(void)> init_cb = nullptr,
        const std::shared_ptr<InputValidator> &validator = nullptr,
        std::function<void(std::string)> result_cb = nullptr);

keyboard-10

  1. Number keyboard
void registerNumberKeyboard(
        QWidget *wd, std::function<std::string(void)> init_cb = nullptr,
        const std::shared_ptr<InputValidator> &validator = nullptr,
        std::function<void(std::string)> result_cb = nullptr);

keyboard-11

II. Methods for Using the Plugin Keyboard of the Teach Pendant:

The ViewApiProviderPtr view_api_{ nullptr }; interface is provided in both the installation node and program node view class, enabling access to the keyboard interfaces mentioned above. The specific invocation method is demonstrated as follows: (Note that when using different types of keyboards, attention should be paid to parameter types. Refer to the definition location in the code for specific requirements.)

Locations where keyboard interfaces can be called in program and installation nodes: (in viewclasses of program and installation nodes)

keyboard-12

Invocation method:

  • Firstly, declare a pointer variable for the keyboard management class in the header file of the contribution class of the program or installation node.

    std::shared_ptr<arcs::aubo_scope::KeyboardManager> keyboard_manager_;

  • Secondly, in the buildUi function of the contribution class of the program or installation node, obtain the KeyboardManager interface as needed. The implementation is as follows:

    keyboard_manager_ = view_api_->getUserInterfaceApi()->getUserInteraction()->getKeyboardManager();

  • Finally, call the register keyboard function in the interface:

keyboard_manager_->registerDoubleKeyboard(
        ui->le_test, 
        [=]() -> std::string { return ui->le_test->text().toStdString(); }, 
        std::make_shared<DoubleRangeValidator>([=]() -> std::pair<double, double> {
                        return { -100.0, 100.0 };
                }), 
        [=](const std::string &text) { ui->le_test->setText(text.c_str()); });

The effect is as follows:

keyboard-15

III. Frequently Questions

Issue 1: The input box in the dialog cannot use the keyboard, clicking the keyboard makes it disappear.

Cause: The blocking execution of QDialog::exec(); preemptively consumes keyboard focus events.To achieve this, you need to use QDialog::open() in conjunction with QEventLoop::exec().

Solution:

Original Code:
CustomInputDialog dialog(s1, s2);
if(dialog.exec() == QDialog::Accepted){
    ....
}

Solution: Override the CustomInputDialog::exec method.
int CustomInputDialog::exec() {
    QEventLoop loop;
    connect(this, &QDialog::finished, this, [&]{
        loop.exit();
    });
    open(); ///< exec captures keyboard focus; switch to open.
    loop.exec(QEventLoop::DialogExec);
    return result();
}