click and double-click dance?

I'm probably silly to want to do this, but here's what I want to do: When the user clicks once in my text output (in a StyledTextCtrl), I want to select the whole sentence containing the click point (I've got all the code for that), and do stuff with the selected data. If the user double-clicks, I want to reduce the selection to the single word containing the click point (default behavior for a double-click in text).

The __init__ for my subclass for the STC contains these lines:
  self.Bind(wx.EVT_LEFT_DOWN, self.OnMouseDown)
  self.Bind(wx.EVT_LEFT_DCLICK, self.OnDoubleClick)

In my def OnMouseDown, I have to end with a Skip() or OnDoubleClick won't get called. Unfortunately, when I include the Skip(), the code on OnMouseDown that selects the whole sentence becomes useless; on a single click, the sentence is selected but then the selection is immediately cleared.

Also, the "automatic" select-a-single-word behavior doesn't happen with a double click, no matter whether my OnDoubleClick handler contains a Skip() or not. So there's something I'm not understanding.

Trust me, it makes sense in this app, from a user's point of view . . . Clues to what I'm doing wrong?

Charles Hartman

How I would handle this:

    def OnMouseDown(self, evt):
        c = time.time()
        if self.clicktime-c < DOUBLECLICKTIME:
            self.SelectWord(evt)
        else:
            self.SelectSentence(evt)
        self.clicktime = c
        #never .Skip() the event, as we want to handle both single and
        #double clicks here

I would guess that you can acquire the platform-specific time for the
DOUBLECLICKTIME constant, though I haven't looked into it.

- Josiah

···

Charles Hartman <charles.hartman@conncoll.edu> wrote:

I'm probably silly to want to do this, but here's what I want to do:
When the user clicks once in my text output (in a StyledTextCtrl), I
want to select the whole sentence containing the click point (I've
got all the code for that), and do stuff with the selected data. If
the user double-clicks, I want to reduce the selection to the single
word containing the click point (default behavior for a double-click
in text).