Can I use Python to set zoom to Fit Page?

Hi,

I’m trying to find a way a keyboard shortcut to Fit Page, directly, using Preferences, or using some Python code. Is there a way to do it?

Thank you,

Ioan Călin

1 Like

That’s in the Canvas Input settings and it’s the ‘2’ key.
If you think about changing it, make sure any change you make doesn’t clash with a keyboard shorcut key.

Now I see the light :smile:

I think Krita has a bit weird way to handle this, but at least now I know where to look for it. Is this accessible through Python?

Thanx.

I’ve no idea about Python but quite a few people here do know a lot about it.
Can you edit the topic title to say ‘Can I use Python to activate keyboard shortcuts?’, or whatever, to draw their attention?

Done. Thanx :+1:

Nearly everything that you can access by a shortcut can be accessed from Python, it’s just a bit hidden. It’s called “action”. You can use it like that:

krita.Krita.instance().action("convert_to_paint_layer").trigger()

And it will act as if you used a shortcut (in this case, it would convert the active layer to paint layer).

All actions are described in krita.action file: https://phabricator.kde.org/source/krita/browse/master/krita/krita.action , you can also just look in the Keyboard Shortcut and find what interests you and use the description/name from there to find the action in krita.action file (you need the name with _).

2 Likes

Running this script:

from krita import Krita
import re

r = re.compile('(zoom|page|fit)', re.IGNORECASE)
for a in Krita.instance().actions():
   if r.search(a.objectName()) or r.search(a.text()):
       print([a.objectName(), a.text()])

I get this output:

['zoom_to_100pct', '&Reset zoom']
['view_zoom_in', 'Zoom &In']
['view_zoom_out', 'Zoom &Out']
['view_zoom', 'Zoom']
['ZoomTool', 'Zoom Tool']

None of these look to be the one I’m looking for specifically – the one that allows me to fit page.

Am I missing something?

1 Like

Perhaps because it is not in Keyboard Shortcuts section, but in Canvas Input Settings section (Zoom Canvas sub-section), so maybe these are different kind of actions?

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.