Opened 2 years ago

Closed 2 months ago

#14450 closed defect (fixed)

"Choice" editor is unexpectedly restricted when used with wx.propgrid.PyEnumProperty

Reported by: mirari Owned by: AW
Priority: normal Milestone:
Component: wxPropertyGrid Version: dev-latest
Keywords: wxEnumProperty index Cc:
Blocked By: Blocking:
Patch: yes

Description

""" ~Minimal example of unexpected behaviour of the "Choice"
editor.
0-eth option of the Choice dropdown menu initially does not respond to selection when used
as editor with wx.propgrid.PyEnumProperty
When overriding OnSetValue in wx.propgrid.PyEnumProperty the problem persists;
if OnSetValue is not overridden the 0-eth option becomes selectable after one other option has first been selected.

System used:
Ubuntu
wx.version: 2.9.3.1 gtk2 (classic)
Python 2.7.3 (default, Apr 20 2012, 22:39:59)
[GCC 4.6.3]

EXPECTED BEHAVIOR:
I would expect all fields to respond to selection from initialization.
Also, according to
http://wxpropgrid.sourceforge.net/docs/pg14/classwxBaseEnumProperty.htm#a04c13f797615778c3359e81c8155200c
the default version of the method OnSetValue does nothing, so overriding it with an empty method should have no effect.

OBSERVED BEHAVIOUR:
When simply setting the editor type to Choice, the 0-eth option does not respond to clicks
in the dropdown menu until another option has first been selected;
the 0-eth option then reponds to selection in the same way as the other fields.

When overriding OnSetValue (e.g. to convert the value to another representation),
the 0-eth option remains unselectable even when another option has first been selected.

Attachments (2)

PropertyGridChoiceBug.py download (4.2 KB) - added by mirari 2 years ago.
Approximately minimal example
Fixed-query-for-index-of-given-value.patch download (477 bytes) - added by awi 4 months ago.
Fixed query for index in wxEnumProperty.

Download all attachments as: .zip

Change History (4)

Changed 2 years ago by mirari

Approximately minimal example

comment:1 Changed 4 months ago by awi

  • Keywords wxEnumProperty index added; Editors "Choice" removed
  • Patch set
  • Version changed from 2.9.3 to dev-latest

Patch to propgrid sample reproducing the issue is quite simple:

--- a/samples/propgrid/propgrid.cpp
+++ b/samples/propgrid/propgrid.cpp
@@ -1289,7 +1289,7 @@ void FormMain::PopulateWithExamples ()
     // number of items is calculated, and this requires that the string pointer
     // array is terminated with NULL.
     pg->Append( new wxEnumProperty(wxT("EnumProperty"),wxPG_LABEL,
-        enum_prop_labels, enum_prop_values, 80 ) );
+        enum_prop_labels, enum_prop_values, 0 ) );
 
     wxPGChoices soc;

The issue happens because there is a coincidence of two things:

  1. Provided initial value (0) is invalid: it doesn't appears on the list of available values of wxEnumProperty elements (stored in enum_prop_values).
  2. Provided initial value is within the range of available indices of selectable wxEnumProperty elements (between 0 and 3 in the sample).

When wxEnumProperty is created and initial value is provided then in the property object there is stored the index of the element to which this value is assigned. If this value cannot be found (in wxEnumProperty::GetIndexForValue()) then there is no indication about it and instead the value itself is returned. In the sample this is a value '0' which further locks possibility to initially select element with index '0'. If e.g. value '1' would be provided as an initial value then selection of the element with index '1' would be initially blocked.

In order to fix the issue there is necessary to indicate by wxEnumProperty::GetIndexForValue() that no index was found for invalid value.
Corresponding patch is attached (attachment:Fixed-query-for-index-of-given-value.patch).

Changed 4 months ago by awi

Fixed query for index in wxEnumProperty.

comment:2 Changed 2 months ago by AW

  • Owner set to AW
  • Resolution set to fixed
  • Status changed from new to closed

In 76876:

Fix wxEnumProperty::GetIndexForValue

GetIndexForValue should indicate that given property value does not exist by returning special index value(-1).

Closes #14450.

Note: See TracTickets for help on using tickets.