comp.lang.ada
 help / color / mirror / Atom feed
* Filling a listsore  real time
@ 2014-02-09 15:13 ldries46
  2014-02-09 17:16 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 4+ messages in thread
From: ldries46 @ 2014-02-09 15:13 UTC (permalink / raw)


In my program I want a combobox with a liststore that is every time the 
dialog in which it is called has a different  number of of iters and another 
value within the iter. In this case the iters are from an array of 
characters.
It looks like the Routine Set_Value  or Set_Char is not correct working 
because I checked the input for Set_Char gchar(ch) gives me the correct 
Character. append also works correct, I get the correct number of items but 
the items should be 1, 2, 3, 4, 5, 6, 7, 8, 9 and they are 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0

n1 := 0;
for nn in 1 .. max loop
   if not Grid(x_vak, y_vak).impossible(n1) then
      ch := CHARACTER'Val(Symbols(n1 ,Set));
      Set_Char(G_char, gchar(ch));
      append(CH_List, CH_Iter);
      Set_Value(CH_List, CH_Iter, 0, G_char);
   end if;
   n1 := n1 + 1;
end loop;

Can anyone tell me what I am doing wrong. The only tutorials I can find who 
are a little bit close to my problem are for c or python.

L. Dries 

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

* Re: Filling a listsore  real time
  2014-02-09 15:13 Filling a listsore real time ldries46
@ 2014-02-09 17:16 ` Dmitry A. Kazakov
  2014-02-10  9:41   ` ldries46
  0 siblings, 1 reply; 4+ messages in thread
From: Dmitry A. Kazakov @ 2014-02-09 17:16 UTC (permalink / raw)


On Sun, 9 Feb 2014 16:13:03 +0100, ldries46 wrote:

> In my program I want a combobox with a liststore that is every time the 
> dialog in which it is called has a different  number of of iters and another 
> value within the iter. In this case the iters are from an array of 
> characters.
> It looks like the Routine Set_Value  or Set_Char is not correct working 
> because I checked the input for Set_Char gchar(ch) gives me the correct 
> Character. append also works correct, I get the correct number of items but 
> the items should be 1, 2, 3, 4, 5, 6, 7, 8, 9 and they are 0, 0, 0, 0, 0, 0, 
> 0, 0, 0, 0
> 
> n1 := 0;
> for nn in 1 .. max loop
>    if not Grid(x_vak, y_vak).impossible(n1) then
>       ch := CHARACTER'Val(Symbols(n1 ,Set));
>       Set_Char(G_char, gchar(ch));
>       append(CH_List, CH_Iter);
>       Set_Value(CH_List, CH_Iter, 0, G_char);
>    end if;
>    n1 := n1 + 1;
> end loop;
> 
> Can anyone tell me what I am doing wrong.

Set_Value needs a GValue. A GValue object must be initialized, set and
finally unset. E.g. a string with GValue:

   Text : GValue;
   Row : Gtk_Tree_Iter;
   Column : GInt := 0;
begin
   Init (Text, GType_String); -- Initialize value as a string
   Set_String (Text, "Hello"); -- Set value into Text
   Store.Append (Row); -- Add a new row to the list store
   Store.Set_Value (Row, Column, Text); -- Set a cell in the store's row
   Unset (Text); -- Free memory allocated for value

Which can be done in a simpler way without Set_Value. Gtk_List_Store_Record
has a ready-to-use operation for setting strings:

   Row : Gtk_Tree_Iter;
   Column : GInt := 0;
begin
   Store.Append (Row); -- Add new row to the store
   Store.Set (Row, Column, "Hello"); -- Set cell in the row

Caution. This seems broken in GtkAda 3.4. AFAIK it causes memory
corruption.

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

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

* Re: Filling a listsore  real time
  2014-02-09 17:16 ` Dmitry A. Kazakov
@ 2014-02-10  9:41   ` ldries46
  2014-02-10 10:28     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 4+ messages in thread
From: ldries46 @ 2014-02-10  9:41 UTC (permalink / raw)


Thanks for the solution. Because I have only single characters in the rows
I used the following code
The column in defining the liststore was set to gchar

Clear(CH_List); -- starting with an empty liststore
n1 := 0;
for nn in 1 .. max loop
   if not Grid(x_vak, y_vak).impossible(n1. ) then
      ch := CHARACTER'Val(Symbols(n1 ,Set));
      Init(G_Char, GType_Char);
      Set_Char (G_Char, gchar(ch));
      append(CH_List, CH_Iter);
      Set_Value (CH_List, CH_Iter, 0, G_Char);
      Unset (G_Char);
   end if;
   n1 := n1 + 1;
