Page 1 of 2

Display of wxStaticText in GTK+3

Posted: Sun Mar 22, 2020 10:26 am
by raananb
On Mint 19.3, with GTK+3 and wxWidgets-3.1.3, a wxStaticText is created with the following statement:

Code: Select all

label_QuotesOn = new wxStaticText( itemDialog1, wxID_STATIC, _("Latest_quote: 99-99-9999 99h99"), wxDefaultPosition, wxDefaultSize, 0 );
label_QuotesOn->Show(false);
itemBoxSizer3->Add(label_QuotesOn, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
'label_QuotesOn' is hidden since the date will only be known later in the application. The initial value corresponds to the Date/Time format which the object will take later on, and wxRESERVE_SPACE_EVEN_IF_HIDDEN is set for this object.

In the course of execution of the application, 'label_QuotesOn' is modified by the following code:

Code: Select all

wxString lastQuote = m_data.ShareQuoteDates->Last(); // '20/03/2020 17h43'
lastQuote.Replace("/","-"); // '20-03-2020 17h43'
    
wxString label = label_QuotesOn->GetLabel(); // 'Latest_quote: 99-99-9999 99h99'
    
int pos = label.Find("9");

label.Truncate(pos);
label.Append(lastQuote); // Should be 'Quotes on: 20-03-2020 17h43'

label_QuotesOn->Show();    
label_QuotesOn->SetLabel(label);
label_QuotesOn->Fit();

Fit();
Layout();
Refresh();
Update();
The debugger shows that 'label' taks the expected value ('Latest_quote: 20-03-2020 17h43');

Code: Select all

Thread 1 "AccountsManager" hit Breakpoint 1, RapportPortefeuille::OnTimerSharesQuotes (this=0x5555563b9400, event=...) at rapportportefeuille.cpp:505
505	    lastQuote.Replace("/","-");
(gdb) p lastQuote
$1 = {static npos = 18446744073709551615, m_impl = L"20/03/2020 17h43", 
  m_convertedToChar = {m_str = 0x0, m_len = 0}}
(gdb) n
507	    wxString label = label_QuotesOn->GetLabel(); // "Latest_quote: 99-99-9999 99-99"
(gdb) p lastQuote
$2 = {static npos = 18446744073709551615, m_impl = L"20-03-2020 17h43", 
  m_convertedToChar = {m_str = 0x0, m_len = 0}}
(gdb) n
509	    int pos = label.Find("9");
(gdb) p label
$3 = {static npos = 18446744073709551615, 
  m_impl = L"Latest_quote: 99-99-9999 99-99", m_convertedToChar = {
    m_str = 0x0, m_len = 0}}
(gdb) n
511	    label.Truncate(pos);
(gdb) n
512	    label.Append(lastQuote);
(gdb) n
514	    label_QuotesOn->SetLabel(label);
(gdb) p label
$4 = {static npos = 18446744073709551615, 
  m_impl = L"Latest_quote: 20-03-2020 17h43", m_convertedToChar = {
    m_str = 0x0, m_len = 0}}
(gdb) c
However, the display shows an incomplete value for 'label': 'Latest quote:'

http://www.pixname.com/0001/Screenshot% ... -09-37.png

On Windows & OSX this code produces the expected display. Is there any reason why GTK+3 does not?

Re: Display of wxStaticText in GTK+3

Posted: Sun Mar 22, 2020 4:08 pm
by ONEEYEMAN
Hi,
What is an exact GTK+ version do you use?
What happens if you omit wxRESERVE_SPACE_EVEN_IF_HIDDEN?

Thank you.

Re: Display of wxStaticText in GTK+3

Posted: Sun Mar 22, 2020 4:21 pm
by raananb
Hi and thanks for responding

Everything was built with GTK+3, but I do not know how to determine a finer definition of the version.

wxRESERVE_SPACE_EVEN_IF_HIDDEN seems to have no effect, the result is the same if it is set or not.

Re: Display of wxStaticText in GTK+3

Posted: Sun Mar 22, 2020 6:41 pm
by doublemax

Code: Select all

label_QuotesOn->Show();    
label_QuotesOn->SetLabel(label);
label_QuotesOn->Fit();

Fit();
Layout();
Try to print the value of "label_QuotesOn->GetSize().x" and "label_QuotesOn->GetMinSize().x" after each of these steps. Maybe it gives a clue.

Re: Display of wxStaticText in GTK+3

Posted: Sun Mar 22, 2020 7:25 pm
by ONEEYEMAN
Hi,
In the meantime why not use a read-only wxDateTimePicker?

Thak you.

Re: Display of wxStaticText in GTK+3

Posted: Sun Mar 22, 2020 9:34 pm
by raananb
@ONEEYEMAN: The value I am inserting comes from the web, so a picker is not relevant.

@doublemax, your hunch was correct.

I inserted wxMessageBoxes (the numbers 513,515... are of the code lines):

label.Truncate(pos);
label.Append(lastQuote);
wxMessageBox(wxString::Format("513 %d %d",label_QuotesOn->GetSize().x, label_QuotesOn->GetMinSize().x));
label_QuotesOn->Show();
wxMessageBox(wxString::Format("515 %d %d",label_QuotesOn->GetSize().x, label_QuotesOn->GetMinSize().x));
label_QuotesOn->SetLabel(label);
wxMessageBox(wxString::Format("517 %d %d",label_QuotesOn->GetSize().x, label_QuotesOn->GetMinSize().x));
label_QuotesOn->Fit();
wxMessageBox(wxString::Format("519 %d %d",label_QuotesOn->GetSize().x, label_QuotesOn->GetMinSize().x));

the results are:
513 201 -1
515 201 -1
517 289 -1
519 289 -1

I noted that
when at line 515, the display is of the label just after truncation.
when at line 517 the display becomes full, as expected

Somehow wxMessageBox makes the problem disappear.

The problem is solved (after removing wxMessageBox statements) with

label_QuotesOn->SetMinSize(wxSize(289,-1));

However, 289 has to be put in manually. The following sequence does not work.

label_QuotesOn->SetLabel(label);
int w = label_QuotesOn->GetSize().x;
label_QuotesOn->SetMinSize(wxSize(w,-1));
label_QuotesOn->Fit();label_QuotesOn->Show();
label_QuotesOn->Centre();

Edit:
changing
int w = label_QuotesOn->GetSize().x; to
const int w = label_QuotesOn->GetSize().x;
makes no difference.
But changing
int w = label_QuotesOn->GetSize().x; to
const int w = 289;
works.

How can I set the minsize dynamically, once the real size is known?

This problem does not exist in Windows/Osx, where the sizing is automatic ; should it be considered a GTK+3 bug?

Re: Display of wxStaticText in GTK+3

Posted: Sun Mar 22, 2020 10:30 pm
by ONEEYEMAN
Hi,
Can you try to find the GTK version with this link?

Thank you.

Re: Display of wxStaticText in GTK+3

Posted: Mon Mar 23, 2020 8:57 am
by raananb
Hi,
Link missing
Thanks

Re: Display of wxStaticText in GTK+3

Posted: Mon Mar 23, 2020 10:19 am
by DavidHart
Hi,
Everything was built with GTK+3, but I do not know how to determine a finer definition of the version.
Two answers:

1) The standard way, on a debianish distro like ubuntu, is to ask 'apt'. I just did here (debian buster):
apt policy libgtk-3*
which produced lines like:
Installed: 3.24.5-1
but a simpler, gui way is to search using synaptic.

