Add Button in row of gridcontrol in a dialog

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Isatis34
Posts: 15
Joined: Wed Jun 28, 2023 11:45 am

Add Button in row of gridcontrol in a dialog

Post by Isatis34 »

Hello,

I've created a dialog and on this dialog, there is a gridcontrol, with colums and rows. I do that like this (code is Python) :

Code: Select all

class MyDlg(unohelper.Base, XDialogEventHandler, XMouseListener):
	...
	def show(self):
			GridJobStatus = self.dialog.getControl('GridJobStatus')
			GridModel = GridJobStatus.getModel()
			columnmodel = GridModel.ColumnModel
			GridDataModel = GridModel.GridDataModel
			
			col = columnmodel.createColumn()
			col.Title = "ID"
			col.Identifier = "ID"
			col.MaxWidth = ColSize
			col.ColumnWidth = ColSize
			columnmodel.addColumn(col)
	etc for other columns...
Is it possible to say that a column contains a button (who will call a function linked to the row) ?

I saw in the page https://wiki.openoffice.org/wiki/API/UN ... id_Control in "Feature Set" paragraph that "Each cell has its own data type", but I can't find any sample.

I try with :

Code: Select all

	Button = _createUnoService("com.sun.star.form.component.CommandButton")
	Button.Name = 'sName'
	Button.Label = 'abc'
	GridDataModel.addRow(None, [ClassJobUser.DataID, Button])
but it doesn't work (and there is no error).


Many thanks for your answer.
LibreOffice 7.5.3.2 (x86 64), Windows 10
User avatar
robleyd
Moderator
Posts: 5087
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: Add Button in row of gridcontrol in a dialog

Post by robleyd »

I'm not a macro user, but there is a tool MRI for use in inspecting objects.
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
Isatis34
Posts: 15
Joined: Wed Jun 28, 2023 11:45 am

Re: Add Button in row of gridcontrol in a dialog

Post by Isatis34 »

Hello,

Thanks, but I don't really know if MRI can inspect a dialog.

Maybe instead of a button, I can use a bitmap (an image of a button), but I have the same problem : I don't know how to display a bitmap in a cell of a GridControl.
LibreOffice 7.5.3.2 (x86 64), Windows 10
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Add Button in row of gridcontrol in a dialog

Post by Villeroy »

MRI comes with a small Basic macro Mri.Module1.mri. Call that macro with any object's event you are interested in.
From within Python, instanciate service mytools.Mri having method inspect(obj)
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Isatis34
Posts: 15
Joined: Wed Jun 28, 2023 11:45 am

Re: Add Button in row of gridcontrol in a dialog

Post by Isatis34 »

I tried MRI but it didn't give me more informations about columns and rows.
LibreOffice 7.5.3.2 (x86 64), Windows 10
JeJe
Volunteer
Posts: 2785
Joined: Wed Mar 09, 2016 2:40 pm

Re: Add Button in row of gridcontrol in a dialog

Post by JeJe »

MRI should display all the properties and methods available.

I doubt the grid control cell is a container for buttons, which are other controls.

Look for something about graphics or images perhaps.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Jurassic Pork
Posts: 24
Joined: Wed Oct 25, 2017 7:55 am
Location: France

Re: Add Button in row of gridcontrol in a dialog

Post by Jurassic Pork »

Hello,
Isatis34 wrote: Sun Dec 31, 2023 3:35 pm Maybe instead of a button, I can use a bitmap (an image of a button), but I have the same problem : I don't know how to display a bitmap in a cell of a GridControl.
Here is a code derivated from a Bernard Marcelly code, to display bitmap on the first column of a grid control.

Code: Select all

Sub Main()
xgraphic = GetGraphFromFile("d:\tmp\button.png")
makegrid(xgraphic)
End Sub

function GetGraphFromFile(FileName as String) as Any
oProvider = createUnoService("com.sun.star.graphic.GraphicProvider")
Dim oProps(0)as new com.sun.star.beans.PropertyValue
oProps(0).Name = "URL"
oProps(0).Value = ConvertToURL(FileName)
GetGraphFromFile = oProvider.queryGraphic(oProps())
end function

Sub makegrid(xgraphic)
Dim dlg As Object, km As Object, oGridModel As Object, columnModel As Object, col As Object
Dim gdatam As Object, gcolm As Object, uneColonne As Object

DialogLibraries.loadLibrary("Standard")
dlg = CreateUnoDialog(DialogLibraries.getByName("Standard").getByName("Dialog1"))
km = dlg.Model.createInstance("com.sun.star.awt.grid.UnoControlGridModel")
km.PositionX = 0
km.PositionY =  0
km.Width = 200
km.Height = 150
km.Name = "Grid1"
km.GridLineColor = RGB(0, 0, 0)
km.TextColor = RGB(0,0,150)
km.ShowColumnHeader = True
km.ShowRowHeader = True
km.HeaderBackgroundColor = RGB(255, 255, 0)
km.RowHeaderWidth = 30
km.RowHeight = 14

 ' add columns
 columnmodel =  km.ColumnModel
 col = columnmodel.createColumn()
 col.Title = "Production"
 columnmodel.addColumn(col)
  col = columnmodel.createColumn()
 col.Title = "Info"
 columnmodel.addColumn(col)
  col = columnmodel.createColumn()
 col.Title = "Result"
