wxTextCtrl, HitTest, HitTestPos

All,

I have a wxTextCtrl that contains a pathname. What I would like, is
to extract a portion of that when the user clicks on part of it. For
example, if the control contains "/root/usr/local/slib/foo/bar/
adnauseam" and the user clicks on the 'i' is slib, I want to get /root/
usr/local/slib which all sort of works, _except_

the return values that I get from HitTestPos are bogus : (-2,
137637644). I can use the col value in the LeftDown event and the
GetCharWidth() to approximate the character, but it doesn't take into
account the variable width of the font, so it is frequently off by
several characters.

    def onAddrBarLeftDown( self, event ):
        pos = event.GetPosition()
        res = self.m_addrBarTextCtrl.HitTestPos( pos )
        cw = self.m_addrBarTextCtrl.GetCharWidth()
        cpos = pos[0]/cw
        str = self.m_addrBarTextCtrl.GetValue()
        target = str[0:cpos]
        while str[cpos] <> '/':
            cpos = cpos + 1
        target = str[0:cpos]

res = (-2, 137637644)

Am I using it (HitTestPos) incorrectly? Am I interpreting the output
incorrectly?
How can I get the font data so I can look up the width of each char?

Is there a better way?

All,

I have a wxTextCtrl that contains a pathname. What I would like, is
to extract a portion of that when the user clicks on part of it. For
example, if the control contains "/root/usr/local/slib/foo/bar/
adnauseam" and the user clicks on the 'i' is slib, I want to get /root/
usr/local/slib which all sort of works, _except_

the return values that I get from HitTestPos are bogus : (-2,
137637644).

What platform and what styles are used with the wx.TextCtrl? Does HitTest have the same problem?

How can I get the font data so I can look up the width of each char?

Make a DC, set the same font used by the widget and use GetTextExtent or GetPartialTextExtents.

···

On 11/23/09 7:05 AM, billy pilgrim wrote:

--
Robin Dunn
Software Craftsman

> All,

> I have a wxTextCtrl that contains a pathname. What I would like, is
> to extract a portion of that when the user clicks on part of it. For
> example, if the control contains "/root/usr/local/slib/foo/bar/
> adnauseam" and the user clicks on the 'i' is slib, I want to get /root/
> usr/local/slib which all sort of works, _except_

> the return values that I get from HitTestPos are bogus : (-2,
> 137637644).

What platform and what styles are used with the wx.TextCtrl? Does
HitTest have the same problem?

Sorry, I should have specified: Linux, via wxformbuilder. All
wxTextCtrl settings are the defaults -- nothing special.
I have used HitTest on a treeCtrl with success.

> How can I get the font data so I can look up the width of each char?

Make a DC, set the same font used by the widget and use GetTextExtent or
GetPartialTextExtents.

I'll try that, thank you. If this is a bug, to where should it be
reported?
Thank you for your help!

:bp:

···

On Nov 23, 8:01 pm, Robin Dunn <ro...@alldunn.com> wrote:

On 11/23/09 7:05 AM, billy pilgrim wrote:

--
Robin Dunn
Software Craftsmanhttp://wxPython.org

Hi,

I'll try that, thank you. If this is a bug, to where should it be
reported?
Thank you for your help!

:bp:

In case it IS a bug, go to the wxPython website and click the "Report
a bug" link that's on the left. It should take you here:

http://trac.wxwidgets.org/

If you don't have an account, you'll need to get one. Be sure to
choose the correct category when you submit the bug.

···

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

Both HitTest and HitTestPos seem to be working fine for me on Linux. Are you using the latest release of wxPython?

···

On 11/23/09 5:32 PM, billy pilgrim wrote:

On Nov 23, 8:01 pm, Robin Dunn<ro...@alldunn.com> wrote:

On 11/23/09 7:05 AM, billy pilgrim wrote:

All,

I have a wxTextCtrl that contains a pathname. What I would like, is
to extract a portion of that when the user clicks on part of it. For
example, if the control contains "/root/usr/local/slib/foo/bar/
adnauseam" and the user clicks on the 'i' is slib, I want to get /root/
usr/local/slib which all sort of works, _except_

the return values that I get from HitTestPos are bogus : (-2,
137637644).

What platform and what styles are used with the wx.TextCtrl? Does
HitTest have the same problem?

Sorry, I should have specified: Linux, via wxformbuilder. All
wxTextCtrl settings are the defaults -- nothing special.
I have used HitTest on a treeCtrl with success.

--
Robin Dunn
Software Craftsman

Robin Dunn wrote:

···

On 11/23/09 5:32 PM, billy pilgrim wrote:
  

On Nov 23, 8:01 pm, Robin Dunn<ro...@alldunn.com> wrote:
    

On 11/23/09 7:05 AM, billy pilgrim wrote:

All,
        
I have a wxTextCtrl that contains a pathname. What I would like, is
to extract a portion of that when the user clicks on part of it. For
example, if the control contains "/root/usr/local/slib/foo/bar/
adnauseam" and the user clicks on the 'i' is slib, I want to get /root/
usr/local/slib which all sort of works, _except_
        
the return values that I get from HitTestPos are bogus : (-2,
137637644).
        

What platform and what styles are used with the wx.TextCtrl? Does
HitTest have the same problem?
      

Sorry, I should have specified: Linux, via wxformbuilder. All
wxTextCtrl settings are the defaults -- nothing special.
I have used HitTest on a treeCtrl with success.
    
Both HitTest and HitTestPos seem to be working fine for me on Linux. Are
you using the latest release of wxPython?

I believe that I am using the latest, the install was quite recent.
Thanks for checking on your system, that points to pilot error :(. I'll
try a shorter test program, and see what results I get.

Again, thank you very much for the support -- it is greatly appreciated.

:bp: