Gtk.stock is deprecated, what's the alternative? - gtk

I've been learning to develop to Gtk and most of the examples online suggests the use of Gtk.stock icons. However, its use produces warnings that it has been deprecated and I can't find the alternative to these icons.
Code examples are:
open_button:Gtk.ToolButton = new ToolButton.from_stock(Stock.OPEN)
open_button.clicked.connect (openfile)
new_button:Gtk.ToolButton = new ToolButton.from_stock(Stock.NEW)
new_button.clicked.connect (createNew)
save_button:Gtk.ToolButton = new ToolButton.from_stock(Stock.SAVE)
save_button.clicked.connect (saveFile)
That generates error as:
/tmp/text_editor-exercise_7_1.vala.c:258:2: warning: 'GtkStock' is deprecated [-Wdeprecated-declarations]
_tmp1_ = (GtkToolButton*) gtk_tool_button_new_from_stock (GTK_STOCK_OPEN);
Which is the alternative and how it would look in the code above?

GTK+3 has moved over to the freedesktop.org Icon Naming Specification and internationalised labels. Taking Gtk.Stock.OPEN as an example. The GNOME Developer documentation for GTK_STOCK_OPEN gives two replacements:
GTK_STOCK_OPEN has been deprecated since version 3.10 and should not be used in newly-written code. Use named icon "document-open" or the label "_Open".
The Named Icon Method
The named icon method would be something like:
var open_icon = new Gtk.Image.from_icon_name( "document-open",
IconSize.SMALL_TOOLBAR
)
var open_button = new Gtk.ToolButton( open_icon, null )
The Label Method
The label method makes use of gettext to translate the label in to the current runtime language of the program. This is indicated by the underscore before the label. The line in your program would be:
var open_button = new Gtk.ToolButton( null, dgettext( "gtk30", "_Open") )
gettext uses domains, which are files containing the translations. The Gtk+3 domain is gtk30. You will also need to add a line at the beginning of your program to change the default locale for the C language, which is US English ASCII, to the locale of the run time environment:
init
Intl.setlocale()
To compile the Genie program you will need to set the default domain for gettext. This is usually set to nothing:
valac -X -DGETTEXT_PACKAGE --pkg gtk+-3.0 my_program.gs
When you run your program you will get the "_Open" translated to your locale. You can also change the locale. If you have the French locale installed then running the program with:
LC_ALL=fr ./my_program
will have the "_Open" label appear in French.
You may see in examples _( "_OPEN" ). The _() is a function like dgettext but uses a default domain. You may want to keep the default domain to the translation file for your own program. Using _( "_translate me" ) is a bit less typing that dgettext( "mydomain", "_translate me" ). To set the default domain in Genie add a line before init:
const GETTEXT_PACKAGE:string = "mydomain"
init
Intl.setlocale()

Related

How to access the child nodes in a device tree (DTS) in Zephyr using DT_FOREACH_CHILD