columnmodel.addColumn(col)
km.ColumnModel =  columnModel
gdatam =  km.GridDataModel
gdatam.addRow("France", array(xgraphic,"aaaa", -217))
gdatam.addRow("Germany", Array(xgraphic,"bbbb", 1234))
gdatam.addRow("Sweden", Array(xgraphic,"cccc", 951.23))

dlg.Model.insertByName(km.Name, km)
dlg.execute
dlg.dispose
End Sub
GridControlWithBitmap.png
GridControlWithBitmap.png (18.73 KiB) Viewed 2650 times

Friendly, J.P
OpenOffice 4.1.14 , LibreOffice 7.6.2.1 on Windows 11/ LibreOffice 7.3.7 on Lubuntu 22.04
nehavilash
Posts: 11
Joined: Wed Aug 23, 2023 10:25 pm
Location: India

Re: Add Button in row of gridcontrol in a dialog

Post by nehavilash »

For adding a button in a row of a grid control within a dialog using Python-uno.
You can test this approach too.

Code: Select all

class MyDlg(unohelper.Base, XDialogEventHandler, XMouseListener):
    ...
    def show(self):
        GridJobStatus = self.dialog.getControl('GridJobStatus')
        GridModel = GridJobStatus.getModel()
        columnmodel = GridModel.ColumnModel
        GridDataModel = GridModel.GridDataModel
        
        col = columnmodel.createColumn()
        col.Title = "ID"
        col.Identifier = "ID"
        col.MaxWidth = ColSize
        col.ColumnWidth = ColSize
        columnmodel.addColumn(col)
        # Add a column with buttons
        col2 = columnmodel.createColumn()
        col2.Title = "Button Column"
        col2.Identifier = "ButtonCol"
        col2.MaxWidth = ColSize  # Set the width as needed
        col2.ColumnWidth = ColSize
        columnmodel.addColumn(col2)
        # Add buttons to each row
        for i in range(GridDataModel.RowCount):
            Button = self.dialog.createInstance('com.sun.star.form.component.CommandButton')
            Button.Label = 'Button Label'
            # Set the action here for the button, replace 'your_function' with your actual function
            Button.ActionCommand = 'your_function'
            GridDataModel.setValueAt(Button, i, 1)  # '1' is the index of the button column

    # Define your_function to handle button click actions
    def your_function(self, event):
        # Your code to handle button click actions goes here
        pass
I hope it helps.
Apache OpenOffice 4.1.14
A004114m1 (Build:9811) - Rev. a0d24fb625
2023-02-08 09:30:40 (Wed, 08 Feb 2023) - Darwin x86_64
Isatis34
Posts: 15
Joined: Wed Jun 28, 2023 11:45 am

Re: Add Button in row of gridcontrol in a dialog

Post by Isatis34 »

Hello,

This line
GridDataModel.setValueAt(Button, i, 1) # '1' is the index of the button column

generate this error :

File "XXXX.py", line 3326, in GetAll
GridDataModel.setValueAt(Button, row, 1) # '1' is the index of the button column
AttributeError: setValueAt

I don't find setValueAt function in https://www.openoffice.org/api/docs/com ... teCellData
LibreOffice 7.5.3.2 (x86 64), Windows 10
nehavilash
Posts: 11
Joined: Wed Aug 23, 2023 10:25 pm
Location: India

Re: Add Button in row of gridcontrol in a dialog

Post by nehavilash »

I gave you for getting some idea don't worry I'll test it and send it to you.

Thank you.
Apache OpenOffice 4.1.14
A004114m1 (Build:9811) - Rev. a0d24fb625
2023-02-08 09:30:40 (Wed, 08 Feb 2023) - Darwin x86_64
Isatis34
Posts: 15
Joined: Wed Jun 28, 2023 11:45 am

Re: Add Button in row of gridcontrol in a dialog

Post by Isatis34 »

hello,

Sorry, I was busy on other projet.

this is what I do :

graphicprovider = _createUnoService('com.sun.star.graphic.GraphicProvider')
Prop = [ PropertyValue(Name='URL', Value=GetResource('INFO_GRID')) ]
xgraphic = graphicprovider.queryGraphic(Prop)

row = -1
GridDataModel.removeAllRows()
for idx, ClassJobUser in enumerate(ClsOUTListofJobs):
row = row + 1
GridDataModel.addRow(None, [ClassJobUser.DataID, xgraphic, ClassJobUser.JobType, 'abc', ClassJobUser.JobStatus, ClassJobUser.Infos, ClassJobUser.Error, ClassJobUser.UserName, str(ClassJobUser.CreationDateDesc) + " " + str(ClassJobUser.CreationTimeDesc), str(ClassJobUser.ModificationDateDesc) + " " + str(ClassJobUser.ModificationTimeDesc), AdaptStringForJSon(ClassJobUser)])

and it works fine with conjuction with XMouseListener - GridJobStatus.addMouseListener(self)

Many thanks for you help
LibreOffice 7.5.3.2 (x86 64), Windows 10
Post Reply