Page 1 of 1

[Solved] Add button in row of gridcontrol in dialog

Posted: Fri Dec 29, 2023 1:25 am
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.

Re: Add Button in row of gridcontrol in a dialog

Posted: Fri Dec 29, 2023 2:39 am
by robleyd
I'm not a macro user, but there is a tool MRI for use in inspecting objects.

Re: Add Button in row of gridcontrol in a dialog

Posted: Sun Dec 31, 2023 3:35 pm
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.

Re: Add Button in row of gridcontrol in a dialog

Posted: Sun Dec 31, 2023 4:25 pm
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)

Re: Add Button in row of gridcontrol in a dialog

Posted: Tue Jan 02, 2024 9:03 am
by Isatis34
I tried MRI but it didn't give me more informations about columns and rows.

Re: Add Button in row of gridcontrol in a dialog

Posted: Tue Jan 02, 2024 12:13 pm
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.

Re: Add Button in row of gridcontrol in a dialog

Posted: Wed Jan 03, 2024 12:27 pm
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 3736 times

Friendly, J.P

Re: Add Button in row of gridcontrol in a dialog

Posted: Fri Jan 05, 2024 9:34 am
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.

Re: Add Button in row of gridcontrol in a dialog

Posted: Mon Jan 08, 2024 11:41 am
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

Re: Add Button in row of gridcontrol in a dialog

Posted: Mon Jan 08, 2024 11:52 am
by nehavilash
I gave you for getting some idea don't worry I'll test it and send it to you.

Thank you.

Re: Add Button in row of gridcontrol in a dialog

Posted: Tue Jan 16, 2024 7:56 pm
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