Python macro: Dialog controls not responding to mouse clicks

Keyboard macros or custom scripts

Python macro: Dialog controls not responding to mouse clicks

Postby frowdow » Sat Aug 19, 2017 3:53 pm

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:
Thanks,
Sachin

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
    HORI_MARGIN = VERT_MARGIN = 8
    BUTTON_WIDTH = 100
    BUTTON_HEIGHT = 26
    HORI_SEP = VERT_SEP = 8
    LABEL_HEIGHT = BUTTON_HEIGHT * 2 + 5
    EDIT_HEIGHT = 24
    HEIGHT = 150
    import uno
    import unohelper
    from com.sun.star.awt.PosSize import POS, SIZE, POSSIZE
    from com.sun.star.awt.PushButtonType import OK, CANCEL
    from com.sun.star.util.MeasureUnit import TWIP
    from com.sun.star.awt import XActionListener
    from com.sun.star.awt import XItemListener

    ctx = uno.getComponentContext()
    def create(name):
        return ctx.getServiceManager().createInstanceWithContext(name, ctx)
    dialog = create("com.sun.star.awt.UnoControlDialog")
    dialog_model = create("com.sun.star.awt.UnoControlDialogModel")
    dialog.setModel(dialog_model)
    dialog.setVisible(False)
    dialog.setTitle(title)
    dialog.setPosSize(0, 0, WIDTH, HEIGHT, SIZE)
    def add(name, type, x_, y_, width_, height_, actListener, props):
        model = dialog_model.createInstance("com.sun.star.awt.UnoControl" + 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)
            oCont.setLabel("YIPPEE")
    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("com.sun.star.frame.Desktop").getCurrentFrame()
    window = frame.getContainerWindow() if frame else None
    dialog.createPeer(create("com.sun.star.awt.Toolkit"), window)
    if not x is None and not y is None:
        ps = dialog.convertSizeToPixel(uno.createUnoStruct("com.sun.star.awt.Size", 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)
    dialog.execute()
    dialog.dispose()
    return 0
#This function can be called as follows:
def inpmacro(*args):
    inputbox("Please input some value", "Input", "Default value")
OpenOffice 3.1 Windows 8.1
frowdow
 
Posts: 3
Joined: Mon Nov 17, 2014 4:23 pm

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

Postby Villeroy » Sat Aug 19, 2017 5:05 pm

I think your controls are too big and overlapping. Try to resize them by means of http://www.openoffice.org/api/docs/comm ... rains.html
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24789
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Postby frowdow » Sun Aug 20, 2017 6:55 am

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.
OpenOffice 3.1 Windows 8.1
frowdow
 
Posts: 3
Joined: Mon Nov 17, 2014 4:23 pm

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

Postby Villeroy » Sun Aug 20, 2017 9:30 am

Root node of the API reference. This is more or less automatically generated from the source code: http://www.openoffice.org/api/docs/comm ... le-ix.html

Developers Guide: https://wiki.openoffice.org/wiki/Docume ... pers_Guide

Self-documentation GUI: https://forum.openoffice.org/en/forum/v ... 74&t=49294

Improved GUI for Python macros: https://extensions.libreoffice.org/exte ... for-python
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24789
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: No registered users and 7 guests