Inspect Spyder Internals HOWTO: find Ctrl-F key action handler and search panel editor component

60 views
Skip to first unread message

anatoly techtonik

unread,
Sep 22, 2011, 5:47:29 AM9/22/11
to spyd...@googlegroups.com
I won't expand on how cool it is if people with no knowledge of Spyder codebase could send a patch in just a few hours. And to make this happen they need two things:
  1. An entrypoint
  2. Some guidance
Even if I know spyderlib a bit, right now I am in position of such a person - with no entrypoint and guidance at all. So, this is a question to all developers - how can one find the source of a problem when Spyder misbehaves? I'd like to limit the scope to this specific case - Spyder fails to focus on search panel that is called by pressing Ctrl-F in editor if this panel is already present.


Carlos Córdoba

unread,
Sep 22, 2011, 5:30:46 PM9/22/11
to spyd...@googlegroups.com
Hi Anatoly,

I've seen you also work on Linux so I think you'll find my few advices useful:

1. First, use ack to find the file you need to work on. ack is a perl script that behaves pretty much like grep, but doesn't search inside binaries, build dirs, nor .hg or .git ones. It's been explicitly designed to easily search source code trees and it has colored output.

In Ubuntu you can install it with:

$ sudo apt-get install ack-grep

In your case, I'd run a search for Ctrl-F with it, because that's how the widget is called. Something like

$ ack-grep 'Ctrl\+F'

inside the spyderlib dir gives one promising result (apart from others):

widgets/findreplace.py
142:        self.togglefind_sc = QShortcut(QKeySequence("Ctrl+F"), parent,
167:                (self.togglefind_sc, "Find text", "Ctrl+F"),

So now you know that widgets/findreplace.py is your starting point.

2. Now my advice become less explicit and more general. Obviously, your next step is open the file and start to look at their classes. Maybe you realize all you need to do is to modify code inside it. But it could be the case that a class in it inherits a class from other file, which is the one you think you have to modify. So you run ack again to find where this new code is located, and so on until you find the right spot.

3. Always maintain the Internal Console open to read the errors you get while you hack on Spyder. I found it an invaluable tool to understand what I am doing wrong. You can also add print statements to any file and the results will be printed in the Internal console too (or simply in the terminal from which you launched Spyder). That's quite cool! For example, it let me solve Issue 647.

4. Browse the Qt docs with passion to find how to use their classes and libraries. At least I have to do that a lot since I know pretty much nothing about Qt.

That's all I have to say. Maybe we could setup an IRC channel or use gmail chat to work on bugs/enhancements together. I'm sure our productivity will improve a lot.

Pierre, what do you think?

Cheers,
Carlos

El 22/09/11 04:47, anatoly techtonik escribió:
--
You received this message because you are subscribed to the Google Groups "spyder" group.
To view this discussion on the web visit https://groups.google.com/d/msg/spyderlib/-/iAJonFU2mNcJ.
To post to this group, send email to spyd...@googlegroups.com.
To unsubscribe from this group, send email to spyderlib+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/spyderlib?hl=en.

Carlos Córdoba

unread,
Sep 23, 2011, 12:36:48 PM9/23/11
to spyd...@googlegroups.com
Anatoly, is this the kind of answer you were expecting? Or were you expecting something else? Unfortunately this is all the advice I can give as a semi-regular developer, but perhaps others can comment on this thread.

Carlos

El 22/09/11 16:30, Carlos Córdoba escribió:

anatoly techtonik

unread,
Sep 24, 2011, 3:41:37 AM9/24/11
to spyd...@googlegroups.com
Hello Carlos. I expected any answer, so this one is fine. Thanks.
However, grep doesn't seem to me as a reliable entrypoint. Not
everybody know how to search for shortcut - I'd search for 'Ctrl-F'
instead of 'Ctrl+F' for example.

I thought of is a more reliable instrument to find the relevant piece
of code - it is a panel that show what happens when you press a key.
This requires:
1. [ ] create panel that can be called from '?' menu entry - probably
called 'Internal messages...'
2. [ ] add function that is called when key is pressed and logs action
and piece of code that it is going to call
Two questions here:
- is that possible at all?
- how seriously it will affect performance?
3. [ ] add checkbox on the messages panel that will allow to
dynamically turn on/off messages from keypresses

Possible message format:
(component) Action, Param1, Param2, ...

Possible format for keys handling component:
(core.keys) Ctrl-F, Action(), Location

Possible format for Location component:
{spyder}.utils.something - message from spyderlib
{plugin}.something - message from external plugin


This will require adding a separate function to add shortcuts. As a
side effect, such function can be used to maintain a registry of
available keys, to show it and spit warnings when on attempt to add
duplicate keys. Maybe Qt maintains such list and handles conflicts
itself already?
--
anatoly t.

2011/9/23 Carlos Córdoba <ccord...@gmail.com>:

Pierre Raybaut

unread,
Oct 8, 2011, 9:31:03 AM10/8/11
to spyder
Regarding the Ctrl+F shortcut misbehavior with PySide:
* debugging: simply using Spyder's "Find in files" with "Ctrl+F" as
search pattern (regexp option unchecked) will guide you to the right
place, i.e. findreplace.py
* why is it happening ? See here:
http://code.google.com/p/spyderlib/issues/detail?id=793

-Pierre
> 2011/9/23 Carlos Córdoba <ccordob...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages