Detect row selection in wxGrid - events

I would like to be warned when user selects the whole row in a wxGrid but I do not see an event that handles this.What is the best way to do it?

You can do this using EVT_GRID_RANGE_SELECT, and then check that the range is a single row when the handler is called.
For example, in the GridSimple.py wxPython demo, put the line in SimpleGrid.__init__
self.Bind(gridlib.EVT_GRID_RANGE_SELECT, self.OnSelectRange)
And then add this to see which cells were selected.
def OnSelectRange(self, evt):
print "on select range", evt.GetTopLeftCoords(), evt.GetBottomRightCoords()
From this you can determine whether the selection was one that you're interested in.

Actually, I figured it out. There are events like EVT_GRID_LABEL_LEFT_CLICK and then I test event.GetCol() == -1, to make sure the click is on a whole row, not a whole column.

Related

Using Tab key to add a row in QTablewidget

I am developing a recipe application using a QTableWidget to add the ingredients for a recipe. I use a button to add a row to insert a new ingredient. This works well but like many existing applications I would like to use the tab key to add a new row when the last column in the last row has the focus. I presume I must identify the tab key pressed and which column and row has the focus but I am not clear on how to do that.
The easiest way is to subclass the table widget and implement the closeEditor() function, which is called whenever a delegate signals that the editor is going to be closed, and is proposing the next action to do after closing.
Using the tab key, the EditNextItem hint is used, so it's enough to check for that flag, ensure if the current index is the last column of the last row, and then add a row before calling the base implementation method:
class TableWidget(QtWidgets.QTableWidget):
def closeEditor(self, editor, hint):
if hint == QtWidgets.QAbstractItemDelegate.EditNextItem:
current = self.currentIndex()
if (current.row() == self.rowCount() - 1 and
current.column() == self.columnCount() - 1):
self.insertRow(self.rowCount())
super().closeEditor(editor, hint)

Filter() formula ignoring blank cells

I'm trying to use the filter() formula within a spreadsheet, from another tab within that spreadsheet.
I've got a number of drop-down menus that, when used, bring up the relevant data from the table I'm filtering from.
I've managed to make it work when it's a table of data from row 2 downwards (row 1 being a header row), but now the table starts from the 6th row down with other information above it (most of it, however, is blank). As such, now all of the options come up automatically when the drop down menus are blank.
I either need the formula below to start from the 6th row down, or to ignore the blank cells. It must be an easy solution but for the life of me, I can't find it anywhere on the internet (I'm pretty new with spreadsheet formulas so please be gentle).
This is the formula I've been using that works when there are no blank rows:
=FILTER(Sheet2!A:T,(Sheet2!D:D=B12)+(Sheet2!F:F=C12)+(Sheet2!G:G=D12)+(Sheet2!H:H=E12)+(Sheet2!I:I=F12)+(Sheet2!N:N=G12)+(Sheet2!O:O=H12)+(Sheet2!T:T=I12))
If it helps, the drop-down options are both numbers and text, and I'm using Google Sheets rather than Excel.
You can probably just change your ranges to 'A6:T' instead of 'A:T'. 'A:A' range syntax gets all rows in that column. 'A6:A' will start it at 6 but not define an ending row, which I think is what you want.
This is your formula with those small changes:
=FILTER(Sheet2!A6:T,(Sheet2!D6:D=B12)+(Sheet2!F6:F=C12)+(Sheet2!G6:G=D12)+(Sheet2!H6:H=E12)+(Sheet2!I6:I=F12)+(Sheet2!N6:N=G12)+(Sheet2!O6:O=H12)+(Sheet2!T6:T=I12))
The =isBlank() formula may be useful to you as well. It takes a cell reference and returns true/false. You can wrap this in NOT() to give the opposite result, i.e =NOT(ISBLANK(A1)) will return true if there is a value.

How to know when NSTableView is done (re)loading its contents?

I have a UI that looks similar to the mail app. A table view along the left with a single column of items. When one of the those items on the left is selected, details about that item are shown on the right.
When some event occurs in my app that requires the data in the left table view to be reloaded, the current selection is lost and then the right detail view and left master view get out of sync.
The way i hoped to solve this problem was, when it was time to reload the table data, I would:
1. Save the current selected item
2. reload the table data
3. Handle a delegate method or notification that let me know when the reloading was done.
4. Re-select the proper item by finding it in the new list of items in the table.
Unfortunately I cannot find any way to determine when the table is done reloading. Is there a. any way to figure this out, or b. a more elegant solution to this problem?
thanks.
update: In case my problem was unclear, imagine you are in the mail app and you have some message selected. That summary cell is shown as selected on the left, and the details of the message are shown on the right. Suppose new mail comes in which appear as new cells at the top of the table. How is the message you are currently viewing preserved, and not de-selected?
reloadData is something of a sledgehammer. 10.7 offers a better solution.
Instead of using reloadData, when you have new rows to add, use insertRowsAtIndexes:withAnimation: . When you have rows to delete, use removeRowsAtIndexes:withAnimation: . And, of course, if an existing row has changed, there's reloadDataForRowIndexes:columnIndexes.
These should remember the selection for you (at least, the equivalents on iOS do).
If you can't target 10.7, some of the other suggestions will probably help out. noteNumberOfRowsChanged may also be helpful but I've not actually used it.
You can save selection on tableView(_:shouldSelectRow:) then select the row right after you create the cell in tableView(_:viewFor:row:) using selectRowIndexes(_:byExtendingSelection:).
It is pretty reliable no matter how / when / how many times you reload the table.

datatables sorting with images

I have the following problem - I have a datatable with n number of rows. The first column is Serial Number using simple counter. My table has a functionality in which when I double click the row, it becomes editable and 'check' and 'cancel' images show up in the first column, right beside the serial number. User can edit row and save/cancel the row accordingly.
The problem with this logic is, since there are images in the first column, I'm not able to sort the table based on the first column. When I remove the images, sorting works perfectly.
I know this is a weird problem, but I really dont want to change the editing logic for this.
Please help!!
Got help from datatables.net. Removed the images from the first column. On edit event, used jQuery append and remove to add/remove the elements to the first column.

How to find a particular table cell in Watir

Using Watir to regression test some changes: I want to 'click' a row in a typical old style web page menu, where the menu is a table of tables. In this particular example, the table cell contains the menu item, and the row, which only consists of the one cell, has an onclick handler. I thought I could
cell = browser.element_by_xpath("//div[#id='Menu']/descendant::td[text()='New!'")
and use the cell to get the parent row, but I get the message
c:/ruby/lib/ruby/1.8/rexml/parsers/xpathparser.rb:330:in 'Predicate': undefined
method `[]' for nil:NilClass (NoMethodError)
which makes no sense to me.
We really need more detail before before an answer can be given
Generally speaking there are a few ways to deal with tables. You can use absolute indexes to the row and column numbers if that will always be the same, but a lot of times that's not the case.
If there's known (unique) text on the row somewhere, and the column of the cell is known, then you can often work via using a regular expression to identify the row with the known (and unique) text, and then identify the needed cell via it's 'column' within the row.
browser.row(:text, /my search text/).cell(:index, 2) # 2nd cell in the row that contains text matched by the regex
try this
cell = browser.div(:id,'Menu').cell(:text,'New!')
cell.click
and, maybe you lost closing ']' ?
cell = browser.element_by_xpath("//div[#id='Menu']/descendant::td[text()='New!']")

Resources