Alternatives to tabs in strings when using Python wxWidgets wxlistbox - python

As noted here: http://docs.wxwidgets.org/trunk/classwx_list_box.html
Notice that currently TAB characters in list box items text are not handled consistently under all platforms, so they should be replaced by spaces to display strings properly everywhere. The list box doesn't support any other control characters at all.
So far in my experience while using Python 2.7 32-bit in Windows 7, using \t within the string of a wxListBox selection has no effect; as expected
I have a bunch of rows from the database and I have multiple columns that I want to display (and eventually use on selection of one or more row) within a row in wxListBox. For now I am using spaces as recommended as the delimiter between values in the string. However, this is not really ideal since the columns are variable length.
Is there an alternative to the \t that is not a simple delimiter? The point here is to have all of the columns for each row presented neatly i.e.
column1 value1 value2
column442142 values24234234 val2
rather than
column1 value1 value2
column442142 values24234234 val2
wxGrid comes to mind but I don't think that would work for me because I don't want to be able to select specific cells within a row (I can't seem to find the function to disable that), I only want the user to be able to select a row or multiple rows.

My advice would be to use wxListCtrl for the simple multicolumn data display or wxDataViewCtrl if you need more features.
FWIW you can use wxGrid::SetSelectionMode() with wxGridSelectRows argument to disable cell selection but wxGrid is arguably still not the best control to use for something like this.
See this slide from my lectures for a brief summary of different controls.

print " 4 whitespaces replace a tab"
print "%20s"%some_string_padded_to_20_chars

Related

how to make a list of a specific column

I have a list of linelists file as below.how do i make a list of only the 3rd column of the output(the one starting with 0.002147)this is how my output is
Assuming linelists looks something like this:
l = ['col11\tcol21\tcol31\tcol41\tcol51',
'col12\tcol22\tcol32\tcol42\tcol52']
you can select the third column with
col3list = [line.split("\t")[2] for line in l]
which gives you ['col31', 'col32'].
Based on the image you provided, it is not clear if the columns are separated by a tab or multiple spaces. If the separators are spaces, you would need to change the argument of the split function.
Something similar to your question was also already answered here.
In general I would recommend loading files with the python library pandas, which can handle all kinds of data loading and selection tasks for you.

How to stop truncating strings when I use the group by function

I have a table with columns: Location, Basic quals, Preferred quals, and Responsibilities.
The last three columns have string entries that I tokenized, I want to group the columns by Location. When I do this my strings Truncate eg. "we want an individual who knows python and java." turns into "we want an individual..."
How do I avoid this from happening?
grouped_location=pd.DataFrame(df1['Pref'].groupby(df1['Location']))
grouped_location.columns = ['Loaction','Pref']
grouped_location=grouped_location.set_index('Loaction')
grouped_location.iat[0,0]
I expect to get
17 [Experience, in, design, verification,, includ (full entry)]
but what I get is:
17 [Experience, in, design, verification,, includ...
Try saving out the dataframe to csv, it's probably only the display configuration that's truncating it.

Using Python & NLP, how can I extract certain text strings & corresponding numbers preceding the strings from Excel column having a lot of free text?

I am relatively new to Python and very new to NLP (and nltk) and I have searched the net for guidance but not finding a complete solution. Unfortunately the sparse code I have been playing with is on another network, but I am including an example spreadsheet. I would like to get suggested steps in plain English (more detailed than I have below) so I could first try to script it myself in Python 3. Unless it would simply be easier for you to just help with the scripting... in which case, thank you.
Problem: A few columns of an otherwise robust spreadsheet are very unstructured with anywhere from 500-5000 English characters that tell a story. I need to essentially make it a bit more structured by pulling out the quantifiable data. I need to:
1) Search for a string in the user supplied unstructured free text column (The user inputs the column header) (I think I am doing this right)
2) Make that string a NEW column header in Excel (I think I am doing this right)
3) Grab the number before the string (This is where I am getting stuck. And as you will see in the sheet, sometimes there is no space between the number and text and of course, sometimes there are misspellings)
4) Put that number in the NEW column on the same row (Have not gotten to this step yet)
I will have to do this repeatedly for multiple keywords but I can figure that part out, I believe, with a loop or something. Thank you very much for your time and expertise...
If I'm understanding this correctly, first we need to obtain the numbers from the string of text.
cell_val = sheet1wb1.cell(row=rowNum,column=4).value
This will create a list containing every number in the string
new_ = [int(s) for s in cell_val.split() if s.isdigit()]
print(new_)
You can use the list to assign the values to the column.
Then define the value of the 1st number in the list to the 5th column
sheet1wb1.cell(row=rowNum, column=5).value = str(new_[1])
I think I have found what I am looking for. https://community.esri.com/thread/86096 has 3 or 4 scripts that seem to do the trick. Thank you..!

PyQt 3.3.6: How to align text in a table?

I have a table in which I put numbers (as a string) in a column. For some reason, it appears that numbers with 2 or more periods (i.e. 5.5.5) will align on the left side of the cell, while numbers with fewer periods (i.e. 55.5) will align on the right side of the cell. Does anyone know how to change this?
I had a similar problem. My solution was slightly different.
When filling each item into your table, check it matches your '5.5.5' format and set the item to be right aligned.
cell = QTableWidgetItem(value)
tableWidget.setItem(row, col, cell)
# check the value matches your requirement, via regex or as below
check = value.replace('.', '')
if check.isdigit():
tableWidget.item(row, col).setTextAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignVCenter)
I understand that the characters used for the thousands separator and the decimal mark may differ between locales, but surely no locale could sensibly interpret 5.5.5 as a number? Given that, it's hardly surprising that Qt wants to treat it as ordinary text.
But anyway, the docs for QTableItem suggest you can work around this by reimplementing the alignment function:
class TableItem(QTableItem):
def alignment(self):
if is_pseudo_number(self.text()):
return Qt.AlignRight
return QTableItem.alignment(self)
...
table.setItem(row, column, TableItem('5.5.5'))
The implementation of is_pseudo_number() is left as an exercise for the reader...
(PS: since you are using PyQt3, the above code is completely untested)

How can I make wxTextCtrls in a FlexGridSizer all be 'x' lines high?

I have an array, of unknown length, of key:val pairs. Each pair occupies a row in a FlexGridSizer. The keys are in the first column, as wx.StaticTexts, and the vals are in the second column, as wx.TextCtrls.
The problem is that there isn't a lot of room available, and some of the vals are relatively long, and don't fit in the wx.TextCtrls. I would like to have all of the wx.TextCtrls be maybe 2 or 3 lines in height.
I've tried using style = wx.TE_MULTILINE, but that just adds a vertical scrollbar, as opposed to the default behaviour of scrolling horizontally with left/right/home/end etc.
Any ideas?
I suggest you use wxGrid.
http://docs.wxwidgets.org/2.9.2/overview_grid.html
According to the documentation for the wx.TextCtrl, you can apply the wx.HSCROLL style to it to make the control have a horizontal scrollbar, but this won't work on GTK1-based systems: http://xoomer.virgilio.it/infinity77/wxPython/Widgets/wx.TextCtrl.html
There's also an ExpandoTextCtrl that you might want to look at: from wx.lib.expando import ExpandoTextCtrl (see the wxPython demo for an example)
I ended up using FlexGridSizer. I made each of the val cells span across two rows, and added empty wx.Size()s below each key. The result is something like this:

Categories