Page 1 of 1

Python macro: Dialog controls not responding to mouse clicks

PostPosted: Sat Aug 19, 2017 3:53 pm
by frowdow
I have a python macro to display a dialog consisting of 2 radio buttons, 2 check boxes, and 2 default buttons, OK and CANCEL. I notice that only the first check box is responding to mouse clicks. But all controls are responding when i move to them using the keyboard and tabbing them. If anyone has any quick insight into why this might be the case, i would be most grateful. The code i have is shown below:

Code: Select all   Expand viewCollapse view

def inputbox(message, title="", default="", x=None, y=None):
    """ Shows dialog with input box.
        @param message message to show on the dialog
        @param title window title
        @param default default value
        @param x dialog positio in twips, pass y also
        @param y dialog position in twips, pass y also
        @return string if OK button pushed, otherwise zero length string
    WIDTH = 300
    BUTTON_WIDTH = 100
    EDIT_HEIGHT = 24
    HEIGHT = 150
    import uno
    import unohelper
    from import POS, SIZE, POSSIZE
    from import OK, CANCEL
    from import TWIP
    from import XActionListener
    from import XItemListener

    ctx = uno.getComponentContext()
    def create(name):
        return ctx.getServiceManager().createInstanceWithContext(name, ctx)
    dialog = create("")
    dialog_model = create("")
    dialog.setPosSize(0, 0, WIDTH, HEIGHT, SIZE)
    def add(name, type, x_, y_, width_, height_, actListener, props):
        model = dialog_model.createInstance("" + type + "Model")
        dialog_model.insertByName(name, model)
        control = dialog.getControl(name)
        control.setPosSize(x_, y_, width_, height_, POSSIZE)
        if actListener != 0:
            control.addItemListener(actListener(dialog, name))
        for key, value in props.items():
            setattr(model, key, value)
    class radioListener( unohelper.Base, XItemListener ):
        def __init__(self, cCont, name):
            self.nCount = 0
            self.cCont = cCont
            self.cName = name
        def itemStateChanged(self, actionEvent):
            cCont = self.cCont
            oCont = cCont.getControl(self.cName)
    add("Chk1", "CheckBox", 10, 5, 150, 150, 0, {"Label": "Show redeemed funds"})
    add("Chk2", "CheckBox", 20, 45, 150, 150, 0, {"Label":"By Fund Subtype"})
    add("Radio1", "RadioButton", 10, 25, 150, 150, radioListener, {"Label":"Fund Type", "State": 1})
    add("Radio2", "RadioButton", 10, 65, 150, 150, radioListener, {"Label":"By Fund AMC", "State": 0})
    add("btn_ok", "Button", 10, 85,
            BUTTON_WIDTH, BUTTON_HEIGHT, 0, {"PushButtonType": OK})
    add("btn_cancel", "Button", 160, 85,
            BUTTON_WIDTH, BUTTON_HEIGHT, 0, {"PushButtonType": CANCEL})
    frame = create("").getCurrentFrame()
    window = frame.getContainerWindow() if frame else None
    dialog.createPeer(create(""), window)
    if not x is None and not y is None:
        ps = dialog.convertSizeToPixel(uno.createUnoStruct("", x, y), TWIP)
        _x, _y = ps.Width, ps.Height
    elif window:
        ps = window.getPosSize()
        _x = ps.Width / 2 - WIDTH / 2
        _y = ps.Height / 2 - HEIGHT / 2
    dialog.setPosSize(_x, _y, 0, 0, POS)
    return 0
#This function can be called as follows:
def inpmacro(*args):
    inputbox("Please input some value", "Input", "Default value")

Re: Python macro: Dialog controls not responding to mouse cl

PostPosted: Sat Aug 19, 2017 5:05 pm
by Villeroy
I think your controls are too big and overlapping. Try to resize them by means of ... rains.html

Re: Python macro: Dialog controls not responding to mouse cl

PostPosted: Sun Aug 20, 2017 6:55 am
by frowdow
Spot on. But then i observed that the labels for the controls were not getting displayed. So i pushed the code for sizing the controls using getPreferredSize() to after setting the labels, and then it worked. Where is all this documented? Seems a little arbitrary to me. Anyway, thanks a ton, Villeroy.

Re: Python macro: Dialog controls not responding to mouse cl

PostPosted: Sun Aug 20, 2017 9:30 am
by Villeroy
Root node of the API reference. This is more or less automatically generated from the source code: ... le-ix.html

Developers Guide: ... pers_Guide

Self-documentation GUI: ... 74&t=49294

Improved GUI for Python macros: ... for-python