end loop;

I expected the result to be a list of characters, instead I got a list of 
ASCII values (exactly the values I had in Symbols(n1 ,Set)) so I know the 
values are at the correct location but the are not presented as I would 
like.
I read the type of the column just before the Clear statement and just after 
and found them both correct (12 = GType_Char).

I think I still haven't got everything correct.

L. Dries


"Dmitry A. Kazakov"  schreef in bericht 
news:1h25bpkw2iqp0.1je0swr7ficvt.dlg@40tude.net...

On Sun, 9 Feb 2014 16:13:03 +0100, ldries46 wrote:

> In my program I want a combobox with a liststore that is every time the
> dialog in which it is called has a different  number of of iters and 
> another
> value within the iter. In this case the iters are from an array of
> characters.
> It looks like the Routine Set_Value  or Set_Char is not correct working
> because I checked the input for Set_Char gchar(ch) gives me the correct
> Character. append also works correct, I get the correct number of items 
> but
> the items should be 1, 2, 3, 4, 5, 6, 7, 8, 9 and they are 0, 0, 0, 0, 0, 
> 0,
> 0, 0, 0, 0
>
> n1 := 0;
> for nn in 1 .. max loop
>    if not Grid(x_vak, y_vak).impossible(n1) then
>       ch := CHARACTER'Val(Symbols(n1 ,Set));
>       Set_Char(G_char, gchar(ch));
>       append(CH_List, CH_Iter);
>       Set_Value(CH_List, CH_Iter, 0, G_char);
>    end if;
>    n1 := n1 + 1;
> end loop;
>
> Can anyone tell me what I am doing wrong.

Set_Value needs a GValue. A GValue object must be initialized, set and
finally unset. E.g. a string with GValue:

   Text : GValue;
   Row : Gtk_Tree_Iter;
   Column : GInt := 0;
begin
   Init (Text, GType_String); -- Initialize value as a string
   Set_String (Text, "Hello"); -- Set value into Text
   Store.Append (Row); -- Add a new row to the list store
   Store.Set_Value (Row, Column, Text); -- Set a cell in the store's row
   Unset (Text); -- Free memory allocated for value

Which can be done in a simpler way without Set_Value. Gtk_List_Store_Record
has a ready-to-use operation for setting strings:

   Row : Gtk_Tree_Iter;
   Column : GInt := 0;
begin
   Store.Append (Row); -- Add new row to the store
   Store.Set (Row, Column, "Hello"); -- Set cell in the row

Caution. This seems broken in GtkAda 3.4. AFAIK it causes memory
corruption.

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



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

* Re: Filling a listsore  real time
  2014-02-10  9:41   ` ldries46
@ 2014-02-10 10:28     ` Dmitry A. Kazakov
  0 siblings, 0 replies; 4+ messages in thread
From: Dmitry A. Kazakov @ 2014-02-10 10:28 UTC (permalink / raw)


On Mon, 10 Feb 2014 10:41:03 +0100, ldries46 wrote:

> Thanks for the solution. Because I have only single characters in the rows
> I used the following code
> The column in defining the liststore was set to gchar
> 
> Clear(CH_List); -- starting with an empty liststore
> n1 := 0;
> for nn in 1 .. max loop
>    if not Grid(x_vak, y_vak).impossible(n1. ) then
>       ch := CHARACTER'Val(Symbols(n1 ,Set));
>       Init(G_Char, GType_Char);
>       Set_Char (G_Char, gchar(ch));
>       append(CH_List, CH_Iter);
>       Set_Value (CH_List, CH_Iter, 0, G_Char);
>       Unset (G_Char);
>    end if;
>    n1 := n1 + 1;
> end loop;
> 
> I expected the result to be a list of characters,

I don't understand this. List store is not a list it is a tree model where
all rows are siblings.

> instead I got a list of 
> ASCII values (exactly the values I had in Symbols(n1 ,Set)) so I know the 
> values are at the correct location but the are not presented as I would 
> like.

Presented by what? By a cell renderer? Which renderer? There are many cell
renderers. If you want to render characters as texts you should use a text
renderer and GType_String. I have no idea how text renderer is supposed to
render GType_Char, probably as a number.

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

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

end of thread, other threads:[~2014-02-10 10:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-09 15:13 Filling a listsore real time ldries46
2014-02-09 17:16 ` Dmitry A. Kazakov
2014-02-10  9:41   ` ldries46
2014-02-10 10:28     ` 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