XGridSelectionListener

Hi,

thanks to https://ask.libreoffice.org/t/how-to-use-a-gridcontrol-in-a-dialog-as-kind-of-multicolumn-listbox/64152 I could create a grid control.

But when I try to get any events captured, nothing happens.

My XGridSelectionListener:

class GridSelectionListener(unohelper.Base, XGridSelectionListener):
def __init__(self):
    super().__init__()
    pass

def selectionChanged(self, evt: GridSelectionEvent):
    self.count = self.count + 1
    mri(evt)
    log("EventListener", evt.Source.Model.Name)
    #if evt.Source.Model.Name == _MY_BUTTON:
    #    evt.Source.Model.Label = _MY_LABEL+ str( self.count )
    return

def actionPerformed(self, evt: EventObject):
    self.count = self.count + 1
    mri(evt)
    log("EventListener", evt.Source.Model.Name)
    #if evt.Source.Model.Name == _MY_BUTTON:
    #    evt.Source.Model.Label = _MY_LABEL+ str( self.count )
    return

def disposing(self, evt: GridSelectionEvent):  # mandatory routine
    pass

and I assigned to the grid control:

def callDialog():
doc = XSCRIPTCONTEXT.getDocument()
dp = SM.createInstanceWithArguments("com.sun.star.awt.DialogProvider", (doc,))
ui = dp.createDialog("vnd.sun.star.script:Standard.dlg_Mapping?location=document")

act = ActionListener()
ctl = ui.getControl("cmd_zuordnen")     #ctl.Model.Label = "xxx"
ctl.addActionListener(act)

gsl = GridSelectionListener()
grid = ui.getControl("grid_transaktionen")
grid.addSelectionListener(gsl)

And idea what could be wrong with the event listener (i would expect it to trigger when I select new lines/cells in the grid …)

Thank you

1 Like

Can you describe your goal with the event listener, the post 64152 you refer to is simply working properly for obtaining values from selected rows, upon closing the dialog.
The post of sep 21 is the most complete example, however the columns are cramped to the right and not properly visible in my LO constellation.

Hi,
my gridcontrol is a kind of dictionary. When I select a line, I want to display additional information, fill certain drop downs based on the selection etc.
Now, I could select the line and use a button to trigger the additional display, but I would prefer if a grid event could do that
Hope it makes more sense now.

Have done something similar (except in basic). See → Calc BASIC | How to alter the previously opened dialog to be active ? And is there double click event for grid in dialog?
.
I am currently attempting to implement in Python but problems occur with the listener. Have used listeners in other Python routines but here seems to have issues.
.
Also, how is your grid control constructed? Did you use the IDE and the control there? If so it is a source of other issues and it is better to construct from scratch.
.
Will post answer if solution occurs.

1 Like

Hello,

Thanks to @parsely for posting sample ( Python grid ). I did not have a Python dialog with grid control and sample data. Used parts of this and parts of others I had on hand.

Make note that using the IDE dialog is OK but not the grid control found there. Experienced problems noted here → Grid Control display issues

Did go off on a tangent with trying to attach a listener based upon the OP’s code, this documentation, and my post here → https://ask.libreoffice.org/t/how-can-form-close-listener-terminate-endless-loop/63738.

That does not work in this case and fortunately have done it differently in another dialog with buttons. Turns out this works well for the grid listeners.

Since the code is a couple of hundred lines, here is a txt file →
GridDialogOrig.odt (8.8 KB)
Simply change extension from odt to py and you can run test_dialog

The mouse listener is active but can change this to a selection listener at line 150 in the code. There are other listeners which can also be used.

1 Like

@Ratslinger thank you. The example works great and explains what I am looking for.

I now prepared a litte demo with some controls (button, combobox, listbox, treecontrol, grid), but used the dialog editor. XGridSelection does not work in this example as expected, but the mouse event seems sufficient.
DialogDemo.ods (14.1 KB)
Thanks again for the support

1 Like

I did note:

It will work if you code the grid control and add it into the dialog as I did in the link. Avoid using the control as you did. Will eventually cause issues.

Edit:
Should have done this first. With your original post, changed the listener from mouse to grid selection and there was no problem. I would still not use the IDE control because of other potential issues.

Warning noted :slight_smile:
I added two lines to the row creation:
column.Resizeable = True
column.Flexibility = False
Now the horizontal scrolling works as well. Created a grid with 100x10000 entries, works ok as far as I can judge
DialogDemo.ods (14.0 KB)

Good research resulting in extended application of the dialog, not achievableby me.

I played aroud with it, and noted that, with only the mouse listener active:

  • the mouse event interferes with clicking on the columnheader: sorting based on the column is deactivated
  • once a columnheader is clicked, the mouse event does not work properly anymore. Clicking on a row results in a repeat of the information of the last row selected, before the columnheader was clicked.

Build ID: 1:6.4.7-0ubuntu0.20.04.2 Just FYI

Strange, I do not have issues with sorting.The only issue with Linux was/is that I don’t have a close button in the dialog’s header line - thats why I introduced a quit button.
My version:
Version: 7.2.5.2 / LibreOffice Community
Build ID: 20(Build:2)
CPU threads: 8; OS: Linux 5.13; UI render: default; VCL: kf5 (cairo+xcb)
Locale: de-DE (de_DE.UTF-8); UI: de-DE
Ubuntu package version: 1:7.2.5~rc2-0ubuntu0.20.04.1~lo1
Calc: threaded

With another look, have no issue with sorting.
.

Version: 7.2.5.2 / LibreOffice Community
Build ID: 499f9727c189e6ef3471021d6132d4c694f357e5
CPU threads: 8; OS: Linux 5.4; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: threaded