comp.lang.ada
 help / color / mirror / Atom feed
* Glade but more flexible
@ 2022-01-30 13:20 ldries46
  2022-01-30 13:59 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 2+ messages in thread
From: ldries46 @ 2022-01-30 13:20 UTC (permalink / raw)


I like the way Glade can be used for designing a gtk GUI. But There is a 
problem I cannot do what I like to do. The best way to illustrate that 
is when I want to design a multi language program. I than need the 
string variables in some kind of array. For instance Language_Open(lan) 
instead of Language_Open where:
Language_Open(English) := To_Unbounded_String("Open");
Language_Open(Deutsch) := To_Unbounded_String("Offnen");
etc,
where lan := (English, Deutsch, ...);

This can be reached if Glade can also produce an Ada program output 
where you can edit output simply or when a program Glade2Ada would be 
created which translates the Glade Output to Ada, where you can edit the 
Ada program accordingly.
The latest version can also be transfered to other language, so Glade2C, 
Glade2python etc.

The question is is something like that available or is it an idea to 
create such a thing for the people who created Glad

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Glade but more flexible
  2022-01-30 13:20 Glade but more flexible ldries46
@ 2022-01-30 13:59 ` Dmitry A. Kazakov
  0 siblings, 0 replies; 2+ messages in thread
From: Dmitry A. Kazakov @ 2022-01-30 13:59 UTC (permalink / raw)


On 2022-01-30 14:20, ldries46 wrote:
> I like the way Glade can be used for designing a gtk GUI. But There is a 
> problem I cannot do what I like to do. The best way to illustrate that 
> is when I want to design a multi language program. I than need the 
> string variables in some kind of array. For instance Language_Open(lan) 
> instead of Language_Open where:
> Language_Open(English) := To_Unbounded_String("Open");
> Language_Open(Deutsch) := To_Unbounded_String("Offnen");
> etc,
> where lan := (English, Deutsch, ...);
> 
> This can be reached if Glade can also produce an Ada program output 
> where you can edit output simply or when a program Glade2Ada would be 
> created which translates the Glade Output to Ada, where you can edit the 
> Ada program accordingly.
> The latest version can also be transfered to other language, so Glade2C, 
> Glade2python etc.
> 
> The question is is something like that available or is it an idea to 
> create such a thing for the people who created Glad

[ Necessary litany: never ever use Glade ]

Regarding localization I am using widget style properties for the purpose:

1. All application widgets are derived, usually from grid or dialog etc.

2. All widgets define a new class:

    Initialize_Class_Record

3. All texts (and other parameters) of a widget are style properties 
from the class:

    Install_Style_Property
    (  Class_Ref (... the widget's type ...),
       Gnew_String
       (  Name    => "hello-label",
          Nick    => "hello",
          Blurb   => "The label 'hello'",
          Default => "Hello"
    )  );

4. Provide Style_Updated to handle style-updated:

    procedure Style_Updated
              (  Widget : access My_Custom_Widget
              )  is
    begin
       Widget.Hello_Label.Set_Text
       (  Style_Get (Widget, "hello-label")
       );
       ...

 From there you set all texts of the widget and all other properties. 
E.g. the label text is set from the value of the "hello-label".

5. Connect to Style_Updated

    Connect
    (  Widget,
       "style-updated",
       To_Marshaller (Style_Updated'Access)
    );

6. Call to Style_Updated at the end of Initialize (called from Gtk_New)

7. Upon application start load a CSS file from some predefined location, 
e.g. from user directory:

    Load_CSS_File

This is basically all. If you want to change a text, e.g. from English 
to German, you simply edit the CSS file.

MyCustomWidget {
    -MyCustomWidget-hello-label: "Hallo";

You can reload CSS any time, the widgets will get the "style-updated" 
event and Style_Updated will change the texts.

No texts in the application code, except for the English default 
fallback, of course.

BTW, in GTK it is possible to walk down the widget tree and generate a 
CSS template with all style properties of. I add this to command-line 
arguments. So adding a new language you will not miss a text (a poor 
man's safety you would get in Ada for free if an enumeration type were 
used for the texts).

The GTK CSS overview is here:

    https://docs.gtk.org/gtk3/css-overview.html

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-30 13:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-30 13:20 Glade but more flexible ldries46
2022-01-30 13:59 ` Dmitry A. Kazakov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox