This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Pan canvas from python API

Tags: None
(comma "," separated)
User avatar
rksk16it
Registered Member
Posts
21
Karma
0
OS

Pan canvas from python API

Wed Jun 06, 2018 5:49 pm
I was writing a plugin to utilize my 3d mouse with krita using spacenav library. I wish to be able to pan, scale and rotate via 3d mouse.

I was able to get events from it using QSocketNotifier via python plugin, but I cannot find a way how to pan the canvas (or view) from there. I searched for any functions regarding that at these places :
- https://api.kde.org/extragear-api/graph ... anvas.html
- https://api.kde.org/extragear-api/graph ... sView.html

Is there any other way to achieve panning via API ?

To clarify, I want smooth panning, which means i'd prefer to be able to tell how much to pan with great precision. This is what you get if you pan via mouse but NOT via keyboard, panning via keyboard is in large steps (which i dont want).
User avatar
halla
KDE Developer
Posts
5092
Karma
20
OS

Re: Pan canvas from python API

Wed Jun 06, 2018 5:58 pm
No that's not possible. Interestingly, we used to have a spacenav plugin, back in the koffice/calligra days. We even had two devices, but they disappeared when the developers who had them left the project. The code should be easy to resurrecct from an older calligra release, though.
User avatar
rksk16it
Registered Member
Posts
21
Karma
0
OS

Re: Pan canvas from python API

Wed Jun 06, 2018 6:04 pm
boudewijn wrote:No that's not possible. Interestingly, we used to have a spacenav plugin, back in the koffice/calligra days. We even had two devices, but they disappeared when the developers who had them left the project. The code should be easy to resurrecct from an older calligra release, though.


Oh. Well... if its old code then I am not very sure if it will be easily useable via python. I was hoping to do it via python only. Thanks anyways though.
User avatar
halla
KDE Developer
Posts
5092
Karma
20
OS

Re: Pan canvas from python API

Wed Jun 06, 2018 6:40 pm
Well if you just want support for the 3d mouse, it might be easier to resurrect the plugin :-)
User avatar
rksk16it
Registered Member
Posts
21
Karma
0
OS

Re: Pan canvas from python API  Topic is solved

Thu Jun 07, 2018 4:15 am
boudewijn wrote:Well if you just want support for the 3d mouse, it might be easier to resurrect the plugin :-)


The problem is I will have to first understand how to make c++ plugins for krita. I did find out the code by searching in git, but I have no idea how can I port it to current Krita. I am not saying its a huge task, but I dont even know how big or small it is. Next I will need to figure out how to retrieve the objects I require, and I havent yet found a nice dev guide for krita (I havent looked very hard though), but this is understandable as krita is undergoing heavy development.

Last, but not the least, I wanted to avoid the compile/run cycle.

That being said, I did found a way to achieve it via Python. :) From skimming the current krita code, I realized there are class(es) called *CanvasController which are used to pan/zoom etc. I also found out that the one which was actually doing it (forgot the exact name) is a derivative of QAbstractScrollArea.

Then I did QObject::dumpObjectTree on the MainWindow object (acquired via .qwindow() method from python API) to find out where these controllers are. I found that they are under KisView objects, which are named view_0, view_1, and so on, depending upon how many views are open. I then searched for children of the toplevel window using regular expression "view_.*" (using QObject.findChildren).

From the list i got, I iterate to check which one of them is under the mouse, and that happens to be the view where I am working on. Then I acquired the KisCanvasController child as QAbstractScrollArea, and then retrieved their .horizontalScrollBar () and .verticalScrollBar () and then modify their .value () property as needed.

Code: Select all
    if win != None and view != None :
      if win.isActiveWindow () :
        views = win.findChildren (QWidget, QRegExp ("view_.*"))
        for view in views :
          if view.underMouse () :
            controller = view.findChild (QAbstractScrollArea)
            break
    if controller == None :
      return

    hbar = controller.horizontalScrollBar ()
    vbar = controller.verticalScrollBar ()

    # ... do whatever i want with those scrollbars...
User avatar
halla
KDE Developer
Posts
5092
Karma
20
OS

Re: Pan canvas from python API

Thu Jun 07, 2018 6:45 am
That is hacky, but cool :-) Or cool, but hacky...


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]