在此文中
This class Banana.Ui contains methods to interact with user interface.
createPropertyEditor(title, params, [dialogId])
Create a dialog to set given params. To display the dialog use the method exec(). To get the modified parameters use the method getParams().
It used in combination of the openPropertyEditor.
For more information on how tu use see:
Public slots:
- void addCustomCommand(functionName, commandLabel)
//allows to call a function of the script from a command in the dialog - void addImportCommand()
//allows to import the extension's settings from other files - QJSValue getParams()
//returns the params of the dialog - void setParams(QSJValue params)
//allows to set the params of the dialog
createUi(uiFilePath)
Read the file uiFilepath and return an object representing the dialog. The uiFileName has to be in the same directory as the running script. You can also load a ui file from the table documents with the prefix 'documents:', ex.: 'documents:calculator.ui', For details and examples see Script dialogs or the tutorial JavaScript Tutorial 1.
Every widget defined in the ui file is exposed to the script environment and you can interact with them like in c++ code. You find further details under Banana.Ui.Widget.
If an error occurred undefined is returned.
Example:
@includejs = ch.banana.calculator.dialog.js; // Define the class Calculator
// that control the .ui file
...
var calculatorUi = Banana.Ui.createUi("ch.banana.calculator.dialog.ui");
var calcJs = new Calculator(calculatorUi);
Banana.application.progressBar.pause(); // Pause wait cursor
calclatorUi.exec(); // Show the dialog
Banana.application.progressBar.resume(); // Restart wait cursor
getDouble(title, label [, value , min, max, decimals])
Show the user a dialog asking to insert a double. Return the inserted double or undefined if the user clicked cancel.
var a = Banana.Ui.getDouble("Title text", "Label text");
var b = Banana.Ui.getDouble("Title text", "Label text", "10.0");
getInt(title, label [, value, min, max, steps])
Show the user a dialog asking to insert an integer. Return the inserted integer or undefined if the user clicked cancel.
var a = Banana.Ui.getInt("Title text", "Label text");
var b = Banana.Ui.getInt("Title text", "Label text", "5", "1", "10","1");
getItem(title, label, items [, current, editable])
Show the user a combo box dialog asking to select an item from a list. Return the selected item or undefined if the user clicked cancel.
var value = Banana.Ui.getItem("Input", "Choose a value", ["a","b","c","d","e"], 2, false);
getItems(title, label, items [, selectedItems])
Show the user a list dialog asking to select one or more items from a list. Return the selected items or undefined if the user clicked cancel.
var value = Banana.Ui.getItems("Input", "Choose one or more values", ["a","b","c","d","e"], ["b","c"]);
Since: Banana Experimental 9.1.0
getPeriod(title, startDate, endDate [, selectionStartDate, selectionEndDate, selectionChecked])
Show the user a dialog asking to select a period like the tab Period. Return an object with the atributes 'startDate', 'endDate' and 'hasSelection' or undefined if the user clicked cancel. Date values are in the format "YYYY-MM-DD".
var period = Banana.Ui.getPeriod("Title text", "2016-01-01", "2016-12-31");
if (period) {
var selectedStartDate = period.startDate; // return the start date of the selected period
var selectedEndDate = period.endDate; // return the end date of the selected period
}
getText(title, label [, text])
Show the user a dialog asking to insert a text. Return the inserted text or undefined if the user clicked cancel.
var text = Banana.Ui.getText("Title text","Label text");
openPropertyEditor(title, params, [dialogId])
For more information:
Show the user a dialog asking to set given params.
Return the modified params or undefined if the user clicked cancel.
- See Invoice Extension containing examples with this method.
- see the structure example on GitHub
showHelp(uiFileName)
Show the help of a dialog. The help is loaded from the Banana.ch web site.
showInformation(title, msg)
Show the user an information dialog.
Banana.Ui.showInformation("Information", 'Insert here the text of the information.');
showQuestion(title, question)
Show the user a question dialog with Yes and No buttons. Return true if the user clicked Yes, otherwise false.
var answer = Banana.Ui.showQuestion("Question title", "Insert here the text of the question");
showText(text)
Show the given text in a dialog. The text can be plain text of html and span over multiple lines. If the text is in html the title is taken form the html. The dialog enables the user to save the content in the formats html, pdf, odf and txt.
The use of pixels to set the font sizes is not supported, the text is not rendered properly.
// Normal text
Banana.Ui.showText("Insert here the text.");
// Html text
Banana.Ui.showText('<html><header><title>This is title</title></header><body>Hello world</body></html>');
showText(title, text)
This is an overloaded function.
Show the given text in a dialog with the given title. The text can be plain text of html and span over multiple lines. The dialog enables the user to save the content in the formats html, pdf, odf and txt.
showText(title, text, options)
This is an overloaded function.
Show the given text in a dialog with the given title. The text can be plain text of html and span over multiple lines. The dialog enables the user to save the content in the formats html, pdf, odf and txt.
Through the object options it is possible to set the following additional parameters:
- codecName: the name of the codec to be used in case the content will be saved as txt file. Default is 'UTF-8'
- outputFileName: the file name without path to be used in case the content will be saved. The path is current open document path or the user's document path.
var options = {
'codecName' : "latin1", // Default is UTF-8
'outputFileName' : "prova.txt"
}
Banana.Ui.showText("Title", "some text...", options);