On Thu, 7 Feb 2013 08:53:22 -0800 (PST)
wgw <[email protected]> wrote:

> I wonder whether a rclick on the overview button might remember the window 
> id and close it.... (but I am way beyond my depth here...)

So this got way more complicated than I thought real fast, but got done
in the end anyway.

 - rclick / mclick don't activate the anchorClicked event, only lclick
 - ok, so use Ctrl-lclick to close, but
 - anchorClicked doesn't know the keyboard modifiers like a regular
   event, only the url
 - so change the script (new version below) to track modifiers
   separately
 - but closing the overview window still leaves the top level
   window with a placeholder in it, so I had to modify
   nested_splitter, new version pushed to launchpad / available
   in snap-shot tomorrow

Cheers -Terry

--- cut here ---
@language python

from PyQt4 import QtGui, QtCore
from xml.sax.saxutils import escape

def add_html(html, nd):
    """recursively add to an html list with links to nodes"""
    
    unl = nd.get_UNL()
    html.append("<div class='level'>"
        "<div><a href='%s' title='%s'>%s</a></div>" %
        (unl, unl, escape(nd.h)))
    html.append("<pre>%s</pre>"%escape(nd.b))
    for child in nd.children():
        add_html(html, child)
    html.append("</div>")

def make_overview(c):
    """build the overview widget"""

    te = QtGui.QTextBrowser()
    te.setReadOnly(True)
    te.setOpenLinks(False)
    
    def anchorClicked(url, c=c, te=te):
        
        url = str(url.toString())
        g.handleUrl(url,c=c,p=c.p)
        
        if te.ctrl_click:
            te.deleteLater()
        
    te.anchorClicked.connect(anchorClicked)
    
    def mousePressEvent(event, te=te, original=te.mousePressEvent):
        te.ctrl_click = bool(event.modifiers() & QtCore.Qt.ControlModifier)
        original(event)
    
    te.mousePressEvent = mousePressEvent
    
    html = ["""<html><head><style>
    .level .level {margin-left: 1.5em}
    a {text-decoration: none; font-size: 120%}
    </style></head><body>"""]
    
    for nd in c.getSelectedPositions():
        add_html(html, nd)

    html.append("</body></html>") 
    
    html = '\n'.join(html)
    
    te.setHtml(html)
    
    return te

class OverviewPaneProvider:
    def __init__(self, c):
        self.c = c
        # Careful: we may be unit testing.
        if hasattr(c, 'free_layout'):
            splitter = c.free_layout.get_top_splitter()
            if splitter:
                splitter.register_provider(self)
    def ns_provides(self):
        return[('Overview', '_add_overview_pane')]
    def ns_provide(self, id_):
        if id_ == '_add_overview_pane':
            w = make_overview(c)
            return w
    def ns_title(self, id_):
        if id_ == '_add_overview_pane':
            return "Leo Outline Overview"
    def ns_provider_id(self):
        # used by register_provider() to unregister previously registered
        # providers of the same service
        return "outline overview window"

OverviewPaneProvider(c)

--- cut here ---

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/leo-editor?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to