Built-in Keyboard for AuboCaps Guide
I. Types of Plugin Keyboard:
- 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);
- 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);
- Expression keyboard
void registerExpressionKeyboard(
QWidget *wd, std::function<ExpressionPtr(void)> init_cb = nullptr,
std::function<void(ExpressionPtr result_value)> result_cb = nullptr);
- 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);
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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
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
view
classes of program and installation nodes)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 thecontribution
class of the program or installation node, obtain theKeyboardManager
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:
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();
}