wxComboCtrl and SetSelection/SetMark()

Hey, it's me again.

While playing around with the new wxComboCtrl control and extending
its behaviour I've noticed that there are weird things happening with SetMark()
applied on wx.ComboCtrl.GetTextCtrl().
In the official manual wxComboCtrl should use SetSelection() for selecting text
inside the TC - wxPython uses SetMark() on wxTextCtrl as substitute for this.

The following example sets the mark perfectly:
elif etype == wx.wxEVT_LEFT_DOWN:
            # textctrl doesnt have focus - wxMSW specific
            if tc.GetInsertionPoint() == 0:
                tc.SetFocus()
                tc.SetMark(0, tc.GetLastPosition())

While raising:
AttributeError: 'TextCtrl' object has no attribute 'SetMark'

Excepting AttributeError around SetMark() leads to not marking the text.

···

--
Hannes Tismer
Software Development
Medical Display Solutions

Rein EDV GmbH Jakob-Krebs-Straße 124
D-47877 Willich

Fon: +49 2156 49490 Fax: +49 2156 494939

Visit us at www.medisol.org

Hannes Tismer wrote:

Hey, it's me again.

While playing around with the new wxComboCtrl control and extending
its behaviour I've noticed that there are weird things happening with SetMark()
applied on wx.ComboCtrl.GetTextCtrl().
In the official manual wxComboCtrl should use SetSelection() for selecting text
inside the TC - wxPython uses SetMark() on wxTextCtrl as substitute for this.

The following example sets the mark perfectly:
elif etype == wx.wxEVT_LEFT_DOWN:
           # textctrl doesnt have focus - wxMSW specific
           if tc.GetInsertionPoint() == 0:
               tc.SetFocus()
               tc.SetMark(0, tc.GetLastPosition())

While raising:
AttributeError: 'TextCtrl' object has no attribute 'SetMark'

You should use SetSelection for textCtrl. The combo controls have the C++ SetSelection(start, end) renamed to SetMark because they also have an overloaded SetSelection(n) inherited from ControlWithItems and renaming is how I tend to handle overloads

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Thank you,

I've looked at SetSelection before but SetMark sounded way more logic to me,
so I simply ignored SetSelection.
I got it working with:

elif etype == wx.wxEVT_LEFT_DOWN:
            if tc.FindFocus() != tc:
                tc.SetFocus()
                tc.SetSelection(-1, -1)
                tc.Refresh()
                return True

Robin Dunn schrieb:

···

Hannes Tismer wrote:

Hey, it's me again.

While playing around with the new wxComboCtrl control and extending
its behaviour I've noticed that there are weird things happening with SetMark()
applied on wx.ComboCtrl.GetTextCtrl().
In the official manual wxComboCtrl should use SetSelection() for selecting text
inside the TC - wxPython uses SetMark() on wxTextCtrl as substitute for this.

The following example sets the mark perfectly:
elif etype == wx.wxEVT_LEFT_DOWN:
           # textctrl doesnt have focus - wxMSW specific
           if tc.GetInsertionPoint() == 0:
               tc.SetFocus()
               tc.SetMark(0, tc.GetLastPosition())

While raising:
AttributeError: 'TextCtrl' object has no attribute 'SetMark'

You should use SetSelection for textCtrl. The combo controls have the C++ SetSelection(start, end) renamed to SetMark because they also have an overloaded SetSelection(n) inherited from ControlWithItems and renaming is how I tend to handle overloads

--
Hannes Tismer
Software Development
Medical Display Solutions

Rein EDV GmbH Jakob-Krebs-Straße 124
D-47877 Willich

Fon: +49 2156 49490 Fax: +49 2156 494939

Visit us at www.medisol.org