Re: Conditional widget style

ChordPro Team <[email protected]> Fri, 4 Feb 2022 12:03:09 +0100
Newsgroups gmane.comp.python.wxglade
Organization ChordPro
Message-ID <[email protected]>
Hi Dietmar,

Thanks for the suggestions.

On Thu, 3 Feb 2022 18:49:53 +0100, Dietmar Schwertberger wrote:

> I think that this is one of the cases where a later call to 'SetStyle' 
> will not work.

Assuming you mean 'SetWindowStyle', yes.

> You may either "simulate" a readonly text ctrl or replace it.

Replacing has the disadvantage that you need to transfer tooltips and
events as well.

> Try code like this in "Code to inserted after":

I set the widget style to wxTE_READONLY and (remember, this is Perl) this
'insert after' code:

if ( $^O =~ /darwin/ ) {
  $self->{t_configfiledialog}->Destroy;
  $self->{t_configfiledialog} = Wx::TextCtrl->new($self, wxID_ANY, "");
}

The generated code then becomes:

$self->{t_configfiledialog} = Wx::TextCtrl->new($self, wxID_ANY, "",
    wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
$self->{t_configfiledialog}->SetToolTipString(_T("...tooltip..."));
if ( $^O =~ /darwin/ ) {
  $self->{t_configfiledialog}->Destroy;
  $self->{t_configfiledialog} = Wx::TextCtrl->new($self, wxID_ANY, "");
}
$self->{sz_configfile}->Add($self->{t_configfiledialog}, 1, wxEXPAND, 0);

This should work, events are attached later, but as you can see the tooltip
is already set so this needs to be copied. Okay, that is doable.

> Alternatively, you could use a CustomWidget.
> 
>  - instance class: TextCtrl
>  - Arguments: $parent, $id, style=style
>  - Code to be inserted before: style = wx.TE_READONLY if
> sys.platform=="darwin" else 0

Even though you prefer the other alternatives, I like this one.

However, the instance class dialog (when creating the widget) does not
accept Perl syntax for the class. When entering "wxTextCtrl" it ends up as
"wxTextCtrl" in the code while for the built-in widgets this is
automatically converted to "Wx::TextCtrl" when generating Perl.
Not a real problem since the class name can be changed in the Common
Instance class text field.

In the Widget tab the following arguments

- $parent
- $id
- ""
- wxDefaultPosition
- wxDefaultSize
- $^O =~ /darwin/ ? 0 : wxTE_READONLY

Seems to work fine.

Note that entering "" (that's two &dquot;s) in the arguments in the Widget
tab yields an error dialog (see at end) that apparently does no (real) harm.

Great job, thanks!

----error details----
ERROR   : None
An unexpected error occurred!

Exception type:      <class 'AttributeError'>
Exception details:   'NoneType' object has no attribute 'finalize'

Application stack traceback:
  File "/home/jv/wrk/wxGlade/wxGlade/new_properties.py", line 2947, in
on_cell_changed self._on_value_edited(row, col, value)                #
this can add a row File "/home/jv/wrk/wxGlade/wxGlade/new_properties.py",
line 2978, in _on_value_edited common.history.property_changed(self)
  File "/home/jv/wrk/wxGlade/wxGlade/history.py", line 445, in
property_changed item = self._finalize_item()
  File "/home/jv/wrk/wxGlade/wxGlade/history.py", line 434, in
_finalize_item item.finalize(self._monitor)

Date and time:       2022-02-04T11:36:53.738036
Python version:      3.9.9
wxPython version:    4.0.7
wxWidgets platform:  __WXGTK__
wxGlade version:     1.1.0pre
----end----


_______________________________________________
wxGlade-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wxglade-general