MH programming model and Scripting plugin

This forum is aimed at user contributions, in the form of assets, side projects, code patches and similar.

Moderator: joepal

MH programming model and Scripting plugin

Postby Solkar » Tue Dec 16, 2014 7:25 pm

I'm working on making the scripting module (7_scripting.py) more comfortable.
Therefor I want to define some local shortcuts, by means of

lib/qtui.py 750 pp¹
Code: Select all
def setShortcut(modifier, key, action):
    action.setShortcut(QtGui.QKeySequence(modifier + key))

which is passed upwards by the mh module.

Thus I have to define "actions" by means of mh's framework, and parent them to a local group, which is itself parented to the Scripting widget.

The gui (i.e. qtgui passed through) adapter exposes a group parameter, which offers means for such custom parenting of actions

lib/qtgui.py 1858 pp²
Code: Select all
class Action(QtGui.QAction, Widget):
    #  [...]
    def __init__(self, name, text, method, tooltip = None, group = None, toggle = False):
        super(Action, self).__init__(self.getIcon(name), text, G.app.mainwin)
        self.name = name
        self.method = method
        if tooltip is not None:
            self.setToolTip(tooltip)
        if group is not None:
            self.setActionGroup(self.getGroup(group))
        if toggle:
            self.setCheckable(True)
        self.connect(self, QtCore.SIGNAL('triggered(bool)'), self._activate)

    # [...]
    def setActionGroup(self, group):
        self.setCheckable(True)
        super(Action, self).setActionGroup(group)

    # [...]


but unfortunately the ActionGroup model exposed by the framework itself gets always parented to main win.

lib/qtgui.py 1916 pp³
# [...]
Code: Select all
class ActionGroup(QtGui.QActionGroup):
    def __init__(self):
        super(ActionGroup, self).__init__(G.app.mainwin)

    # [...]
# [...]


Of course, I could add an optional parameter to the ActionGroup ctor, but I'd rather not change an interface in a central layer of mh just for tiny task in a plugin.

Are there other means the mh's framework offers for defining local shortcuts than the one I sketched?

¹ https://bitbucket.org/MakeHuman/makehum ... ult#cl-750
² https://bitbucket.org/MakeHuman/makehum ... lt#cl-1858
³ https://bitbucket.org/MakeHuman/makehum ... lt#cl-1916
User avatar
Solkar
 
Posts: 63
Joined: Thu May 02, 2013 5:34 pm

Return to User contributions

Who is online

Users browsing this forum: No registered users and 1 guest