Hi All,

I am hoping someone can jump in here and help (Detlev?). Please ???

I thought I would have a go at implementing the kind on functionality that I 
was after but don't seem to be able to 
get it to work correctly. I thought that I would try the straight forward 
logical approach which is to iterate through
the current document looking for function definitions and folding them - slow 
but simple - leave the error handling till
after the basic function works etc.
Unfortunately it turns out to be very unreliable. Some times it works perfectly 
and all functions fold, sometimes it 
only seems to toggle the folds on half of the functions in a class, sometimes 
none at all.  I have no idea why this
is so and can't seem to make heads or tails from the doc's for QScintilla.  I 
looked at the Scintilla web site but that was
even worse (never written a C++ program in my life).

The code I have been using is below.  I have tried adding small delays between 
each iteration incase this is caused by
some sort of race condition and also have tried to move the cursor to the 
current line etc - nothing seems to help

I modified the viewmanager.py class for with the following:

1) add the following snippet of code to the initViewActions method to add an 
extra menu option to the view menu
   (no problem here.)

    def initViewActions(self):
        
        ... <snip most of function to save space - is pretty easy to work out 
where to put this code >
        ... < word wrap makes this look funny :) >

        self.toggleAllAct = E3Action(self.trUtf8('Toggle method folds'),
                            self.trUtf8('Toggle &method folds'),
                            0, 0, self.viewFoldActGrp, 
'vm_view_toggle_method_folds')
        self.toggleAllAct.setStatusTip(self.trUtf8('Toggle method folds'))
        self.toggleAllAct.setWhatsThis(self.trUtf8(
                """<b>Toggle folds for all methods</b>"""
                """<p>Toggle all folds of methods in the current editor.</p>"""
                ))
        
self.toggleAllAct.connectIt(SIGNAL('activated()'),self.handleToggleMethods)
        self.viewActions.append(self.toggleAllAct)

2) add the following method to iterate through the current window and collapse 
any lines that contain 
    module definitions.

    def handleToggleMethods(self):
        """
        Private method to handle the toggle method fold action.
        """
        aw = self.activeWindow()
        tmpRange = range(aw.lines())
        tmpRange.reverse()              # run backwards to avoid folding over 
myself.
        for line in tmpRange:
            ltext = unicode(aw.text(line)).strip()
            if ltext.startswith("def") and ltext.endswith(":"):
                ##aw.setCursorPosition(line, 1)
                ##aw.ensureLineVisible(line)
                aw.foldLine(line)

Does anyone have any idea how to make this work?  
Can anyone explain why it doesn't work the way it is? <- this would be really 
great as I can learn something

Thanks in advance.

Regards,
Brad Ralph

On Fri, 14 Oct 2005 04:21 am, Mario Beauchamp wrote:
> Hi all,
> 
> Brad Ralph wrote:
> > 
> > When I create classes, I often want to fold all of the methods of the class 
> 
> I've been using eric3 for a few months now and I like it very much but I must 
> admit this problem
> has been bugging me from the start. Now, I don't know a lot about QScintilla 
> and/or Scintilla
> itself but I was using the Pythonwin IDE (also based on Scintilla) under 
> Windows before and it
> has a code folding feature that collapses everything. So it may not be that 
> difficult to
> implement that in eric3.
> 
> Just a thought...
> --
> Mario B.
> 
> _______________________________________________
> PyKDE mailing list    PyKDE@mats.imk.fraunhofer.de
> http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
> 

_______________________________________________
PyKDE mailing list    PyKDE@mats.imk.fraunhofer.de
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde

Reply via email to