I'm developing an application for an nRF52 SoC to access some external devices, kind of detectors in this case, so I have defined a custom format (and its corresponding yaml file) for my device access description node. It is kind of:
n: detectors {
compatible = "foo-detectors";
// Definition of first channel
det0: det_0 {
irq-pins = <13 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
label = "Bar detector channel 1";
};
// Definition of second channel
det1: det_1 {
irq-pins = <17 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
label = "Bar detector channel 2";
};
};
Suppose I have a structure definition for holding data about the pins to which those devices are physically connected, say:
struct foo_detector_desc {
int irqpin;
int irqpin_flags;
}
Using Zephyr macros, I can use from my code the individual values for those nodes. For instance, DT_PROP_BY_IDX(DT_NODELABEL(det0), irq_pins, 0) expands to 13, DT_PROP_BY_IDX(DT_NODELABEL(det0), irq_pins, 1) expands to the value of OR'ed flags GPIO_PULL_UP | GPIO_ACTIVE_LOW.
But I don't want to create a ten-page code full of conditionals in the form DT_NODE_EXISTS(DT_ALIAS(det#)), but something more compact, flexible and maintainable.
I came across Zephyr macro DT_FOREACH_CHILD that is intended for being used in that scenario with which I can create a list with the labels, as showcased in the example embedded in the documentation:
#define LABEL_AND_COMMA(node_id) DT_LABEL(node_id),
const char *child_labels[] = {
DT_FOREACH_CHILD(DT_NODELABEL(n), LABEL_AND_COMMA)
};
Trying to use that for filling a static structures array, I tried following code but, yet it expands to two elements in the array, the structure fields are not initialised with desired values.
#define PIN_INFO_AND_COMMA(node_id) \
{ \
.pin=DT_PROP_BY_IDX(node_id, irq_pins, 0),\
.flags=DT_PROP_BY_IDX(node_id, irq_pins, 1),\
},
const struct detector_data _det_data[] = {
DT_FOREACH_CHILD(DT_NODELABEL(n), PIN_INFO_AND_COMMA)
};
I'm using Visual Studio Code with the nRF Connect plugin.
Is there a way to generate/see how those macros expand when compiled?
What is the correct way for initialising the structure fields (pins, flags)?
BR
It is possible to expand the macros one level at a time in VS Code. It is needed to click over the macro, then select it by double-clicking on it, and a bulb light will, eventually, show up. The option Insert Macro will replace the macro with its expansion.
Regarding using the DTS in code, the code I wrote in my previous post is OK, but I think I found a bug in the debugger. If I don't include any code using the value of _det_data, the debugger doesn't say the constant was optimised-out and displays wrong values when inspecting its content. That made me waste a lot of time.
For anyone interested on using DTS files for nRF devices in Zephyr, I posted all details in a thread in Nordic's developers forum (here).
BR

SAP custom translations for standard SAPUI5 application

I am currently implementing an extension to a standard application from SAP Marketing.
The extension contains new texts that need to be translated into different languages. In my previous extensions I could use the translation key of the standard application for my extension as well. The first line in the i18n.properties file in this case was always structured as follows:
# SAPUI5 TRANSLATION-KEY XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
However, in the standard app that I'm currently editing, it looks like this:
# This is the resource bundle for Campaigns
# __ldi.translation.uuid = 8e965d5e-c905-4b60-ac2a-205abb14046
In transaction se63, the translation key (is it even a translation key?) is not found - either with hyphens or without. Furthermore, in the standard app, the translations are kept in a single file for each language (e.g., i18n_de.properties). That's why I'm not sure if there's even a translation key for this standard app.
I don't want to create a new translation key for my extension and use this one. Once I did this, all the translations of the standard app had to be maintained for the new translation key as well.
Is anyone familiar with this type of translation? How can I maintain the translations for my extension?
Best Regards,
Christian
I found some solution to my problem:
I generated a new translation key by running program /UI5/TEXT_FILE_GEN_TRANS_KEY in transaction se38
I created a new folder i18n and added a i18nCustom.properties file to it. Then I added the translation key and default translations to the file just like for a regular i18n.properties file.
In the next step, I added the following code to the sap.ui5 property of the extension's manifest.json file to initiate the custom translation file:
"models": {
"i18nCustom": {
"type": "sap.ui.model.resource.ResourceModel",
"settings": {
"bundleName": "<Your Component>.i18n.i18nCustom"
}
}
}
Please note that you have to use something like {i18nCustom>property} in your view now instead of using i18n model.
To enhance the standard translation file with the custom one, I added the following code to the BaseController. You could also add the code only in the controller whose view is using the custom translations.
onBeforeRendering: function() {
var i18n = this.getModel("i18n"); // Get the standard i18n file
var sBundleURL = this.getModel("i18nCustom").getResourceBundle().oUrlInfo.url;
i18n.enhance({bundleUrl:sBundleURL}); // Merge the custom i18n file with the standard one
}
Hope this helps if someone has the same problem.

decreaseIndentPattern has no effect

I am trying to create a TextMate bundle for a new language but am having issues with the decreaseIndentPattern. It seems to have no effect whatsoever, even with a trivial example:
increaseIndentPattern = 'start';
decreaseIndentPattern = 'end';
I have set the scope correctly and the other settings in the same file do work (including the increaseIndentPattern). Am I missing something?
Found out that to enable indentation correction on text based files (my scope starts with text), the following is also required:
disableIndentCorrections = :false;

