-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New KeySequence Editor for Keyboard Shortcut Preferences #2367
Conversation
So far I just slimmed it down to one column, next I will go and make it editable. |
Note to self, use gist: https://gist.github.com/blink1073/946df268c3685a3f443e |
I used the native shortcut display (this is OSX). |
@ccordoba12, you can now enter the key sequences, and they are getting set properly in |
Looks cool :-) |
Beautiful ! |
I stand corrected, I had just forgotten to do a |
This is a great work @blink1073!! Thanks for this :-) I just have one suggestion for you, that I don't know if it's implemented in your PR or not. I'd like to have every entry in the new editor localized, i.e. that we can read Completado del código (when the locale is es) instead of code completion. We are very good at localization, so it's really ugly to not have our shortcuts localized right now. |
Also the options displayed should be Capitalized in English too, right ? |
Yep, that's true too :-) |
I have no idea what that means! but looks awesome |
How are we going to localize the name of the shortcuts? |
@@ -159,17 +63,12 @@ def data(self, index, role=Qt.DisplayRole): | |||
column = index.column() | |||
if role == Qt.DisplayRole: | |||
if column == CONTEXT: | |||
return to_qvariant(shortcut.context) | |||
return to_qvariant(_(shortcut.context.capitalize())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if this is enough to get things localized.
Don't we need to pass a real string to _(...)
instead of something computed from a method/function, so that gettext
grabs that string for translation?
I say it because I haven't seen any examples in our sourcecode of _(...)
applied to something that's not a string :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I think this wont do, and we will need to add a tuple or something to the shortcuts list and fix where needed in config.py
and the create_shortcut
calls... and wherever needed...?
spyderlib\config.py
...
('shortcuts',
{
# ---- Global ----
# -- In spyder.py
'_/close pane': ("Shift+Ctrl+F4", _('Close pane')),
'_/preferences': ("Ctrl+Alt+Shift+P", _('Preferences')),
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is _
not just a function call, where we pass in the result, which is the computed string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really... the gettext scripts when ran, go through the source code and grab any text and create the .po files. This process is done offline every time we need to update the translations. On runtime the _() will fetch the corresponding translated text...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So they need to be capitalized in config.py
then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like that should be a separate PR, non?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I think is better for another PR, plus not sure what would be the best way @ccordoba12 to implement it...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sorry for the noise. Let's leave localization for another PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only the modifiers are to be localized, right ? In that case the string should be parsed, each modifier translated, then the string would be rebuilt and displayed. I, don't see us providing a translation for every existing possible keybind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Nodd I was thinking of providing localization for the Context
and the Name
column only
@blink1073 I am trying this on win7 py2.7 and there is something not working. If I do not use any modifier it works great, but if I enter a shortcut that uses a modifier (for instance |
My Windows laptop is near dead, @goanpeca, can you try with the new outfitted debug statements and tell me what you find? |
So I opened the preferences and took the second shortcut for testing (Debug continue) .... Here is what I get when pressing (I put some comments in between what was printed by the debug_print): # Pressed Ctrl (and hold)
key 16777249, npressed: 1
# Pressed and released F12 (still holding Ctrl)
key 16777275, npressed: 2
decrementing
keys: set([83886139])
# Release Ctrl
keys: set([]) |
Hmm, |
Ok I checked now... it seems to be related to the Ctrl key only.
# Press Ctrl
keyPressEvent key 16777249, npressed: 1
# Press and release F12
keyPressEvent key 16777275, npressed: 2
keyPressEvent: decrementing
keyReleaseEvent keys before clear second if: set([83886139])
keyReleaseEvent keys after clear second if: set([])
# Release Ctrl
keyReleaseEvent keys before clear second if: set([])
keyReleaseEvent keys after clear second if: set([]) |
Why decremented only when it is a Ctrl modifier? if modifiers & Qt.ControlModifier:
key += Qt.CTRL
self.npressed -= 1
debug_print('keyPressEvent: decrementing') If I comment |
I notice that only shift and alt allow to put sequence of commands, whereas Ctrl does not allow for that... is this desired/normal? |
@blink1073 this is the "fix" I found for the moment, but I am not sure if it results in the desired behavior... def keyReleaseEvent(self, e):
if self.currentIndex().column() != SEQUENCE:
debug_print('keyReleaseEvent before clear first if: keys: %s' % self.keys)
self.keys = set()
self.npressed = 0
return
self.npressed -= 1
debug_print(self.npressed)
if self.npressed <= 0:
if self.keys:
keySequence = QKeySequence(*self.keys)
self.model.setData(self.currentIndex(),
keySequence.toString())
debug_print('keyReleaseEvent before clear second if: %s' % self.keys)
self.keys = set()
self.npressed = 0 |
@goanpeca, you could make a PR against @blink1073 PR with your changes :-) |
@goanpeca, that should fix it. It looks like the decrement was only needed on OSX (but I'll have to test in Linux to be sure). |
I tried it on Win7 and we can now use multi-key Ctrl sequences as well. |
@ccordoba12 you can have fun now reviewing this one ;-) |
MODIFIERS = {Qt.Key_Shift: Qt.SHIFT, | ||
Qt.Key_Control: Qt.CTRL, | ||
Qt.Key_Alt: Qt.ALT, | ||
Qt.Key_Meta: Qt.META} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this mapping necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, I think @blink1073 did this ? ?
border: 0px solid grey; | ||
padding:0px; | ||
border-radius: 0px; | ||
}""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this style work well on all OSes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea on mac... but Windows and Linux works fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I have been using this style in other widgets now... (like the array builder) so maybe we should have a centralized point for styles (that are used in several places?)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a qss stylesheet for Mac already. But let's leave that for another PR :-)
Rough edgeOn this image from @blink1073, the color of the text should be white... I thought I had fixed that... at least in linux it looks ok |
QDialogButtonBox, QLabel, QGridLayout, | ||
QLineEdit, QAbstractItemView, | ||
QSortFilterProxyModel, QStyledItemDelegate, | ||
QStyleOptionViewItemV4, QApplication, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems there's nothing named QStyleOptionViewItemV4
on Qt5. There is only QStyleOptionViewItem
, so this PR is failing there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, ok I will check this then
Could we perhaps merge it as it is? I can make a new PR to address the pending issues, I feel at this point most of the feedback relates to the changes I introduced so it would make life easier for @blink1073 and myself... |
Ok, @blink1073 says he doesn't have a problem with that. So let me finish reviewing this PR, and then you can create a new one to address my comments. |
# QKeySequence accepts a maximum of 4 different sequences | ||
if len(self.keys) > 4: | ||
# If the user enters more than 4, take the first 4 only | ||
self.keys = set([0, 1, 2, 3]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't agree with this behavior. I think we shouldn't allow a shortcut in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if an user enter a sequence of 5 and bigger nothing should happen ???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, instead of taking part of it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
Ok, good to go, on Qt5 too! |
New KeySequence Editor for Keyboard Shortcut Preferences
Fixes #478
Fixes #494
Fixes #1940
Fixes #2125
Allows the user to enter keyboard shortcut preferences by typing them in.