stc folding

26 views
Skip to first unread message

andreas graeper

unread,
Apr 26, 2013, 9:04:01 AM4/26/13
to wxpytho...@googlegroups.com
hi, 
i use stc for var declaration 
- var
   ..  
  end_var
- var constant 
   ..
  end_var

when now collapsed all that sections 

+ var
+ var constant (HERE) 

and the cursor is (HERE) and i type newline to start a new var declaration section 

+ var
+ var constant
-  var_input
    ..
   end_var

then the new section is inside the second 
  var constant
  var input
  end_var
  end_var

is there a trick to avoid this. i want the new line to appear after the collapsed block. 

thanks in advance 
andreas 

Cody

unread,
Apr 26, 2013, 12:22:49 PM4/26/13
to wxpytho...@googlegroups.com
Hi,




is there a trick to avoid this. i want the new line to appear after the collapsed block. 


You need to manually check the the fold state of the cursor line and apply the desired action when the Enter key is pressed.


Cody
 

andreas graeper

unread,
Apr 29, 2013, 5:43:35 AM4/29/13
to wxpytho...@googlegroups.com
hi,
thanks for your answer. 

i need to save the keycode from previous on_key_down ( in on_stc_modified, insertbefore the keycode is 0 ) 

what i have done so far, is: 
 finding out that fold level has headerflag ( x2000 (x2400) ) 
 finding out that block is not expanded 
 finding the line of lastchild 

   ...
 10 [+] xxx  (head, collapsed, lastchild in line 19) 
 #        ..             
 #        end_xxx
 20 [+] yyy
           

 what now i have to do ?
 do i have to write a method that inserts an \n in position after lastchild and wx.CallAfter that method and then event.Veto() the original \n at wrong position ? 
 or can i simply change the cursor-position and event.Skip() so that the \n is inserted in modified position ?

 StyledTextEvent has no Veto() ?! 
 if instead of veto i simply return (no .Skip()) the \n is inserted, nevertheless. i thought insertbefore can avoid what is intended to be inserted ?

now i have a property .veto and in mod_before_insert i set .veto=true 
in mod_inserttext i check .veto and if set i clear it and return (instead of not existing .Veto()) 
but no success.

please help.

Cody

unread,
Apr 29, 2013, 9:16:42 AM4/29/13
to wxpytho...@googlegroups.com
Hi,

       

 what now i have to do ?
 do i have to write a method that inserts an \n in position after lastchild and wx.CallAfter that method and then event.Veto() the original \n at wrong position ? 
 or can i simply change the cursor-position and event.Skip() so that the \n is inserted in modified position ?


Yes, while handling the EVT_KEY_DOWN event you just need to insert the new line at the desired location and return from the event without calling Skip.
 
 StyledTextEvent has no Veto() ?! 
 if instead of veto i simply return (no .Skip()) the \n is inserted, nevertheless. i thought insertbefore can avoid what is intended to be inserted ?

Not calling Skip on the event should result in the behavior your looking for (nothing inserted). What version of wxPython are you using and on what OS?
 

now i have a property .veto and in mod_before_insert i set .veto=true 
in mod_inserttext i check .veto and if set i clear it and return (instead of not existing .Veto()) 
but no success.


I don't know what these events in your program are you are referring to but if they are related to EVT_STC_MODIFIED then this is expected as you cannot make modifications to the buffer while in this event handler.


Cody

andreas graeper

unread,
Apr 29, 2013, 10:05:11 AM4/29/13
to wxpytho...@googlegroups.com
hi,
thanks for help.
os and wxpy versions are rather old. maybe this causes some trouble. but in this case i guess, i simply not yet understand whats going on. 

order of events 
 1) keydown
 2) stc_modified mode=beforeinsert
 3) stc_modified mode=inserttext 

do you actually say, that i have to catch the newline in keydown and from keydown-handler or with CallAfter i have to insert the newline at correct position and do not skip(), so the stc_modified events ( 2 + 3 ) are not generated ? 
i need to get all the info from stc-object instead of getting it from event-object ?! 
when i use CallAfter is there danger that if typing rather quick or reading text from file, the second key could generate a new [keydown +] beforeinsert + insert before the moved newline is inserted ? 

what are these beforeinsert beforedelete events good for ? 

andreas

Cody

unread,
Apr 29, 2013, 10:17:51 AM4/29/13
to wxpytho...@googlegroups.com
Hi,


On Mon, Apr 29, 2013 at 9:05 AM, andreas graeper <agra...@googlemail.com> wrote:
hi,
thanks for help.
os and wxpy versions are rather old. maybe this causes some trouble. but in this case i guess, i simply not yet understand whats going on. 

Are they so old that they are only representable in some ancient form of Sanskrit that prevents you from simply typing them into this message?

 

order of events 
 1) keydown
 2) stc_modified mode=beforeinsert
 3) stc_modified mode=inserttext 

do you actually say, that i have to catch the newline in keydown and from keydown-handler or with CallAfter i have to insert the newline at correct position and do not skip(), so the stc_modified events ( 2 + 3 ) are not generated ? 
i need to get all the info from stc-object instead of getting it from event-object ?! 
when i use CallAfter is there danger that if typing rather quick or reading text from file, the second key could generate a new [keydown +] beforeinsert + insert before the moved newline is inserted ? 


def OnKeyDown(self, event):
    ...
    if INeedToModifyEnter(): # your criteria check
        self.InsertText(position_i_want_newline, os.linsep)
        return
    else:
        event.Skip()

The modification events will still be triggered because you are still modifying the buffer, but it doesn't matter.
 

what are these beforeinsert beforedelete events good for ? 


They are strictly notifications for your application to use (i.e. can use to trigger update in document label to show its modified *myFile.txt).


Cody 

andreas graeper

unread,
Apr 29, 2013, 10:46:38 AM4/29/13
to wxpytho...@googlegroups.com
xubuntu 10.04, wxpy 2.8.10.1 

it is working now. i have used GotoPos(p) and AddText(). but will try InsertText() and os.linesep (little additional lesson) 
thanks a lot. 
Reply all
Reply to author
Forward
0 new messages