New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wxpg.PGEditor.GetValueFromControl & wxpg.PGProperty.StringToValue #742

Closed
Lokla opened this Issue Feb 9, 2018 · 3 comments

Comments

Projects
3 participants
@Lokla
Contributor

Lokla commented Feb 9, 2018

Operating system: Windows 10 64 Bit
wxPython version: 4.0.2a1 msw (phoenix)
Stock or custom build: Stock
Python version: 2.7.14
Stock or custom build: Stock

Related with #394
Reported in wxpython-users here:
https://groups.google.com/forum/#!topic/wxpython-users/F5l-QrKQEfk

I have two problems here when implementing a custom editor. I tried to fix it myself, but I am stuck along the way.

PGEditor Overload of GetValueFromControl crashes application:

File to create the crash:
pgEditorCrash.zip

Also happens in demo (example is created mostly from demo code).

Steps to reproduce:

  • Edit the label
  • Save the edited value

I already managed to at least jump into the function by removing the third D in the format - I think it might be too much there. But I have no experience with sip, so it is just a guess.

PyObject *sipResObj = sipCallMethod(0, sipMethod, "DD",
                                            property, sipType_wxPGProperty, NULL,
                                            ctrl, sipType_wxWindow, NULL);

My code now reaches the Python function (yay), but the return value (once the second problem is avoided) will still report an error:

TypeError: invalid result from CustomEditor.GetValueFromControl(), a 'bool' is expected not 'tuple'

So it seems that the sipParseResult is not executed correctly.

But I also ran into the following additional problem:

PGProperty function StringToValue returns boolean and not tuple of Boolean and String:

import wx
import wx.propgrid as wxpg
app = wx.App()
frame = wx.Frame(None)
pg = wxpg.PropertyGrid(frame)
prop = wxpg.StringProperty("Simple Property", name="mine", value="Change me!!")
print(prop.StringToValue(wxpg.PG_EDITABLE_VALUE, 'My New Value'))
  • This code returns just the boolean True which indicates that the result is valid, but not the result itself.
  • At the moment this function also cannot be overridden for custom Properties

This might also affect IntToValue.

For funtions like the GetValueFromControl, you really need both return values (the bool and the string), so the function should return a tuple.

Thanks,
Michael

@jensgoe

This comment has been minimized.

Contributor

jensgoe commented May 15, 2018

@RobinD42
I can confirm this crash. It happens with all custom editors that overrides GetValueFromControl. Somehow sip does not handle this method correctly.

To reproduce:

  • start the wxPython demo (PropertyGrid.py)
  • start editing and CHANGE the value of the last editor (StringWithCustomEditor)
  • confirm the changes by clicking somewhere or hit enter
  • --> Crash

The debugger stops in generated code of sip.

@jensgoe

This comment has been minimized.

Contributor

jensgoe commented May 15, 2018

Ok, i fixed the crash by removing the virtualCatcherCode of GetValueFromControl in the etg script. After that i had the same issue like Lokla that StringToValue is not working properly. All the StringToValue functions that receives the result in the first argument are not marked as an out parameter in the sip code. I fixed this by modifying the sip file like this (adding /Out/):

    virtual
    bool StringToValue(
        wxPGVariant & variant   /Out/,
        const wxString & text,
        int argFlags = 0
    ) const;

This seems to be done in the etg script by:

    c = module.find('wxPGProperty')
    tools.ignoreConstOverloads(c)
    c.find('StringToValue.variant').out = True
    c.find('IntToValue.variant').out = True

Somehow this does not work. I guess this seems not to consider all the derived subclasses.

@RobinD42 RobinD42 added this to To do in 4.0.2 May 15, 2018

@RobinD42 RobinD42 moved this from To do to In progress in 4.0.2 Jun 5, 2018

@RobinD42

This comment has been minimized.

Member

RobinD42 commented Jun 5, 2018

Fixed by #877

@RobinD42 RobinD42 closed this Jun 5, 2018

4.0.2 automation moved this from In progress to Done Jun 5, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment