Pyqt5 return value in a qtablewidget - pyqt5

im trying to recover a value from a qtablewidget and i have two problems:
First: when i clicked pushbutton i get tablewidget.currentrow but when i change and press another row one, the row printed is not correct.
Second: How can i get the currentrow first column value?
Thanks in advance
def loadtable():
database = DataBase()
cur = database.cursor
cur.execute('select * from sge_job where state like \'r\'')
result = cur.fetchall()
database.close()
ui.tableWidget.setRowCount(0)
header = ui.tableWidget.horizontalHeader()
for i in range(9):
header.setSectionResizeMode(i, QtWidgets.QHeaderView.ResizeToContents)
for row_number, row_data in enumerate(result):
ui.tableWidget.insertRow(row_number)
button = QtWidgets.QPushButton(ui.tableWidget)
button.setText("Clear")
ui.tableWidget.setCellWidget(row_number, 6, button)
button.clicked.connect(printrow)
for colum_number, data in enumerate(row_data):
ui.tableWidget.setItem(row_number, colum_number, QTableWidgetItem(str(data)))
print(row_number, colum_number)
def printrow():
print(ui.tableWidget.currentRow())

Related

How to get row data from web table in Karate framework

The web table has a combination of textbox, span and checkboxes. I need to get first row of all the data in single def and have to verify with DB in order wise.
Ex: First row of table has columns like below.
OrderID(span), EmpName(input), IsHeEligible(checkbox), Address(span)
By using below,
def tebleFirstData = scriptAll("table/tbody/tr/td",'_.textContent')
Able to get only span text data, not able to get input tag test data.
I tried below,
data = attribute("table/tbody/tr/td[5]/input",'value')
But, I'm able to get only single input tag attribute value.
How can I get all the data in single def, i.e span data and input data?
Below is the solution to get all row data from table..!
* def UiFirstRowElements = locateAll("Row xpath")
print UiFirstRowElements
def tableData = []
def RowHtml = UiFirstRowElements[0].html
print RowHtml
eval
"""
for(var i=0; i<UiFirstRowElements.length; i++)
if(UiFirstRowElements[i].html.contains("input") && UiFirstRowElements[i].html.contains("date")){
tableData.push(locate("//table/tbody/tr/td["+(i+1)+"]/div/input").property('value'))
}
else if(UiFirstRowElements[i].html.contains("input") && UiFirstRowElements[i].html.contains("checkbox")){
tableData.push(locate("//table/tbody/tr/td["+(i+1)+"]/div/input").property('checked'))
}
else {
tableData.push(locate("//table/tbody/tr/td["+(i+1)+"]").property('textContent'))
}
"""
* print 'TableName-->', TableName
* print tableData

compare values in an table in lua

I need help. I am having an table like this:
local dict = {}
dict[1] = {achan = '7f', aseq='02'} --ACK
dict[2] = {dchan = '7f', dseq='03'} --DATA
dict[3] = {achan = '7f', aseq='03'} --ACK
dict[4] = {dchan = '7f', dseq='04'} --DATA
dict[5] = {achan = '7f', aseq='04'} --ACK
dict[6] = {dchan = '7f', dseq='02'} --DATA
Basically I am using this in an Dissector so I don't know the Index except the one I am actually "standing" at the moment.
So what I want to have is:
if the "achan" and the "dchan" is the same and the "aseq" i am standing at the moment is the same as an "dseq" value on positions from the past which are already saved into the table then it should give me back the index from the same "dseq" value from the past.
if (dict[position at the moment].achan == dict[?].dchan) and (dict[position at the moment].aseq == dict[?].dseq) then
return index
end
for example: dchan from position 6 is the same es achan from position 1 and dseq from position 6 is the same as aseq from position 1. So I want to get the position 1 back
You can use a numeric for loop with a negative step size to go back in your table, starting from the previous element. Check wether the achan and aseq fields exist, then compare them vs the dchan and dseq fields of your current entry.
function getPreviousIndex(dict, currentIndex)
for i = currentIndex - 1, 1, -1 do
if dict[i].achan and dict[currentIndex].dchan
and dict[i].achan == dict[currentIndex].dchan
and dict[i].aseq and dict[currentIndex].dseq
and dict[i].aseq == dict[currentIndex].dseq then
return i
end
end
end
This code assumes you have no gaps in your table. You should also add some error handling that makes sure you actually are at a dchan entry and that your index is in range and so on...

How to call a function into another function with different parameters?

Part 1:
Write function def setPixelToBlack(pixel) to change each pixel's colour to black.
Part2:
Write the function def setPictureToBlack(picture) which blacks out the picture. The function has to call setPixelToBlack from part 1.
I have set up my setPixelToBlack(pixel) code but do not know how to use it within the setPictureToBlack(picture) function!
def setPixelToBlack(pixel):
for p in getPixels(pixel):
value = getRed(p)
setRed(p, value * 0)
value = getGreen(p)
setGreen(p, value * 0)
value = getBlue(p)
setBlue(p, value * 0)
def setPictureToBlack(picture):
for p in getPixels(pixel):
setPixelToBlack(pixel)
> f = pickAFile()
>>p = makePicture(f)
>>>setPictureToBlack(p)
>>>>explore(p), this should black out the image selected!
for p in getPixels(pixel): isn't necessary in setPixelToBlack, as you're not looking at multiple pixels.
You also don't need to get the original value of the pixel if you're just setting it to zero.
I assume the getPixels() function takes in the picture, so change that and setPixelToBlack(p) should get you the desired outcome

How to print records number in form view in odoo?

I have in my python file this function to count number of records in (Order Lines):
class Class_sale_order(models.Model):
_inherit = 'sale.order'
caseacocher_sale_order = fields.Boolean(string='Print customized')
new_field2 = fields.Integer(compute='function_count_saleorderlines')
#api.depends('order_line')
def function_count_saleorderlines(self):
for rec in self:
rec.new_field2 = len('order_line')
But when i see the form view i find that the value of filed is 10, the problem that i have only 5 records.
len('order_line') returns the size of the string 'order_line' which is 10 that's why you are getting the value 10. Set like following:
rec.new_field2 = len(rec.order_line)

How to get first row from Google Spreadsheets Data API

Here is an example: https://spreadsheets.google.com/feeds/list/1a2JzZzUjSIcpROgR5v_M-UmWyT-iokcegIxHJOopZWA/od6/public/full?alt=json
The returned JSON data doesn't contain the first row from the spreadsheet.
You can view the contents of the spreadsheet in HTML (https://docs.google.com/spreadsheets/d/1a2JzZzUjSIcpROgR5v_M-UmWyT-iokcegIxHJOopZWA/pubhtml) to verify that "first row" exists in the sheet.
How can I get the first row from the spreadsheet? There is a "openSearch$startIndex" = 1 in the returned JSON. Maybe if you could set this to 0, I could get the first row also.
1st Row - Cell feed
https://spreadsheets.google.com/feeds/cells/key/worksheetId/private/full?min-row=1&min-col=1&max-col=4
Docs: https://developers.google.com/google-apps/spreadsheets/#fetching_specific_rows_or_columns
Cell feed is better for almost everything. But append a data row is better in list feed, I think.
In C# you would do it like this:
var link = worksheet.Links.FindService(GDataSpreadsheetsNameTable.CellRel, null).HRef.ToString();
var cellQuery = new CellQuery(link)
{
MinimumRow = 1,
MaximumRow = 1,
MinimumColumn = 1
};
CellFeed header = spreadsheetService.Query(cellQuery);