How to capture special events?

Hi,

I would like to do one thing when enter is pressed in a wxTextCtrl and
something else when shift-enter is pressed.

How can I do that?

I would also like to do something similar in a wxTreeCtrl..

···

--
Anders
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS/O d--@ s:+ a-- C++ $UL+++ P++ L+++ E- W+ N(+) o K? w O- M-- V
PS+ PE@ Y+ PGP+ t 5 X R+ tv+ b+ DI+++ D+ G e- h !r y?
------END GEEK CODE BLOCK------
PGPKey: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8BFECB41

Should I interpret the complete lack of responses as there is no way to
do this??

···

On Mon, Dec 09, 2002 at 09:27:16PM +0100, Anders Bruun Olsen wrote:

I would like to do one thing when enter is pressed in a wxTextCtrl and
something else when shift-enter is pressed.
How can I do that?
I would also like to do something similar in a wxTreeCtrl..

--
Anders
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS/O d--@ s:+ a-- C++ $UL+++ P++ L+++ E- W+ N(+) o K? w O- M-- V
PS+ PE@ Y+ PGP+ t 5 X R+ tv+ b+ DI+++ D+ G e- h !r y?
------END GEEK CODE BLOCK------
PGPKey: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8BFECB41

Anders Bruun Olsen wrote:

···

On Mon, Dec 09, 2002 at 09:27:16PM +0100, Anders Bruun Olsen wrote:

I would like to do one thing when enter is pressed in a wxTextCtrl and
something else when shift-enter is pressed.
How can I do that?
I would also like to do something similar in a wxTreeCtrl..

Should I interpret the complete lack of responses as there is no way to
do this??

patience - if nobody answers a question here, Robin usually does once he gets to it. He typically does a bunch at a time once every day or two, so don't despair just yet...

Shi.

from wxPython.wx import *

class MyTextCtrl(wxTextCtrl):
    def __init__(self, parent, id):
        wxTextCtrl.__init__(self, parent, id,
                            style = wxTE_PROCESS_ENTER)
        EVT_CHAR(self, self.OnChar)
        EVT_TEXT_ENTER(self, self.GetId(), self.OnEnter)
        
    def OnChar(self, event):
        print "type a char"
        print "MyTextCtrl", event
        event.Skip()

    def OnEnter(self, event):
        print "pressed enter"
        print "MyTextCtrl", event
        event.Skip()

class MyPanel(wxPanel):
    def __init__(self, parent, id):
        wxPanel.__init__(self, parent, id)
        child = MyTextCtrl(self, -1)

class MyFrame(wxFrame):
    def __init__(self, parent, id, title):
        wxFrame.__init__(self, parent, -1, title)
        self.panel = MyPanel(self, -1)
        
class MyApp(wxApp):
    def OnInit(self):
        frame = MyFrame(None, -1, "")
        frame.Show(true)
        return true

app = MyApp()
app.MainLoop()

···

On Tue, 2002-12-10 at 13:58, Anders Bruun Olsen wrote:

On Mon, Dec 09, 2002 at 09:27:16PM +0100, Anders Bruun Olsen wrote:
> I would like to do one thing when enter is pressed in a wxTextCtrl and
> something else when shift-enter is pressed.
> How can I do that?
> I would also like to do something similar in a wxTreeCtrl..

Should I interpret the complete lack of responses as there is no way to
do this??

--
Cliff Wells, Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308 (800) 735-0555 x308

Sorry, I didn't mean to be unpatient or sound angry.. I just wanted to
put a little focus on my post to make sure it hadn't been completely
forgotten :slight_smile:

···

On Tue, Dec 10, 2002 at 05:05:18PM -0500, Shi Sherebrin wrote:

>>I would like to do one thing when enter is pressed in a wxTextCtrl and
>>something else when shift-enter is pressed.
>>How can I do that?
>>I would also like to do something similar in a wxTreeCtrl..
>Should I interpret the complete lack of responses as there is no way to
>do this??
patience - if nobody answers a question here, Robin usually does once he
gets to it. He typically does a bunch at a time once every day or two,
so don't despair just yet...

