I have a QTableWidget of 5 columns with horizontal headers.
I need to launch a function when header of column 4 is clicked. Currently, I have a working solution that consists of calling this function for every header clicked and then parsing the index and test if it's the right column.
Here is the current code:
self.table = QtGuiWidgets.QTableWidget()
self.table.horizontalHeader().sectionClicked.connect(self.onHeaderClicked)
def onHeaderClicked(self, logicalIndex):
if logicalIndex == 4:
print "ok"
Is there a way to avoid calling this function on every header click but just calling it when the right column header is clicked?
Related
I have an Excel file in which I want to convert the number formatting from 'General' to 'Date'. I know how to do so for one column when referring to the column letter:
workbook = openpyxl.load_workbook('path\filename.xlsx')
worksheet = workbook['Sheet1']
for row in range(2, worksheet.max_row+1):
ws["{}{}".format(ColNames['Report_date'], row)].number_format='yyyy-mm-dd;#'
As you can see, I now use the column letter "D" to point out the column that I want to be formatted differently. Now, I would like to use the header in row 1 called "Start_Date" to refer to this column. I tried a method from the following post to achieve this: select a column by its name - openpyxl. However, that resulted in a KeyError: "Start_Date":
# Create a dictionary of column names
ColNames = {}
Current = 0
for COL in worksheet.iter_cols(1, worksheet.max_column):
ColNames[COL[0].value] = Current
Current += 1
for row in range(2, worksheet.max_row+1):
ws["{}{}".format(ColNames['Start_Date'], row)].number_format='yyyy-mm-dd;#'
EDIT
This method results in the following error:
AttributeError: 'tuple' object has no attribute 'number_format'
Additionally, I have more columns from which the number formatting needs to be changed. I have a list with the names of those columns:
DateColumns = ['Start_Date', 'End_Date', 'Birthday']
Is there a way that I can use the list DateColumns so that I can save some lines of code?
Thanks in advance.
Please note that I posted a similar question earlier. The following post was referred to as an answer Python: Simulating CSV.DictReader with OpenPyXL. However, I don't see how the answers in that post can be adjusted to my needs.
You need to know which columns you want to change the number format on which you have conveniently put into a list, so why not just use that list.
Get the headers in your sheet, check if the Header is in the DateColumns list, if so then update all the entries in that column from row 2 to max with the date format you want...
...
DateColumns = ['Start_Date', 'End_Date', 'Birthday']
for COL in worksheet.iter_cols(min_row=1,max_row=1):
header = COL[0]
if header.value in DateColumns:
for row in range(2, worksheet.max_row+1):
worksheet.cell(row, COL[0].column).number_format='yyyy-mm-dd;#'
I am able to enter to the operation in SAP GUI via VBA but I am unable to find how to select or copy the value of these fields.
While recording the script via SAP GUI, copying the fields into the clipboard won't appear in the script as an action.
Any help or reference is highly appreciated.
Please find code and screenshot below (screen of type "ABAP List").
Sub XXXX()
Call SAPConnections
Session.FindById("wnd[0]/tbar[0]/okcd").Text = "Operation"
Session.FindById("wnd[0]").SendVKey 0
Session.FindById("wnd[0]/usr/ctxtP_MATRL").Text = "PartNumber"
Session.FindById("wnd[0]").SendVKey 8
Session.FindById("wnd[0]/tbar[1]/btn[1]").Press
The screen you are showing is named an "ABAP List".
It contains labels and text fields, they belong to the property Children of the GuiUserArea object, and their IDs are made of prefix lbl or txt followed by the column and row numbers. The respective SAP GUI Scripting objects are GuiLabel and GuiTextField, for example:
label at column 0 (first column) row 12 (object GuiLabel):
/app/con[0]/ses[0]/wnd[0]/usr/lbl[0,12]
text field at column 22 row 12 (object GuiTextField):
/app/con[0]/ses[0]/wnd[0]/usr/txt[22,12]
checkbox at column 0 row 0 (first row) (object GuiCheckBox):
/app/con[0]/ses[0]/wnd[0]/usr/chk[0,0]`
If you want to know all the fields which are in the ABAP list, you must loop at the property Children of the GuiUserArea object.
EDIT: checkbox added in the list above. I think we now have all the possible types of fields for an ABAP List (I guess other simple graphical elements objects like GuiButton, GuiComboBox, GuiCTextField, GuiRadioButton, are not possible).
EDIT: see this more detailed answer with a script to loop at all ABAP List fields and example with a screen and corresponding property values.
I want to select the 1st row text on the attached photo:
a = driver.find_elements_by_css_selector('a[role=option]').text
When I print above code,
It returns
1st row + 2nd row together ; 진로 두꺼비 피규어 (+600원)
But I want a 1st row text only. ; 진로 두꺼비 피규어
How can I select the 1st row text from the multiple texts in one tag?
Try this:
ele = driver.find_element_by_css_selector('a[role=option]')
ele_value = driver.execute_script("return arguments[0].childNodes[1].textContent;", ele)
print(ele_value)
I have a VBA form which is used to enter data on a sheet. I am currently coding the form so as it will load any data already existing in the sheet back into the form.
For simple text strings it works perfectly.
e.g.
ReqSetup.ReqText = Application.Worksheets("Req Sheet").Range("F11").Value
However, I have some combo boxes, that on the form, when they are selected will enter a number in the corresponding cell.
Fail 1. - Run Time Error 380 - Invalid property value.
ReqSetup.MinPerKgCB = Application.Worksheets("Req Sheet").Range("C27").Value
Fail 2.
Dim MinPerKg As Range
Set MinPerKg = Application.Worksheets("Req Sheet").Range("C27")
ReqSetup.MinPerKgCB = MinPerKg
I'm obviously doing something really simple wrong but I can't work out what it is!!
Kind Regards!
I have some combo boxes, that on the form, when they are selected will
enter a number in the corresponding cell
Then you'd need to do the opposite of your code attempt, i.e.:
Worksheets("Req Sheet").Range("C27").Value = ReqSetup.MinPerKgCB.Value
That you'd better wrap inside a check that any combobox value is actually selected :
With ReqSetup.MinPerKgCB
If .ListIndex <> -1 Then Worksheets("Req Sheet").Range("C27").Value = .Value
End With
I've got an issue with my listbox. In the user form initialize event I'm using the following code to populate it:
RecordSelectionBox.List = WorkingCopy.Worksheets(1).Range("A2:P20").Value
Which works out fine. I have column width adjustments which also work out fine. Once the user has selected a record, a line from the listbox I'm setting the captions of a bunch of labels to the value of the listbox columns. It fills out label captions 1 to 15 just fine. When it hits 16 I get an error "Could Not Get the Column Property. Invalid Argument" "Run-time error '-2147024809 (80070057)'"
Here is the code:
Explanation.Caption = RecordSelectionBox.Column(16)
a debug.print of RecordSelectionBox.ColumnCount shows that I indeed have 16 columns. The explanation field is the longest of the fields I'm using, but I'm not sure that I see how that would become an issue. If anyone has an idea, I'm all ears.
That is because the First Column of the listbox starts with 0
Your first Label should be
Label1.Caption = RecordSelectionBox.Column(0)
and the 16th should be
Explanation.Caption = RecordSelectionBox.Column(15)