2) For any running wx program, do Ctrl-Alt-Middleclick over it. That should produce a dialog with the wx version information, and also the gtk+ versions used both to build and to run the program.

Regards,

David

Re: Display of wxStaticText in GTK+3

Posted: Mon Mar 23, 2020 10:25 am
by raananb
Surfing the internet, I came across the issue webkit/webkit2: webkit is single process and webkit2 is multiprocess, which can explain the unexpected display.

How can I control the webkit which is used?

Re: Display of wxStaticText in GTK+3

Posted: Mon Mar 23, 2020 10:32 am
by raananb
apt policy libgtk-3* produces

Installed: 3.22.30-1ubuntu4

Re: Display of wxStaticText in GTK+3

Posted: Tue Mar 24, 2020 1:36 am
by ONEEYEMAN
Hi,
3 questions:

1. Why do you play with all those truncation:

Code: Select all

wxString label = label_QuotesOn->GetLabel(); // 'Latest_quote: 99-99-9999 99h99'
    
int pos = label.Find("9");

label.Truncate(pos);
label.Append(lastQuote); // Should be 'Quotes on: 20-03-2020 17h43'
Why not just do:

Code: Select all

label = lastQuote;
?

2.

Code: Select all

label_QuotesOn->Show();    
label_QuotesOn->SetLabel(label);
label_QuotesOn->Fit();
What happens if you call "SetLabel()" first?

It is possible that GTK is waiting for the label to be displayed in order to calculate the proper size of the text.

3. Why did you say:
@ONEEYEMAN: The value I am inserting comes from the web, so a picker is not relevant.
?

It doesn't matter where the date is coming from. This is the date/time object and the best way to display it is either wxCalendarCtrl or wxDateTimePicker. It can be read-only or disabled to indicate there shouldn't be any editing. But it's a natural choice.

Thank you.

Re: Display of wxStaticText in GTK+3

Posted: Tue Mar 24, 2020 11:12 am
by raananb
@ONEEYEMAN
Hi,

1.
The original code was very simple:
wxString label = "Values on: *";
label.Replace("*",m_data.ValuesDate); // this explains why a picker is not appropriate.
label_ValuesOn->SetLabel(label);

That works fine on Window and OSX, and I exepcted it to work on GTK, but it does not.

I then tried to do things differently for GTK:

I created the wxStaticText with "Values on: 99-99-9999 99h99", hoping that this will ensure a correct size.
I then replaced the pattern '99-99-9999 99h99' with a date (european non-Iso format, eg '24-03-2020 15h23').

This does not work either, and the only display I am getting is of "Values on: ".

2. I tries different sequences, including the one you suggest, but none worked.

Now, when I inserted the wxMessageBox statement (see earlier post), the display became correct.

The display also became correct when I inserted SetMinSize(wxSize(289,-1)).

It did not work when the size was inserted dynamically, by inserting in different code sequences:
int w = label_ValuesOn->GetSize().x;
label_ValuesOn->SetMinSize(wxSize(w,1));

This makes me think that the problem may come from the webkit. webkit2 is described (in https://stackoverflow.com/questions/196 ... -gtk2-gtk3) as multi-process, contrary to webkit1 which is described as monoprocess. The process retrieving the 'label' value after it is truncated, not waiting for it to be completes with the date. The fact that the display bacame correct when wxMessageBox or SetMinSize(wxSize(289,-1)) may indicate a process which behaves differently.

If you know how to force the use of webkit1 instead of webkit2, please let me know.

Thanks.

Re: Display of wxStaticText in GTK+3

Posted: Tue Mar 24, 2020 11:25 am
by doublemax
Webkit is the browser component. It's not relevant here.

Re: Display of wxStaticText in GTK+3

Posted: Tue Mar 24, 2020 3:54 pm
by ONEEYEMAN
Hi,
Moreover, WebKit1 is outdated and is not supported anymore.

Now I still don't understand why you need the wxStaticText.
You can use read-only disabled wxDatePicker + wxTimePicker.

Thank you.