Re: Learning from IPython
As usual this process is solid. I made it about halfway through this process before getting lost. I will remember to reference this in the future. Hopefully will get time to make the change soon. On Friday, September 25, 2015 at 8:01:05 AM UTC-4, Edward K. Ream wrote: > > On Thu, Sep 24, 2015 at 10:58 AM, john lunzer> wrote: > > I'm finding myself stumped by the KeyHandler class. One thing that the >> autocomplete Qt popup doesn't handle right now is PgUp and PgDown, both of >> these keybinding exit the popup. I was trying to fix this but I'm having >> difficulty figuring out where to do this. >> >> Any guidance would be much appreciated. >> > > No doubt about it, key handling is complex. I never remember the > details. > > Here is how I found the interesting code. I recommend variations of this > technique to find relevant code. > > 1. I started with the gui *independent* code in leoPy.leo#Code-->Gui base > classes-->@file leoKeys.py-->class AutoCompleterClass > > 2. I knew there was an ivar that tells whether to use inline completion or > a Qt popup. I found the use_qcompleter ivar in the ctor. Searching for > usages of that ivar, I eventually found ac.show_completion_list, which has > this code: > > if self.use_qcompleter: > # Put the completions in the QListView. > if self.qw: > self.qw.show_completions(tabList) > > 3. The qw ivar is the Qt-related widget, so I searched for "def > show_completions". I found this class: > > leoPy.leo#re: qt completer-->class LeoQListWidget(QListWidget) > > Now we're getting somewhere :-) > > BTW, I could have found this class another way. I knew that this > Qt-related class existed somewhere in this tree: leoPy.leo#Code-->Qt gui, > but I had forgotten which file. So an alternate way of finding this class > would have been to look for all the classes in the Qt-related tree, that is > leoPy.leo#Code-->Qt gui > > Anyway, the relevant method of the LeoQListWidget class is: > > def keyPressEvent(self, event): > '''Handle a key event from QListWidget.''' > trace = False and not g.unitTesting > c = self.leo_c > w = c.frame.body.wrapper > qt = QtCore.Qt > key = event.key() > if event.modifiers() != qt.NoModifier and not event.text(): > # A modifier key on it's own. > pass > elif key in (qt.Key_Up, qt.Key_Down): > QtWidgets.QListWidget.keyPressEvent(self, event) > elif key == qt.Key_Tab: > if trace: g.trace('') > self.tab_callback() > elif key in (qt.Key_Enter, qt.Key_Return): > if trace: g.trace('') > self.select_callback() > else: > # Pass all other keys to the autocompleter > # via the event filter. > w.ev_filter.eventFilter(obj=self, event=event) > > So this is where the change should be made. *Important*: the default > eventFilter method, that is, LeoQtEventFilter.eventFilter, is insanely > complicated. Don't change it! So you have to special case PageUp and > PageDown in lqlw.keyPressEvent. > > To repeat, I *never *try to remember implementation details. I had > forgotten that LeoQListWidget.keyPressEvent event existed. The only things > I knew at the start was: > > 1. The gui-independent autocompleter in @file leoKeys.py-->class > AutoCompleterClass > has one or more ivars that would tell when to use Qt popup completions > rather than inline completions. > > 2. There was a Qt-specific class that handles Qt popup completions. This > class is defined somewhere in the tree whose root is leoPy.leo#Code-->Qt > gui. > > 3. > Changing LeoQtEventFilter.eventFilter should be a last resort. > > HTH. Please feel free to ask more questions. > > Edward > -- 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 leo-editor+unsubscr...@googlegroups.com. To post to this group, send email to leo-editor@googlegroups.com. Visit this group at http://groups.google.com/group/leo-editor. For more options, visit https://groups.google.com/d/optout.
Re: Learning from IPython
On Thu, Sep 24, 2015 at 10:58 AM, john lunzerwrote: I'm finding myself stumped by the KeyHandler class. One thing that the > autocomplete Qt popup doesn't handle right now is PgUp and PgDown, both of > these keybinding exit the popup. I was trying to fix this but I'm having > difficulty figuring out where to do this. > > Any guidance would be much appreciated. > No doubt about it, key handling is complex. I never remember the details. Here is how I found the interesting code. I recommend variations of this technique to find relevant code. 1. I started with the gui *independent* code in leoPy.leo#Code-->Gui base classes-->@file leoKeys.py-->class AutoCompleterClass 2. I knew there was an ivar that tells whether to use inline completion or a Qt popup. I found the use_qcompleter ivar in the ctor. Searching for usages of that ivar, I eventually found ac.show_completion_list, which has this code: if self.use_qcompleter: # Put the completions in the QListView. if self.qw: self.qw.show_completions(tabList) 3. The qw ivar is the Qt-related widget, so I searched for "def show_completions". I found this class: leoPy.leo#re: qt completer-->class LeoQListWidget(QListWidget) Now we're getting somewhere :-) BTW, I could have found this class another way. I knew that this Qt-related class existed somewhere in this tree: leoPy.leo#Code-->Qt gui, but I had forgotten which file. So an alternate way of finding this class would have been to look for all the classes in the Qt-related tree, that is leoPy.leo#Code-->Qt gui Anyway, the relevant method of the LeoQListWidget class is: def keyPressEvent(self, event): '''Handle a key event from QListWidget.''' trace = False and not g.unitTesting c = self.leo_c w = c.frame.body.wrapper qt = QtCore.Qt key = event.key() if event.modifiers() != qt.NoModifier and not event.text(): # A modifier key on it's own. pass elif key in (qt.Key_Up, qt.Key_Down): QtWidgets.QListWidget.keyPressEvent(self, event) elif key == qt.Key_Tab: if trace: g.trace('') self.tab_callback() elif key in (qt.Key_Enter, qt.Key_Return): if trace: g.trace('') self.select_callback() else: # Pass all other keys to the autocompleter # via the event filter. w.ev_filter.eventFilter(obj=self, event=event) So this is where the change should be made. *Important*: the default eventFilter method, that is, LeoQtEventFilter.eventFilter, is insanely complicated. Don't change it! So you have to special case PageUp and PageDown in lqlw.keyPressEvent. To repeat, I *never *try to remember implementation details. I had forgotten that LeoQListWidget.keyPressEvent event existed. The only things I knew at the start was: 1. The gui-independent autocompleter in @file leoKeys.py-->class AutoCompleterClass has one or more ivars that would tell when to use Qt popup completions rather than inline completions. 2. There was a Qt-specific class that handles Qt popup completions. This class is defined somewhere in the tree whose root is leoPy.leo#Code-->Qt gui. 3. Changing LeoQtEventFilter.eventFilter should be a last resort. HTH. Please feel free to ask more questions. Edward -- 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 leo-editor+unsubscr...@googlegroups.com. To post to this group, send email to leo-editor@googlegroups.com. Visit this group at http://groups.google.com/group/leo-editor. For more options, visit https://groups.google.com/d/optout.
Re: Learning from IPython
I'm intrigued by this and in fact instead of implementing Jedi or Rope the functionality here might offer enough of a base to gussy it up. I'd eventually like to improve the aesthetics of the autocomplete popup window itself. However I'm finding myself stumped by the KeyHandler class. One thing that the autocomplete Qt popup doesn't handle right now is PgUp and PgDown, both of these keybinding exit the popup. I was trying to fix this but I'm having difficulty figuring out where to do this. Any guidance would be much appreciated. On Tuesday, September 15, 2015 at 12:16:19 PM UTC-4, Edward K. Ream wrote: > > On Tue, Sep 15, 2015 at 10:08 AM, 'Terry Brown' via leo-editor < > leo-e...@googlegroups.com > wrote: > >> On Tue, 15 Sep 2015 07:53:57 -0700 (PDT) >> "Edward K. Ream"wrote: >> >> > More interestingly Leo could use IPython's scheme of basing code >> > completion of live objects, provided users are willing to execute the >> > code in an outline. Yes, this could be dangerous, and people must be >> > aware of the dangers. >> >> Leo can already do this after a fas >> h >> ion via my additions[1] to the >> valuespace plugin. >> > > Very good. Glad to hear it. > > Edward > -- 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 leo-editor+unsubscr...@googlegroups.com. To post to this group, send email to leo-editor@googlegroups.com. Visit this group at http://groups.google.com/group/leo-editor. For more options, visit https://groups.google.com/d/optout.
Re: Learning from IPython
On Tue, 15 Sep 2015 07:53:57 -0700 (PDT) "Edward K. Ream"wrote: > More interestingly Leo could use IPython's scheme of basing code > completion of live objects, provided users are willing to execute the > code in an outline. Yes, this could be dangerous, and people must be > aware of the dangers. Leo can already do this after a fasion via my additions[1] to the valuespace plugin. e.g. csv. No Completions import csv select that text, and `vs-eval`. csv. Normal completion occurs. csv.reader? Docs. shown in log window. `vs-eval` selects the next line after executing one selected line, so it's easy to step through code. You have to select multi-line blocks for it though, things like for loops. vs-last(-pretty) just insert the result of the last vs-eval into the body. [1] vs-eval, vs-last, and vs-last-pretty are commands I shoehorned into valuespace to avoid creating yet another plugin. The execute / evaluate in the c.vs namespace created by valuespace. Cheers -Terry -- 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 leo-editor+unsubscr...@googlegroups.com. To post to this group, send email to leo-editor@googlegroups.com. Visit this group at http://groups.google.com/group/leo-editor. For more options, visit https://groups.google.com/d/optout.
Re: Learning from IPython
On Tue, Sep 15, 2015 at 10:08 AM, 'Terry Brown' via leo-editor < leo-editor@googlegroups.com> wrote: > On Tue, 15 Sep 2015 07:53:57 -0700 (PDT) > "Edward K. Ream"wrote: > > > More interestingly Leo could use IPython's scheme of basing code > > completion of live objects, provided users are willing to execute the > > code in an outline. Yes, this could be dangerous, and people must be > > aware of the dangers. > > Leo can already do this after a fas > h > ion via my additions[1] to the > valuespace plugin. > Very good. Glad to hear it. Edward -- 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 leo-editor+unsubscr...@googlegroups.com. To post to this group, send email to leo-editor@googlegroups.com. Visit this group at http://groups.google.com/group/leo-editor. For more options, visit https://groups.google.com/d/optout.