I'm debugging a clone navigation plugin, clone_nav.  It is similar to
the quicksearch plugin in that it creates a tab in the log pane.

Clone_nav controls the focus as I intend in every case but one.  This
problem case is immediately after clone_nav pops-up a question using
QtGui.QMessageBox.question().  When I drop the pop-up, the code works.
When the pop-up occurs, the focus setting code is ineffective and the
focus is always left in the body--not in the clone_nav tab as intended.

Does Leo-editor not allow pop-up windows?  Aside from this focus
problem, I've seen no other ill effects.

Is there a mistake in my use of PyQt4?

The problem code is in itemActivated().  See attached files ref.leo and
clone_nav.py.

If I ever finish debugging this plugin, should I push it to the contrib
branch or should I put it somewhere else?

Bob Hossley (SegundoBob)

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

Attachment: ref.leo
Description: application/leo-outline

#...@+leo-ver=5-thin
#...@+node:bob.20101130143836.1344: * @file clone_nav.py
#...@+<< docstring >>
#...@+node:bob.20101130143836.1345: ** << docstring >>
"""  The "cloneNav" plugin creates a log pane tab and
assigns Alt-Shift-C to command clone-nav which populates
the cloneNav tab with a list of all the headline strings
of the parents of the current node.  If the current node
is a root, then "Clone is a root" is put in the list
because a root has no parent.

Alt-Shift-C leaves the focus on the entry in the list
corresponding to the current outline position.  This allows
cloneNav to be used without a mouse.  The arrow keys move the focus
up and down the list.  Carriage return selects the currently focused
parent.

Optionally, clicking on a parent headline selects that clone.

Either way, selecting a clone leaves the focus on the chosen clone node
in the outline pane.

If after the clone list is created, the operator changes the outline
so that a clone list entry is no longer valid and then the operator 
selects the no longer valid entry, a message box pops up stating,
"Selected clone position no longer exists.", and asking,
"Regenerate the clones list?" and displaying a "Yes" button and a "No" button
with the "Yes" button as the default.
This allows the operator to regenerate the clone list by hitting carriage return.
Any arrow key and the tab key cycle focus from one button to the other.
Carriage return selects the currently focused button.

Optionally, the operator can click on either button.

"""
#...@-<< docstring >>

__version__ = '1.0'
#...@+<< version_history >>
#...@+node:bob.20101204110352.1341: ** << version_history >>
"""
2010-11-30 - 2010-12-07 SegundoBob (Bob Hossley)
    First released version
"""
#...@-<< version_history >>

#...@+<< imports >>
#...@+node:bob.20101130143836.1347: ** << imports >>
import leo.core.leoGlobals as g

g.assertUi('qt')

from leo.core import leoNodes
    # Uses leoNodes.posList.

import PyQt4.QtGui as QtGui
import PyQt4.QtCore as QtCore
#...@-<< imports >>

#...@+others
#...@+node:bob.20101130143836.1348: ** init
def init ():

    ok = g.app.gui.guiName() == "qt"

    if ok:
        g.registerHandler('after-create-leo-frame',onCreate)
        g.plugin_signon(__name__)

    return ok
#...@+node:bob.20101130143836.1349: ** onCreate
def onCreate (tag, keys):

    c = keys.get('c')
    if not c: return

    c.frame.log.deleteTab('cloneNav')
    qtWidg = CloneNav(c)
    c.frame.log.createTab("cloneNav", widget = qtWidg)

    def createListFocusToCloneNav(event):
        qlistwgt = qtWidg.createCloneList()
        qtWidg.listWidget.setCurrentItem(qlistwgt)
        c.frame.log.selectTab('cloneNav', widget = qtWidg)
        c.widgetWantsFocusNow(qtWidg.listWidget)

    c.k.registerCommand(
            'clone-nav','Alt-Shift-c', createListFocusToCloneNav)





#...@+node:bob.20101130190826.1406: ** class CloneNav
class CloneNav(QtGui.QWidget):
    """
    Class representing and controlling the cloneNav tab.
    This class is only instantiated once per Leo-editor application instance.
    """
    #...@+others
    #...@+node:bob.20101204113945.1346: *3* __init__()
    def __init__(self, c, parent=None):
        """
        @param c:  Leo-editor "commander" for the current .leo file

        """

        QtGui.QWidget.__init__(self, parent)
        self._c = c
        self.setObjectName("cloneNav")
        self.resize(868,572)
        self._verticalLayout = QtGui.QVBoxLayout(self)
        self._verticalLayout.setContentsMargins(0,1,0,1)
        self._verticalLayout.setObjectName("verticalLayout")
        self.listWidget = QtGui.QListWidget(self)
        self.listWidget.setObjectName("listWidget")
        self._verticalLayout.addWidget(self.listWidget)
        self.connect(self.listWidget, QtCore.SIGNAL('itemClicked(QListWidgetItem *)'), self.itemActivated)
        self.connect(self.listWidget, QtCore.SIGNAL('itemActivated(QListWidgetItem *)'), self.itemActivated)
    #...@+node:bob.20101130190826.1407: *3* itemActivated()
    def itemActivated(self, qwiditm):
        idx = self.listWidget.currentRow()
        tarPtr = self._clonesList[idx]
        c = self._c
        if not c.positionExists(tarPtr):
            reply = QtGui.QMessageBox.question(self, 'Selected clone position no longer exists.',
                "Regenerate the clones list?", QtGui.QMessageBox.No | QtGui.QMessageBox.Yes, QtGui.QMessageBox.Yes)
            if reply == QtGui.QMessageBox.Yes:
                qlistwgt = self.createCloneList()
                self.listWidget.setCurrentItem(qlistwgt)
                c.frame.log.selectTab('cloneNav', widget = self)
                #c.logWantsFocusNow()  --- This call has no effect I can detect.
                c.widgetWantsFocusNow(self.listWidget)
                #c.k.showStateAndMode() --- This call has no effect I can detect.
            return
        c.selectPosition(tarPtr)
        c.redraw_after_select(tarPtr)
        c.widgetWantsFocusNow(c.frame.tree.canvas)
        c.k.showStateAndMode()
    #...@+node:bob.20101203131421.1340: *3* createCloneList()
    def createCloneList(self):
        """
        @param self: The unique instance of CloneNav representing and controlling the "cloneNav" tab
            of the log pane
        @param return:  The QListWidgetItem instance corresponding to the current outline position.
        """

        c = self._c
        self.listWidget.clear()
        self._clonesList = findClones(c)
        self.qlistItems = []
        for clone in self._clonesList:
            qlistwgt = QtGui.QListWidgetItem()
            if clone == c.p:
                retVal = qlistwgt
            if clone.parent():
                qlistwgt.setText(clone.parent().h)
            else:
                qlistwgt.setText('Clone is a root')
            self.qlistItems.append(qlistwgt)
            self.listWidget.addItem(qlistwgt)
        return retVal
    #...@-others
#...@+node:bob.20101130190826.1409: ** findClones()
def findClones(c):
    p = c.p
    return [z.copy() for z in c.all_positions() if z.v == p.v]
#...@-others
#...@-leo

Reply via email to