Get font of recognized character with Tesseract-OCR

Is it possible to get the font of the recognized characters with Tesseract-OCR, i.e. are they Arial or Times New Roman, either from the command-line or using the API.
I'm scanning documents that might have different parts with different fonts, and it would be useful to have this information.
Tesseract has an API WordFontAttributes function defined in ResultIterator class that you can use.
Based on nguyenq's answer i wrote a simple python script that prints the font name for each detected char. This script uses the python lib tesserocr.
from tesserocr import PyTessBaseAPI, RIL, iterate_level
def get_font(image_path):
with PyTessBaseAPI() as api:
api.SetImageFile(image_path)
api.Recognize()
ri = api.GetIterator()
level = RIL.SYMBOL
for r in iterate_level(ri, level):
symbol = r.GetUTF8Text(level)
word_attributes = r.WordFontAttributes()
if symbol:
print(u'symbol {}, font: {}'.format(symbol, word_attributes['font_name']))
get_font('logo.jpg')

ICU custom transliteration

I am looking to utilize the ICU library for transliteration, but I would like to provide a custom transliteration file for a set of specific custom transliterations, to be incorporated into the ICU core at compile time for use in binary form elsewhere. I am working with the source of ICU 4.2 for compatibility reasons.
As I understand it, from the ICU Data page of their website, one way of going about this is to create the file trnslocal.mk within ICUHOME/source/data/translit/ , and within this file have the single line TRANSLIT_SOURCE_LOCAL=custom.txt.
For the custom.txt file itself, I used the following format, based on the master file root.txt:
custom{
RuleBasedTransliteratorIDs {
Kanji-Romaji {
file {
resource:process(transliterator){"custom/Kanji_Romaji.txt"}
direction{"FORWARD"}
}
}
}
TransliteratorNamePattern {
// Format for the display name of a Transliterator.
// This is the language-neutral form of this resource.
"{0,choice,0#|1#{1}|2#{1}-{2}}" // Display name
}
// Transliterator display names
// This is the English form of this resource.
"%Translit%Hex" { "%Translit%Hex" }
"%Translit%UnicodeName" { "%Translit%UnicodeName" }
"%Translit%UnicodeChar" { "%Translit%UnicodeChar" }
TransliterateLATIN{
"",
""
}
}
I then store within the directory custom the file Kanji_Romaji.txt, as found here. Because it uses > instead of the → I have seen in other files, I converted each entry appropriately, so they now look like:
丁 → Tei ;
七 → Shichi ;
When I compile the ICU project, I am presented with no errors.
When I attempt to utilize this custom transliterator within a testfile, however (a testfile that works fine with the in-built transliterators), I am met with the error error: 65569:U_INVALID_ID.
I am using the following code to construct the transliterator and output the error:
UErrorCode status = U_ZERO_ERROR;
Transliterator *K_R = Transliterator::createInstance("Kanji-Romaji", UTRANS_FORWARD, status);
if (U_FAILURE(status))
{
std::cout << "error: " << status << ":" << u_errorName(status) << std::endl;
return 0;
}
Additionally, a loop through to Transliterator::countAvailableIDs() and Transliterator::getAvailableID(i) does not list my custom transliteration. I remember reading with regard to custom converters that they must be registered within /source/data/mappings/convrtrs.txt . Is there a similar file for transliterators?
It seems that my custom transliterator is either not being built into the appropriate packages (though there are no compile errors), is improperly formatted, or somehow not being registered for use. Incidentally, I am aware of the RuleBasedTransliterator route at runtime, but I would prefer to be able to compile the custom transliterations for use in any produced binary.
Let me know if any additional clarification is necessary. I know there is at least one ICU programmer on here, who has been quite helpful in other posts I have written and seen elsewhere as well. I would appreciate any help I can find. Thank you in advance!
Transliterators are sourced from CLDR - you could add your transliterator to CLDR (the crosswire directory contains it in XML format in the cldr/ directory) and rebuild ICU data. ICU doesn't have a simple mechanism for adding transliterators as you are trying to do. What I would do is forget about trnslocal.mk or custom.txt as you don't need to add any files, and simply modify root.txt - you might file a bug if you have a suggested improvement.