--
Anders
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS/O d--@ s:+ a-- C++ $UL+++ P++ L+++ E- W+ N(+) o K? w O- M-- V
PS+ PE@ Y+ PGP+ t 5 X R+ tv+ b+ DI+++ D+ G e- h !r y?
------END GEEK CODE BLOCK------
PGPKey: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8BFECB41

[SNIP]

Thanks - this didn't do quite what I needed, but it set me on the way to
figure out what I needed to do. This is how I do it:

class MyTextCtrl(wxTextCtrl):
    def __init__(self, parent, id, pos, size):
        wxTextCtrl.__init__(self, parent, id, pos=pos, size=size, style = wxTE_PROCESS_ENTER)
        EVT_CHAR(self, self.OnChar)

    def OnChar(self, event):
        if event.m_shiftDown == TRUE and event.GetKeyCode() == 13:
                print "shift-enter"
        elif event.GetKeyCode() == 13:
                print "enter"
        event.Skip()

Thanks for your help...

···

On Tue, Dec 10, 2002 at 02:09:47PM -0800, Cliff Wells wrote:

> > I would like to do one thing when enter is pressed in a wxTextCtrl and
> > something else when shift-enter is pressed.
> > How can I do that?
> > I would also like to do something similar in a wxTreeCtrl..
> Should I interpret the complete lack of responses as there is no way to
> do this??
from wxPython.wx import *

--
Anders
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS/O d--@ s:+ a-- C++ $UL+++ P++ L+++ E- W+ N(+) o K? w O- M-- V
PS+ PE@ Y+ PGP+ t 5 X R+ tv+ b+ DI+++ D+ G e- h !r y?
------END GEEK CODE BLOCK------
PGPKey: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8BFECB41

Oh yeah, you wanted to differentiate between enter and shift+enter...
sorry, I was in such a hurry I forgot what you asked for :wink:

Anyway, glad that helped.

···

On Tue, 2002-12-10 at 14:38, Anders Bruun Olsen wrote:

Thanks - this didn't do quite what I needed, but it set me on the way to
figure out what I needed to do. This is how I do it:

--
Cliff Wells, Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308 (800) 735-0555 x308

class MyTextCtrl(wxTextCtrl):
    def __init__(self, parent, id, pos, size):
        wxTextCtrl.__init__(self, parent, id, pos=pos, size=size, style = wxTE_PROCESS_ENTER)
        EVT_CHAR(self, self.OnChar)

    def OnChar(self, event):

        if event.m_shiftDown == TRUE and event.GetKeyCode() == 13:
                print "shift-enter"
        elif event.GetKeyCode() == 13:
                print "enter"
        event.Skip()

Just nitpicking, but you could change it a bit to:
  
    def OnChar(self, event):
        if event.GetKeyCode() == 13:
            if event.m_shiftDown == TRUE:
                print "shift-enter"
            else:
                print "enter"
        event.Skip()

Regards,

···

On Tue, 2002-12-10 at 14:38, Anders Bruun Olsen wrote:

--
Cliff Wells, Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308 (800) 735-0555 x308

Yeah.. that makes it a little easier to read.. thanks..

···

On Tue, Dec 10, 2002 at 02:46:18PM -0800, Cliff Wells wrote:

Just nitpicking, but you could change it a bit to:
    def OnChar(self, event):
        if event.GetKeyCode() == 13:
            if event.m_shiftDown == TRUE:
                print "shift-enter"
            else:
                print "enter"
        event.Skip()

--
Anders
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS/O d--@ s:+ a-- C++ $UL+++ P++ L+++ E- W+ N(+) o K? w O- M-- V
PS+ PE@ Y+ PGP+ t 5 X R+ tv+ b+ DI+++ D+ G e- h !r y?
------END GEEK CODE BLOCK------
PGPKey: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8BFECB41

Hi There,

I am looking for a method in the TablePrint module to force a hard page
break so I can print individual items on seprate pages ... I have been
looking at the source but can not see anything there ( maybe I am blind :slight_smile:

thanks in advance

Ben C