how can I move mouse pointer by arrow key among stc?

hello,

how can I move mouse pointer by arrow key among stc?
--> http://codepad.org/0swJTX7a

Wonjun, Choi

See the wx.Window.WarpPointer method.

···

On 2/21/12 1:44 AM, Wonjun, Choi wrote:

hello,

how can I move mouse pointer by arrow key among stc?
--> http://codepad.org/0swJTX7a

--
Robin Dunn
Software Craftsman

Wonjun, Choi wrote:

hello,

how can I move mouse pointer by arrow key among stc?

That's not really the right question. I assume you really want to know
how to move from editor to editor using only the keyboard. Ordinarily,
as you know, the "tab" key would do this, a service provided by the
panel. But, in your case, the styled text controls are grabbing the tab
key to indent and dedent the text, so the panel never sees them.

You will have to decide which keystroke should do this motion (ctrl-tab
and ctrl-shift-tab, maybe?), then grab the keystrokes and manage the
focus yourself.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

I tested like this but it’s not working well

def OnKeyPressed(self, event):
    curStc = event.GetEventObject()
    print curStc.GetCurrentLine()
    privious = None
    if curStc.GetCurrentLine() == 0:
        allitems = [w.GetWindow() for w in self.GetGrandParent().Autosizer.GetChildren() if w.GetWindow() is not None]
        useNextone = False
        for item in allitems: # except GA part
            if isinstance(item, wx.stc.StyledTextCtrl):
                if curStc == item:
                    previous.SetFocus()
                    useNextone = True
                    break
                elif useNextone:
                    curStc.SetFocus()
                else:
                    previous = item
            useNextone = False

Try using the Navigate method. For example, this will move forward on Ctrl-Tab, backwards on Shift-Ctrl-Tab, and ignore all other keystrokes so they can be handled by the STC like normal:

     def OnKeyDown(self, evt):
         if not (evt.ControlDown() and evt.GetKeyCode() == wx.WXK_TAB):
             evt.Skip()
             return
         flag = wx.NavigationKeyEvent.IsForward
         if evt.ShiftDown():
             flag = 0
         self.Navigate(flag)

···

On 2/21/12 7:22 PM, 최원준 wrote:

I tested like this but it's not working well

--
Robin Dunn
Software Craftsman

it works fine but I need more code in onkeydown method.

def autoindent(self):
    pos = self.GetCurrentPos()
    line = self.GetCurrentLine()
    if line:
        level = self.GetLineIndentation(line - 1)
        if self.GetLine(line - 1).strip().endswith(":"):
            level += 6
            self.SetLineIndentation(line, level)
#            self.GotoPos(pos + level)
            self.GotoPos(pos + len(self.GetLine(line)) - 1)

def OnKeyPressed(self, event):
    if not (event.ControlDown() and event.GetKeyCode() == wx.WXK_TAB):
       event.Skip()
       return
       flag = wx.NavigationKeyEvent.IsForward
       if event.ShiftDown():
           flag = 0
       self.Navigate(flag)

    try:
        if event.KeyCode == wx.WXK_RETURN:
            wx.CallAfter(self.autoindent)
        elif (
            chr(event.KeyCode) in string.letters or
            event.KeyCode == 32 and event.ControlDown()
        ):
           
            self.timer.Stop()
            self.timer.Start(200, True)
    except ValueError:
        pass
    event.Skip()

I like to use below method

def OnKeyDown(self, evt):
if not (evt.ControlDown() and evt.GetKeyCode() == wx.WXK_TAB):
evt.Skip()
return
flag = wx.NavigationKeyEvent.IsForwar

d

    if evt.ShiftDown():

        flag = 0

    self.Navigate(flag)

but my ui is like attached screenshot so tab function key also searchs statictext control in sizer.

concept.png

but the sizer1 and sizer2 in Autosizer don’t need to be considered. all control is in Autosizer.

StaticText widgets can not accept the focus so the navigation should already skip past them.

···

On 2/26/12 9:28 PM, 최원준 wrote:

I like to use below method

    def OnKeyDown(self, evt):
        if not (evt.ControlDown() and evt.GetKeyCode() == wx.WXK_TAB):
            evt.Skip()
            return
        flag = wx.NavigationKeyEvent.IsForwar
d
        if evt.ShiftDown():
            flag = 0
        self.Navigate(flag)

but my ui is like attached screenshot so tab function key also searchs
statictext control in sizer.

--
Robin Dunn
Software Craftsman

I am sorrry, it’s wx.Button control not StaticText.

so what I tested is here.
this is not good I think due to it’s wx.Button

what I want to do : when I move up arrow button at the top of stc, the cursor is at the last line of previous stc. vice versa.

position_move.py (3.35 KB)